Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the CloudFlare.NET.Yaml project to create YAML configuration #10

Merged
merged 8 commits into from
Aug 21, 2015
Merged
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
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ init:
# scripts that run after cloning repository
install:
- choco install gitversion.portable -y
- set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%

assembly_info:
patch: false
Expand Down
19 changes: 10 additions & 9 deletions coverage.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@
::@echo %xunit_exe%

@SET test_assemblies=%~dp0src\Tests\CloudFlare.NET.Tests\bin\%config%\CloudFlare.NET.Tests.dll
@SET test_assemblies=%test_assemblies% %~dp0src\Tests\CloudFlare.NET.Yaml.Tests\bin\%config%\CloudFlare.NET.Yaml.Tests.dll
@SET spec_results=%~dp0src\TestResults\Specifications.html
@SET xunit_results=%~dp0src\TestResults\Xunit.Tests.html
@SET coverage_filter=+[CloudFlare.NET]*
@SET coverage_filter=+[CloudFlare.NET*]* -[*.Tests]*
@SET coverage_results=%~dp0src\TestResults\Test.Coverage.xml

@IF NOT EXIST "%~dp0src\TestResults" MD "%~dp0src\TestResults"
::@echo "%mspec_exe%" "%test_assemblies%" --timeinfo --silent --html "%spec_results%"
::@"%mspec_exe%" "%test_assemblies%" --timeinfo --silent --html "%spec_results%"
::@echo "%xunit_exe%" "%test_assemblies%" -noshadow -html "%xunit_results%"
::@"%xunit_exe%" "%test_assemblies%" -noshadow -html "%xunit_results%"
::@echo "%mspec_exe%" %test_assemblies% --timeinfo --silent --html "%spec_results%"
::@"%mspec_exe%" %test_assemblies% --timeinfo --silent --html "%spec_results%"
::@echo "%xunit_exe%" %test_assemblies% -noshadow -html "%xunit_results%"
::@"%xunit_exe%" %test_assemblies% -noshadow -html "%xunit_results%"

@echo "%cover_exe%" -register:user "-target:%mspec_exe%" "-targetargs:%test_assemblies% --timeinfo --silent --html %spec_results%" -returntargetcode -filter:%coverage_filter% "-output:%coverage_results%"
@"%cover_exe%" -register:user "-target:%mspec_exe%" "-targetargs:%test_assemblies% --timeinfo --silent --html %spec_results%" -returntargetcode -filter:%coverage_filter% "-output:%coverage_results%"
@echo "%cover_exe%" -register:user "-target:%mspec_exe%" "-targetargs:%test_assemblies% --timeinfo --silent --html %spec_results%" -returntargetcode -filter:^"%coverage_filter%^" "-output:%coverage_results%"
@"%cover_exe%" -register:user "-target:%mspec_exe%" "-targetargs:%test_assemblies% --timeinfo --silent --html %spec_results%" -returntargetcode -filter:^"%coverage_filter%^" "-output:%coverage_results%"
@IF ERRORLEVEL 1 GOTO :EOF

@echo "%cover_exe%" -register:user "-target:%xunit_exe%" "-targetargs:%test_assemblies% -noshadow -html %xunit_results%" -returntargetcode -mergeoutput -filter:%coverage_filter% "-output:%coverage_results%"
@"%cover_exe%" -register:user "-target:%xunit_exe%" "-targetargs:%test_assemblies% -noshadow -html %xunit_results%" -returntargetcode -mergeoutput -filter:%coverage_filter% "-output:%coverage_results%"
@echo "%cover_exe%" -register:user "-target:%xunit_exe%" "-targetargs:%test_assemblies% -noshadow -html %xunit_results%" -returntargetcode -mergeoutput -filter:^"%coverage_filter%^" "-output:%coverage_results%"
@"%cover_exe%" -register:user "-target:%xunit_exe%" "-targetargs:%test_assemblies% -noshadow -html %xunit_results%" -returntargetcode -mergeoutput -filter:^"%coverage_filter%^" "-output:%coverage_results%"
@IF ERRORLEVEL 1 GOTO :EOF

@echo "%report_exe%" -verbosity:Error "-reports:%coverage_results%" "-targetdir:%~dp0src\TestResults" -reporttypes:XmlSummary
Expand Down
114 changes: 114 additions & 0 deletions src/CloudFlare.NET.Yaml/CloudFlare.NET.Yaml.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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>{86A16950-15A6-4BC3-90B6-00E4D08A1319}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CloudFlare.NET</RootNamespace>
<AssemblyName>CloudFlare.NET.Yaml</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>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>..\Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\CloudFlare.NET.Yaml.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</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>
<CodeAnalysisRuleSet>..\Analyzers.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Release\CloudFlare.NET.Yaml.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Extensions, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\portable-net40+sl4+win8+wp71+wpa81\System.Net.Http.Primitives.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="YamlDotNet, Version=3.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.3.6.1\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\YamlDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CloudFlare.NET\CloudFlare.NET.csproj">
<Project>{895ae2d8-6602-406e-b2ed-7ca9bc3174a5}</Project>
<Name>CloudFlare.NET</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="CloudFlareClientExtensions.cs" />
<Compile Include="JsonYamlTypeConverter.cs" />
<Compile Include="Serialization\DnsRecordFormatter.cs" />
<Compile Include="Serialization\FormatterHelpers.cs" />
<Compile Include="Serialization\IPostJsonFormatter.cs" />
<Compile Include="Serialization\IPreJsonFormatter.cs" />
<Compile Include="Serialization\StandardNonconfigurablePropertyFormatter.cs" />
<Compile Include="Serialization\TypedJsonFormatter.cs" />
<Compile Include="Serialization\YamlJsonFormatter.cs" />
<Compile Include="Serialization\ZoneFormatter.cs" />
<Compile Include="ToYamlExtensions.cs" />
<Compile Include="ZoneData.cs" />
<None Include="app.config" />
<None Include="CloudFlare.NET.Yaml.nuspec" />
<None Include="packages.config" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\AsyncFixer.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\RoslynUtilities.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\System.Composition.AttributedModel.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\System.Composition.Convention.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\System.Composition.Hosting.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\System.Composition.Runtime.dll" />
<Analyzer Include="..\packages\AsyncFixer.1.0.0.0\tools\analyzers\System.Composition.TypedParts.dll" />
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0-beta003\analyzers\dotnet\cs\StyleCop.Analyzers.dll" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use 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('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.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>
15 changes: 15 additions & 0 deletions src/CloudFlare.NET.Yaml/CloudFlare.NET.Yaml.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>0.0.2</version>
<title>$title$</title>
<authors>James Skimming</authors>
<owners>James Skimming</owners>
<licenseUrl>https://github.com/JSkimming/CloudFlare.NET/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/JSkimming/CloudFlare.NET</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<tags>CloudFlare YAML API Client</tags>
</metadata>
</package>
Binary file not shown.
47 changes: 47 additions & 0 deletions src/CloudFlare.NET.Yaml/CloudFlareClientExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace CloudFlare.NET
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

/// <summary>
/// Helper extension methods on <see cref="ICloudFlareClient"/>.
/// </summary>
public static class CloudFlareClientExtensions
{
/// <summary>
/// Gets the all the zone data.
/// </summary>
public static Task<ZoneData> GetZoneDataAsync(
this ICloudFlareClient client,
IdentifierTag zoneId,
CloudFlareAuth auth = null)
{
return client.GetZoneDataAsync(zoneId, CancellationToken.None, auth);
}

/// <summary>
/// Gets the all the zone data.
/// </summary>
public static async Task<ZoneData> GetZoneDataAsync(
this ICloudFlareClient client,
IdentifierTag zoneId,
CancellationToken cancellationToken,
CloudFlareAuth auth = null)
{
if (client == null)
throw new ArgumentNullException(nameof(client));
if (zoneId == null)
throw new ArgumentNullException(nameof(zoneId));

Task<Zone> zoneTask = client.GetZoneAsync(zoneId, cancellationToken, auth);
Task<IReadOnlyList<DnsRecord>> dnsRecordsTask = client.GetDnsRecordsAsync(zoneId, cancellationToken, auth);

await Task.WhenAll(zoneTask, dnsRecordsTask).ConfigureAwait(false);

return new ZoneData(zoneTask.Result, dnsRecordsTask.Result);
}
}
}
43 changes: 43 additions & 0 deletions src/CloudFlare.NET.Yaml/JsonYamlTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace CloudFlare.NET
{
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;

internal class JsonYamlTypeConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
if (type == null)
throw new ArgumentNullException(nameof(type));

return type == typeof(JValue);
}

public object ReadYaml(IParser parser, Type type)
{
if (parser == null)
throw new ArgumentNullException(nameof(parser));
if (type == null)
throw new ArgumentNullException(nameof(type));

throw new NotImplementedException();
}

public void WriteYaml(IEmitter emitter, object value, Type type)
{
if (emitter == null)
throw new ArgumentNullException(nameof(emitter));
if (value == null)
throw new ArgumentNullException(nameof(value));
if (type == null)
throw new ArgumentNullException(nameof(type));

emitter.Emit(new Scalar(value.ToString()));
}
}
}
28 changes: 28 additions & 0 deletions src/CloudFlare.NET.Yaml/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Reflection;
using System.Resources;

// 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("CloudFlare.NET.Yaml")]
[assembly: AssemblyDescription("CloudFlare.NET.Yaml")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CloudFlare.NET.Yaml")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]

// 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("0.0.2.0")]
[assembly: AssemblyFileVersion("0.0.2.0")]
23 changes: 23 additions & 0 deletions src/CloudFlare.NET.Yaml/Serialization/DnsRecordFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace CloudFlare.NET.Serialization
{
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;

/// <summary>
/// Performs post processing on a <see cref="DnsRecord"/> before conversion to YAML.
/// </summary>
public class DnsRecordFormatter : TypedJsonFormatter<DnsRecord>
{
/// <summary>
/// Post formats the <paramref name="json"/> of a <see cref="DnsRecord"/>.
/// </summary>
protected override JObject PostFormat(JObject json, DnsRecord value)
{
base.PostFormat(json, value);

return json.Keep(new[] { "name", "type", "content", "proxied", "ttl", "priority" });
}
}
}
42 changes: 42 additions & 0 deletions src/CloudFlare.NET.Yaml/Serialization/FormatterHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace CloudFlare.NET.Serialization
{
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;

internal static class FormatterHelpers
{
public static JObject Remove(this JObject json, IEnumerable<string> properties)
{
if (json == null)
throw new ArgumentNullException(nameof(json));
if (properties == null)
throw new ArgumentNullException(nameof(properties));

foreach (string property in properties)
{
json.Remove(property);
}

return json;
}

public static JObject Keep(this JObject json, IEnumerable<string> properties)
{
if (json == null)
throw new ArgumentNullException(nameof(json));
if (properties == null)
throw new ArgumentNullException(nameof(properties));

IEnumerable<JProperty> toRemove = json.Properties().Where(p => !properties.Contains(p.Name)).ToList();

foreach (JProperty property in toRemove)
{
property.Remove();
}

return json;
}
}
}
24 changes: 24 additions & 0 deletions src/CloudFlare.NET.Yaml/Serialization/IPostJsonFormatter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace CloudFlare.NET.Serialization
{
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;

/// <summary>
/// Implementing this interface provides a mechanism of formatting an object after conversion to a JSON.NET DOM.
/// </summary>
public interface IPostJsonFormatter
{
/// <summary>
/// Returns <see langword="true"/> if this <see cref="IPostJsonFormatter"/> accepts entities of the specified
/// <paramref name="type"/>; otherwise <see langword="false"/>.
/// </summary>
bool Accepts(Type type);

/// <summary>
/// Allows for post-formatting of the <paramref name="value"/>.
/// </summary>
JObject PostFormat(JObject json, object value, Type type);
}
}
Loading