diff --git a/.gitignore b/.gitignore index f1e3d20..db99fe7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,252 +1,6 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ - -# Visual Studio 2015 cache/options directory -.vs/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# TODO: Comment the next line if you want to checkin your web deploy settings -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config -# NuGet v3's project.json files produces more ignoreable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# JetBrains Rider -.idea/ -*.sln.iml +packages +bin +obj +.vs +dist +node_modules diff --git a/Shop.AzureUtilities.sln b/Shop.AzureUtilities.sln new file mode 100644 index 0000000..c802bea --- /dev/null +++ b/Shop.AzureUtilities.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shop.AzureUtilities", "Shop.AzureUtilities\Shop.AzureUtilities.csproj", "{FFE58CB9-F39A-48DE-9C88-6E87223CF50C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FFE58CB9-F39A-48DE-9C88-6E87223CF50C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFE58CB9-F39A-48DE-9C88-6E87223CF50C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFE58CB9-F39A-48DE-9C88-6E87223CF50C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFE58CB9-F39A-48DE-9C88-6E87223CF50C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Shop.AzureUtilities/ActiveDirectoryAccessTokenHelper.cs b/Shop.AzureUtilities/ActiveDirectoryAccessTokenHelper.cs new file mode 100644 index 0000000..a239189 --- /dev/null +++ b/Shop.AzureUtilities/ActiveDirectoryAccessTokenHelper.cs @@ -0,0 +1,26 @@ +using Microsoft.IdentityModel.Clients.ActiveDirectory; +using System; +using System.Threading.Tasks; +using System.Web.Configuration; + +namespace Shop.WebApi.AzureUtilities +{ + public static class ActiveDirectoryAccessTokenHelper + { + public static async Task GetToken(string authority, string resource, string scope) + { + var authContext = new AuthenticationContext(authority); + var clientCred = new ClientCredential( + WebConfigurationManager.AppSettings["ClientId"], + WebConfigurationManager.AppSettings["ClientSecret"]); + var result = await authContext.AcquireTokenAsync(resource, clientCred); + + if (result == null) + { + throw new InvalidOperationException("Failed to obtain the JWT token"); + } + + return result.AccessToken; + } + } +} \ No newline at end of file diff --git a/Shop.AzureUtilities/ApplicationInsightsExceptionLogger.cs b/Shop.AzureUtilities/ApplicationInsightsExceptionLogger.cs new file mode 100644 index 0000000..3efaa3a --- /dev/null +++ b/Shop.AzureUtilities/ApplicationInsightsExceptionLogger.cs @@ -0,0 +1,27 @@ +using Microsoft.ApplicationInsights; +using System.Threading.Tasks; +using System.Web.Http.ExceptionHandling; + +namespace Shop.WebApi.AzureUtilities +{ + public class ApplicationInsightsExceptionLogger : ExceptionLogger + { + readonly TelemetryClient telemetryClient; + + public ApplicationInsightsExceptionLogger(TelemetryClient telemetryClient) + { + this.telemetryClient = telemetryClient; + } + + public override Task LogAsync(ExceptionLoggerContext context, System.Threading.CancellationToken cancellationToken) + { + telemetryClient.TrackException(context.Exception); + return Task.FromResult(null); + } + + public override void Log(ExceptionLoggerContext context) + { + telemetryClient.TrackException(context.Exception); + } + } +} \ No newline at end of file diff --git a/Shop.AzureUtilities/CloudTableExtensions.cs b/Shop.AzureUtilities/CloudTableExtensions.cs new file mode 100644 index 0000000..e76e5a9 --- /dev/null +++ b/Shop.AzureUtilities/CloudTableExtensions.cs @@ -0,0 +1,25 @@ +using Microsoft.WindowsAzure.Storage.Table; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Shop.WebApi.AzureUtilities +{ + public static class CloudTableExtensions + { + public static async Task> ExecuteQueryAsync(this CloudTable table, TableQuery query) where T : ITableEntity, new() + { + var items = new List(); + TableContinuationToken token = null; + + do + { + var seg = await table.ExecuteQuerySegmentedAsync(query, token); + token = seg.ContinuationToken; + items.AddRange(seg); + + } while (token != null); + + return items; + } + } +} \ No newline at end of file diff --git a/Shop.AzureUtilities/Properties/AssemblyInfo.cs b/Shop.AzureUtilities/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..36fa0b6 --- /dev/null +++ b/Shop.AzureUtilities/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 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("Shop.AzureUtilities")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Shop.AzureUtilities")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ffe58cb9-f39a-48de-9c88-6e87223cf50c")] + +// 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("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Shop.AzureUtilities/Shop.AzureUtilities.1.0.0.nuspec b/Shop.AzureUtilities/Shop.AzureUtilities.1.0.0.nuspec new file mode 100644 index 0000000..a1bf972 --- /dev/null +++ b/Shop.AzureUtilities/Shop.AzureUtilities.1.0.0.nuspec @@ -0,0 +1,21 @@ + + + + Shop.AzureUtilities + 1.0.0 + Rainer Stropek + false + My package description. + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shop.AzureUtilities/Shop.AzureUtilities.csproj b/Shop.AzureUtilities/Shop.AzureUtilities.csproj new file mode 100644 index 0000000..c92559e --- /dev/null +++ b/Shop.AzureUtilities/Shop.AzureUtilities.csproj @@ -0,0 +1,125 @@ + + + + + Debug + AnyCPU + {FFE58CB9-F39A-48DE-9C88-6E87223CF50C} + Library + Properties + Shop.AzureUtilities + Shop.AzureUtilities + v4.6.1 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + packages\Microsoft.ApplicationInsights.2.1.0\lib\net46\Microsoft.ApplicationInsights.dll + True + + + packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll + True + + + packages\Microsoft.Data.Edm.5.8.1\lib\net40\Microsoft.Data.Edm.dll + True + + + packages\Microsoft.Data.OData.5.8.1\lib\net40\Microsoft.Data.OData.dll + True + + + packages\Microsoft.Data.Services.Client.5.8.1\lib\net40\Microsoft.Data.Services.Client.dll + True + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll + True + + + packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.13.8\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll + True + + + packages\Microsoft.Owin.3.0.1\lib\net45\Microsoft.Owin.dll + True + + + packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + True + + + packages\WindowsAzure.Storage.7.2.1\lib\net40\Microsoft.WindowsAzure.Storage.dll + True + + + packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + True + + + packages\Owin.1.0\lib\net40\Owin.dll + True + + + + + packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + True + + + packages\System.Spatial.5.8.1\lib\net40\System.Spatial.dll + True + + + + packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll + True + + + packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll + True + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shop.AzureUtilities/app.config b/Shop.AzureUtilities/app.config new file mode 100644 index 0000000..db59e4f --- /dev/null +++ b/Shop.AzureUtilities/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Shop.AzureUtilities/packages.config b/Shop.AzureUtilities/packages.config new file mode 100644 index 0000000..f5ba6e6 --- /dev/null +++ b/Shop.AzureUtilities/packages.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file