Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions src/Documentation/Documentation.Portable.shfbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<!-- The configuration and platform will be used to determine which
assemblies to include from solution and project documentation
sources -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{89f7811c-b169-430a-87fd-895865c3fbdc}</ProjectGuid>
<SHFBSchemaVersion>1.9.9.0</SHFBSchemaVersion>
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
Studio adds them anyway -->
<AssemblyName>Documentation</AssemblyName>
<RootNamespace>Documentation</RootNamespace>
<Name>Documentation</Name>
<!-- SHFB properties -->
<FrameworkVersion>.NET Portable Library 4.0 %28Legacy%29</FrameworkVersion>
<OutputPath>.\Help\portable-net40\</OutputPath>
<HtmlHelpName>SimpleRESTServices</HtmlHelpName>
<Language>en-US</Language>
<DocumentationSources>
<DocumentationSource sourceFile="..\SimpleRestServices\SimpleRestServices.Portable.csproj" />
</DocumentationSources>
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
<HelpFileFormat>HtmlHelp1, Website</HelpFileFormat>
<IndentHtml>False</IndentHtml>
<KeepLogFile>True</KeepLogFile>
<DisableCodeBlockComponent>False</DisableCodeBlockComponent>
<CppCommentsFixup>False</CppCommentsFixup>
<CleanIntermediates>True</CleanIntermediates>
<SyntaxFilters>Standard</SyntaxFilters>
<SdkLinkTarget>Blank</SdkLinkTarget>
<RootNamespaceTitle>API Reference</RootNamespaceTitle>
<RootNamespaceContainer>True</RootNamespaceContainer>
<PresentationStyle>VS2013</PresentationStyle>
<Preliminary>True</Preliminary>
<NamingMethod>MemberName</NamingMethod>
<HelpTitle>SimpleRESTServices API Reference Documentation</HelpTitle>
<FeedbackEMailAddress>openstack.net%40lists.rackspace.com</FeedbackEMailAddress>
<ContentPlacement>AboveNamespaces</ContentPlacement>
<WebsiteSdkLinkType>Msdn</WebsiteSdkLinkType>
<HtmlSdkLinkType>Msdn</HtmlSdkLinkType>
<IncludeFavorites>True</IncludeFavorites>
<BinaryTOC>True</BinaryTOC>
<VisibleItems>Attributes, ExplicitInterfaceImplementations, InheritedMembers, InheritedFrameworkMembers, Protected, ProtectedInternalAsProtected, SealedProtected</VisibleItems>
<ComponentConfigurations>
<ComponentConfig id="IntelliSense Component" enabled="True">
<component id="IntelliSense Component" type="Microsoft.Ddue.Tools.IntelliSenseComponent" assembly="{@SandcastlePath}ProductionTools\BuildComponents.dll">
<output includeNamespaces="false" namespacesFile="Namespaces" folder="{@OutputFolder}\..\..\Api\portable-net40" />
</component>
</ComponentConfig>
</ComponentConfigurations>
<ApiFilter />
<HelpAttributes />
<NamespaceSummaries />
<PlugInConfigurations>
<PlugInConfig id="Lightweight TOC" enabled="True">
<configuration />
</PlugInConfig>
</PlugInConfigurations>
<BuildLogFile />
<HtmlHelp1xCompilerPath />
<HtmlHelp2xCompilerPath />
<WorkingPath />
<ComponentPath />
<MaximumGroupParts>2</MaximumGroupParts>
<NamespaceGrouping>False</NamespaceGrouping>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional
common platform types that may appear. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SimpleRestServices\SimpleRestServices.Portable.csproj">
<Name>SimpleRestServices.Portable</Name>
<Project>{1960d862-8ad9-48be-9290-b7e23ea03d5c}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ContentLayout Include="SimpleRestServices.content" />
</ItemGroup>
<ItemGroup>
<None Include="Content\MSHelpViewerRoot.aml" />
<None Include="Content\Welcome.aml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\" />
</ItemGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>
11 changes: 11 additions & 0 deletions src/SimpleRestServices.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleRestServices.v3.5", "
EndProject
Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "Documentation.v3.5", "Documentation\Documentation.v3.5.shfbproj", "{93356B99-D84C-4291-B739-EF8EC6A9B382}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleRestServices.Portable", "SimpleRestServices\SimpleRestServices.Portable.csproj", "{FC3F3205-19B5-4CE0-BB04-2502C99A4B24}"
EndProject
Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "Documentation.Portable", "Documentation\Documentation.Portable.shfbproj", "{89F7811C-B169-430A-87FD-895865C3FBDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A57581E8-CE20-4E4A-81AA-B6BB5611D10F}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
Expand Down Expand Up @@ -54,6 +58,13 @@ Global
{93356B99-D84C-4291-B739-EF8EC6A9B382}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93356B99-D84C-4291-B739-EF8EC6A9B382}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93356B99-D84C-4291-B739-EF8EC6A9B382}.Release|Any CPU.Build.0 = Release|Any CPU
{FC3F3205-19B5-4CE0-BB04-2502C99A4B24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC3F3205-19B5-4CE0-BB04-2502C99A4B24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC3F3205-19B5-4CE0-BB04-2502C99A4B24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC3F3205-19B5-4CE0-BB04-2502C99A4B24}.Release|Any CPU.Build.0 = Release|Any CPU
{89F7811C-B169-430A-87FD-895865C3FBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89F7811C-B169-430A-87FD-895865C3FBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89F7811C-B169-430A-87FD-895865C3FBDC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions src/SimpleRestServices/Client/HttpHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ namespace JSIStudios.SimpleRESTServices.Client
/// <summary>
/// Represents a single header included with an HTTP response.
/// </summary>
#if !PORTABLE
[Serializable]
#endif
[DebuggerDisplay("{Key,nq} = {Value,nq}")]
public class HttpHeader
{
Expand Down
2 changes: 2 additions & 0 deletions src/SimpleRestServices/Client/Response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace JSIStudios.SimpleRESTServices.Client
/// Represents the basic response of an HTTP REST request, where the body of the response
/// is stored as a text string.
/// </summary>
#if !PORTABLE
[Serializable]
#endif
public class Response
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/SimpleRestServices/Client/ResponseOfT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace JSIStudios.SimpleRESTServices.Client
/// from the response.
/// </summary>
/// <typeparam name="T">The type of the data included with the response.</typeparam>
#if !PORTABLE
[Serializable]
#endif
public class Response<T> : Response
{
/// <summary>
Expand Down
52 changes: 51 additions & 1 deletion src/SimpleRestServices/Client/RestServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#if !NET35
using System.Diagnostics.Contracts;
#endif
#if PORTABLE
using System.Threading.Tasks;
#endif

namespace JSIStudios.SimpleRESTServices.Client
{
Expand Down Expand Up @@ -176,13 +179,20 @@ public virtual Response Execute(Uri url, HttpMethod method, Func<HttpWebResponse
if (!string.IsNullOrEmpty(body))
{
byte[] formData = UTF8Encoding.UTF8.GetBytes(body);
#if !PORTABLE
req.ContentLength = formData.Length;

// Send the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
#else
using (Stream post = Task.Factory.FromAsync<Stream>(req.BeginGetRequestStream(null, null), req.EndGetRequestStream).Result)
{
post.Write(formData, 0, formData.Length);
}
#endif
}

return body;
Expand Down Expand Up @@ -321,13 +331,21 @@ public virtual Response Stream(Uri url, HttpMethod method, Func<HttpWebResponse,

if (settings.ChunkRequest || maxReadLength > 0 )
{
#if !PORTABLE
req.SendChunked = settings.ChunkRequest;
req.AllowWriteStreamBuffering = false;

req.ContentLength = content.Length > maxReadLength ? maxReadLength : content.Length;
#else
throw new NotSupportedException("This platform does not support chunked HTTP requests.");
#endif
}

#if !PORTABLE
using (Stream stream = req.GetRequestStream())
#else
using (Stream stream = Task.Factory.FromAsync<Stream>(req.BeginGetRequestStream(null, null), req.EndGetRequestStream).Result)
#endif
{
var buffer = new byte[bufferSize];
int count;
Expand Down Expand Up @@ -416,16 +434,24 @@ public virtual Response ExecuteRequest(Uri url, HttpMethod method, Func<HttpWebR
req.Method = method.ToString();
req.ContentType = settings.ContentType;
req.Accept = settings.Accept;
#if !PORTABLE
if(settings.ContentLength > 0 || settings.AllowZeroContentLength)
req.ContentLength = settings.ContentLength;
#endif

#if !PORTABLE
if (settings.ConnectionLimit != null)
req.ServicePoint.ConnectionLimit = settings.ConnectionLimit.Value;
#endif

#if !PORTABLE
req.Timeout = (int)settings.Timeout.TotalMilliseconds;
#endif

#if !PORTABLE
if (!string.IsNullOrEmpty(settings.UserAgent))
req.UserAgent = settings.UserAgent;
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no #else in the above 4 #if and there is no code between, can they be combined to a single #if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, yes. However, they are conceptually different restrictions that may be addressed in different ways later.


if (settings.Credentials != null)
req.Credentials = settings.Credentials;
Expand All @@ -434,13 +460,21 @@ public virtual Response ExecuteRequest(Uri url, HttpMethod method, Func<HttpWebR
{
foreach (var header in headers)
{
#if !PORTABLE
req.Headers.Add(header.Key, header.Value);
#else
req.Headers[header.Key] = header.Value;
#endif
}
}

requestBodyText = executeCallback(req);

#if !PORTABLE
using (var resp = req.GetResponse() as HttpWebResponse)
#else
using (var resp = Task.Factory.FromAsync<WebResponse>(req.BeginGetResponse(null, null), req.EndGetResponse).Result as HttpWebResponse)
#endif
{
if (responseBuilderCallback != null)
response = responseBuilderCallback(resp, false);
Expand Down Expand Up @@ -495,9 +529,15 @@ private Response BuildWebResponse(HttpWebResponse resp)
respBody = reader.ReadToEnd();
}

#if !PORTABLE
var respHeaders =
resp.Headers.AllKeys.Select(key => new HttpHeader(key, resp.GetResponseHeader(key)))
.ToList();
#else
var respHeaders =
resp.Headers.AllKeys.Select(key => new HttpHeader(key, resp.Headers[key]))
.ToList();
#endif
return new Response(resp.StatusCode, respHeaders, respBody);
}

Expand All @@ -524,6 +564,7 @@ private Encoding GetEncoding(HttpWebResponse response)
Contract.EndContractBlock();
#endif

#if !PORTABLE
string contentEncoding = response.ContentEncoding;
if (!string.IsNullOrEmpty(contentEncoding))
{
Expand All @@ -536,7 +577,9 @@ private Encoding GetEncoding(HttpWebResponse response)
// continue below
}
}
#endif

#if !PORTABLE
string characterSet = response.CharacterSet;
if (string.IsNullOrEmpty(characterSet))
return Encoding.Default;
Expand All @@ -547,8 +590,15 @@ private Encoding GetEncoding(HttpWebResponse response)
}
catch (ArgumentException)
{
return Encoding.Default;
// continue below
}
#endif

#if !PORTABLE
return Encoding.Default;
#else
return Encoding.UTF8;
#endif
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions src/SimpleRestServices/Client/UrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ public string Build(string baseAbsoluteUrl, Dictionary<string, string> queryStri

if (queryStringParameters != null && queryStringParameters.Count > 0)
{
#if !PORTABLE
var paramsCombinedList =
queryStringParameters.Select(
param =>
string.Format("{0}={1}", System.Web.HttpUtility.UrlEncode(param.Key),
System.Web.HttpUtility.UrlEncode(param.Value)));
#else
var paramsCombinedList =
queryStringParameters.Select(
param =>
string.Format("{0}={1}", Uri.EscapeUriString(param.Key),
Uri.EscapeUriString(param.Value)));
#endif
var paramsCombined = string.Join("&", paramsCombinedList.ToArray());

var separator = baseAbsoluteUrl.Contains("?") ? "&" : "?";
Expand Down
9 changes: 9 additions & 0 deletions src/SimpleRestServices/Client/WebResponseRetryLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ public Response Execute(Func<Response> callback, IEnumerable<HttpStatusCode> non

retryCount--;
if (retryCount >= 0)
{
#if !PORTABLE
Thread.Sleep(retryDelay ?? TimeSpan.Zero);
#else
using (ManualResetEvent ev = new ManualResetEvent(false))
{
ev.WaitOne(retryDelay ?? TimeSpan.Zero);
}
#endif
}
}
while (retryCount > 0);

Expand Down
2 changes: 2 additions & 0 deletions src/SimpleRestServices/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(true)]

#if !PORTABLE
// 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("5a741815-e26d-4cb0-a42b-78f7c1611190")]
#endif

// Refer to the following issue before changing these version numbers:
// https://github.com/JSIStudios/SimpleRestServices/issues/53
Expand Down
Loading