Last active
January 12, 2017 15:38
-
-
Save guitarrapc/1530d1066f0dd57db338669a15bf5792 to your computer and use it in GitHub Desktop.
Precompiled Azure Functions C# Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scriptFile": "PreCompileEnvironmentVariables.dll", | |
"entryPoint": "PreCompileEnvironmentVariables.MyFunction.Run", | |
"bindings": [ | |
{ | |
"webHookType": "genericJson", | |
"type": "httpTrigger", | |
"direction": "in", | |
"name": "req" | |
}, | |
{ | |
"type": "http", | |
"direction": "out", | |
"name": "$return" | |
} | |
], | |
"disabled": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.WebJobs.Host; | |
using Newtonsoft.Json; | |
namespace PreCompileEnvironmentVariables | |
{ | |
public class MyFunction | |
{ | |
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
{ | |
log.Info($"Webhook was triggered!"); | |
var appKey = "FooKey"; | |
var appValue = Environment.GetEnvironmentVariable(appKey); | |
log.Info($"App Setting. Key : {appKey}, Value : {appValue}"); | |
string jsonContent = await req.Content.ReadAsStringAsync(); | |
dynamic data = JsonConvert.DeserializeObject(jsonContent); | |
if (data.first == null || data.last == null) | |
{ | |
return req.CreateResponse(HttpStatusCode.BadRequest, new | |
{ | |
error = "Please pass first/last properties in the input object" | |
}); | |
} | |
return req.CreateResponse(HttpStatusCode.OK, new | |
{ | |
greeting = $"Hello {data.first} {data.last}!" | |
}); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" /> | |
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" /> | |
<package id="Microsoft.Azure.WebJobs" version="1.1.2" targetFramework="net46" /> | |
<package id="Microsoft.Azure.WebJobs.Core" version="1.1.2" targetFramework="net46" /> | |
<package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net46" /> | |
<package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net46" /> | |
<package id="Microsoft.Data.Services.Client" version="5.6.2" targetFramework="net46" /> | |
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="1.8.0.0" targetFramework="net46" /> | |
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" /> | |
<package id="System.Spatial" version="5.6.2" targetFramework="net46" /> | |
<package id="WindowsAzure.Storage" version="4.3.0" targetFramework="net46" /> | |
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> | |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |
<ProjectGuid>{FD5FD41F-D92D-47FC-9AF7-37CB957F98BC}</ProjectGuid> | |
<OutputType>Library</OutputType> | |
<AppDesignerFolder>Properties</AppDesignerFolder> | |
<RootNamespace>PreCompileEnvironmentVariables</RootNamespace> | |
<AssemblyName>PreCompileEnvironmentVariables</AssemblyName> | |
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | |
<FileAlignment>512</FileAlignment> | |
<TargetFrameworkProfile /> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |
<DebugSymbols>true</DebugSymbols> | |
<DebugType>full</DebugType> | |
<Optimize>false</Optimize> | |
<OutputPath>..\..\PreCompileEnvironmentVariablesWebhookCSharp\</OutputPath> | |
<DefineConstants>DEBUG;TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
<PlatformTarget>x86</PlatformTarget> | |
</PropertyGroup> | |
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |
<DebugType>pdbonly</DebugType> | |
<Optimize>true</Optimize> | |
<OutputPath>..\..\PreCompileEnvironmentVariables\</OutputPath> | |
<DefineConstants>TRACE</DefineConstants> | |
<ErrorReport>prompt</ErrorReport> | |
<WarningLevel>4</WarningLevel> | |
</PropertyGroup> | |
<ItemGroup> | |
<Reference Include="Microsoft.Azure.WebJobs, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.Azure.WebJobs.Core.1.1.2\lib\net45\Microsoft.Azure.WebJobs.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.Azure.WebJobs.Host, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.Azure.WebJobs.1.1.2\lib\net45\Microsoft.Azure.WebJobs.Host.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.Data.Edm, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.Data.Edm.5.6.2\lib\net40\Microsoft.Data.Edm.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.Data.OData, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.Data.OData.5.6.2\lib\net40\Microsoft.Data.OData.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.Data.Services.Client, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.Data.Services.Client.5.6.2\lib\net40\Microsoft.Data.Services.Client.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.WindowsAzure.Configuration, Version=1.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.WindowsAzure.ConfigurationManager.1.8.0.0\lib\net35-full\Microsoft.WindowsAzure.Configuration.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Microsoft.WindowsAzure.Storage, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\WindowsAzure.Storage.4.3.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="System" /> | |
<Reference Include="System.Core" /> | |
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="System.Spatial, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\System.Spatial.5.6.2\lib\net40\System.Spatial.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath> | |
<Private>True</Private> | |
</Reference> | |
<Reference Include="System.Xml.Linq" /> | |
<Reference Include="System.Data.DataSetExtensions" /> | |
<Reference Include="Microsoft.CSharp" /> | |
<Reference Include="System.Data" /> | |
<Reference Include="System.Net.Http" /> | |
<Reference Include="System.Xml" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Compile Include="MyFunction.cs" /> | |
<Compile Include="Properties\AssemblyInfo.cs" /> | |
</ItemGroup> | |
<ItemGroup> | |
<None Include="app.config" /> | |
<Content Include="function.json"> | |
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
</Content> | |
<None Include="packages.config"> | |
<SubType>Designer</SubType> | |
</None> | |
<None Include="TestOutput.json" /> | |
</ItemGroup> | |
<Import Project="$(MSBuildToolsPath)\Microsoft.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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment