From df0b5249fafd43e59387943b26ef81a9392c8a79 Mon Sep 17 00:00:00 2001 From: sta Date: Thu, 17 Feb 2022 21:45:40 +0900 Subject: [PATCH] [Modify] Remove notify-sharp from Example --- Example/Example.csproj | 8 +--- Example/NotificationMessage.cs | 24 ---------- Example/Notifier.cs | 83 ---------------------------------- Example/Program.cs | 44 ++++++++---------- 4 files changed, 20 insertions(+), 139 deletions(-) delete mode 100644 Example/NotificationMessage.cs delete mode 100644 Example/Notifier.cs diff --git a/Example/Example.csproj b/Example/Example.csproj index 38c5b420..ee89d9f6 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -34,7 +34,7 @@ full false bin\Debug_Ubuntu - DEBUG,UBUNTU + DEBUG prompt 4 true @@ -43,16 +43,12 @@ none false bin\Release_Ubuntu - UBUNTU prompt 4 true - - notify-sharp - @@ -65,7 +61,5 @@ - - \ No newline at end of file diff --git a/Example/NotificationMessage.cs b/Example/NotificationMessage.cs deleted file mode 100644 index fd1bd307..00000000 --- a/Example/NotificationMessage.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace Example -{ - internal class NotificationMessage - { - public string Body { - get; set; - } - - public string Icon { - get; set; - } - - public string Summary { - get; set; - } - - public override string ToString () - { - return String.Format ("{0}: {1}", Summary, Body); - } - } -} diff --git a/Example/Notifier.cs b/Example/Notifier.cs deleted file mode 100644 index 6cc0923c..00000000 --- a/Example/Notifier.cs +++ /dev/null @@ -1,83 +0,0 @@ -#if UBUNTU -using Notifications; -#endif -using System; -using System.Collections; -using System.Collections.Generic; -using System.Threading; - -namespace Example -{ - internal class Notifier : IDisposable - { - private volatile bool _enabled; - private ManualResetEvent _exited; - private Queue _queue; - private object _sync; - - public Notifier () - { - _enabled = true; - _exited = new ManualResetEvent (false); - _queue = new Queue (); - _sync = ((ICollection) _queue).SyncRoot; - - ThreadPool.QueueUserWorkItem ( - state => { - while (_enabled || Count > 0) { - var msg = dequeue (); - - if (msg != null) { -#if UBUNTU - var nf = new Notification (msg.Summary, msg.Body, msg.Icon); - nf.AddHint ("append", "allowed"); - nf.Show (); -#else - Console.WriteLine (msg); -#endif - } - else { - Thread.Sleep (500); - } - } - - _exited.Set (); - } - ); - } - - public int Count { - get { - lock (_sync) - return _queue.Count; - } - } - - private NotificationMessage dequeue () - { - lock (_sync) - return _queue.Count > 0 ? _queue.Dequeue () : null; - } - - public void Close () - { - _enabled = false; - - _exited.WaitOne (); - _exited.Close (); - } - - public void Notify (NotificationMessage message) - { - lock (_sync) { - if (_enabled) - _queue.Enqueue (message); - } - } - - void IDisposable.Dispose () - { - Close (); - } - } -} diff --git a/Example/Program.cs b/Example/Program.cs index c4e5754b..91104ab6 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -18,7 +18,6 @@ namespace Example // If you would like to connect to the server with the secure connection, // you should create a new instance with a wss scheme WebSocket URL. - using (var nf = new Notifier ()) using (var ws = new WebSocket ("ws://echo.websocket.org")) //using (var ws = new WebSocket ("wss://echo.websocket.org")) //using (var ws = new WebSocket ("ws://localhost:4649/Echo")) @@ -32,32 +31,27 @@ namespace Example ws.OnOpen += (sender, e) => ws.Send ("Hi, there!"); - ws.OnMessage += (sender, e) => - nf.Notify ( - new NotificationMessage { - Summary = "WebSocket Message", - Body = !e.IsPing ? e.Data : "Received a ping.", - Icon = "notification-message-im" - } - ); + ws.OnMessage += (sender, e) => { + var fmt = "WebSocket Message: {0}"; + var body = !e.IsPing ? e.Data : "Received a ping."; + var msg = String.Format (fmt, body); - ws.OnError += (sender, e) => - nf.Notify ( - new NotificationMessage { - Summary = "WebSocket Error", - Body = e.Message, - Icon = "notification-message-im" - } - ); + Console.WriteLine (msg); + }; - ws.OnClose += (sender, e) => - nf.Notify ( - new NotificationMessage { - Summary = String.Format ("WebSocket Close ({0})", e.Code), - Body = e.Reason, - Icon = "notification-message-im" - } - ); + ws.OnError += (sender, e) => { + var fmt = "WebSocket Error: {0}"; + var msg = String.Format (fmt, e.Message); + + Console.WriteLine (msg); + }; + + ws.OnClose += (sender, e) => { + var fmt = "WebSocket Close ({0}): {1}"; + var msg = String.Format (fmt, e.Code, e.Reason); + + Console.WriteLine (msg); + }; #if DEBUG // To change the logging level. ws.Log.Level = LogLevel.Trace;