Completato test modalità PubSub REDIS x steamwarelibs
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace TestBench
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper gestione UITHread e deleghe
|
||||
/// https://www.codeproject.com/Articles/37642/Avoiding-InvokeRequired
|
||||
/// </summary>
|
||||
internal static class ControlExtensions
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
public static void UIThread(this Control control, Action code)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.BeginInvoke(code);
|
||||
return;
|
||||
}
|
||||
code.Invoke();
|
||||
}
|
||||
|
||||
public static void UIThreadInvoke(this Control control, Action code)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(code);
|
||||
return;
|
||||
}
|
||||
code.Invoke();
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
Generated
+68
-65
@@ -90,15 +90,15 @@
|
||||
this.label10 = new System.Windows.Forms.Label();
|
||||
this.txtUser = new System.Windows.Forms.TextBox();
|
||||
this.label9 = new System.Windows.Forms.Label();
|
||||
this.tabPage8 = new System.Windows.Forms.TabPage();
|
||||
this.btnStartSub = new System.Windows.Forms.Button();
|
||||
this.txtMessaggio = new System.Windows.Forms.TextBox();
|
||||
this.btnSendMessage = new System.Windows.Forms.Button();
|
||||
this.txtChannelName = new System.Windows.Forms.TextBox();
|
||||
this.label12 = new System.Windows.Forms.Label();
|
||||
this.clockTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.LogTimer = new System.Windows.Forms.Timer(this.components);
|
||||
this.tabPage8 = new System.Windows.Forms.TabPage();
|
||||
this.label12 = new System.Windows.Forms.Label();
|
||||
this.txtChannelName = new System.Windows.Forms.TextBox();
|
||||
this.btnSendMessage = new System.Windows.Forms.Button();
|
||||
this.txtMessaggio = new System.Windows.Forms.TextBox();
|
||||
this.btnStartSub = new System.Windows.Forms.Button();
|
||||
this.lblChannerReceive = new System.Windows.Forms.Label();
|
||||
this.lblChannelLog = new System.Windows.Forms.Label();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.tabControl1.SuspendLayout();
|
||||
this.tabPage1.SuspendLayout();
|
||||
@@ -291,7 +291,7 @@
|
||||
this.tabControl1.Location = new System.Drawing.Point(0, 0);
|
||||
this.tabControl1.Name = "tabControl1";
|
||||
this.tabControl1.SelectedIndex = 0;
|
||||
this.tabControl1.Size = new System.Drawing.Size(776, 379);
|
||||
this.tabControl1.Size = new System.Drawing.Size(776, 392);
|
||||
this.tabControl1.TabIndex = 10;
|
||||
//
|
||||
// tabPage1
|
||||
@@ -776,19 +776,9 @@
|
||||
this.label9.TabIndex = 0;
|
||||
this.label9.Text = "User";
|
||||
//
|
||||
// clockTimer
|
||||
//
|
||||
this.clockTimer.Interval = 50;
|
||||
this.clockTimer.Tick += new System.EventHandler(this.clockTimer_Tick);
|
||||
//
|
||||
// LogTimer
|
||||
//
|
||||
this.LogTimer.Interval = 10;
|
||||
this.LogTimer.Tick += new System.EventHandler(this.LogTimer_Tick);
|
||||
//
|
||||
// tabPage8
|
||||
//
|
||||
this.tabPage8.Controls.Add(this.lblChannerReceive);
|
||||
this.tabPage8.Controls.Add(this.lblChannelLog);
|
||||
this.tabPage8.Controls.Add(this.btnStartSub);
|
||||
this.tabPage8.Controls.Add(this.txtMessaggio);
|
||||
this.tabPage8.Controls.Add(this.btnSendMessage);
|
||||
@@ -797,11 +787,50 @@
|
||||
this.tabPage8.Location = new System.Drawing.Point(4, 22);
|
||||
this.tabPage8.Name = "tabPage8";
|
||||
this.tabPage8.Padding = new System.Windows.Forms.Padding(3);
|
||||
this.tabPage8.Size = new System.Drawing.Size(768, 353);
|
||||
this.tabPage8.Size = new System.Drawing.Size(768, 366);
|
||||
this.tabPage8.TabIndex = 7;
|
||||
this.tabPage8.Text = "PubSub (REDIS)";
|
||||
this.tabPage8.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// btnStartSub
|
||||
//
|
||||
this.btnStartSub.Location = new System.Drawing.Point(619, 12);
|
||||
this.btnStartSub.Name = "btnStartSub";
|
||||
this.btnStartSub.Size = new System.Drawing.Size(141, 23);
|
||||
this.btnStartSub.TabIndex = 5;
|
||||
this.btnStartSub.Text = "Start Channel Sub";
|
||||
this.btnStartSub.UseVisualStyleBackColor = true;
|
||||
this.btnStartSub.Click += new System.EventHandler(this.btnStartSub_Click);
|
||||
//
|
||||
// txtMessaggio
|
||||
//
|
||||
this.txtMessaggio.Enabled = false;
|
||||
this.txtMessaggio.Location = new System.Drawing.Point(103, 62);
|
||||
this.txtMessaggio.Name = "txtMessaggio";
|
||||
this.txtMessaggio.Size = new System.Drawing.Size(152, 20);
|
||||
this.txtMessaggio.TabIndex = 4;
|
||||
this.txtMessaggio.Text = "...";
|
||||
this.txtMessaggio.TextChanged += new System.EventHandler(this.txtMessaggio_TextChanged);
|
||||
//
|
||||
// btnSendMessage
|
||||
//
|
||||
this.btnSendMessage.Enabled = false;
|
||||
this.btnSendMessage.Location = new System.Drawing.Point(23, 62);
|
||||
this.btnSendMessage.Name = "btnSendMessage";
|
||||
this.btnSendMessage.Size = new System.Drawing.Size(74, 23);
|
||||
this.btnSendMessage.TabIndex = 2;
|
||||
this.btnSendMessage.Text = "Send";
|
||||
this.btnSendMessage.UseVisualStyleBackColor = true;
|
||||
this.btnSendMessage.Click += new System.EventHandler(this.btnSendMessage_Click);
|
||||
//
|
||||
// txtChannelName
|
||||
//
|
||||
this.txtChannelName.Location = new System.Drawing.Point(103, 14);
|
||||
this.txtChannelName.Name = "txtChannelName";
|
||||
this.txtChannelName.Size = new System.Drawing.Size(152, 20);
|
||||
this.txtChannelName.TabIndex = 1;
|
||||
this.txtChannelName.Text = "myTestChannel";
|
||||
//
|
||||
// label12
|
||||
//
|
||||
this.label12.AutoSize = true;
|
||||
@@ -811,60 +840,34 @@
|
||||
this.label12.TabIndex = 0;
|
||||
this.label12.Text = "Channel Name";
|
||||
//
|
||||
// txtChannelName
|
||||
// clockTimer
|
||||
//
|
||||
this.txtChannelName.Location = new System.Drawing.Point(103, 14);
|
||||
this.txtChannelName.Name = "txtChannelName";
|
||||
this.txtChannelName.Size = new System.Drawing.Size(152, 20);
|
||||
this.txtChannelName.TabIndex = 1;
|
||||
this.txtChannelName.Text = "myTestChannel";
|
||||
this.clockTimer.Interval = 50;
|
||||
this.clockTimer.Tick += new System.EventHandler(this.clockTimer_Tick);
|
||||
//
|
||||
// btnSendMessage
|
||||
// LogTimer
|
||||
//
|
||||
this.btnSendMessage.Location = new System.Drawing.Point(23, 62);
|
||||
this.btnSendMessage.Name = "btnSendMessage";
|
||||
this.btnSendMessage.Size = new System.Drawing.Size(74, 23);
|
||||
this.btnSendMessage.TabIndex = 2;
|
||||
this.btnSendMessage.Text = "Send";
|
||||
this.btnSendMessage.UseVisualStyleBackColor = true;
|
||||
this.btnSendMessage.Click += new System.EventHandler(this.btnSendMessage_Click);
|
||||
this.LogTimer.Interval = 10;
|
||||
this.LogTimer.Tick += new System.EventHandler(this.LogTimer_Tick);
|
||||
//
|
||||
// txtMessaggio
|
||||
// lblChannelLog
|
||||
//
|
||||
this.txtMessaggio.Location = new System.Drawing.Point(103, 62);
|
||||
this.txtMessaggio.Name = "txtMessaggio";
|
||||
this.txtMessaggio.Size = new System.Drawing.Size(152, 20);
|
||||
this.txtMessaggio.TabIndex = 4;
|
||||
this.txtMessaggio.Text = "...";
|
||||
this.txtMessaggio.TextChanged += new System.EventHandler(this.txtMessaggio_TextChanged);
|
||||
//
|
||||
// btnStartSub
|
||||
//
|
||||
this.btnStartSub.Location = new System.Drawing.Point(619, 17);
|
||||
this.btnStartSub.Name = "btnStartSub";
|
||||
this.btnStartSub.Size = new System.Drawing.Size(141, 23);
|
||||
this.btnStartSub.TabIndex = 5;
|
||||
this.btnStartSub.Text = "Start Channel Sub";
|
||||
this.btnStartSub.UseVisualStyleBackColor = true;
|
||||
this.btnStartSub.Click += new System.EventHandler(this.btnStartSub_Click);
|
||||
//
|
||||
// lblChannerReceive
|
||||
//
|
||||
this.lblChannerReceive.AutoSize = true;
|
||||
this.lblChannerReceive.BackColor = System.Drawing.Color.Black;
|
||||
this.lblChannerReceive.ForeColor = System.Drawing.Color.Gold;
|
||||
this.lblChannerReceive.Location = new System.Drawing.Point(360, 67);
|
||||
this.lblChannerReceive.MinimumSize = new System.Drawing.Size(400, 100);
|
||||
this.lblChannerReceive.Name = "lblChannerReceive";
|
||||
this.lblChannerReceive.Size = new System.Drawing.Size(400, 100);
|
||||
this.lblChannerReceive.TabIndex = 6;
|
||||
this.lblChannerReceive.Text = "...";
|
||||
this.lblChannelLog.AutoSize = true;
|
||||
this.lblChannelLog.BackColor = System.Drawing.Color.Black;
|
||||
this.lblChannelLog.ForeColor = System.Drawing.Color.Yellow;
|
||||
this.lblChannelLog.Location = new System.Drawing.Point(378, 65);
|
||||
this.lblChannelLog.MaximumSize = new System.Drawing.Size(400, 300);
|
||||
this.lblChannelLog.MinimumSize = new System.Drawing.Size(400, 300);
|
||||
this.lblChannelLog.Name = "lblChannelLog";
|
||||
this.lblChannelLog.Size = new System.Drawing.Size(400, 300);
|
||||
this.lblChannelLog.TabIndex = 9;
|
||||
this.lblChannelLog.Text = "log";
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(776, 379);
|
||||
this.ClientSize = new System.Drawing.Size(776, 392);
|
||||
this.Controls.Add(this.tabControl1);
|
||||
this.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.Name = "MainForm";
|
||||
@@ -970,7 +973,7 @@
|
||||
private System.Windows.Forms.Button btnSendMessage;
|
||||
private System.Windows.Forms.TextBox txtChannelName;
|
||||
private System.Windows.Forms.Label label12;
|
||||
private System.Windows.Forms.Label lblChannerReceive;
|
||||
private System.Windows.Forms.Label lblChannelLog;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+78
-13
@@ -296,17 +296,32 @@ namespace TestBench
|
||||
|
||||
protected MessagePipe MPipeChannel = new MessagePipe("testCh");
|
||||
|
||||
protected bool pubSubEnabled = false;
|
||||
|
||||
private void btnStartSub_Click(object sender, EventArgs e)
|
||||
{
|
||||
// avvio un nuovo messaggePipe x il canale richiesto...
|
||||
MPipeChannel = new MessagePipe(txtChannelName.Text, false);
|
||||
MPipeChannel.EA_NewMessage += MPipeChannel_EA_NewMessage;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("--------------------------------------");
|
||||
sb.AppendLine($" Start PubSub | {DateTime.Now:HH:mm:ss}");
|
||||
sb.AppendLine("--------------------------------------");
|
||||
lblChannelReceive.Text = sb.ToString();
|
||||
lblChannelReceive.Refresh();
|
||||
pubSubEnabled = !pubSubEnabled;
|
||||
btnStartSub.Text = pubSubEnabled ? "Stop PubSub" : "Start Sub";
|
||||
btnSendMessage.Enabled = pubSubEnabled;
|
||||
txtMessaggio.Enabled = pubSubEnabled;
|
||||
// sistemo messaggio
|
||||
if (pubSubEnabled)
|
||||
{
|
||||
// avvio un nuovo messaggePipe x il canale richiesto...
|
||||
MPipeChannel = new MessagePipe(txtChannelName.Text, false);
|
||||
MPipeChannel.EA_NewMessage += MPipeChannel_EA_NewMessage;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine("--------------------------------------");
|
||||
sb.AppendLine($" Start PubSub | {DateTime.Now:HH:mm:ss}");
|
||||
sb.AppendLine("--------------------------------------");
|
||||
logPubSubChannel = sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
logWatchString = "";
|
||||
logPubSubChannel = ".... waiting ....";
|
||||
MPipeChannel.EA_NewMessage -= MPipeChannel_EA_NewMessage;
|
||||
}
|
||||
}
|
||||
|
||||
private void MPipeChannel_EA_NewMessage(object sender, EventArgs e)
|
||||
@@ -315,9 +330,7 @@ namespace TestBench
|
||||
PubSubEventArgs currArgs = (PubSubEventArgs)e;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine($"{currArgs.newMessage} | RECEIVED: {DateTime.Now:HH:mm:ss.ffffff}");
|
||||
string oldMess = lblChannelReceive.Text;
|
||||
lblChannelReceive.Text = $"{sb.ToString()}{oldMess}";
|
||||
lblChannelReceive.Refresh();
|
||||
logPubSubChannel = sb.ToString();
|
||||
}
|
||||
|
||||
protected string testoMessaggio
|
||||
@@ -332,7 +345,59 @@ namespace TestBench
|
||||
|
||||
private void txtMessaggio_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
//MPipeChannel.sendMessage(testoMessaggio);
|
||||
MPipeChannel.sendMessage(testoMessaggio);
|
||||
}
|
||||
|
||||
protected int nLine2show = 30;
|
||||
|
||||
/// <summary>
|
||||
/// Effettua un trim della stringa al numero max di linee da mostrare a video
|
||||
/// </summary>
|
||||
/// <param name="newString"></param>
|
||||
/// <returns></returns>
|
||||
public string limitLine2show(string newString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(newString))
|
||||
{
|
||||
// se num righe superiore a limite trimmo...
|
||||
if (newString.Split('\n').Length > nLine2show)
|
||||
{
|
||||
//int idx = newString.LastIndexOf('\r');
|
||||
int idx = newString.LastIndexOf(Environment.NewLine);
|
||||
newString = newString.Substring(0, idx);
|
||||
}
|
||||
}
|
||||
return newString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stringa corrente di log...
|
||||
/// </summary>
|
||||
protected string logWatchString { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Logwatcher (in modalità "accodamento in testa" ultimi messaggi...)
|
||||
/// </summary>
|
||||
public string logPubSubChannel
|
||||
{
|
||||
get
|
||||
{
|
||||
return lblChannelLog.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
try
|
||||
{
|
||||
logWatchString = limitLine2show($"{value}{logWatchString}");
|
||||
lblChannelLog.Text = logWatchString;
|
||||
lblChannelLog.Refresh();
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
logger.lg.scriviLog($"Errore in esecuzione logWatcher{Environment.NewLine}--> {value}");
|
||||
logger.lg.scriviLog($"{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -85,6 +85,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ControlExtensions.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user