├── 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 GetChannelsAsync(this IPushOperations operations, CancellationToken cancellationToken = default(CancellationToken)) 41 | { 42 | using (var _result = await operations.GetChannelsWithHttpMessagesAsync(null, cancellationToken).ConfigureAwait(false)) 43 | { 44 | return _result.Body; 45 | } 46 | } 47 | 48 | /// 49 | /// Notify a channel that an event was trigged 50 | /// 51 | /// 52 | /// The operations group for this extension method. 53 | /// 54 | /// 55 | /// 56 | public static object Notify(this IPushOperations operations, Notify notify) 57 | { 58 | return Task.Factory.StartNew(s => ((IPushOperations)s).NotifyAsync(notify), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); 59 | } 60 | 61 | /// 62 | /// Notify a channel that an event was trigged 63 | /// 64 | /// 65 | /// The operations group for this extension method. 66 | /// 67 | /// 68 | /// 69 | /// 70 | /// The cancellation token. 71 | /// 72 | public static async Task NotifyAsync(this IPushOperations operations, Notify notify, CancellationToken cancellationToken = default(CancellationToken)) 73 | { 74 | using (var _result = await operations.NotifyWithHttpMessagesAsync(notify, null, cancellationToken).ConfigureAwait(false)) 75 | { 76 | return _result.Body; 77 | } 78 | } 79 | 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Chaso.Push.Client/ClientClient/PushClient.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 Microsoft.Rest; 11 | using Microsoft.Rest.Serialization; 12 | using Newtonsoft.Json; 13 | 14 | /// 15 | /// Push Notification over SignalR, To Notify Clients about an event 16 | /// 17 | public partial class PushClient : ServiceClient, IPushClient 18 | { 19 | /// 20 | /// The base URI of the service. 21 | /// 22 | public Uri BaseUri { get; set; } 23 | 24 | /// 25 | /// Gets or sets json serialization settings. 26 | /// 27 | public JsonSerializerSettings SerializationSettings { get; private set; } 28 | 29 | /// 30 | /// Gets or sets json deserialization settings. 31 | /// 32 | public JsonSerializerSettings DeserializationSettings { get; private set; } 33 | 34 | /// 35 | /// Subscription credentials which uniquely identify client subscription. 36 | /// 37 | public ServiceClientCredentials Credentials { get; private set; } 38 | 39 | /// 40 | /// Gets the IPushOperations. 41 | /// 42 | public virtual IPushOperations PushOperations { get; private set; } 43 | 44 | /// 45 | /// Initializes a new instance of the PushClient class. 46 | /// 47 | /// 48 | /// Optional. The delegating handlers to add to the http client pipeline. 49 | /// 50 | protected PushClient(params DelegatingHandler[] handlers) : base(handlers) 51 | { 52 | this.Initialize(); 53 | } 54 | 55 | /// 56 | /// Initializes a new instance of the PushClient class. 57 | /// 58 | /// 59 | /// Optional. The http client handler used to handle http transport. 60 | /// 61 | /// 62 | /// Optional. The delegating handlers to add to the http client pipeline. 63 | /// 64 | protected PushClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base(rootHandler, handlers) 65 | { 66 | this.Initialize(); 67 | } 68 | 69 | /// 70 | /// Initializes a new instance of the PushClient class. 71 | /// 72 | /// 73 | /// Optional. The base URI of the service. 74 | /// 75 | /// 76 | /// Optional. The delegating handlers to add to the http client pipeline. 77 | /// 78 | protected PushClient(Uri baseUri, params DelegatingHandler[] handlers) : this(handlers) 79 | { 80 | if (baseUri == null) 81 | { 82 | throw new ArgumentNullException("baseUri"); 83 | } 84 | this.BaseUri = baseUri; 85 | } 86 | 87 | /// 88 | /// Initializes a new instance of the PushClient class. 89 | /// 90 | /// 91 | /// Optional. The base URI of the service. 92 | /// 93 | /// 94 | /// Optional. The http client handler used to handle http transport. 95 | /// 96 | /// 97 | /// Optional. The delegating handlers to add to the http client pipeline. 98 | /// 99 | protected PushClient(Uri baseUri, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) 100 | { 101 | if (baseUri == null) 102 | { 103 | throw new ArgumentNullException("baseUri"); 104 | } 105 | this.BaseUri = baseUri; 106 | } 107 | 108 | /// 109 | /// Initializes a new instance of the PushClient class. 110 | /// 111 | /// 112 | /// Required. Subscription credentials which uniquely identify client subscription. 113 | /// 114 | /// 115 | /// Optional. The delegating handlers to add to the http client pipeline. 116 | /// 117 | public PushClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers) 118 | { 119 | if (credentials == null) 120 | { 121 | throw new ArgumentNullException("credentials"); 122 | } 123 | this.Credentials = credentials; 124 | if (this.Credentials != null) 125 | { 126 | this.Credentials.InitializeServiceClient(this); 127 | } 128 | } 129 | 130 | /// 131 | /// Initializes a new instance of the PushClient class. 132 | /// 133 | /// 134 | /// Required. Subscription credentials which uniquely identify client subscription. 135 | /// 136 | /// 137 | /// Optional. The http client handler used to handle http transport. 138 | /// 139 | /// 140 | /// Optional. The delegating handlers to add to the http client pipeline. 141 | /// 142 | public PushClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) 143 | { 144 | if (credentials == null) 145 | { 146 | throw new ArgumentNullException("credentials"); 147 | } 148 | this.Credentials = credentials; 149 | if (this.Credentials != null) 150 | { 151 | this.Credentials.InitializeServiceClient(this); 152 | } 153 | } 154 | 155 | /// 156 | /// Initializes a new instance of the PushClient class. 157 | /// 158 | /// 159 | /// Optional. The base URI of the service. 160 | /// 161 | /// 162 | /// Required. Subscription credentials which uniquely identify client subscription. 163 | /// 164 | /// 165 | /// Optional. The delegating handlers to add to the http client pipeline. 166 | /// 167 | public PushClient(Uri baseUri, ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : this(handlers) 168 | { 169 | if (baseUri == null) 170 | { 171 | throw new ArgumentNullException("baseUri"); 172 | } 173 | if (credentials == null) 174 | { 175 | throw new ArgumentNullException("credentials"); 176 | } 177 | this.BaseUri = baseUri; 178 | this.Credentials = credentials; 179 | if (this.Credentials != null) 180 | { 181 | this.Credentials.InitializeServiceClient(this); 182 | } 183 | } 184 | 185 | /// 186 | /// Initializes a new instance of the PushClient class. 187 | /// 188 | /// 189 | /// Optional. The base URI of the service. 190 | /// 191 | /// 192 | /// Required. Subscription credentials which uniquely identify client subscription. 193 | /// 194 | /// 195 | /// Optional. The http client handler used to handle http transport. 196 | /// 197 | /// 198 | /// Optional. The delegating handlers to add to the http client pipeline. 199 | /// 200 | public PushClient(Uri baseUri, ServiceClientCredentials credentials, HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : this(rootHandler, handlers) 201 | { 202 | if (baseUri == null) 203 | { 204 | throw new ArgumentNullException("baseUri"); 205 | } 206 | if (credentials == null) 207 | { 208 | throw new ArgumentNullException("credentials"); 209 | } 210 | this.BaseUri = baseUri; 211 | this.Credentials = credentials; 212 | if (this.Credentials != null) 213 | { 214 | this.Credentials.InitializeServiceClient(this); 215 | } 216 | } 217 | 218 | /// 219 | /// An optional partial-method to perform custom initialization. 220 | /// 221 | partial void CustomInitialize(); 222 | /// 223 | /// Initializes client properties. 224 | /// 225 | private void Initialize() 226 | { 227 | this.PushOperations = new PushOperations(this); 228 | //TODO: Change to your Chaso.Push.Server url 229 | this.BaseUri = new Uri("http://localhost:4478"); 230 | SerializationSettings = new JsonSerializerSettings 231 | { 232 | Formatting = Formatting.Indented, 233 | DateFormatHandling = DateFormatHandling.IsoDateFormat, 234 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 235 | NullValueHandling = NullValueHandling.Ignore, 236 | ReferenceLoopHandling = ReferenceLoopHandling.Serialize, 237 | ContractResolver = new ReadOnlyJsonContractResolver(), 238 | Converters = new List 239 | { 240 | new Iso8601TimeSpanConverter() 241 | } 242 | }; 243 | DeserializationSettings = new JsonSerializerSettings 244 | { 245 | DateFormatHandling = DateFormatHandling.IsoDateFormat, 246 | DateTimeZoneHandling = DateTimeZoneHandling.Utc, 247 | NullValueHandling = NullValueHandling.Ignore, 248 | ReferenceLoopHandling = ReferenceLoopHandling.Serialize, 249 | ContractResolver = new ReadOnlyJsonContractResolver(), 250 | Converters = new List 251 | { 252 | new Iso8601TimeSpanConverter() 253 | } 254 | }; 255 | CustomInitialize(); 256 | } 257 | } 258 | } 259 | -------------------------------------------------------------------------------- /Chaso.Push.Client/ClientClient/PushOperations.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.Linq; 9 | using System.Collections.Generic; 10 | using System.Net; 11 | using System.Net.Http; 12 | using System.Net.Http.Headers; 13 | using System.Text; 14 | using System.Text.RegularExpressions; 15 | using System.Threading; 16 | using System.Threading.Tasks; 17 | using Microsoft.Rest; 18 | using Microsoft.Rest.Serialization; 19 | using Newtonsoft.Json; 20 | using Models; 21 | 22 | /// 23 | /// PushOperations operations. 24 | /// 25 | public partial class PushOperations : IServiceOperations, IPushOperations 26 | { 27 | /// 28 | /// Initializes a new instance of the PushOperations class. 29 | /// 30 | /// 31 | /// Reference to the service client. 32 | /// 33 | public PushOperations(PushClient client) 34 | { 35 | if (client == null) 36 | { 37 | throw new ArgumentNullException("client"); 38 | } 39 | this.Client = client; 40 | } 41 | 42 | /// 43 | /// Gets a reference to the ClientClient 44 | /// 45 | public PushClient Client { get; private set; } 46 | 47 | /// 48 | /// Return all Channel listening by SignalR 49 | /// 50 | /// 51 | /// Headers that will be added to request. 52 | /// 53 | /// 54 | /// The cancellation token. 55 | /// 56 | /// 57 | /// A response object containing the response body and response headers. 58 | /// 59 | public async Task> GetChannelsWithHttpMessagesAsync(Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) 60 | { 61 | // Tracing 62 | bool _shouldTrace = ServiceClientTracing.IsEnabled; 63 | string _invocationId = null; 64 | if (_shouldTrace) 65 | { 66 | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); 67 | Dictionary tracingParameters = new Dictionary(); 68 | tracingParameters.Add("cancellationToken", cancellationToken); 69 | ServiceClientTracing.Enter(_invocationId, this, "GetChannels", tracingParameters); 70 | } 71 | // Construct URL 72 | var _baseUrl = this.Client.BaseUri.AbsoluteUri; 73 | var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/push/channels").ToString(); 74 | // Create HTTP transport objects 75 | HttpRequestMessage _httpRequest = new HttpRequestMessage(); 76 | HttpResponseMessage _httpResponse = null; 77 | _httpRequest.Method = new HttpMethod("GET"); 78 | _httpRequest.RequestUri = new Uri(_url); 79 | // Set Headers 80 | if (customHeaders != null) 81 | { 82 | foreach(var _header in customHeaders) 83 | { 84 | if (_httpRequest.Headers.Contains(_header.Key)) 85 | { 86 | _httpRequest.Headers.Remove(_header.Key); 87 | } 88 | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); 89 | } 90 | } 91 | 92 | // Serialize Request 93 | string _requestContent = null; 94 | // Set Credentials 95 | if (this.Client.Credentials != null) 96 | { 97 | cancellationToken.ThrowIfCancellationRequested(); 98 | await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); 99 | } 100 | // Send Request 101 | if (_shouldTrace) 102 | { 103 | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); 104 | } 105 | cancellationToken.ThrowIfCancellationRequested(); 106 | _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); 107 | if (_shouldTrace) 108 | { 109 | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); 110 | } 111 | HttpStatusCode _statusCode = _httpResponse.StatusCode; 112 | cancellationToken.ThrowIfCancellationRequested(); 113 | string _responseContent = null; 114 | if ((int)_statusCode != 200) 115 | { 116 | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); 117 | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 118 | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); 119 | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); 120 | if (_shouldTrace) 121 | { 122 | ServiceClientTracing.Error(_invocationId, ex); 123 | } 124 | _httpRequest.Dispose(); 125 | if (_httpResponse != null) 126 | { 127 | _httpResponse.Dispose(); 128 | } 129 | throw ex; 130 | } 131 | // Create Result 132 | var _result = new HttpOperationResponse(); 133 | _result.Request = _httpRequest; 134 | _result.Response = _httpResponse; 135 | // Deserialize Response 136 | if ((int)_statusCode == 200) 137 | { 138 | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 139 | try 140 | { 141 | _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings); 142 | } 143 | catch (JsonException ex) 144 | { 145 | _httpRequest.Dispose(); 146 | if (_httpResponse != null) 147 | { 148 | _httpResponse.Dispose(); 149 | } 150 | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); 151 | } 152 | } 153 | if (_shouldTrace) 154 | { 155 | ServiceClientTracing.Exit(_invocationId, _result); 156 | } 157 | return _result; 158 | } 159 | 160 | /// 161 | /// Notify a channel that an event was trigged 162 | /// 163 | /// 164 | /// 165 | /// 166 | /// Headers that will be added to request. 167 | /// 168 | /// 169 | /// The cancellation token. 170 | /// 171 | /// 172 | /// A response object containing the response body and response headers. 173 | /// 174 | public async Task> NotifyWithHttpMessagesAsync(Notify notify, Dictionary> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) 175 | { 176 | if (notify == null) 177 | { 178 | throw new ValidationException(ValidationRules.CannotBeNull, "notify"); 179 | } 180 | // Tracing 181 | bool _shouldTrace = ServiceClientTracing.IsEnabled; 182 | string _invocationId = null; 183 | if (_shouldTrace) 184 | { 185 | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); 186 | Dictionary tracingParameters = new Dictionary(); 187 | tracingParameters.Add("notify", notify); 188 | tracingParameters.Add("cancellationToken", cancellationToken); 189 | ServiceClientTracing.Enter(_invocationId, this, "Notify", tracingParameters); 190 | } 191 | // Construct URL 192 | var _baseUrl = this.Client.BaseUri.AbsoluteUri; 193 | var _url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/push/notify").ToString(); 194 | // Create HTTP transport objects 195 | HttpRequestMessage _httpRequest = new HttpRequestMessage(); 196 | HttpResponseMessage _httpResponse = null; 197 | _httpRequest.Method = new HttpMethod("POST"); 198 | _httpRequest.RequestUri = new Uri(_url); 199 | // Set Headers 200 | if (customHeaders != null) 201 | { 202 | foreach(var _header in customHeaders) 203 | { 204 | if (_httpRequest.Headers.Contains(_header.Key)) 205 | { 206 | _httpRequest.Headers.Remove(_header.Key); 207 | } 208 | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); 209 | } 210 | } 211 | 212 | // Serialize Request 213 | string _requestContent = null; 214 | if(notify != null) 215 | { 216 | _requestContent = SafeJsonConvert.SerializeObject(notify, this.Client.SerializationSettings); 217 | _httpRequest.Content = new StringContent(_requestContent, Encoding.UTF8); 218 | _httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); 219 | } 220 | // Set Credentials 221 | if (this.Client.Credentials != null) 222 | { 223 | cancellationToken.ThrowIfCancellationRequested(); 224 | await this.Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); 225 | } 226 | // Send Request 227 | if (_shouldTrace) 228 | { 229 | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); 230 | } 231 | cancellationToken.ThrowIfCancellationRequested(); 232 | _httpResponse = await this.Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); 233 | if (_shouldTrace) 234 | { 235 | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); 236 | } 237 | HttpStatusCode _statusCode = _httpResponse.StatusCode; 238 | cancellationToken.ThrowIfCancellationRequested(); 239 | string _responseContent = null; 240 | if ((int)_statusCode != 200) 241 | { 242 | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); 243 | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 244 | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); 245 | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); 246 | if (_shouldTrace) 247 | { 248 | ServiceClientTracing.Error(_invocationId, ex); 249 | } 250 | _httpRequest.Dispose(); 251 | if (_httpResponse != null) 252 | { 253 | _httpResponse.Dispose(); 254 | } 255 | throw ex; 256 | } 257 | // Create Result 258 | var _result = new HttpOperationResponse(); 259 | _result.Request = _httpRequest; 260 | _result.Response = _httpResponse; 261 | // Deserialize Response 262 | if ((int)_statusCode == 200) 263 | { 264 | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); 265 | try 266 | { 267 | _result.Body = SafeJsonConvert.DeserializeObject(_responseContent, this.Client.DeserializationSettings); 268 | } 269 | catch (JsonException ex) 270 | { 271 | _httpRequest.Dispose(); 272 | if (_httpResponse != null) 273 | { 274 | _httpResponse.Dispose(); 275 | } 276 | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); 277 | } 278 | } 279 | if (_shouldTrace) 280 | { 281 | ServiceClientTracing.Exit(_invocationId, _result); 282 | } 283 | return _result; 284 | } 285 | 286 | } 287 | } 288 | --------------------------------------------------------------------------------