Permalink
Browse files

update C# client to include an example and the binary

  • Loading branch information...
bwillard committed Jan 26, 2012
1 parent d0795b2 commit f561888a7906b1ecad5d2109e6f1e2b2d9f59767
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XStreamlyClient", "src\XStreamlyClient.csproj", "{5E59322B-F692-46A7-806A-CAA2C2F7CC3A}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XStreamlyClientTests", "examples\XStreamlyExamples.csproj", "{7432F523-09AB-4217-9C10-D8F3CCB5767F}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5E59322B-F692-46A7-806A-CAA2C2F7CC3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5E59322B-F692-46A7-806A-CAA2C2F7CC3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5E59322B-F692-46A7-806A-CAA2C2F7CC3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5E59322B-F692-46A7-806A-CAA2C2F7CC3A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7432F523-09AB-4217-9C10-D8F3CCB5767F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7432F523-09AB-4217-9C10-D8F3CCB5767F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7432F523-09AB-4217-9C10-D8F3CCB5767F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7432F523-09AB-4217-9C10-D8F3CCB5767F}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Binary file not shown.
@@ -0,0 +1,30 @@
+using System;
+using XStreamly.Client;
+
+namespace XStreamlyExamples
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ Client client = new Client("10bc1643-c9f5-4210-9814-cae3203af316","bwillard@x-stream.ly","mypass123");
+
+ client.Send("MyChannel","MyEvent",new {Name="Brian", Age=28});
+
+ String callbackKey = client.SetCallback(new Callback
+ {
+ Channel ="MyOtherChannel",
+ Endpoint = "http://my.end.point",
+ EventName = "EventName",
+ Secret = "No one should know this"
+ });
+
+ foreach(Callback c in client.Callbacks)
+ {
+ Console.WriteLine(c);
+ }
+
+ client.RemoveCallback(callbackKey);
+ }
+ }
+}
@@ -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("XStreamlyClientTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("XStreamlyClientTests")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[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("3273778a-29a1-4d0b-af9b-c1214e44e811")]
+
+// 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")]
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{7432F523-09AB-4217-9C10-D8F3CCB5767F}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>XStreamlyExamples</RootNamespace>
+ <AssemblyName>XStreamlyExamples</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <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' ">
+ <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">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\src\XStreamlyClient.csproj">
+ <Project>{5E59322B-F692-46A7-806A-CAA2C2F7CC3A}</Project>
+ <Name>XStreamlyClient</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- 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>
File renamed without changes.
@@ -61,10 +61,14 @@ public void Send(string channel,string eventName, object data)
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
- using(StreamReader sr = new StreamReader(response.GetResponseStream()))
+ if (response.StatusCode != HttpStatusCode.OK || response.StatusCode != HttpStatusCode.Accepted)
{
- string responseData = sr.ReadToEnd();
- Console.WriteLine(responseData);
+ String resposneText = "";
+ using (StreamReader sr = new StreamReader(response.GetResponseStream()))
+ {
+ resposneText= sr.ReadToEnd();
+ }
+ throw new Exception("Server did not accept your request: " + resposneText);
}
response.Close();
@@ -79,7 +83,7 @@ public void Send(string channel,string eventName, object data)
/// a specific channel (and optionally event name) your end point will be notified
/// </summary>
/// <param name="callback">The call back definition</param>
- public void SetCallback(Callback callback)
+ public string SetCallback(Callback callback)
{
HttpWebRequest myRequest = GetAuthenticatedRequest(string.Format(s_subscriptionFormatString, m_appKey));
@@ -101,6 +105,10 @@ public void SetCallback(Callback callback)
try
{
response = (HttpWebResponse)myRequest.GetResponse();
+ using (StreamReader sr = new StreamReader(response.GetResponseStream()))
+ {
+ return sr.ReadToEnd();
+ }
}
catch (WebException wex)
{
@@ -124,10 +132,10 @@ public void SetCallback(Callback callback)
/// <summary>
/// Removes an existing callback from X-Stream.ly
/// </summary>
- /// <param name="index"></param>
- public void RemoveCallback(string index)
+ /// <param name="key"></param>
+ public void RemoveCallback(string key)
{
- HttpWebRequest myRequest = GetAuthenticatedRequest(string.Format(s_subscriptionFormatString,m_appKey)+"/"+index);
+ HttpWebRequest myRequest = GetAuthenticatedRequest(string.Format(s_subscriptionFormatString,m_appKey)+"/"+key);
myRequest.Method = "DELETE";
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f561888

Please sign in to comment.