From 2df26b084abe6528ea5caea02df94bea431e1c41 Mon Sep 17 00:00:00 2001 From: Ziya SARIKAYA Date: Fri, 26 Dec 2014 15:53:36 +0200 Subject: [PATCH] Add console sample --- src/FireSharp.Test.Console/App.config | 6 ++ .../FireSharp.Test.Console.csproj | 88 +++++++++++++++++++ src/FireSharp.Test.Console/Program.cs | 28 ++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ src/FireSharp.Test.Console/packages.config | 6 ++ src/FireSharp.Tests/FiresharpTests.cs | 3 +- src/FireSharp.sln | 6 ++ src/FireSharp/FirebaseClient.cs | 8 +- src/FireSharp/FirebaseRequestManager.cs | 2 +- src/FireSharp/Interfaces/IFirebaseClient.cs | 4 +- .../Interfaces/IFirebaseRequestManager.cs | 2 +- 11 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 src/FireSharp.Test.Console/App.config create mode 100644 src/FireSharp.Test.Console/FireSharp.Test.Console.csproj create mode 100644 src/FireSharp.Test.Console/Program.cs create mode 100644 src/FireSharp.Test.Console/Properties/AssemblyInfo.cs create mode 100644 src/FireSharp.Test.Console/packages.config diff --git a/src/FireSharp.Test.Console/App.config b/src/FireSharp.Test.Console/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/src/FireSharp.Test.Console/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FireSharp.Test.Console/FireSharp.Test.Console.csproj b/src/FireSharp.Test.Console/FireSharp.Test.Console.csproj new file mode 100644 index 0000000..6bf40a4 --- /dev/null +++ b/src/FireSharp.Test.Console/FireSharp.Test.Console.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {0DF0042E-769D-409B-A9F7-19449FD0AFD0} + Exe + Properties + FireSharp.Test.Console + FireSharp.Test.Console + v4.5.1 + 512 + true + ..\ + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll + + + ..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll + + + + + + + + + + + + + + + + + + + {7613B723-E81B-4C02-A3EC-54F8F02C60F6} + FireSharp + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + \ No newline at end of file diff --git a/src/FireSharp.Test.Console/Program.cs b/src/FireSharp.Test.Console/Program.cs new file mode 100644 index 0000000..cb02bc5 --- /dev/null +++ b/src/FireSharp.Test.Console/Program.cs @@ -0,0 +1,28 @@ +using FireSharp.Config; + +namespace FireSharp.Test.Console +{ + public class Program + { + private static FirebaseClient _client; + protected const string BASE_PATH = "https://firesharp.firebaseio.com/"; + protected const string FIREBASE_SECRET = "fubr9j2Kany9KU3SHCIHBLm142anWCzvlBs1D977"; + static void Main() + { + IFirebaseConfig config = new FirebaseConfig + { + AuthSecret = FIREBASE_SECRET, + BasePath = BASE_PATH + }; + + _client = new FirebaseClient(config); //Uses RestSharp JsonSerializer as default + + _client.Listen("chat", added: (sender, args) => + { + System.Console.WriteLine(args.Data); + }); + + System.Console.Read(); + } + } +} diff --git a/src/FireSharp.Test.Console/Properties/AssemblyInfo.cs b/src/FireSharp.Test.Console/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bdd4097 --- /dev/null +++ b/src/FireSharp.Test.Console/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FireSharp.Test.Console")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FireSharp.Test.Console")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("36e73638-c60a-48e8-a807-e705468013a1")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/FireSharp.Test.Console/packages.config b/src/FireSharp.Test.Console/packages.config new file mode 100644 index 0000000..d94744a --- /dev/null +++ b/src/FireSharp.Test.Console/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/FireSharp.Tests/FiresharpTests.cs b/src/FireSharp.Tests/FiresharpTests.cs index 526a3b6..249edb2 100644 --- a/src/FireSharp.Tests/FiresharpTests.cs +++ b/src/FireSharp.Tests/FiresharpTests.cs @@ -10,8 +10,7 @@ public partial class FiresharpTests : FiresharpTestBase { private IFirebaseClient _client; - [SetUp] - public void Setup() + protected override void FinalizeSetUp() { IFirebaseConfig config = new FirebaseConfig { diff --git a/src/FireSharp.sln b/src/FireSharp.sln index 15c16aa..de48e1c 100644 --- a/src/FireSharp.sln +++ b/src/FireSharp.sln @@ -16,6 +16,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{83537A .nuget\NuGet.targets = .nuget\NuGet.targets EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FireSharp.Test.Console", "FireSharp.Test.Console\FireSharp.Test.Console.csproj", "{0DF0042E-769D-409B-A9F7-19449FD0AFD0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,6 +36,10 @@ Global {36E7801E-AF0D-47F7-9C6C-7BE3DBB9DF30}.Debug|Any CPU.Build.0 = Debug|Any CPU {36E7801E-AF0D-47F7-9C6C-7BE3DBB9DF30}.Release|Any CPU.ActiveCfg = Release|Any CPU {36E7801E-AF0D-47F7-9C6C-7BE3DBB9DF30}.Release|Any CPU.Build.0 = Release|Any CPU + {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DF0042E-769D-409B-A9F7-19449FD0AFD0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/FireSharp/FirebaseClient.cs b/src/FireSharp/FirebaseClient.cs index 47fcccc..4184646 100644 --- a/src/FireSharp/FirebaseClient.cs +++ b/src/FireSharp/FirebaseClient.cs @@ -101,11 +101,11 @@ public FirebaseResponse Update(string path, T data) return response; } - public FirebaseResponse GetStreaming(string path, ValueAddedEventHandler added = null, + public FirebaseResponse Listen(string path, ValueAddedEventHandler added = null, ValueChangedEventHandler changed = null, ValueRemovedEventHandler removed = null) { - return GetStreamingAsync(path, added, changed, removed).Result; + return ListenAsync(path, added, changed, removed).Result; } public async Task GetTaskAsync(string path) @@ -178,14 +178,14 @@ public async Task UpdateTaskAsync(string path, T data) return response; } - public async Task GetStreamingAsync(string path, ValueAddedEventHandler added = null, + public async Task ListenAsync(string path, ValueAddedEventHandler added = null, ValueChangedEventHandler changed = null, ValueRemovedEventHandler removed = null) { FirebaseResponse response; try { - response = new FirebaseResponse(await _requestManager.GetStreaming(path), added, changed, removed); + response = new FirebaseResponse(await _requestManager.Listen(path), added, changed, removed); } catch (FirebaseException ex) { diff --git a/src/FireSharp/FirebaseRequestManager.cs b/src/FireSharp/FirebaseRequestManager.cs index 5e925ed..215a8ac 100644 --- a/src/FireSharp/FirebaseRequestManager.cs +++ b/src/FireSharp/FirebaseRequestManager.cs @@ -87,7 +87,7 @@ public async Task PatchTaskAsync(string path, T data) //return await ProcessRequestTaskAsync(HttpMethod.Patch, path, data); } - public async Task GetStreaming(string path) + public async Task Listen(string path) { var uri = PrepareUri(path); diff --git a/src/FireSharp/Interfaces/IFirebaseClient.cs b/src/FireSharp/Interfaces/IFirebaseClient.cs index cbf8825..4cddeb8 100644 --- a/src/FireSharp/Interfaces/IFirebaseClient.cs +++ b/src/FireSharp/Interfaces/IFirebaseClient.cs @@ -12,7 +12,7 @@ public interface IFirebaseClient DeleteResponse Delete(string path); FirebaseResponse Update(string path, T data); - FirebaseResponse GetStreaming(string path, + FirebaseResponse Listen(string path, ValueAddedEventHandler added = null, ValueChangedEventHandler changed = null, ValueRemovedEventHandler removed = null); @@ -23,7 +23,7 @@ FirebaseResponse GetStreaming(string path, Task DeleteTaskAsync(string path); Task UpdateTaskAsync(string path, T data); - Task GetStreamingAsync(string path, + Task ListenAsync(string path, ValueAddedEventHandler added = null, ValueChangedEventHandler changed = null, ValueRemovedEventHandler removed = null); diff --git a/src/FireSharp/Interfaces/IFirebaseRequestManager.cs b/src/FireSharp/Interfaces/IFirebaseRequestManager.cs index f9104b3..aee839c 100644 --- a/src/FireSharp/Interfaces/IFirebaseRequestManager.cs +++ b/src/FireSharp/Interfaces/IFirebaseRequestManager.cs @@ -10,7 +10,7 @@ internal interface IFirebaseRequestManager Task Post(string path, T data); Task Delete(string path); Task Patch(string path, T data); - Task GetStreaming(string path); + Task Listen(string path); Task GetTaskAsync(string path); Task PutTaskAsync(string path, T data); Task PostTaskAsync(string path, T data);