Skip to content

Commit

Permalink
Add console sample
Browse files Browse the repository at this point in the history
  • Loading branch information
bugthesystem committed Dec 26, 2014
1 parent bd8da2c commit 2df26b0
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/FireSharp.Test.Console/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
88 changes: 88 additions & 0 deletions src/FireSharp.Test.Console/FireSharp.Test.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0DF0042E-769D-409B-A9F7-19449FD0AFD0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FireSharp.Test.Console</RootNamespace>
<AssemblyName>FireSharp.Test.Console</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\packages\Microsoft.Net.Http.2.2.28\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FireSharp\FireSharp.csproj">
<Project>{7613B723-E81B-4C02-A3EC-54F8F02C60F6}</Project>
<Name>FireSharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="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=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
28 changes: 28 additions & 0 deletions src/FireSharp.Test.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
36 changes: 36 additions & 0 deletions src/FireSharp.Test.Console/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
6 changes: 6 additions & 0 deletions src/FireSharp.Test.Console/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net451" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net451" />
<package id="Microsoft.Net.Http" version="2.2.28" targetFramework="net451" />
</packages>
3 changes: 1 addition & 2 deletions src/FireSharp.Tests/FiresharpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public partial class FiresharpTests : FiresharpTestBase
{
private IFirebaseClient _client;

[SetUp]
public void Setup()
protected override void FinalizeSetUp()
{
IFirebaseConfig config = new FirebaseConfig
{
Expand Down
6 changes: 6 additions & 0 deletions src/FireSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/FireSharp/FirebaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ public FirebaseResponse Update<T>(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<FirebaseResponse> GetTaskAsync(string path)
Expand Down Expand Up @@ -178,14 +178,14 @@ public async Task<FirebaseResponse> UpdateTaskAsync<T>(string path, T data)
return response;
}

public async Task<FirebaseResponse> GetStreamingAsync(string path, ValueAddedEventHandler added = null,
public async Task<FirebaseResponse> 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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FireSharp/FirebaseRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task<HttpResponseMessage> PatchTaskAsync<T>(string path, T data)
//return await ProcessRequestTaskAsync(HttpMethod.Patch, path, data);
}

public async Task<HttpResponseMessage> GetStreaming(string path)
public async Task<HttpResponseMessage> Listen(string path)
{
var uri = PrepareUri(path);

Expand Down
4 changes: 2 additions & 2 deletions src/FireSharp/Interfaces/IFirebaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IFirebaseClient
DeleteResponse Delete(string path);
FirebaseResponse Update<T>(string path, T data);

FirebaseResponse GetStreaming(string path,
FirebaseResponse Listen(string path,
ValueAddedEventHandler added = null,
ValueChangedEventHandler changed = null,
ValueRemovedEventHandler removed = null);
Expand All @@ -23,7 +23,7 @@ FirebaseResponse GetStreaming(string path,
Task<DeleteResponse> DeleteTaskAsync(string path);
Task<FirebaseResponse> UpdateTaskAsync<T>(string path, T data);

Task<FirebaseResponse> GetStreamingAsync(string path,
Task<FirebaseResponse> ListenAsync(string path,
ValueAddedEventHandler added = null,
ValueChangedEventHandler changed = null,
ValueRemovedEventHandler removed = null);
Expand Down
2 changes: 1 addition & 1 deletion src/FireSharp/Interfaces/IFirebaseRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal interface IFirebaseRequestManager
Task<HttpResponseMessage> Post<T>(string path, T data);
Task<HttpResponseMessage> Delete(string path);
Task<HttpResponseMessage> Patch<T>(string path, T data);
Task<HttpResponseMessage> GetStreaming(string path);
Task<HttpResponseMessage> Listen(string path);
Task<HttpResponseMessage> GetTaskAsync(string path);
Task<HttpResponseMessage> PutTaskAsync<T>(string path, T data);
Task<HttpResponseMessage> PostTaskAsync<T>(string path, T data);
Expand Down

0 comments on commit 2df26b0

Please sign in to comment.