├── Chaso.Push.Client.Test
├── Properties
│ └── AssemblyInfo.cs
├── app.config
├── ChasoPushClienteTest.cs
└── Chaso.Push.Client.Test.csproj
├── README.md
├── Chaso.Push.Client
├── app.config
├── IChasoPushClient.cs
├── Properties
│ └── AssemblyInfo.cs
├── Chaso.Push.Client.csproj
├── ClientClient
│ ├── IPushClient.cs
│ ├── IPushOperations.cs
│ ├── Models
│ │ └── Notify.cs
│ ├── PushOperationsExtensions.cs
│ ├── PushClient.cs
│ └── PushOperations.cs
└── ChasoPushClient.cs
├── .gitignore
├── Chaso.Push.Client.sln
└── .gitattributes
/Chaso.Push.Client.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | [assembly: AssemblyTrademark("")]
5 | [assembly: AssemblyCulture("")]
6 |
7 | [assembly: ComVisible(false)]
8 |
9 | [assembly: Guid("02fd8dde-4754-45f4-982a-ef7abbb75e80")]
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chaso.Push.Client
2 | It is a light client of Push Notification to Fire SignalREvent on [Chaso.SignalR.Server](https://github.com/chasoliveira/Chaso.Push.Server).
3 |
4 | ## Dependecies
5 | - Microsoft.Rest.ClientRuntime
6 |
7 | You Can use [Chaso.Push.Client](https://github.com/chasoliveira/Chaso.Push.Client) to connect to your Push Server [Chaso.SignalR.Server](https://github.com/chasoliveira/Chaso.Push.Server) to send and receive notifications.
--------------------------------------------------------------------------------
/Chaso.Push.Client/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chaso.Push.Client.Test/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/IChasoPushClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Chaso.Push.Client
5 | {
6 | public interface IChasoPushClient: IDisposable
7 | {
8 | void Add(string channelName, string eventName);
9 | void Add(string channelName, string eventName, int key, object value);
10 | void Clear();
11 | IEnumerable Send();
12 | string Send(string channel, string eventName, object data = null);
13 | }
14 | }
--------------------------------------------------------------------------------
/Chaso.Push.Client/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | [assembly: AssemblyTrademark("")]
5 | [assembly: AssemblyCulture("")]
6 |
7 | // Setting ComVisible to false makes the types in this assembly not visible
8 | // to COM components. If you need to access a type in this assembly from
9 | // COM, set the ComVisible attribute to true on that type.
10 | [assembly: ComVisible(false)]
11 |
12 | // The following GUID is for the ID of the typelib if this project is exposed to COM
13 | [assembly: Guid("d00c5bd9-7b95-48c3-8a56-47cc9880226c")]
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 |
28 |
29 | # NuGet Packages
30 | *.nupkg
31 | # The packages folder can be ignored because of Package Restore
32 | packages/
33 |
34 | # NuGet v3's project.json files produces more ignoreable files
35 | .nuget.props
36 | .nuget.targets
37 | /Chaso.Push.Client/ClientClient
38 |
--------------------------------------------------------------------------------
/Chaso.Push.Client.Test/ChasoPushClienteTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace Chaso.Push.Client.Test
5 | {
6 | [TestClass]
7 | public class ChasoPushClienteTest
8 | {
9 | [TestMethod]
10 | public void MustBeSentAPushToSpecificUrl()
11 | {
12 | string returnedSend = string.Empty;
13 | var url = "http://localhost:4478";
14 | using (IChasoPushClient pushClient = new ChasoPushClient("Test",url))
15 | {
16 | returnedSend = pushClient.Send("SourceIntegration", "EventIntegration"," {\"Data\" : {\"Code\":\"CodeSomeThing\" } }");
17 | }
18 | Assert.IsNotNull(returnedSend);
19 | Assert.AreEqual("Event EventIntegration on $SourceIntegration completed!. OK", returnedSend);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Chaso.Push.Client.Test/Chaso.Push.Client.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | false
5 | Chaso.Push.Client.Test
6 | Chaso.Push.Client.Test
7 | Copyright © 2017
8 | 1.0.0.0
9 | 1.0.0.0
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/Chaso.Push.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | 2.0.0
5 | Library
6 | false
7 | Chaso.Push.Client
8 | Chaso.Push.Client
9 | Copyright © 2017
10 | 1.0.0.0
11 | 1.0.0.0
12 | True
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/ClientClient/IPushClient.cs:
--------------------------------------------------------------------------------
1 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
2 | // Changes may cause incorrect behavior and will be lost if the code is
3 | // regenerated.
4 |
5 | namespace Chaso.Push.Client
6 | {
7 | using System;
8 | using Newtonsoft.Json;
9 | using Microsoft.Rest;
10 |
11 | ///
12 | /// Push Notification over SignalR, To Notify Clients about an event
13 | ///
14 | public partial interface IPushClient : IDisposable
15 | {
16 | ///
17 | /// The base URI of the service.
18 | ///
19 | Uri BaseUri { get; set; }
20 |
21 | ///
22 | /// Gets or sets json serialization settings.
23 | ///
24 | JsonSerializerSettings SerializationSettings { get; }
25 |
26 | ///
27 | /// Gets or sets json deserialization settings.
28 | ///
29 | JsonSerializerSettings DeserializationSettings { get; }
30 |
31 | ///
32 | /// Subscription credentials which uniquely identify client
33 | /// subscription.
34 | ///
35 | ServiceClientCredentials Credentials { get; }
36 |
37 |
38 | ///
39 | /// Gets the IPushOperations.
40 | ///
41 | IPushOperations PushOperations { get; }
42 |
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Chaso.Push.Client.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26730.16
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chaso.Push.Client", "Chaso.Push.Client\Chaso.Push.Client.csproj", "{D00C5BD9-7B95-48C3-8A56-47CC9880226C}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chaso.Push.Client.Test", "Chaso.Push.Client.Test\Chaso.Push.Client.Test.csproj", "{02FD8DDE-4754-45F4-982A-EF7ABBB75E80}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {D00C5BD9-7B95-48C3-8A56-47CC9880226C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {D00C5BD9-7B95-48C3-8A56-47CC9880226C}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {D00C5BD9-7B95-48C3-8A56-47CC9880226C}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {D00C5BD9-7B95-48C3-8A56-47CC9880226C}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {02FD8DDE-4754-45F4-982A-EF7ABBB75E80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {02FD8DDE-4754-45F4-982A-EF7ABBB75E80}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {02FD8DDE-4754-45F4-982A-EF7ABBB75E80}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {02FD8DDE-4754-45F4-982A-EF7ABBB75E80}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {F28E6597-9726-4AB0-B757-36D1DD5F344B}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/ClientClient/IPushOperations.cs:
--------------------------------------------------------------------------------
1 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
2 | // Changes may cause incorrect behavior and will be lost if the code is
3 | // regenerated.
4 |
5 | namespace Chaso.Push.Client
6 | {
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Net.Http;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 | using Microsoft.Rest;
13 | using Models;
14 |
15 | ///
16 | /// PushOperations operations.
17 | ///
18 | public partial interface IPushOperations
19 | {
20 | ///
21 | /// Return all Channel listening by SignalR
22 | ///
23 | ///
24 | /// The headers that will be added to request.
25 | ///
26 | ///
27 | /// The cancellation token.
28 | ///
29 | Task> GetChannelsWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
30 | ///
31 | /// Notify a channel that an event was trigged
32 | ///
33 | ///
34 | ///
35 | ///
36 | /// The headers that will be added to request.
37 | ///
38 | ///
39 | /// The cancellation token.
40 | ///
41 | Task> NotifyWithHttpMessagesAsync(Notify notify, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken));
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/ClientClient/Models/Notify.cs:
--------------------------------------------------------------------------------
1 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
2 | // Changes may cause incorrect behavior and will be lost if the code is
3 | // regenerated.
4 |
5 | namespace Chaso.Push.Client.Models
6 | {
7 | using System;
8 | using System.Linq;
9 | using System.Collections.Generic;
10 | using Newtonsoft.Json;
11 | using Microsoft.Rest;
12 | using Microsoft.Rest.Serialization;
13 |
14 | ///
15 | /// Class for Send and receive a Notification
16 | ///
17 | public partial class Notify
18 | {
19 | ///
20 | /// Initializes a new instance of the Notify class.
21 | ///
22 | public Notify() { }
23 |
24 | ///
25 | /// Initializes a new instance of the Notify class.
26 | ///
27 | public Notify(string origin = default(string), string channel = default(string), string eventName = default(string), object data = default(object))
28 | {
29 | Origin = origin;
30 | Channel = channel;
31 | EventName = eventName;
32 | Data = data;
33 | }
34 |
35 | ///
36 | /// Origin of interation on channel
37 | ///
38 | [JsonProperty(PropertyName = "Origin")]
39 | public string Origin { get; set; }
40 |
41 | ///
42 | /// Nome of the Channel to interact
43 | ///
44 | [JsonProperty(PropertyName = "Channel")]
45 | public string Channel { get; set; }
46 |
47 | ///
48 | /// Name of Evento to execute in Channel
49 | ///
50 | [JsonProperty(PropertyName = "EventName")]
51 | public string EventName { get; set; }
52 |
53 | ///
54 | /// Object to Send and Receive by Notification
55 | ///
56 | [JsonProperty(PropertyName = "Data")]
57 | public object Data { get; set; }
58 |
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/ChasoPushClient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace Chaso.Push.Client
6 | {
7 | public class ChasoPushClient : IChasoPushClient
8 | {
9 | internal class PushNotify : PushClient
10 | {
11 | protected PushNotify(Uri uri) : base(uri)
12 | {
13 |
14 | }
15 | private static PushNotify pushNotify;
16 | public static PushNotify GetInstance(string url) { return pushNotify ?? (pushNotify = new PushNotify(new Uri(url))); }
17 | }
18 |
19 | public string Origin { get; private set; }
20 | PushNotify PushNotifyIntance;
21 | private Dictionary>> _itemsToPush;
22 | public ChasoPushClient(string origin,string url)
23 | {
24 | _itemsToPush = new Dictionary>>();
25 | PushNotifyIntance = PushNotify.GetInstance(url);
26 | Origin = origin;
27 | }
28 | public void Add(string channelName, string eventName)
29 | {
30 | Add(channelName, eventName, new KeyValuePair(0, new { }));
31 | }
32 | public void Add(string channelName, string eventName, int key, object value)
33 | {
34 | Add(channelName, eventName, new KeyValuePair(key, value));
35 | }
36 | private void Add(string channelName, string eventName, KeyValuePair keyValuePair)
37 | {
38 | if (!_itemsToPush.Any(l => l.Key.Channel == channelName && l.Key.EventName == eventName))
39 | _itemsToPush.Add(new Models.Notify(Origin, channelName, eventName), new List>());
40 | var key = _itemsToPush.First(l => l.Key.Channel == channelName && l.Key.EventName == eventName);
41 | if (!key.Value.Any(l => l.Key == keyValuePair.Key))
42 | key.Value.Add(keyValuePair);
43 | }
44 | public void Clear()
45 | {
46 | _itemsToPush.Clear();
47 | }
48 | public IEnumerable Send()
49 | {
50 | var alerts = new List();
51 |
52 | foreach (var item in _itemsToPush)
53 | {
54 | foreach (var value in item.Value)
55 | alerts.Add(SendNotify(item.Key.Channel, item.Key.EventName, Newtonsoft.Json.JsonConvert.SerializeObject(value.Value)));
56 | }
57 | _itemsToPush.Clear();
58 | return alerts;
59 | }
60 | public string Send(string channel, string eventName, object data = null)
61 | {
62 | return SendNotify(channel, eventName, data);
63 | }
64 | private string SendNotify(string channel, string eventName, object data)
65 | {
66 | var result = PushNotifyIntance.PushOperations.NotifyWithHttpMessagesAsync(new Models.Notify(Origin, channel, eventName, data)).Result;
67 | return string.Format("{0}. {1}", result.Body.ToString(), result.Response.ReasonPhrase);
68 | }
69 |
70 | private bool disposing = false;
71 |
72 | public void Dispose()
73 | {
74 | Dispose(true);
75 | }
76 | private void Dispose(bool dispose)
77 | {
78 | if (disposing) return;
79 | if (dispose)
80 | {
81 | disposing = true;
82 | PushNotifyIntance?.Dispose();
83 | }
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/Chaso.Push.Client/ClientClient/PushOperationsExtensions.cs:
--------------------------------------------------------------------------------
1 | // Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0
2 | // Changes may cause incorrect behavior and will be lost if the code is
3 | // regenerated.
4 |
5 | namespace Chaso.Push.Client
6 | {
7 | using System;
8 | using System.Collections;
9 | using System.Collections.Generic;
10 | using System.Threading;
11 | using System.Threading.Tasks;
12 | using Microsoft.Rest;
13 | using Models;
14 |
15 | ///
16 | /// Extension methods for PushOperations.
17 | ///
18 | public static partial class PushOperationsExtensions
19 | {
20 | ///
21 | /// Return all Channel listening by SignalR
22 | ///
23 | ///
24 | /// The operations group for this extension method.
25 | ///
26 | public static object GetChannels(this IPushOperations operations)
27 | {
28 | return Task.Factory.StartNew(s => ((IPushOperations)s).GetChannelsAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
29 | }
30 |
31 | ///
32 | /// Return all Channel listening by SignalR
33 | ///
34 | ///
35 | /// The operations group for this extension method.
36 | ///
37 | ///
38 | /// The cancellation token.
39 | ///
40 | public static async Task