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
248 changes: 248 additions & 0 deletions ImageResizer.FluentExtensions.Portable/HttpValueCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;

namespace ImageResizer.FluentExtensions.Portable
{
public sealed class HttpUtility
{
public static HttpValueCollection ParseQueryString(string query)
{
if (query == null)
{
throw new ArgumentNullException("query");
}

if ((query.Length > 0) && (query[0] == '?'))
{
query = query.Substring(1);
}

return new HttpValueCollection(query, true);
}

public static string UrlEncode(string value)
{
return WebUtility.UrlEncode(value);
}
}

public sealed class HttpValue
{
public HttpValue()
{
}

public HttpValue(string key, string value)
{
this.Key = key;
this.Value = value;
}

public string Key { get; set; }
public string Value { get; set; }
}

public class HttpValueCollection : Collection<HttpValue>
{
#region Constructors

public HttpValueCollection()
{
}

public HttpValueCollection(string query)
: this(query, true)
{
}

public HttpValueCollection(string query, bool urlencoded)
{
if (!string.IsNullOrEmpty(query))
{
this.FillFromString(query, urlencoded);
}
}

#endregion

#region Parameters

public string this[string key]
{
get { return this.First(x => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase)).Value; }
set { this.First(x => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase)).Value = value; }
}

#endregion

#region Public Methods

public void Add(string key, string value)
{
this.Add(new HttpValue(key, value));
}

public void Add(HttpValueCollection collection)
{
foreach (var item in collection)
{
Add(item.Key, item.Value);
}
}

public void Set(string key, string value)
{
if (ContainsKey(key))
{
this[key] = value;
}
else
{
Add(key, value);
}
}

public bool ContainsKey(string key)
{
return this.Any(x => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase));
}

public string[] GetValues(string key)
{
return this.Where(x => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase)).Select(x => x.Value).ToArray();
}

public string[] AllKeys
{
get { return this.Select(x => x.Key).ToArray(); }
}

public void Remove(string key)
{
var items = this.Where(x => string.Equals(x.Key, key, StringComparison.OrdinalIgnoreCase))
.ToList();
foreach (var item in items)
{
this.Remove(item);
}
}

public override string ToString()
{
return this.ToString(true);
}

public virtual string ToString(bool urlencoded)
{
return this.ToString(urlencoded, null);
}

public virtual string ToString(bool urlencoded, IDictionary excludeKeys)
{
if (this.Count == 0)
{
return string.Empty;
}

StringBuilder stringBuilder = new StringBuilder();

foreach (HttpValue item in this)
{
string key = item.Key;

if ((excludeKeys == null) || !excludeKeys.Contains(key))
{
string value = item.Value;

if (urlencoded)
{
// If .NET 4.5 and above (Thanks @Paya)
key = WebUtility.UrlDecode(key);
// If .NET 4.0 use this instead.
// key = Uri.EscapeDataString(key);
}

if (stringBuilder.Length > 0)
{
stringBuilder.Append('&');
}

stringBuilder.Append((key != null) ? (key + "=") : string.Empty);

if ((value != null) && (value.Length > 0))
{
if (urlencoded)
{
value = Uri.EscapeDataString(value);
}

stringBuilder.Append(value);
}
}
}

return stringBuilder.ToString();
}

#endregion

#region Private Methods

private void FillFromString(string query, bool urlencoded)
{
int num = (query != null) ? query.Length : 0;
for (int i = 0; i < num; i++)
{
int startIndex = i;
int num4 = -1;
while (i < num)
{
char ch = query[i];
if (ch == '=')
{
if (num4 < 0)
{
num4 = i;
}
}
else if (ch == '&')
{
break;
}
i++;
}
string str = null;
string str2 = null;
if (num4 >= 0)
{
str = query.Substring(startIndex, num4 - startIndex);
str2 = query.Substring(num4 + 1, (i - num4) - 1);
}
else
{
str2 = query.Substring(startIndex, i - startIndex);
}

if (urlencoded)
{
this.Add(Uri.UnescapeDataString(str), Uri.UnescapeDataString(str2));
}
else
{
this.Add(str, str2);
}

if ((i == (num - 1)) && (query[i] == '&'))
{
this.Add(null, string.Empty);
}
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.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>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2D6D2C3F-8E07-4D36-92D2-B547A292C458}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ImageResizer.FluentExtensions.Portable</RootNamespace>
<AssemblyName>ImageResizer.FluentExtensions.Portable</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;PORTABLE</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;PORTABLE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\src\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\AlignmentExpression.cs">
<Link>AlignmentExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\DropShadowExpression.cs">
<Link>DropShadowExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\GradientExpression.cs">
<Link>GradientExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\ImageUrlBuilder.cs">
<Link>ImageUrlBuilder.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\ImageUrlBuilderExpression.cs">
<Link>ImageUrlBuilderExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\MiscExtensions.cs">
<Link>MiscExtensions.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\ModifierExtensions.cs">
<Link>ModifierExtensions.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\NumberExtensions.cs">
<Link>NumberExtensions.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\OutputExpression.cs">
<Link>OutputExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\ResizeExpression.cs">
<Link>ResizeExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\SimpleFiltersExpression.cs">
<Link>SimpleFiltersExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\StyleExpression.cs">
<Link>StyleExpression.cs</Link>
</Compile>
<Compile Include="..\src\ImageResizer.FluentExtensions\TransformExpression.cs">
<Link>TransformExpression.cs</Link>
</Compile>
<Compile Include="HttpValueCollection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Reflection;

// 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("Fluent Extensions for Image Resizer (Portable Class Library)")]
[assembly: AssemblyDescription("Portable Class Library Helpers for generating Image Resizer URL api requests.")]
10 changes: 8 additions & 2 deletions ImageResizer.FluentExtensions.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16881C95-E325-4AF5-BA38-048BB9649722}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizer.FluentExtensio
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizer.FluentExtensions.Tests", "tests\ImageResizer.FluentExtensions.Tests\ImageResizer.FluentExtensions.Tests.csproj", "{1ABDEC38-BA6A-4D24-A324-0C0D790413C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageResizer.FluentExtensions.Portable", "ImageResizer.FluentExtensions.Portable\ImageResizer.FluentExtensions.Portable.csproj", "{2D6D2C3F-8E07-4D36-92D2-B547A292C458}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -49,6 +51,10 @@ Global
{1ABDEC38-BA6A-4D24-A324-0C0D790413C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ABDEC38-BA6A-4D24-A324-0C0D790413C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ABDEC38-BA6A-4D24-A324-0C0D790413C8}.Release|Any CPU.Build.0 = Release|Any CPU
{2D6D2C3F-8E07-4D36-92D2-B547A292C458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D6D2C3F-8E07-4D36-92D2-B547A292C458}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D6D2C3F-8E07-4D36-92D2-B547A292C458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D6D2C3F-8E07-4D36-92D2-B547A292C458}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading