mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Partial MessageItem creation
This commit is contained in:
parent
fdd8c97f66
commit
2d1e656ba1
@ -651,6 +651,9 @@ namespace DisplayMagician {
|
|||||||
myMessageWindow.Show();
|
myMessageWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show any messages we need to show
|
||||||
|
ShowMessages();
|
||||||
|
|
||||||
// Run the program with normal startup
|
// Run the program with normal startup
|
||||||
AppMainForm = new MainForm();
|
AppMainForm = new MainForm();
|
||||||
Application.Run(AppMainForm);
|
Application.Run(AppMainForm);
|
||||||
@ -964,6 +967,36 @@ namespace DisplayMagician {
|
|||||||
return parsedHotkey;
|
return parsedHotkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ShowMessages()
|
||||||
|
{
|
||||||
|
// Get the message index
|
||||||
|
string json;
|
||||||
|
List<MessageItem> messageIndex;
|
||||||
|
WebClient client = new WebClient();
|
||||||
|
string indexUrl = "https://displaymagician.littlebitbig.com/messages/index_2.0.json";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
json = client.DownloadString(indexUrl);
|
||||||
|
messageIndex = JsonConvert.DeserializeObject<List<MessageItem>>(json);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error(ex, $"Program/ShowMessages: Exception while trying to load the messages index from {indexUrl}.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
StartMessageForm myMessageWindow = new StartMessageForm();
|
||||||
|
foreach (MessageItem message in messageIndex)
|
||||||
|
{
|
||||||
|
myMessageWindow.MessageMode = message.Mode;
|
||||||
|
myMessageWindow.URL = message.Url;
|
||||||
|
myMessageWindow.HeadingText = message.HeadingText;
|
||||||
|
myMessageWindow.ButtonText = message.ButtonText;
|
||||||
|
myMessageWindow.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void CheckForUpdates()
|
public static void CheckForUpdates()
|
||||||
{
|
{
|
||||||
//Run the AutoUpdater to see if there are any updates available.
|
//Run the AutoUpdater to see if there are any updates available.
|
||||||
|
@ -16,10 +16,20 @@ namespace DisplayMagician.UIForms
|
|||||||
{
|
{
|
||||||
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
private readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public string Filename;
|
public string MessageMode
|
||||||
public string URL;
|
{ get; set; } = "RTF";
|
||||||
public string HeadingText;
|
|
||||||
public string ButtonText;
|
public string Filename
|
||||||
|
{ get; set; }
|
||||||
|
|
||||||
|
public string URL
|
||||||
|
{ get; set; }
|
||||||
|
|
||||||
|
public string HeadingText
|
||||||
|
{ get; set; } = "DisplayMagician Message";
|
||||||
|
|
||||||
|
public string ButtonText
|
||||||
|
{ get; set; } = "&Close";
|
||||||
|
|
||||||
public StartMessageForm()
|
public StartMessageForm()
|
||||||
{
|
{
|
||||||
@ -66,10 +76,17 @@ namespace DisplayMagician.UIForms
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (File.Exists(Filename))
|
if (File.Exists(Filename))
|
||||||
|
{
|
||||||
|
if (MessageMode == "RTF")
|
||||||
{
|
{
|
||||||
rtb_message.LoadFile(Filename, RichTextBoxStreamType.RichText);
|
rtb_message.LoadFile(Filename, RichTextBoxStreamType.RichText);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from file {Filename} is in an unsupported MessageMode: {MessageMode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
logger.Error($"StartMessageForm/StartMessageForm_Load: Couldn't find the Filename supplied (\"{Filename}\") and load it into the RichTextBox message object");
|
logger.Error($"StartMessageForm/StartMessageForm_Load: Couldn't find the Filename supplied (\"{Filename}\") and load it into the RichTextBox message object");
|
||||||
}
|
}
|
||||||
@ -92,6 +109,8 @@ namespace DisplayMagician.UIForms
|
|||||||
}
|
}
|
||||||
// If we get here, then the URL is good. See if we can access the URL supplied
|
// If we get here, then the URL is good. See if we can access the URL supplied
|
||||||
WebClient client = new WebClient();
|
WebClient client = new WebClient();
|
||||||
|
if (MessageMode == "RTF")
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
byte[] byteArray = client.DownloadData(URL);
|
byte[] byteArray = client.DownloadData(URL);
|
||||||
@ -102,12 +121,17 @@ namespace DisplayMagician.UIForms
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Exception while trying to load the URL supplied (\"{Filename}\") into the RichTextBox message object");
|
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Exception while trying to load the URL supplied (\"{URL}\") into the RichTextBox message object (RTF Mode)");
|
||||||
this.Close();
|
this.Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from URL {URL} is in an unsupported MessageMode: {MessageMode}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsURLValid(string url)
|
public static bool IsURLValid(string url)
|
||||||
|
Loading…
Reference in New Issue
Block a user