Navigation Menu

Skip to content

Commit

Permalink
Upgraded some leftover references from Newtonsoft.Json.4.0.3 to Newto…
Browse files Browse the repository at this point in the history
…nsoft.Json.4.0.5.

Changed TwitterStream to close immediately when invoking EndStream(), instead of lingering about. Removed unused method parameters to EndStream(). Invoke EndStream() from Dispose(), to make sure the stream is always closed properly.
  • Loading branch information
henrik committed Feb 2, 2012
1 parent 691474e commit 882ddb1
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 56 deletions.
7 changes: 3 additions & 4 deletions Twitterizer.OAuth/Twitterizer.OAuth.csproj
Expand Up @@ -29,6 +29,8 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -57,9 +59,6 @@
<AssemblyOriginatorKeyFile>..\Twitterizer2\Twitterizer2.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.4.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
Expand Down Expand Up @@ -116,13 +115,13 @@
<None Include="..\Twitterizer2\Twitterizer2.snk">
<Link>Twitterizer2.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
Expand Up @@ -17,6 +17,8 @@
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<!-- This property group is only here to support building this project using the
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
Expand Down Expand Up @@ -146,6 +148,7 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
7 changes: 5 additions & 2 deletions Twitterizer2.Async/Twitterizer2.Async.csproj
Expand Up @@ -28,6 +28,8 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -58,9 +60,9 @@
<AssemblyOriginatorKeyFile>..\Twitterizer2\Twitterizer2.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.0.3.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -134,6 +136,7 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
1 change: 0 additions & 1 deletion Twitterizer2.Async/packages.config
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="4.0.5" />
<package id="Newtonsoft.Json" version="4.0.3" />
</packages>
3 changes: 3 additions & 0 deletions Twitterizer2.Silverlight/Twitterizer2.Silverlight.csproj
Expand Up @@ -19,6 +19,8 @@
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<SignManifests>false</SignManifests>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<!-- This property group is only here to support building this project using the
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
Expand Down Expand Up @@ -654,6 +656,7 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
Expand Up @@ -17,6 +17,8 @@
<SilverlightApplication>false</SilverlightApplication>
<ValidateXaml>true</ValidateXaml>
<ThrowErrorsInValidation>true</ThrowErrorsInValidation>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<!-- This property group is only here to support building this project using the
MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs
Expand Down Expand Up @@ -107,6 +109,7 @@
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
63 changes: 35 additions & 28 deletions Twitterizer2.Streaming/TwitterStream.cs
Expand Up @@ -93,33 +93,40 @@ public class TwitterStream : IDisposable
private StatusCreatedCallback statusCreatedCallback;
private StatusDeletedCallback statusDeletedCallback;

/// <summary>
/// The userAgent which shall be used in connections to Twitter (a must in the specs of the API)
/// </summary>
private string userAgent = null;

/// <summary>
/// This value is set to true to indicate that the stream connection should be closed.
/// </summary>
private bool stopReceived;

private HttpWebRequest request;

private StreamStoppedCallback streamStoppedCallback;

/// <summary>
/// Initializes a new instance of the <see cref = "TwitterStream" /> class.
/// </summary>
/// <param name = "tokens">The tokens.</param>
/// <param name = "userAgent">The useragent string which shall include the version of your client.</param>
/// <param name = "userAgent">The user agent string which shall include the version of your client.</param>
/// <param name = "streamoptions">The stream or user stream options to intially use when starting the stream.</param>
public TwitterStream(OAuthTokens tokens, string userAgent, StreamOptions streamoptions)
{
#if !SILVERLIGHT
// No non-silverlight user-agent as Assembly.GetName() isn't supported and setting the request.UserAgent is also not supported.
if (string.IsNullOrEmpty(userAgent))
{
UserAgent = string.Format(
this.userAgent = string.Format(
CultureInfo.InvariantCulture,
"Twitterizer/{0}",
Assembly.GetExecutingAssembly().GetName().Version);
}
else
{
UserAgent = string.Format(
this.userAgent = string.Format(
CultureInfo.InvariantCulture,
"{0} (via Twitterizer/{1})",
userAgent,
Expand All @@ -132,11 +139,6 @@ public TwitterStream(OAuthTokens tokens, string userAgent, StreamOptions streamo
StreamOptions = streamoptions;
}

/// <summary>
/// The useragant which shall be used in connections to Twitter (a must in the specs of the API)
/// </summary>
private string UserAgent { get; set; }

/// <summary>
/// Gets or sets the tokens.
/// </summary>
Expand All @@ -162,6 +164,7 @@ public TwitterStream(OAuthTokens tokens, string userAgent, StreamOptions streamo
/// </summary>
public void Dispose()
{
EndStream();
friendsCallback = null;
streamStoppedCallback = null;
statusCreatedCallback = null;
Expand All @@ -170,7 +173,6 @@ public void Dispose()
directMessageDeletedCallback = null;
eventCallback = null;
rawJsonCallback = null;
stopReceived = true;
}

#endregion
Expand All @@ -189,8 +191,13 @@ public void Dispose()
RawJsonCallback rawJsonCallback = null
)
{
if (request != null)
{
throw new InvalidOperationException("Stream is already open");
}

WebRequestBuilder builder = new WebRequestBuilder(new Uri("https://userstream.twitter.com/2/user.json"),
HTTPVerb.GET, Tokens, UserAgent);
HTTPVerb.GET, Tokens, userAgent);

PrepareStreamOptions(builder);

Expand All @@ -200,7 +207,7 @@ public void Dispose()
builder.Parameters.Add("replies", "all");
}

HttpWebRequest request = builder.PrepareRequest();
request = builder.PrepareRequest();
this.friendsCallback = friendsCallback;
this.streamStoppedCallback = streamStoppedCallback;
this.statusCreatedCallback = statusCreatedCallback;
Expand All @@ -223,25 +230,30 @@ public void Dispose()
/// Starts the public stream.
/// </summary>
public IAsyncResult StartPublicStream(
StreamStoppedCallback streamErrorCallback,
StreamStoppedCallback streamStoppedCallback,
StatusCreatedCallback statusCreatedCallback,
StatusDeletedCallback statusDeletedCallback,
EventCallback eventCallback,
RawJsonCallback rawJsonCallback = null
)
{
if (request != null)
{
throw new InvalidOperationException("Stream is already open");
}

WebRequestBuilder builder;
if (Tokens == null)
builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"),
HTTPVerb.POST, UserAgent, NetworkCredentials);
HTTPVerb.POST, userAgent, NetworkCredentials);
else
builder = new WebRequestBuilder(new Uri("https://stream.twitter.com/1/statuses/filter.json"),
HTTPVerb.POST, Tokens, UserAgent);
HTTPVerb.POST, Tokens, userAgent);
PrepareStreamOptions(builder);

HttpWebRequest request = builder.PrepareRequest();
request = builder.PrepareRequest();

streamStoppedCallback = streamErrorCallback;
this.streamStoppedCallback = streamStoppedCallback;
this.statusCreatedCallback = statusCreatedCallback;
this.statusDeletedCallback = statusDeletedCallback;
this.eventCallback = eventCallback;
Expand Down Expand Up @@ -346,11 +358,11 @@ private void StreamCallback(IAsyncResult result)
}

reader.Close();

OnStreamStopped(stopReceived ? StopReasons.StoppedByRequest : StopReasons.WebConnectionFailed);
}
catch
{
reader.Close();
OnStreamStopped(stopReceived ? StopReasons.StoppedByRequest : StopReasons.WebConnectionFailed);
}
}
Expand Down Expand Up @@ -523,22 +535,17 @@ private void OnStreamStopped(StopReasons reason)
streamStoppedCallback(reason);
}

/// <summary>
/// Ends the stream.
/// </summary>
public void EndStream()
{
EndStream(StopReasons.Unknown, "General reason");
}

/// <summary>
/// Ends the stream.
/// </summary>
/// <param name="reason">The reason.</param>
/// <param name="description">The description.</param>
public void EndStream(StopReasons reason, string description)
public void EndStream()
{
stopReceived = true;
if (request != null)
{
request.Abort();
request = null;
}
}
}
}
7 changes: 5 additions & 2 deletions Twitterizer2.Streaming/Twitterizer2.Streaming.csproj
Expand Up @@ -32,6 +32,8 @@
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -61,9 +63,9 @@
<AssemblyOriginatorKeyFile>..\Twitterizer2\Twitterizer2.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.0.3.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Newtonsoft.Json, Version=4.0.5.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.4.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.4.0.5\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down Expand Up @@ -129,6 +131,7 @@
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down
1 change: 0 additions & 1 deletion Twitterizer2.Streaming/packages.config
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="4.0.5" />
<package id="Newtonsoft.Json" version="4.0.3" />
</packages>
3 changes: 3 additions & 0 deletions Twitterizer2.TestCases/Twitterizer2.TestCases.csproj
Expand Up @@ -32,6 +32,8 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\twitterizer\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -172,6 +174,7 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.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">
Expand Down

0 comments on commit 882ddb1

Please sign in to comment.