Skip to content

Commit ac13585

Browse files
committed
Add Web API sample project
1 parent 9f1131b commit ac13585

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Web.Http;
2+
3+
namespace SampleWebApi
4+
{
5+
public static class WebApiConfig
6+
{
7+
public static void Register(HttpConfiguration config)
8+
{
9+
// Web API configuration and services
10+
11+
// Web API routes
12+
config.MapHttpAttributeRoutes();
13+
14+
config.Routes.MapHttpRoute(
15+
name: "DefaultApi",
16+
routeTemplate: "api/{controller}/{id}",
17+
defaults: new { id = RouteParameter.Optional }
18+
);
19+
}
20+
}
21+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Web.Http;
2+
using InEngine.Commands.Sample;
3+
using InEngine.Core.Queuing;
4+
5+
namespace SampleWebApi.Controllers
6+
{
7+
public class HomeController : ApiController
8+
{
9+
public IHttpActionResult Get()
10+
{
11+
Enqueue.Command(new SayHello()).Dispatch();
12+
13+
return Ok("ok");
14+
}
15+
}
16+
}

src/SampleWebApi/Global.asax

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%@ Application Inherits="SampleWebApi.Global" %>

src/SampleWebApi/Global.asax.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Web;
2+
using System.Web.Http;
3+
using InEngine.Core.Queuing;
4+
using InEngine.Core.Scheduling;
5+
6+
namespace SampleWebApi
7+
{
8+
public class Global : HttpApplication
9+
{
10+
public SuperScheduler SuperScheduler { get; set; }
11+
public Dequeue Dequeue { get; set; }
12+
13+
protected void Application_Start()
14+
{
15+
GlobalConfiguration.Configure(WebApiConfig.Register);
16+
17+
SuperScheduler = new SuperScheduler();
18+
SuperScheduler.Initialize();
19+
SuperScheduler.Start();
20+
21+
Dequeue = new Dequeue();
22+
StartQueueServerAsync();
23+
}
24+
25+
async void StartQueueServerAsync() => await Dequeue.StartAsync();
26+
27+
protected void Application_End()
28+
{
29+
SuperScheduler?.Shutdown();
30+
}
31+
}
32+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{169D410B-68C4-4D3E-9178-216748DFE69D}</ProjectGuid>
7+
<ProjectTypeGuids>{349C5851-65DF-11DA-9384-00065B846F21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>SampleWebApi</RootNamespace>
10+
<AssemblyName>SampleWebApi</AssemblyName>
11+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14+
<DebugSymbols>true</DebugSymbols>
15+
<DebugType>full</DebugType>
16+
<Optimize>false</Optimize>
17+
<OutputPath>bin</OutputPath>
18+
<DefineConstants>DEBUG;</DefineConstants>
19+
<ErrorReport>prompt</ErrorReport>
20+
<WarningLevel>4</WarningLevel>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23+
<Optimize>true</Optimize>
24+
<OutputPath>bin</OutputPath>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<ItemGroup>
29+
<Reference Include="System" />
30+
<Reference Include="System.Web" />
31+
<Reference Include="System.Xml" />
32+
<Reference Include="System.Core" />
33+
<Reference Include="System.Web.Services" />
34+
<Reference Include="System.Web.Routing" />
35+
<Reference Include="System.Web.Extensions" />
36+
<Reference Include="System.Web.Abstractions" />
37+
<Reference Include="System.Web.DynamicData" />
38+
<Reference Include="System.ComponentModel.DataAnnotations" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Net.Http.Formatting">
43+
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System.Net.Http" />
46+
<Reference Include="System.Web.Http">
47+
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
48+
</Reference>
49+
<Reference Include="System.Web.Http.WebHost">
50+
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Newtonsoft.Json">
53+
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
54+
</Reference>
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Content Include="Web.config" />
58+
<Content Include="Global.asax" />
59+
<Content Include="packages.config" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Compile Include="Global.asax.cs">
63+
<DependentUpon>Global.asax</DependentUpon>
64+
</Compile>
65+
<Compile Include="App_Start\WebApiConfig.cs" />
66+
<Compile Include="Controllers\HomeController.cs" />
67+
</ItemGroup>
68+
<ItemGroup>
69+
<ProjectReference Include="..\InEngine.Core\InEngine.Core.csproj">
70+
<Project>{1C604C4F-3F98-483C-89E3-C951BE03366A}</Project>
71+
<Name>InEngine.Core</Name>
72+
</ProjectReference>
73+
<ProjectReference Include="..\InEngine.Commands\InEngine.Commands.csproj">
74+
<Project>{5EDAF024-3BD1-4D22-A6E5-9EF808DB14C8}</Project>
75+
<Name>InEngine.Commands</Name>
76+
</ProjectReference>
77+
</ItemGroup>
78+
<ItemGroup>
79+
<None Include="appsettings.json">
80+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
81+
</None>
82+
</ItemGroup>
83+
<ItemGroup>
84+
<Folder Include="Controllers\" />
85+
</ItemGroup>
86+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
87+
<ProjectExtensions>
88+
<MonoDevelop>
89+
<Properties>
90+
<XspParameters Port="8080" Address="127.0.0.1" SslMode="None" SslProtocol="Default" KeyType="None" CertFile="" KeyFile="" PasswordOptions="None" Password="" Verbose="True" />
91+
</Properties>
92+
</MonoDevelop>
93+
</ProjectExtensions>
94+
</Project>

src/SampleWebApi/Web.config

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Web.config file for SampleWebApi.
4+
5+
The settings that can be used in this file are documented at
6+
http://www.mono-project.com/Config_system.web and
7+
http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
8+
-->
9+
<configuration>
10+
<system.web>
11+
<compilation debug="true" targetFramework="4.5">
12+
<assemblies />
13+
</compilation>
14+
<httpRuntime targetFramework="4.5" />
15+
</system.web>
16+
<system.webServer>
17+
<handlers>
18+
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
19+
<remove name="OPTIONSVerbHandler" />
20+
<remove name="TRACEVerbHandler" />
21+
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
22+
</handlers>
23+
</system.webServer>
24+
</configuration>

src/SampleWebApi/appsettings.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"InEngine": {
3+
"Plugins": {
4+
"InEngine.Commands": "/Users/hanne01/InEngine.NET/src/SampleMvcWebsite/bin"
5+
},
6+
"ExecWhitelist": {
7+
},
8+
"Mail": {
9+
"Host": "localhost",
10+
"Port": 1025,
11+
"From": "no-reply@inengine.net"
12+
},
13+
"Queue": {
14+
"UseCompression": false,
15+
"PrimaryQueueConsumers": 16,
16+
"SecondaryQueueConsumers": 4,
17+
"QueueDriver": "redis",
18+
"QueueName": "InEngineQueue",
19+
"RedisHost": "localhost",
20+
"RedisPort": 6379,
21+
"RedisDb": 0,
22+
"RedisPassword": ""
23+
}
24+
}
25+
}

src/SampleWebApi/packages.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
4+
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
5+
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
6+
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
7+
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
8+
</packages>

0 commit comments

Comments
 (0)