[Modify] Remove notify-sharp from Example
This commit is contained in:
parent
23354ad602
commit
df0b5249fa
@ -34,7 +34,7 @@
|
|||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug_Ubuntu</OutputPath>
|
<OutputPath>bin\Debug_Ubuntu</OutputPath>
|
||||||
<DefineConstants>DEBUG,UBUNTU</DefineConstants>
|
<DefineConstants>DEBUG</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Externalconsole>true</Externalconsole>
|
<Externalconsole>true</Externalconsole>
|
||||||
@ -43,16 +43,12 @@
|
|||||||
<DebugType>none</DebugType>
|
<DebugType>none</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Release_Ubuntu</OutputPath>
|
<OutputPath>bin\Release_Ubuntu</OutputPath>
|
||||||
<DefineConstants>UBUNTU</DefineConstants>
|
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Externalconsole>true</Externalconsole>
|
<Externalconsole>true</Externalconsole>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="notify-sharp, Version=0.4.0.0, Culture=neutral, PublicKeyToken=2df29c54e245917a">
|
|
||||||
<Package>notify-sharp</Package>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -65,7 +61,5 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="Notifier.cs" />
|
|
||||||
<Compile Include="NotificationMessage.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<NotificationMessage> _queue;
|
|
||||||
private object _sync;
|
|
||||||
|
|
||||||
public Notifier ()
|
|
||||||
{
|
|
||||||
_enabled = true;
|
|
||||||
_exited = new ManualResetEvent (false);
|
|
||||||
_queue = new Queue<NotificationMessage> ();
|
|
||||||
_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 ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -18,7 +18,6 @@ namespace Example
|
|||||||
// If you would like to connect to the server with the secure connection,
|
// 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.
|
// 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 ("ws://echo.websocket.org"))
|
||||||
//using (var ws = new WebSocket ("wss://echo.websocket.org"))
|
//using (var ws = new WebSocket ("wss://echo.websocket.org"))
|
||||||
//using (var ws = new WebSocket ("ws://localhost:4649/Echo"))
|
//using (var ws = new WebSocket ("ws://localhost:4649/Echo"))
|
||||||
@ -32,32 +31,27 @@ namespace Example
|
|||||||
|
|
||||||
ws.OnOpen += (sender, e) => ws.Send ("Hi, there!");
|
ws.OnOpen += (sender, e) => ws.Send ("Hi, there!");
|
||||||
|
|
||||||
ws.OnMessage += (sender, e) =>
|
ws.OnMessage += (sender, e) => {
|
||||||
nf.Notify (
|
var fmt = "WebSocket Message: {0}";
|
||||||
new NotificationMessage {
|
var body = !e.IsPing ? e.Data : "Received a ping.";
|
||||||
Summary = "WebSocket Message",
|
var msg = String.Format (fmt, body);
|
||||||
Body = !e.IsPing ? e.Data : "Received a ping.",
|
|
||||||
Icon = "notification-message-im"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ws.OnError += (sender, e) =>
|
Console.WriteLine (msg);
|
||||||
nf.Notify (
|
};
|
||||||
new NotificationMessage {
|
|
||||||
Summary = "WebSocket Error",
|
|
||||||
Body = e.Message,
|
|
||||||
Icon = "notification-message-im"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
ws.OnClose += (sender, e) =>
|
ws.OnError += (sender, e) => {
|
||||||
nf.Notify (
|
var fmt = "WebSocket Error: {0}";
|
||||||
new NotificationMessage {
|
var msg = String.Format (fmt, e.Message);
|
||||||
Summary = String.Format ("WebSocket Close ({0})", e.Code),
|
|
||||||
Body = e.Reason,
|
Console.WriteLine (msg);
|
||||||
Icon = "notification-message-im"
|
};
|
||||||
}
|
|
||||||
);
|
ws.OnClose += (sender, e) => {
|
||||||
|
var fmt = "WebSocket Close ({0}): {1}";
|
||||||
|
var msg = String.Format (fmt, e.Code, e.Reason);
|
||||||
|
|
||||||
|
Console.WriteLine (msg);
|
||||||
|
};
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
// To change the logging level.
|
// To change the logging level.
|
||||||
ws.Log.Level = LogLevel.Trace;
|
ws.Log.Level = LogLevel.Trace;
|
||||||
|
Loading…
Reference in New Issue
Block a user