mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Message display working
This is a first working message display, but doesn't ignore messages seen already. This needs fixing.
This commit is contained in:
parent
28445c53a9
commit
e64e836525
@ -12,7 +12,7 @@ namespace DisplayMagician
|
|||||||
{ get; set; }
|
{ get; set; }
|
||||||
|
|
||||||
public string MessageMode
|
public string MessageMode
|
||||||
{ get; set; } = "RTF";
|
{ get; set; } = "txt";
|
||||||
|
|
||||||
public string MinVersion
|
public string MinVersion
|
||||||
{ get; set; }
|
{ get; set; }
|
||||||
|
@ -985,14 +985,82 @@ namespace DisplayMagician {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartMessageForm myMessageWindow = new StartMessageForm();
|
|
||||||
foreach (MessageItem message in messageIndex)
|
foreach (MessageItem message in messageIndex)
|
||||||
{
|
{
|
||||||
|
// Firstly, check that the version is correct
|
||||||
|
Version myAppVersion = Assembly.GetEntryAssembly().GetName().Version;
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.MinVersion))
|
||||||
|
{
|
||||||
|
Version minVersion;
|
||||||
|
if (!(Version.TryParse(message.MinVersion,out minVersion)))
|
||||||
|
{
|
||||||
|
logger.Error($"Program/ShowMessages: Couldn't show message \"{message.HeadingText}\" (#{message.Id}) as we couldn't parse the minversion string.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(myAppVersion >= minVersion))
|
||||||
|
{
|
||||||
|
logger.Debug($"Program/ShowMessages: Message is for version >= {minVersion} and this is version {myAppVersion} so not showing message.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.MaxVersion))
|
||||||
|
{
|
||||||
|
Version maxVersion;
|
||||||
|
if (!(Version.TryParse(message.MaxVersion, out maxVersion)))
|
||||||
|
{
|
||||||
|
logger.Error($"Program/ShowMessages: Couldn't show message \"{message.HeadingText}\" (#{message.Id}) as we couldn't parse the maxversion string.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(myAppVersion <= maxVersion))
|
||||||
|
{
|
||||||
|
logger.Debug($"Program/ShowMessages: Message is for version <= {maxVersion} and this is version {myAppVersion} so not showing message.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Secondly check if the dates are such that we should show this
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.StartDate))
|
||||||
|
{
|
||||||
|
// Convert datestring to a datetime
|
||||||
|
DateTime startTime;
|
||||||
|
if (!DateTime.TryParse(message.StartDate,out startTime))
|
||||||
|
{
|
||||||
|
logger.Error($"Program/ShowMessages: Couldn't show message \"{message.HeadingText}\" (#{message.Id}) as we couldn't parse the start date.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(DateTime.Now >= startTime))
|
||||||
|
{
|
||||||
|
logger.Debug($"Program/ShowMessages: Message start date for \"{message.HeadingText}\" (#{message.Id}) not yet reached so not ready to show message.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(message.EndDate))
|
||||||
|
{
|
||||||
|
// Convert datestring to a datetime
|
||||||
|
DateTime endTime;
|
||||||
|
if (!DateTime.TryParse(message.EndDate, out endTime))
|
||||||
|
{
|
||||||
|
logger.Error($"Program/ShowMessages: Couldn't show message \"{message.HeadingText}\" (#{message.Id}) as we couldn't parse the end date.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(DateTime.Now <= endTime))
|
||||||
|
{
|
||||||
|
logger.Debug($"Program/ShowMessages: Message end date for \"{message.HeadingText}\" (#{message.Id}) past so not showing message as it's too old.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StartMessageForm myMessageWindow = new StartMessageForm();
|
||||||
myMessageWindow.MessageMode = message.MessageMode;
|
myMessageWindow.MessageMode = message.MessageMode;
|
||||||
myMessageWindow.URL = message.Url;
|
myMessageWindow.URL = message.Url;
|
||||||
myMessageWindow.HeadingText = message.HeadingText;
|
myMessageWindow.HeadingText = message.HeadingText;
|
||||||
myMessageWindow.ButtonText = message.ButtonText;
|
myMessageWindow.ButtonText = message.ButtonText;
|
||||||
myMessageWindow.Show();
|
myMessageWindow.ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ using System.Resources;
|
|||||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||||
|
|
||||||
// Version information
|
// Version information
|
||||||
[assembly: AssemblyVersion("2.0.0.10")]
|
[assembly: AssemblyVersion("2.0.0.15")]
|
||||||
[assembly: AssemblyFileVersion("2.0.0.10")]
|
[assembly: AssemblyFileVersion("2.0.0.15")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|
||||||
|
@ -77,10 +77,16 @@ namespace DisplayMagician.UIForms
|
|||||||
{
|
{
|
||||||
if (File.Exists(Filename))
|
if (File.Exists(Filename))
|
||||||
{
|
{
|
||||||
if (MessageMode == "RTF")
|
if (MessageMode == "rtf")
|
||||||
{
|
{
|
||||||
|
rtb_message.Show();
|
||||||
rtb_message.LoadFile(Filename, RichTextBoxStreamType.RichText);
|
rtb_message.LoadFile(Filename, RichTextBoxStreamType.RichText);
|
||||||
}
|
}
|
||||||
|
else if (MessageMode == "txt")
|
||||||
|
{
|
||||||
|
rtb_message.Show();
|
||||||
|
rtb_message.LoadFile(Filename, RichTextBoxStreamType.PlainText);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from file {Filename} is in an unsupported MessageMode: {MessageMode}");
|
logger.Error($"StartMessageForm/StartMessageForm_Load: Message from file {Filename} is in an unsupported MessageMode: {MessageMode}");
|
||||||
@ -109,7 +115,7 @@ 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")
|
if (MessageMode == "rtf")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -117,6 +123,7 @@ namespace DisplayMagician.UIForms
|
|||||||
MemoryStream theMemStream = new MemoryStream();
|
MemoryStream theMemStream = new MemoryStream();
|
||||||
theMemStream.Write(byteArray, 0, byteArray.Length);
|
theMemStream.Write(byteArray, 0, byteArray.Length);
|
||||||
theMemStream.Position = 0;
|
theMemStream.Position = 0;
|
||||||
|
rtb_message.Show();
|
||||||
rtb_message.LoadFile(theMemStream, RichTextBoxStreamType.RichText);
|
rtb_message.LoadFile(theMemStream, RichTextBoxStreamType.RichText);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -124,8 +131,22 @@ namespace DisplayMagician.UIForms
|
|||||||
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Exception while trying to load the URL supplied (\"{URL}\") into the RichTextBox message object (RTF Mode)");
|
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 if (MessageMode == "txt")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string textToShow = client.DownloadString(URL);
|
||||||
|
rtb_message.Show();
|
||||||
|
rtb_message.Text = textToShow;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger.Error(ex, $"StartMessageForm/StartMessageForm_Load: Exception while trying to load the URL supplied (\"{URL}\") into the RichTextBox message object (TXT Mode)");
|
||||||
|
this.Close();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user