Skip to content

Commit

Permalink
Added source code
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKrutov committed Jun 19, 2015
1 parent fc17019 commit aeaf121
Show file tree
Hide file tree
Showing 68 changed files with 4,828 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ $RECYCLE.BIN/
Network Trash Folder
Temporary Items
.apdisk
*.suo
bin
obj
packages
*.nupkg
9 changes: 9 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
144 changes: 144 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup>
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
</PropertyGroup>

<PropertyGroup>
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
15 changes: 15 additions & 0 deletions Radish.Demo/Controllers/ApiControllerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Results;

namespace Radish.Demo.Controllers
{
public static class ApiControllerExtensions
{
public static ResponseMessageResult NotFound(this ApiController controller, string message)
{
return new ResponseMessageResult(new System.Net.Http.HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent(message) });
}
}
}
40 changes: 40 additions & 0 deletions Radish.Demo/Controllers/HelpController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Net.Http;
using System.Text;
using System.Web.Http;
using System.Web.Http.Results;

namespace Radish.Demo.Controllers
{
public class HelpController : ApiController
{
[HttpGet]
[Route("help/{ts}")]
public IHttpActionResult GetHelp(string ts)
{
// Step 1. Create Documentor instance.
Documentor documentor = new Documentor();

// Step 2. Define methods groups.
documentor.AddMethodGroup("persons", "Persons", "Describes methods to work with Person objects", 1);
documentor.AddMethodGroup("pets", "Pets", "Describes methods to work with Pet objects", 2);

// Step 3. Create template set according to requiested documentation output type (simple or Bootstrap-based).
BasicTemplateSet templateSet = null;

if (String.Equals(ts, "simple"))
templateSet = new SimpleTemplateSet() { Title = "Radish Demo" };
else if (String.Equals(ts, "bootstrap"))
templateSet = new BootstrapTemplateSet() { Title = "Radish Demo" };

// Step 4. Specify template set for the documentor.
documentor.TemplateSet = templateSet;

// Step 5. Get the help content.
string helpContent = documentor.Content;

HttpResponseMessage message = new HttpResponseMessage() { Content = new StringContent(helpContent, Encoding.UTF8, "text/html") };
return new ResponseMessageResult(message);
}
}
}
145 changes: 145 additions & 0 deletions Radish.Demo/Controllers/PersonsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using Radish.Demo.Model;
using System;
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Description;

namespace Radish.Demo.Controllers
{
public class PersonsController : ApiController
{
private const string JSON_PERSON_WITHOUT_ID = @"{""FirstName"":""Bob"",""LastName"":""Brown"",""Age"":35,""Pets"":[],""Gender"":1}";
private const string JSON_PERSON_WITH_ID = @"{""Id"":2,""FirstName"":""Bob"",""LastName"":""Brown"",""Age"":35,""Pets"":[],""Gender"":1}";
private const string JSON_PERSONS_LIST = @"[{""Id"":1,""FirstName"":""Alice"",""LastName"":""Appleseed"",""Age"":20,""Pets"":[],""Gender"":2},{""Id"":2,""FirstName"":""Bob"",""LastName"":""Brown"",""Age"":35,""Pets"":[],""Gender"":1},{""Id"":3,""FirstName"":""Chris"",""LastName"":""Campbell"",""Age"":27,""Pets"":[],""Gender"":1},{""Id"":4,""FirstName"":""Diana"",""LastName"":""Doll"",""Age"":64,""Pets"":[],""Gender"":2}]";

#region Radish
[Order("persons", 1)]
[Method("GET", "/api/persons/", "persons-get")]
[MethodTitle("Get all persons")]
[ResponseBodyDescription("Json-serialized list of Persons objects")]
[ResponseBodyExample(JSON_PERSONS_LIST)]
[ResponseCode(200, "OK. On successfull result.")]
#endregion
[HttpGet]
[Route("persons")]
[ResponseType(typeof(List<Person>))]
public IHttpActionResult GetAllPersons()
{
List<Person> persons = DataBase.Instance.GetAllPersons();
return Ok(persons);
}

#region Radish
[Order("persons", 2)]
[Method("GET", "/api/persons/<id>", "person-get-by-id")]
[MethodTitle("Get person")]
[MethodDescription("Returns Person object by specified id.")]
[RequestParameter("id", "Integer", "Id of the Person")]
[ResponseBodyDescription("Json-serialized Person object")]
[ResponseBodyExample(JSON_PERSON_WITH_ID)]
[ResponseCode(200, "OK. On successful result.")]
[ResponseCode(404, "Not Found. When person with specified id was not found.")]
#endregion
[HttpGet]
[Route("persons/{personId:long}")]
[ResponseType(typeof(Person))]
public IHttpActionResult GetPerson(int personId)
{
Person person = DataBase.Instance.GetPerson(personId);
if (person == null)
{
return this.NotFound(String.Format("Person with id = {0} not found.", personId));
}
return Ok(person);
}

#region Radish
[Order("persons", 3)]
[Method("POST", "/api/persons", "persons-add")]
[MethodTitle("Add new person")]
[MethodDescription("Adds new Person.")]
[RequestBodyDescription("Json-serialized Person object")]
[RequestBodyExample(JSON_PERSON_WITHOUT_ID, DataFormat.Json)]
[ResponseBodyDescription("Json-serialized Person object with assigned id")]
[ResponseBodyExample(JSON_PERSON_WITH_ID)]
[ResponseCode(200, "OK. When person was successfully added.")]
[ResponseCode(400, "Bad request. When incorrect data were passed.")]
[ResponseCode(400, "Bad request. When passed Person object already contains assigned Id.")]
#endregion
[HttpPost]
[Route("persons")]
[ResponseType(typeof(Person))]
public IHttpActionResult AddPerson([FromBody] Person person)
{
if (person == null)
{
return BadRequest("Incorrect JSON data were passed.");
}

if (person.Id != 0)
{
return BadRequest("Unable to add person with already assigned id.");
}

Person added = DataBase.Instance.AddPerson(person);
return Ok<Person>(added);
}

#region Radish
[Order("persons", 4)]
[Method("PUT", "/api/persons/<id>", "persons-update-by-id")]
[MethodTitle("Update person")]
[MethodDescription("Updates person with specified id.")]
[RequestParameter("id", "Integer", "Id of the Person")]
[RequestBodyDescription("Json-serialized Person object to be updated.")]
[RequestBodyExample(JSON_PERSON_WITH_ID, DataFormat.Json)]
[ResponseBodyDescription("Updated Json-serialized Person object.")]
[ResponseBodyExample(JSON_PERSON_WITH_ID)]
[ResponseCode(200, "OK. On successful update")]
[ResponseCode(400, "Bad request. When incorrect data were passed.")]
[ResponseCode(404, "Not Found. When person with specified Id was not found.")]
#endregion
[HttpPut]
[Route("persons/{petId:long}")]
[ResponseType(typeof(Person))]
public IHttpActionResult UpdatePerson([FromBody] Person person, long personId)
{
if (person == null)
{
return BadRequest("Incorrect JSON data were passed.");
}

Person personInDb = DataBase.Instance.GetPerson(person.Id);
if (personInDb == null)
{
return this.NotFound(String.Format("Person with id = {0} not found.", person.Id));
}

Person updatedPerson = DataBase.Instance.UpdatePerson(person);

return Ok(updatedPerson);
}

#region Radish
[Order("persons", 5)]
[Method("DELETE", "/api/persons/<id>", "delete-person-by-id")]
[MethodTitle("Delete person")]
[MethodDescription("Deletes person with specified id.")]
[RequestParameter("id", "Integer", "Id of the Person")]
[ResponseCode(200, "OK. When person was deleted successful.")]
[ResponseCode(404, "Not Found. When person with specified Id was not found.")]
#endregion
[HttpDelete]
[Route("persons/{personId:long}")]
public IHttpActionResult DeletePerson(long personId)
{
Person pet = DataBase.Instance.GetPerson(personId);
if (pet == null)
{
return this.NotFound(String.Format("Person with id = {0} not found.", personId));
}
DataBase.Instance.DeletePerson(personId);
return Ok();
}
}
}
Loading

0 comments on commit aeaf121

Please sign in to comment.