├── .gitignore └── src ├── Booking.Activities.Tests ├── Booking.Activities.Tests.csproj ├── ContextSetup.cs ├── FetchAvatar_Specs.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Booking.Activities ├── Booking.Activities.csproj ├── FetchAvatar │ ├── FetchAvatarActivity.cs │ ├── FetchAvatarActivitySettings.cs │ └── FetchAvatarArguments.cs ├── Properties │ └── AssemblyInfo.cs ├── ReserveRoom │ ├── ReserveRoomActivity.cs │ ├── ReserveRoomArguments.cs │ └── ReserveRoomLog.cs └── packages.config ├── Booking.Contracts ├── Booking.Contracts.csproj ├── Commands │ └── BookMeeting.cs ├── Events │ ├── BookingRequestNotAccepted.cs │ ├── BookingRequestReceived.cs │ └── BookingRequestRedelivered.cs ├── Properties │ └── AssemblyInfo.cs ├── ReasonCode.cs └── ReasonCodes.cs ├── Booking.Services ├── App.config ├── BookMeetingConsumer.cs ├── BookMeetingEndpoint.cs ├── Booking.Services.csproj ├── BookingRequestHandler.cs ├── BookingRequestHandlerSettings.cs ├── BookingService.cs ├── IBookingRequestHandler.cs ├── Properties │ └── AssemblyInfo.cs ├── RoutingSlipExtensions.cs └── packages.config ├── Booking.Tracking.Tests ├── BookMeetingCommand.cs ├── Booking.Tracking.Tests.csproj ├── BookingRequestTracking_Specs.cs ├── ContextSetup.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── Booking.Tracking ├── Booking.Tracking.csproj ├── BookingRequestState.cs ├── BookingRequestStateMachine.cs ├── EventTrackingConsumer.cs ├── ITrackingEventWriter.cs ├── Properties │ └── AssemblyInfo.cs ├── TrackingEvent.cs └── packages.config ├── BookingService ├── App.config ├── BookingService.cs ├── BookingService.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── BookingWeb ├── App_Start │ ├── BundleConfig.cs │ ├── FilterConfig.cs │ ├── RouteConfig.cs │ ├── Startup.Auth.cs │ └── WebApiConfig.cs ├── Areas │ └── HelpPage │ │ ├── ApiDescriptionExtensions.cs │ │ ├── App_Start │ │ └── HelpPageConfig.cs │ │ ├── Controllers │ │ └── HelpController.cs │ │ ├── HelpPage.css │ │ ├── HelpPageAreaRegistration.cs │ │ ├── HelpPageConfigurationExtensions.cs │ │ ├── ModelDescriptions │ │ ├── CollectionModelDescription.cs │ │ ├── ComplexTypeModelDescription.cs │ │ ├── DictionaryModelDescription.cs │ │ ├── EnumTypeModelDescription.cs │ │ ├── EnumValueDescription.cs │ │ ├── IModelDocumentationProvider.cs │ │ ├── KeyValuePairModelDescription.cs │ │ ├── ModelDescription.cs │ │ ├── ModelDescriptionGenerator.cs │ │ ├── ModelNameAttribute.cs │ │ ├── ModelNameHelper.cs │ │ ├── ParameterAnnotation.cs │ │ ├── ParameterDescription.cs │ │ └── SimpleTypeModelDescription.cs │ │ ├── Models │ │ └── HelpPageApiModel.cs │ │ ├── SampleGeneration │ │ ├── HelpPageSampleGenerator.cs │ │ ├── HelpPageSampleKey.cs │ │ ├── ImageSample.cs │ │ ├── InvalidSample.cs │ │ ├── ObjectGenerator.cs │ │ ├── SampleDirection.cs │ │ └── TextSample.cs │ │ ├── Views │ │ ├── Help │ │ │ ├── Api.cshtml │ │ │ ├── DisplayTemplates │ │ │ │ ├── ApiGroup.cshtml │ │ │ │ ├── CollectionModelDescription.cshtml │ │ │ │ ├── ComplexTypeModelDescription.cshtml │ │ │ │ ├── DictionaryModelDescription.cshtml │ │ │ │ ├── EnumTypeModelDescription.cshtml │ │ │ │ ├── HelpPageApiModel.cshtml │ │ │ │ ├── ImageSample.cshtml │ │ │ │ ├── InvalidSample.cshtml │ │ │ │ ├── KeyValuePairModelDescription.cshtml │ │ │ │ ├── ModelDescriptionLink.cshtml │ │ │ │ ├── Parameters.cshtml │ │ │ │ ├── Samples.cshtml │ │ │ │ ├── SimpleTypeModelDescription.cshtml │ │ │ │ └── TextSample.cshtml │ │ │ ├── Index.cshtml │ │ │ └── ResourceModel.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── Web.config │ │ └── _ViewStart.cshtml │ │ └── XmlDocumentationProvider.cs ├── BookingWeb.csproj ├── Content │ ├── Site.css │ ├── bootstrap.css │ └── bootstrap.min.css ├── Controllers │ ├── AcceptedActionResult.cs │ ├── BookController.cs │ ├── EnhancedApiController.cs │ └── HomeController.cs ├── Global.asax ├── Global.asax.cs ├── Models │ ├── BookingRequestModel.cs │ └── BookingRequestResult.cs ├── Project_Readme.html ├── Properties │ └── AssemblyInfo.cs ├── Results │ └── ChallengeResult.cs ├── Scripts │ ├── _references.js │ ├── bootstrap.js │ ├── bootstrap.min.js │ ├── jquery-1.10.2.intellisense.js │ ├── jquery-1.10.2.js │ ├── jquery-1.10.2.min.js │ ├── jquery-1.10.2.min.map │ ├── jquery.validate-vsdoc.js │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ ├── jquery.validate.unobtrusive.min.js │ ├── modernizr-2.6.2.js │ ├── respond.js │ └── respond.min.js ├── Startup.cs ├── Views │ ├── Home │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ └── _Layout.cshtml │ ├── Web.config │ └── _ViewStart.cshtml ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── favicon.ico ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff └── packages.config ├── Sample.Booking.sln └── TrackingService ├── App.config ├── BookingRequestStateMap.cs ├── EntityFrameworkTrackingEventWriter.cs ├── LocalDatabaseSelector.cs ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── TrackingEventDbContext.cs ├── TrackingEventMap.cs ├── TrackingService.cs ├── TrackingService.csproj └── packages.config /.gitignore: -------------------------------------------------------------------------------- 1 | build_output/* 2 | build_artifacts/* 3 | *.suo 4 | *.user 5 | packages 6 | *.dotCover 7 | 8 | Gemfile.lock 9 | 10 | *.ncrunch* 11 | 12 | .vs 13 | 14 | src/logs/* 15 | 16 | bin 17 | obj 18 | _ReSharper* 19 | src/Samples/HeavyLoad/logs 20 | 21 | *.csproj.user 22 | *.resharper.user 23 | *.resharper 24 | *.ReSharper 25 | *.cache 26 | *~ 27 | *.swp 28 | *.bak 29 | *.orig 30 | 31 | NuGet.exe 32 | 33 | packages 34 | 35 | TestResult.xml 36 | submit.xml 37 | tests/* 38 | SolutionVersion.cs 39 | src/SolutionVersion.cs 40 | tests 41 | doc/build/* 42 | 43 | # osx noise 44 | .DS_Store 45 | NuGet.Exe 46 | 47 | nuspecs/ 48 | -------------------------------------------------------------------------------- /src/Booking.Activities.Tests/Booking.Activities.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {02D11FE8-6357-4BB2-A9C9-71763BB7D908} 8 | Library 9 | Properties 10 | Booking.Activities.Tests 11 | Booking.Activities.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll 35 | True 36 | 37 | 38 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 39 | True 40 | 41 | 42 | ..\packages\MassTransit.Log4Net.3.1.2\lib\net45\MassTransit.Log4NetIntegration.dll 43 | True 44 | 45 | 46 | ..\packages\MassTransit.TestFramework.3.1.2\lib\net45\MassTransit.TestFramework.dll 47 | True 48 | 49 | 50 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 51 | True 52 | 53 | 54 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 55 | True 56 | 57 | 58 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll 59 | True 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4} 81 | Booking.Activities 82 | 83 | 84 | 85 | 92 | -------------------------------------------------------------------------------- /src/Booking.Activities.Tests/ContextSetup.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.Tests 2 | { 3 | using System.IO; 4 | using System.Text; 5 | using log4net.Config; 6 | using MassTransit.Log4NetIntegration.Logging; 7 | using MassTransit.Logging; 8 | using NUnit.Framework; 9 | 10 | 11 | [SetUpFixture] 12 | public class ContextSetup 13 | { 14 | [SetUp] 15 | public void Setup() 16 | { 17 | ConfigureLogger(); 18 | 19 | Logger.UseLogger(new Log4NetLogger()); 20 | } 21 | 22 | static void ConfigureLogger() 23 | { 24 | const string logConfig = @" 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | "; 39 | 40 | using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(logConfig))) 41 | { 42 | XmlConfigurator.Configure(stream); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/Booking.Activities.Tests/FetchAvatar_Specs.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.Tests 2 | { 3 | using System; 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | using FetchAvatar; 7 | using MassTransit; 8 | using MassTransit.Courier; 9 | using MassTransit.Courier.Contracts; 10 | using MassTransit.TestFramework; 11 | using NUnit.Framework; 12 | 13 | 14 | [TestFixture] 15 | public class FetchAvatar_Specs : 16 | InMemoryActivityTestFixture 17 | { 18 | [Test] 19 | public async Task Should_write_avatar_address_to_routing_slip_variables() 20 | { 21 | var completed = await _completed; 22 | 23 | var avatarFileName = completed.Message.GetVariable("AvatarFileName"); 24 | 25 | Assert.IsNotNullOrEmpty(avatarFileName); 26 | 27 | Console.WriteLine($"Avatar path: {avatarFileName}"); 28 | } 29 | 30 | [TestFixtureSetUp] 31 | public void Setup() 32 | { 33 | var builder = new RoutingSlipBuilder(Guid.NewGuid()); 34 | 35 | var fetchAvatarActivity = GetActivityContext(); 36 | builder.AddActivity(fetchAvatarActivity.Name, fetchAvatarActivity.ExecuteUri); 37 | 38 | builder.AddVariable("EmailAddress", "chris@phatboyg.com"); 39 | builder.AddVariable("BookingRequestId", NewId.NextGuid()); 40 | 41 | _routingSlip = builder.Build(); 42 | 43 | Await(() => Bus.Execute(_routingSlip)); 44 | } 45 | 46 | Task> _completed; 47 | Task> _activityCompleted; 48 | RoutingSlip _routingSlip; 49 | 50 | protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator) 51 | { 52 | _completed = Handled(configurator); 53 | 54 | var fetchAvatarActivity = GetActivityContext(); 55 | 56 | _activityCompleted = Handled(configurator, context => context.Message.ActivityName.Equals(fetchAvatarActivity.Name)); 57 | } 58 | 59 | protected override void SetupActivities() 60 | { 61 | SetupFetchAvatarActivity(); 62 | } 63 | 64 | void SetupFetchAvatarActivity() 65 | { 66 | var avatarPath = CreateAvatarPath(); 67 | 68 | FetchAvatarActivitySettings fetchAvatarActivitySettings = new TestFetchAvatarActivitySettings(avatarPath); 69 | 70 | AddActivityContext(() => new FetchAvatarActivity(fetchAvatarActivitySettings)); 71 | } 72 | 73 | static string CreateAvatarPath() 74 | { 75 | var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; 76 | 77 | var avatarPath = Path.Combine(baseDirectory, "avatars"); 78 | 79 | Directory.CreateDirectory(avatarPath); 80 | 81 | return avatarPath; 82 | } 83 | 84 | 85 | class TestFetchAvatarActivitySettings : 86 | FetchAvatarActivitySettings 87 | { 88 | public TestFetchAvatarActivitySettings(string cacheFolderPath) 89 | { 90 | CacheFolderPath = cacheFolderPath; 91 | } 92 | 93 | public string CacheFolderPath { get; } 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /src/Booking.Activities.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Activities.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Activities.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("02d11fe8-6357-4bb2-a9c9-71763bb7d908")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Activities.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Booking.Activities/Booking.Activities.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4} 8 | Library 9 | Properties 10 | Booking.Activities 11 | Booking.Activities 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 35 | True 36 | 37 | 38 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 39 | True 40 | 41 | 42 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53} 64 | Booking.Contracts 65 | 66 | 67 | 68 | 75 | -------------------------------------------------------------------------------- /src/Booking.Activities/FetchAvatar/FetchAvatarActivity.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.FetchAvatar 2 | { 3 | using System; 4 | using System.IO; 5 | using System.Net.Http; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Contracts; 10 | using Contracts.Events; 11 | using MassTransit.Courier; 12 | using MassTransit.Courier.Exceptions; 13 | 14 | 15 | public class FetchAvatarActivity : 16 | ExecuteActivity 17 | { 18 | readonly FetchAvatarActivitySettings _settings; 19 | 20 | public FetchAvatarActivity(FetchAvatarActivitySettings settings) 21 | { 22 | _settings = settings; 23 | } 24 | 25 | public async Task Execute(ExecuteContext context) 26 | { 27 | var emailAddress = context.Arguments.EmailAddress; 28 | if (string.IsNullOrWhiteSpace(emailAddress)) 29 | throw new ActivityExecutionException("EmailAddress is required"); 30 | 31 | var avatarName = GenerateAvatarName(emailAddress); 32 | var avatarAddress = GetAvatarAddress(avatarName); 33 | var avatarFileName = Path.Combine(_settings.CacheFolderPath, $"{avatarName}.jpg"); 34 | 35 | await Console.Out.WriteLineAsync($"Fetching avatar {avatarName}"); 36 | 37 | using (var httpClient = new HttpClient()) 38 | { 39 | var request = await httpClient.GetAsync(avatarAddress); 40 | if (request.IsSuccessStatusCode) 41 | { 42 | using (var fileStream = File.Create(avatarFileName, 4096, FileOptions.Asynchronous)) 43 | { 44 | await request.Content.CopyToAsync(fileStream); 45 | } 46 | 47 | return context.CompletedWithVariables(new 48 | { 49 | AvatarAddress = avatarAddress, 50 | AvatarFileName = avatarFileName 51 | }); 52 | } 53 | 54 | await context.Publish(new RequestNotAccepted(context.Arguments, ReasonCodes.AvatarNotFound.Code, 55 | $"Avatar not found: {emailAddress}")); 56 | 57 | return context.Terminate(); 58 | } 59 | } 60 | 61 | Uri GetAvatarAddress(string avatarName) 62 | { 63 | var uriBuilder = new UriBuilder($"http://www.gravatar.com/avatar/{avatarName}.jpg"); 64 | 65 | return uriBuilder.Uri; 66 | } 67 | 68 | string GenerateAvatarName(string emailAddress) 69 | { 70 | var bytes = Encoding.UTF8.GetBytes(emailAddress.Trim()); 71 | 72 | using (var md5 = new MD5Cng()) 73 | { 74 | var hash = md5.ComputeHash(bytes, 0, bytes.Length); 75 | 76 | var avatarName = ByteArrayToString(hash); 77 | 78 | return avatarName; 79 | } 80 | } 81 | 82 | static string ByteArrayToString(byte[] ba) 83 | { 84 | var hex = new StringBuilder(ba.Length * 2); 85 | 86 | for (var i = 0; i < ba.Length; i++) 87 | hex.Append(ba[i].ToString("x2")); 88 | 89 | return hex.ToString(); 90 | } 91 | 92 | 93 | class RequestNotAccepted : 94 | BookingRequestNotAccepted 95 | { 96 | readonly FetchAvatarArguments _arguments; 97 | 98 | public RequestNotAccepted(FetchAvatarArguments arguments, int reasonCode, string reasonText) 99 | { 100 | _arguments = arguments; 101 | ReasonCode = reasonCode; 102 | ReasonText = reasonText; 103 | } 104 | 105 | public Guid BookingRequestId => _arguments.BookingRequestId; 106 | public int ReasonCode { get; } 107 | public string ReasonText { get; } 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /src/Booking.Activities/FetchAvatar/FetchAvatarActivitySettings.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.FetchAvatar 2 | { 3 | public interface FetchAvatarActivitySettings 4 | { 5 | /// 6 | /// The folder where avatars are to be cached 7 | /// 8 | string CacheFolderPath { get; } 9 | } 10 | } -------------------------------------------------------------------------------- /src/Booking.Activities/FetchAvatar/FetchAvatarArguments.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.FetchAvatar 2 | { 3 | using System; 4 | 5 | 6 | public interface FetchAvatarArguments 7 | { 8 | /// 9 | /// The unique identifier for the booking request 10 | /// 11 | Guid BookingRequestId { get; } 12 | 13 | /// 14 | /// Use the email address to fetch the avatar 15 | /// 16 | string EmailAddress { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Booking.Activities/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Activities")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Activities")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("d4d28f1d-7a94-485c-94c1-34fa6d1278f4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Activities/ReserveRoom/ReserveRoomActivity.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.ReserveRoom 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | using MassTransit; 6 | using MassTransit.Courier; 7 | 8 | 9 | public class ReserveRoomActivity : 10 | Activity 11 | { 12 | public async Task Execute(ExecuteContext context) 13 | { 14 | await Task.Delay(1000); 15 | 16 | var reservationId = NewId.NextGuid().ToString("N"); 17 | 18 | await Console.Out.WriteLineAsync($"Booking room {reservationId} using {context.Arguments.ReservationApiKey}"); 19 | 20 | return context.Completed(new Log(reservationId)); 21 | } 22 | 23 | public async Task Compensate(CompensateContext context) 24 | { 25 | await Console.Out.WriteLineAsync($"Cancelling reservationId: {context.Log.ReservationId}"); 26 | 27 | return context.Compensated(); 28 | } 29 | 30 | 31 | class Log : 32 | ReserveRoomLog 33 | { 34 | public Log(string reservationId) 35 | { 36 | ReservationId = reservationId; 37 | } 38 | 39 | public string ReservationId { get; } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /src/Booking.Activities/ReserveRoom/ReserveRoomArguments.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.ReserveRoom 2 | { 3 | public interface ReserveRoomArguments 4 | { 5 | /// 6 | /// Key used with room reservation service 7 | /// 8 | string ReservationApiKey { get; } 9 | 10 | /// 11 | /// Capacity of room, pulled from variables 12 | /// 13 | int RoomCapacity { get; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/Booking.Activities/ReserveRoom/ReserveRoomLog.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.ReserveRoom 2 | { 3 | public interface ReserveRoomLog 4 | { 5 | string ReservationId { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/Booking.Activities/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Booking.Contracts/Booking.Contracts.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53} 8 | Library 9 | Properties 10 | Booking.Contracts 11 | Booking.Contracts 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 53 | -------------------------------------------------------------------------------- /src/Booking.Contracts/Commands/BookMeeting.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Contracts.Commands 2 | { 3 | using System; 4 | 5 | 6 | public interface BookMeeting 7 | { 8 | /// 9 | /// Uniquely identifies the booking request 10 | /// 11 | Guid BookingRequestId { get; } 12 | 13 | /// 14 | /// The timestamp of the booking request 15 | /// 16 | DateTime Timestamp { get; } 17 | 18 | /// 19 | /// The email address of the booking party 20 | /// 21 | string EmailAddress { get; } 22 | 23 | /// 24 | /// The start time of the meeting to book 25 | /// 26 | DateTime StartTime { get; } 27 | 28 | /// 29 | /// The meeting duration 30 | /// 31 | TimeSpan Duration { get; } 32 | 33 | /// 34 | /// The room capacity required for the meeting 35 | /// 36 | int RoomCapacity { get; } 37 | } 38 | } -------------------------------------------------------------------------------- /src/Booking.Contracts/Events/BookingRequestNotAccepted.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Contracts.Events 2 | { 3 | using System; 4 | 5 | 6 | public interface BookingRequestNotAccepted 7 | { 8 | Guid BookingRequestId { get; } 9 | 10 | /// 11 | /// A reason code for the booking not being accepted 12 | /// 13 | int ReasonCode { get; } 14 | 15 | // A display reason of why the booking was not accepted 16 | string ReasonText { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Booking.Contracts/Events/BookingRequestReceived.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Contracts.Events 2 | { 3 | using System; 4 | using Commands; 5 | 6 | 7 | public interface BookingRequestReceived 8 | { 9 | DateTime Timestamp { get; } 10 | 11 | /// 12 | /// The actual meeting request 13 | /// 14 | BookMeeting Request { get; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Booking.Contracts/Events/BookingRequestRedelivered.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Contracts.Events 2 | { 3 | using System; 4 | using Commands; 5 | 6 | 7 | /// 8 | /// This event is published when a booking request is redelivered, either by the transport 9 | /// or due to an exception handling case 10 | /// 11 | public interface BookingRequestRedelivered 12 | { 13 | /// 14 | /// The time the request was redelivered 15 | /// 16 | DateTime Timestamp { get; } 17 | 18 | /// 19 | /// The actual meeting request 20 | /// 21 | BookMeeting Request { get; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Booking.Contracts/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Contracts")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Contracts")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("4a3e87bf-2a26-4f41-bb90-f91766b00c53")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Contracts/ReasonCode.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Contracts 2 | { 3 | public struct ReasonCode 4 | { 5 | public readonly int Code; 6 | public readonly string Text; 7 | 8 | public ReasonCode(int code, string text) 9 | { 10 | Code = code; 11 | Text = text; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/Booking.Contracts/ReasonCodes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Booking.Contracts 8 | { 9 | public static class ReasonCodes 10 | { 11 | public static readonly ReasonCode AvatarNotFound = new ReasonCode(4001, "Avatar not found"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Booking.Services/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Booking.Services/BookMeetingConsumer.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | using Contracts.Commands; 6 | using Contracts.Events; 7 | using MassTransit; 8 | 9 | 10 | /// 11 | /// Consumes the initial meeting request, and determines how to process it based on the delivery context 12 | /// 13 | public class BookMeetingConsumer : 14 | IConsumer 15 | { 16 | readonly IBookingRequestHandler _handler; 17 | 18 | public BookMeetingConsumer(IBookingRequestHandler handler) 19 | { 20 | _handler = handler; 21 | } 22 | 23 | public async Task Consume(ConsumeContext context) 24 | { 25 | await context.Publish(new Received(context.Message)); 26 | 27 | // If the message was previously delivered, follow the slow path 28 | if (context.ReceiveContext.Redelivered) 29 | { 30 | await context.Publish(new Redelivered(context.Message)); 31 | } 32 | else 33 | { 34 | await _handler.BookMeeting(context); 35 | } 36 | } 37 | 38 | 39 | class Received : 40 | BookingRequestReceived 41 | { 42 | public Received(BookMeeting request) 43 | { 44 | Timestamp = DateTime.UtcNow; 45 | Request = request; 46 | } 47 | 48 | public BookMeeting Request { get; } 49 | 50 | public DateTime Timestamp { get; } 51 | } 52 | 53 | class Redelivered : 54 | BookingRequestRedelivered 55 | { 56 | public Redelivered(BookMeeting request) 57 | { 58 | Timestamp = DateTime.UtcNow; 59 | Request = request; 60 | } 61 | 62 | public DateTime Timestamp { get; } 63 | public BookMeeting Request { get; } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/Booking.Services/BookMeetingEndpoint.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System; 4 | using MassTransit; 5 | using MassTransit.Hosting; 6 | 7 | 8 | /// 9 | /// Configures an endpoint for the assembly 10 | /// 11 | public class BookMeetingEndpoint : 12 | IEndpointSpecification 13 | { 14 | readonly IConsumerFactory _consumerFactory; 15 | 16 | public BookMeetingEndpoint(IConsumerFactory consumerFactory) 17 | { 18 | _consumerFactory = consumerFactory; 19 | } 20 | 21 | /// 22 | /// The default queue name for the endpoint, which can be overridden in the .config 23 | /// file for the assembly 24 | /// 25 | public string QueueName => "book-meeting"; 26 | 27 | /// 28 | /// The default concurrent consumer limit for the endpoint, which can be overridden in the .config 29 | /// file for the assembly 30 | /// 31 | public int ConsumerLimit => Environment.ProcessorCount; 32 | 33 | /// 34 | /// Configures the endpoint, with consumers, handlers, sagas, etc. 35 | /// 36 | public void Configure(IReceiveEndpointConfigurator configurator) 37 | { 38 | configurator.Consumer(_consumerFactory); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Booking.Services/Booking.Services.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA} 8 | Library 9 | Properties 10 | Booking.Services 11 | Booking.Services 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 35 | True 36 | 37 | 38 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 39 | True 40 | 41 | 42 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 43 | True 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53} 65 | Booking.Contracts 66 | 67 | 68 | 69 | 76 | -------------------------------------------------------------------------------- /src/Booking.Services/BookingRequestHandler.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System.Threading.Tasks; 4 | using Contracts.Commands; 5 | using MassTransit; 6 | using MassTransit.Courier; 7 | 8 | 9 | public class BookingRequestHandler : 10 | IBookingRequestHandler 11 | { 12 | readonly BookingRequestHandlerSettings _settings; 13 | 14 | public BookingRequestHandler(BookingRequestHandlerSettings settings) 15 | { 16 | _settings = settings; 17 | } 18 | 19 | public async Task BookMeeting(ConsumeContext context) 20 | { 21 | var builder = new RoutingSlipBuilder(NewId.NextGuid()); 22 | 23 | builder.AddActivity(_settings.ReserveRoomActivityName, 24 | _settings.ReserveRoomExecuteAddress, new 25 | { 26 | ReservationApiKey = "secret" 27 | }); 28 | 29 | builder.AddActivity(_settings.FetchAvatarActivityName, _settings.FetchAvatarExecuteAddress); 30 | 31 | builder.SetVariables(new 32 | { 33 | context.Message.EmailAddress, 34 | context.Message.StartTime, 35 | context.Message.Duration, 36 | context.Message.RoomCapacity 37 | }); 38 | 39 | var routingSlip = builder.Build(); 40 | 41 | await context.Execute(routingSlip); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /src/Booking.Services/BookingRequestHandlerSettings.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System; 4 | using MassTransit.Hosting; 5 | 6 | 7 | public interface BookingRequestHandlerSettings : 8 | ISettings 9 | { 10 | /// 11 | /// The display name of the activity 12 | /// 13 | string FetchAvatarActivityName { get; } 14 | 15 | /// 16 | /// The execute address of the activity for the routing slip 17 | /// 18 | Uri FetchAvatarExecuteAddress { get; } 19 | 20 | /// 21 | /// The name of the reserve room activity 22 | /// 23 | string ReserveRoomActivityName { get; } 24 | 25 | /// 26 | /// The execute address of the activity 27 | /// 28 | Uri ReserveRoomExecuteAddress { get; } 29 | } 30 | } -------------------------------------------------------------------------------- /src/Booking.Services/BookingService.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using MassTransit; 4 | using MassTransit.Hosting; 5 | 6 | 7 | /// 8 | /// Configures the bus settings for the service and all endpoints in the same assembly. 9 | /// 10 | public class BookingService : 11 | IServiceSpecification 12 | { 13 | public void Configure(IServiceConfigurator configurator) 14 | { 15 | configurator.UseRetry(Retry.None); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Booking.Services/IBookingRequestHandler.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System.Threading.Tasks; 4 | using Contracts.Commands; 5 | using MassTransit; 6 | 7 | 8 | public interface IBookingRequestHandler 9 | { 10 | Task BookMeeting(ConsumeContext context); 11 | } 12 | } -------------------------------------------------------------------------------- /src/Booking.Services/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Services")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Services")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("de2891a8-f54e-43bd-ad00-e38ffeb484aa")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Services/RoutingSlipExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Services 2 | { 3 | using System.Threading.Tasks; 4 | using MassTransit; 5 | using MassTransit.Courier; 6 | using MassTransit.Courier.Contracts; 7 | 8 | 9 | public static class RoutingSlipExtensions 10 | { 11 | /// 12 | /// This is a temp workaround until I update MT 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | public static async Task Execute(this T bus, RoutingSlip routingSlip) 19 | where T : IPublishEndpoint, ISendEndpointProvider 20 | { 21 | var endpoint = await bus.GetSendEndpoint(routingSlip.GetNextExecuteAddress()); 22 | 23 | await endpoint.Send(routingSlip); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/Booking.Services/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/BookMeetingCommand.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking.Tests 2 | { 3 | using System; 4 | using Contracts.Commands; 5 | 6 | 7 | public class BookMeetingCommand : 8 | BookMeeting 9 | { 10 | public BookMeetingCommand(Guid bookingRequestId, string emailAddress, DateTime startTime, TimeSpan duration, int roomCapacity) 11 | { 12 | BookingRequestId = bookingRequestId; 13 | EmailAddress = emailAddress; 14 | StartTime = startTime; 15 | Duration = duration; 16 | RoomCapacity = roomCapacity; 17 | 18 | Timestamp = DateTime.UtcNow; 19 | } 20 | 21 | public Guid BookingRequestId { get; } 22 | 23 | public DateTime Timestamp { get; } 24 | 25 | public string EmailAddress { get; } 26 | 27 | public DateTime StartTime { get; } 28 | 29 | public TimeSpan Duration { get; } 30 | 31 | public int RoomCapacity { get; } 32 | } 33 | } -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/Booking.Tracking.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B4487E8B-A0D8-4740-93A2-6DC91245F7C6} 8 | Library 9 | Properties 10 | Booking.Tracking.Tests 11 | Booking.Tracking.Tests 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Automatonymous.3.1.0\lib\net45\Automatonymous.dll 35 | True 36 | 37 | 38 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll 39 | True 40 | 41 | 42 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 43 | True 44 | 45 | 46 | ..\packages\MassTransit.Automatonymous.3.1.2\lib\net45\MassTransit.AutomatonymousIntegration.dll 47 | True 48 | 49 | 50 | ..\packages\MassTransit.Log4Net.3.1.2\lib\net45\MassTransit.Log4NetIntegration.dll 51 | True 52 | 53 | 54 | ..\packages\MassTransit.TestFramework.3.1.2\lib\net45\MassTransit.TestFramework.dll 55 | True 56 | 57 | 58 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 59 | True 60 | 61 | 62 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 63 | True 64 | 65 | 66 | ..\packages\NUnit.2.6.4\lib\nunit.framework.dll 67 | True 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | {4a3e87bf-2a26-4f41-bb90-f91766b00c53} 87 | Booking.Contracts 88 | 89 | 90 | {547191ed-8f53-4ca8-b4be-afea30fd7e1b} 91 | Booking.Tracking 92 | 93 | 94 | 95 | 102 | -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/BookingRequestTracking_Specs.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.Tests 2 | { 3 | using System; 4 | using System.Threading.Tasks; 5 | using Automatonymous; 6 | using Contracts.Commands; 7 | using Contracts.Events; 8 | using MassTransit; 9 | using MassTransit.Saga; 10 | using MassTransit.TestFramework; 11 | using NUnit.Framework; 12 | using Tracking; 13 | using Tracking.Tests; 14 | 15 | 16 | [TestFixture] 17 | public class BookingRequestTracking_Specs : 18 | InMemoryTestFixture 19 | { 20 | [Test] 21 | public async Task Should_insert_a_new_tracking_instance() 22 | { 23 | Guid sagaId = NewId.NextGuid(); 24 | 25 | var command = new BookMeetingCommand(sagaId, "chris@phatboyg.com", new DateTime(2016, 10, 1, 14, 0, 0), TimeSpan.FromHours(1), 8); 26 | await Bus.Publish(new RequestReceived(sagaId, command)); 27 | 28 | Guid? foundSagaId = await _bookingRequestSagaRepository.ShouldContainSaga(sagaId, TestTimeout); 29 | 30 | Assert.IsTrue(foundSagaId.HasValue); 31 | Assert.AreEqual(sagaId, foundSagaId.Value); 32 | } 33 | 34 | 35 | public class RequestReceived : 36 | BookingRequestReceived 37 | { 38 | public RequestReceived(Guid bookingRequestId, BookMeeting request) 39 | { 40 | BookingRequestId = bookingRequestId; 41 | Timestamp = DateTime.UtcNow; 42 | Request = request; 43 | } 44 | 45 | public Guid BookingRequestId { get; } 46 | public DateTime Timestamp { get; } 47 | 48 | public BookMeeting Request { get; } 49 | } 50 | 51 | 52 | InMemorySagaRepository _bookingRequestSagaRepository; 53 | BookingRequestStateMachine _bookingRequestStateMachine; 54 | 55 | protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator) 56 | { 57 | _bookingRequestSagaRepository = new InMemorySagaRepository(); 58 | _bookingRequestStateMachine = new BookingRequestStateMachine(); 59 | 60 | configurator.StateMachineSaga(_bookingRequestStateMachine, _bookingRequestSagaRepository); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/ContextSetup.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Activities.Tests 2 | { 3 | using System.IO; 4 | using System.Text; 5 | using log4net.Config; 6 | using MassTransit.Log4NetIntegration.Logging; 7 | using MassTransit.Logging; 8 | using NUnit.Framework; 9 | 10 | 11 | [SetUpFixture] 12 | public class ContextSetup 13 | { 14 | [SetUp] 15 | public void Setup() 16 | { 17 | ConfigureLogger(); 18 | 19 | Logger.UseLogger(new Log4NetLogger()); 20 | } 21 | 22 | static void ConfigureLogger() 23 | { 24 | const string logConfig = @" 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | "; 39 | 40 | using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(logConfig))) 41 | { 42 | XmlConfigurator.Configure(stream); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Tracking.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Tracking.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b4487e8b-a0d8-4740-93a2-6dc91245f7c6")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Tracking.Tests/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/Booking.Tracking/Booking.Tracking.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B} 8 | Library 9 | Properties 10 | Booking.Tracking 11 | Booking.Tracking 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | ..\packages\Automatonymous.3.1.0\lib\net45\Automatonymous.dll 35 | True 36 | 37 | 38 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 39 | True 40 | 41 | 42 | ..\packages\MassTransit.Automatonymous.3.1.2\lib\net45\MassTransit.AutomatonymousIntegration.dll 43 | True 44 | 45 | 46 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 47 | True 48 | 49 | 50 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 51 | True 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53} 71 | Booking.Contracts 72 | 73 | 74 | 75 | 82 | -------------------------------------------------------------------------------- /src/Booking.Tracking/BookingRequestState.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking 2 | { 3 | using System; 4 | using Automatonymous; 5 | 6 | 7 | public class BookingRequestState : 8 | SagaStateMachineInstance 9 | { 10 | /// 11 | /// The state of the saga 12 | /// 13 | public int State { get; set; } 14 | 15 | /// 16 | /// When the booking request was received 17 | /// 18 | public DateTime? ReceiveTime { get; set; } 19 | 20 | /// 21 | /// The correlationId of the saga state instance (matches the booking requestId) 22 | /// 23 | public Guid CorrelationId { get; set; } 24 | 25 | 26 | public DateTime CreateTime { get; set; } 27 | public DateTime UpdateTime { get; set; } 28 | 29 | public string EmailAddress { get; set; } 30 | public int? RoomCapacity { get; set; } 31 | public DateTime? StartTime { get; set; } 32 | public TimeSpan? Duration { get; set; } 33 | } 34 | } -------------------------------------------------------------------------------- /src/Booking.Tracking/BookingRequestStateMachine.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking 2 | { 3 | using System; 4 | using Automatonymous; 5 | using Contracts.Commands; 6 | using Contracts.Events; 7 | 8 | 9 | public class BookingRequestStateMachine : 10 | MassTransitStateMachine 11 | { 12 | public BookingRequestStateMachine() 13 | { 14 | InstanceState(state => state.State, Received); 15 | 16 | Event(() => RequestReceived, x => 17 | { 18 | x.CorrelateById(context => context.Message.Request.BookingRequestId); 19 | x.InsertOnInitial = true; 20 | x.SetSagaFactory(context => CreateBookingRequestState(context.Message.Timestamp, context.Message.Request)); 21 | }); 22 | 23 | Event(() => RequestRedelivered, x => 24 | { 25 | x.CorrelateById(context => context.Message.Request.BookingRequestId); 26 | x.InsertOnInitial = true; 27 | x.SetSagaFactory(context => CreateBookingRequestState(context.Message.Timestamp, context.Message.Request)); 28 | }); 29 | 30 | Initially( 31 | When(RequestReceived) 32 | .Then(context => context.Instance.ReceiveTime = context.Data.Timestamp) 33 | .TransitionTo(Received), 34 | When(RequestRedelivered) 35 | .Then(context => context.Instance.ReceiveTime = context.Data.Timestamp) 36 | .Then(context => 37 | { 38 | // send the command to execute the routing slip, because it is new 39 | }) 40 | .TransitionTo(Executing)); 41 | } 42 | 43 | public State Received { get; private set; } 44 | public State Executing { get; private set; } 45 | 46 | public Event RequestReceived { get; private set; } 47 | public Event RequestRedelivered { get; private set; } 48 | 49 | static BookingRequestState CreateBookingRequestState(DateTime timestamp, BookMeeting request) 50 | { 51 | return new BookingRequestState 52 | { 53 | CorrelationId = request.BookingRequestId, 54 | CreateTime = timestamp, 55 | UpdateTime = timestamp, 56 | EmailAddress = request.EmailAddress, 57 | StartTime = request.StartTime, 58 | Duration = request.Duration, 59 | RoomCapacity = request.RoomCapacity 60 | }; 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/Booking.Tracking/EventTrackingConsumer.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking 2 | { 3 | using System; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Contracts.Events; 7 | using MassTransit; 8 | using MassTransit.Courier.Contracts; 9 | using Newtonsoft.Json; 10 | 11 | 12 | public class EventTrackingConsumer : 13 | IConsumer, 14 | IConsumer, 15 | IConsumer, 16 | IConsumer, 17 | IConsumer 18 | 19 | { 20 | readonly ITrackingEventWriter _writer; 21 | 22 | public EventTrackingConsumer(ITrackingEventWriter writer) 23 | { 24 | _writer = writer; 25 | } 26 | 27 | public Task Consume(ConsumeContext context) 28 | { 29 | return WriteEvent(context, context.Message.Timestamp, 30 | JsonConvert.SerializeObject(new 31 | { 32 | context.Message.Request.EmailAddress, 33 | context.Message.Request.StartTime, 34 | context.Message.Request.Duration, 35 | context.Message.Request.RoomCapacity 36 | }), context.Message.Request.BookingRequestId); 37 | } 38 | 39 | public Task Consume(ConsumeContext context) 40 | { 41 | return WriteEvent(context, context.Message.Timestamp, context.Message.ActivityName, 42 | duration: context.Message.Duration); 43 | } 44 | 45 | public Task Consume(ConsumeContext context) 46 | { 47 | return WriteEvent(context, context.Message.Timestamp, context.Message.ActivityName, 48 | duration: context.Message.Duration); 49 | } 50 | 51 | public Task Consume(ConsumeContext context) 52 | { 53 | return WriteEvent(context, context.Message.Timestamp, duration: context.Message.Duration); 54 | } 55 | 56 | public Task Consume(ConsumeContext context) 57 | { 58 | return WriteEvent(context, context.Message.Timestamp, duration: context.Message.Duration, 59 | text: JsonConvert.SerializeObject(new 60 | { 61 | Exceptions = context.Message.ActivityExceptions.Select(x => new { x.ExceptionInfo.ExceptionType, x.ExceptionInfo.Message}).ToList(), 62 | context.Message.TrackingNumber, 63 | })); 64 | } 65 | 66 | Task WriteEvent(ConsumeContext context, DateTime timestamp, string text = default(string), Guid? bookingRequestId = default(Guid?), 67 | TimeSpan? duration = default(TimeSpan?)) 68 | where T : class 69 | { 70 | var trackingEvent = new TrackingEvent 71 | { 72 | MessageId = context.MessageId ?? NewId.NextGuid(), 73 | Timestamp = timestamp, 74 | Duration = duration, 75 | Text = text, 76 | CorrelationId = context.CorrelationId, 77 | ConversationId = context.ConversationId, 78 | InitiatorId = context.InitiatorId, 79 | BookingRequestId = bookingRequestId, 80 | EventType = typeof(T).Name 81 | }; 82 | 83 | return _writer.Write(trackingEvent); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/Booking.Tracking/ITrackingEventWriter.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking 2 | { 3 | using System.Threading.Tasks; 4 | 5 | 6 | public interface ITrackingEventWriter 7 | { 8 | Task Write(TrackingEvent trackingEvent); 9 | } 10 | } -------------------------------------------------------------------------------- /src/Booking.Tracking/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Booking.Tracking")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Booking.Tracking")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("547191ed-8f53-4ca8-b4be-afea30fd7e1b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/Booking.Tracking/TrackingEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Booking.Tracking 2 | { 3 | using System; 4 | 5 | 6 | public class TrackingEvent 7 | { 8 | public Guid MessageId { get; set; } 9 | public DateTime Timestamp { get; set; } 10 | 11 | public Guid? CorrelationId { get; set; } 12 | public Guid? ConversationId { get; set; } 13 | public Guid? InitiatorId { get; set; } 14 | 15 | public Guid? BookingRequestId { get; set; } 16 | 17 | public string EventType { get; set; } 18 | 19 | public string Text { get; set; } 20 | 21 | public TimeSpan? Duration { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Booking.Tracking/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/BookingService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/BookingService/BookingService.cs: -------------------------------------------------------------------------------- 1 | namespace BookingService 2 | { 3 | using System; 4 | using System.Configuration; 5 | using System.IO; 6 | using Booking.Activities.FetchAvatar; 7 | using Booking.Activities.ReserveRoom; 8 | using Booking.Services; 9 | using MassTransit; 10 | using MassTransit.Courier; 11 | using MassTransit.Util; 12 | using Topshelf; 13 | using Topshelf.Logging; 14 | 15 | 16 | class BookingService : 17 | ServiceControl 18 | { 19 | readonly LogWriter _log = HostLogger.Get(); 20 | 21 | IBusControl _busControl; 22 | BusHandle _busHandle; 23 | BookingRequestHandlerSettings _settings; 24 | FetchAvatarActivitySettings _fetchAvatarActivitySettings; 25 | 26 | public bool Start(HostControl hostControl) 27 | { 28 | _settings = new Settings(); 29 | _fetchAvatarActivitySettings = new FetchAvatarSettings(); 30 | 31 | _log.Info("Creating bus..."); 32 | 33 | 34 | _busControl = Bus.Factory.CreateUsingRabbitMq(x => 35 | { 36 | var host = x.Host(GetHostAddress(), h => 37 | { 38 | h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); 39 | h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); 40 | }); 41 | 42 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookMeetingQueueName"], e => 43 | { 44 | e.Consumer(() => 45 | { 46 | var handler = new BookingRequestHandler(_settings); 47 | 48 | return new BookMeetingConsumer(handler); 49 | }); 50 | }); 51 | 52 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["FetchAvatarActivityQueue"], e => 53 | { 54 | e.ExecuteActivityHost(() => new FetchAvatarActivity(_fetchAvatarActivitySettings)); 55 | }); 56 | 57 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ReserveRoomCompensateQueue"], c => 58 | { 59 | var compensateAddress = c.InputAddress; 60 | 61 | c.ExecuteActivityHost(); 62 | 63 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ReserveRoomExecuteQueue"], e => 64 | { 65 | e.ExecuteActivityHost(compensateAddress); 66 | }); 67 | }); 68 | }); 69 | 70 | _log.Info("Starting bus..."); 71 | 72 | _busHandle = _busControl.Start(); 73 | 74 | TaskUtil.Await(() => _busHandle.Ready); 75 | 76 | return true; 77 | } 78 | 79 | public bool Stop(HostControl hostControl) 80 | { 81 | _log.Info("Stopping bus..."); 82 | 83 | _busHandle?.Stop(TimeSpan.FromSeconds(30)); 84 | 85 | return true; 86 | } 87 | 88 | static Uri GetHostAddress() 89 | { 90 | var uriBuilder = new UriBuilder 91 | { 92 | Scheme = "rabbitmq", 93 | Host = ConfigurationManager.AppSettings["RabbitMQHost"] 94 | }; 95 | 96 | return uriBuilder.Uri; 97 | } 98 | 99 | 100 | class Settings : 101 | BookingRequestHandlerSettings 102 | { 103 | public Settings() 104 | { 105 | FetchAvatarActivityName = ConfigurationManager.AppSettings["FetchAvatarActivityName"]; 106 | FetchAvatarExecuteAddress = new Uri(ConfigurationManager.AppSettings["FetchAvatarExecuteAddress"]); 107 | ReserveRoomActivityName = ConfigurationManager.AppSettings["ReserveRoomActivityName"]; 108 | ReserveRoomExecuteAddress = new Uri(ConfigurationManager.AppSettings["ReserveRoomExecuteAddress"]); 109 | } 110 | 111 | public string FetchAvatarActivityName { get; } 112 | 113 | public Uri FetchAvatarExecuteAddress { get; } 114 | public string ReserveRoomActivityName { get; } 115 | public Uri ReserveRoomExecuteAddress { get; } 116 | } 117 | 118 | 119 | class FetchAvatarSettings : 120 | FetchAvatarActivitySettings 121 | { 122 | public FetchAvatarSettings() 123 | { 124 | CacheFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avatars"); 125 | 126 | Directory.CreateDirectory(CacheFolderPath); 127 | } 128 | 129 | public string CacheFolderPath { get; } 130 | } 131 | } 132 | } -------------------------------------------------------------------------------- /src/BookingService/BookingService.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {23F088E8-6486-4923-9E77-36EFA1820E27} 8 | Exe 9 | Properties 10 | BookingService 11 | BookingService 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | 36 | ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll 37 | True 38 | 39 | 40 | ..\packages\MassTransit.3.1.2\lib\net45\MassTransit.dll 41 | True 42 | 43 | 44 | ..\packages\MassTransit.Log4Net.3.1.2\lib\net45\MassTransit.Log4NetIntegration.dll 45 | True 46 | 47 | 48 | ..\packages\MassTransit.RabbitMQ.3.1.2\lib\net45\MassTransit.RabbitMqTransport.dll 49 | True 50 | 51 | 52 | ..\packages\NewId.2.1.3\lib\net45\NewId.dll 53 | True 54 | 55 | 56 | ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll 57 | True 58 | 59 | 60 | ..\packages\RabbitMQ.Client.3.6.0\lib\net45\RabbitMQ.Client.dll 61 | True 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | ..\packages\Topshelf.3.3.1\lib\net40-full\Topshelf.dll 71 | True 72 | 73 | 74 | ..\packages\Topshelf.Log4Net.3.3.1\lib\net40-full\Topshelf.Log4Net.dll 75 | True 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4} 90 | Booking.Activities 91 | 92 | 93 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA} 94 | Booking.Services 95 | 96 | 97 | 98 | 105 | -------------------------------------------------------------------------------- /src/BookingService/Program.cs: -------------------------------------------------------------------------------- 1 | namespace BookingService 2 | { 3 | using System.IO; 4 | using System.Text; 5 | using log4net.Config; 6 | using MassTransit.Log4NetIntegration.Logging; 7 | using Topshelf; 8 | using Topshelf.Logging; 9 | 10 | 11 | class Program 12 | { 13 | static int Main(string[] args) 14 | { 15 | ConfigureLogger(); 16 | 17 | // Topshelf to use Log4Net 18 | Log4NetLogWriterFactory.Use(); 19 | 20 | // MassTransit to use Log4Net 21 | Log4NetLogger.Use(); 22 | 23 | return (int)HostFactory.Run(x => x.Service()); 24 | } 25 | 26 | static void ConfigureLogger() 27 | { 28 | const string logConfig = @" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | "; 43 | 44 | using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(logConfig))) 45 | { 46 | XmlConfigurator.Configure(stream); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/BookingService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BookingService")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BookingService")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("23f088e8-6486-4923-9e77-36efa1820e27")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/BookingService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/BookingWeb/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Optimization; 3 | 4 | namespace BookingWeb 5 | { 6 | public class BundleConfig 7 | { 8 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 9 | public static void RegisterBundles(BundleCollection bundles) 10 | { 11 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 12 | "~/Scripts/jquery-{version}.js")); 13 | 14 | // Use the development version of Modernizr to develop with and learn from. Then, when you're 15 | // ready for production, use the build tool at http://modernizr.com to pick only the tests you need. 16 | bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( 17 | "~/Scripts/modernizr-*")); 18 | 19 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 20 | "~/Scripts/bootstrap.js", 21 | "~/Scripts/respond.js")); 22 | 23 | bundles.Add(new StyleBundle("~/Content/css").Include( 24 | "~/Content/bootstrap.css", 25 | "~/Content/site.css")); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/BookingWeb/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | using System.Web; 2 | using System.Web.Mvc; 3 | 4 | namespace BookingWeb 5 | { 6 | public class FilterConfig 7 | { 8 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 9 | { 10 | filters.Add(new HandleErrorAttribute()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/BookingWeb/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Mvc; 6 | using System.Web.Routing; 7 | 8 | namespace BookingWeb 9 | { 10 | public class RouteConfig 11 | { 12 | public static void RegisterRoutes(RouteCollection routes) 13 | { 14 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 15 | 16 | routes.MapRoute( 17 | name: "Default", 18 | url: "{controller}/{action}/{id}", 19 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 20 | ); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/BookingWeb/App_Start/Startup.Auth.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb 2 | { 3 | using Owin; 4 | 5 | 6 | public partial class Startup 7 | { 8 | public void ConfigureAuth(IAppBuilder app) 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BookingWeb/App_Start/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb 2 | { 3 | using System.Web.Http; 4 | 5 | 6 | public static class WebApiConfig 7 | { 8 | public static void Register(HttpConfiguration config) 9 | { 10 | // Web API routes 11 | config.MapHttpAttributeRoutes(); 12 | 13 | config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional} 14 | ); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ApiDescriptionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Web; 4 | using System.Web.Http.Description; 5 | 6 | namespace BookingWeb.Areas.HelpPage 7 | { 8 | public static class ApiDescriptionExtensions 9 | { 10 | /// 11 | /// Generates an URI-friendly ID for the . E.g. "Get-Values-id_name" instead of "GetValues/{id}?name={name}" 12 | /// 13 | /// The . 14 | /// The ID as a string. 15 | public static string GetFriendlyId(this ApiDescription description) 16 | { 17 | string path = description.RelativePath; 18 | string[] urlParts = path.Split('?'); 19 | string localPath = urlParts[0]; 20 | string queryKeyString = null; 21 | if (urlParts.Length > 1) 22 | { 23 | string query = urlParts[1]; 24 | string[] queryKeys = HttpUtility.ParseQueryString(query).AllKeys; 25 | queryKeyString = String.Join("_", queryKeys); 26 | } 27 | 28 | StringBuilder friendlyPath = new StringBuilder(); 29 | friendlyPath.AppendFormat("{0}-{1}", 30 | description.HttpMethod.Method, 31 | localPath.Replace("/", "-").Replace("{", String.Empty).Replace("}", String.Empty)); 32 | if (queryKeyString != null) 33 | { 34 | friendlyPath.AppendFormat("_{0}", queryKeyString.Replace('.', '-')); 35 | } 36 | return friendlyPath.ToString(); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/App_Start/HelpPageConfig.cs: -------------------------------------------------------------------------------- 1 | // Uncomment the following to provide samples for PageResult. Must also add the Microsoft.AspNet.WebApi.OData 2 | // package to your project. 3 | ////#define Handle_PageResultOfT 4 | 5 | using System; 6 | using System.Collections; 7 | using System.Collections.Generic; 8 | using System.Diagnostics; 9 | using System.Diagnostics.CodeAnalysis; 10 | using System.Linq; 11 | using System.Net.Http.Headers; 12 | using System.Reflection; 13 | using System.Web; 14 | using System.Web.Http; 15 | #if Handle_PageResultOfT 16 | using System.Web.Http.OData; 17 | #endif 18 | 19 | namespace BookingWeb.Areas.HelpPage 20 | { 21 | /// 22 | /// Use this class to customize the Help Page. 23 | /// For example you can set a custom to supply the documentation 24 | /// or you can provide the samples for the requests/responses. 25 | /// 26 | public static class HelpPageConfig 27 | { 28 | [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", 29 | MessageId = "BookingWeb.Areas.HelpPage.TextSample.#ctor(System.String)", 30 | Justification = "End users may choose to merge this string with existing localized resources.")] 31 | [SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", 32 | MessageId = "bsonspec", 33 | Justification = "Part of a URI.")] 34 | public static void Register(HttpConfiguration config) 35 | { 36 | //// Uncomment the following to use the documentation from XML documentation file. 37 | //config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 38 | 39 | //// Uncomment the following to use "sample string" as the sample for all actions that have string as the body parameter or return type. 40 | //// Also, the string arrays will be used for IEnumerable. The sample objects will be serialized into different media type 41 | //// formats by the available formatters. 42 | //config.SetSampleObjects(new Dictionary 43 | //{ 44 | // {typeof(string), "sample string"}, 45 | // {typeof(IEnumerable), new string[]{"sample 1", "sample 2"}} 46 | //}); 47 | 48 | // Extend the following to provide factories for types not handled automatically (those lacking parameterless 49 | // constructors) or for which you prefer to use non-default property values. Line below provides a fallback 50 | // since automatic handling will fail and GeneratePageResult handles only a single type. 51 | #if Handle_PageResultOfT 52 | config.GetHelpPageSampleGenerator().SampleObjectFactories.Add(GeneratePageResult); 53 | #endif 54 | 55 | // Extend the following to use a preset object directly as the sample for all actions that support a media 56 | // type, regardless of the body parameter or return type. The lines below avoid display of binary content. 57 | // The BsonMediaTypeFormatter (if available) is not used to serialize the TextSample object. 58 | config.SetSampleForMediaType( 59 | new TextSample("Binary JSON content. See http://bsonspec.org for details."), 60 | new MediaTypeHeaderValue("application/bson")); 61 | 62 | //// Uncomment the following to use "[0]=foo&[1]=bar" directly as the sample for all actions that support form URL encoded format 63 | //// and have IEnumerable as the body parameter or return type. 64 | //config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable)); 65 | 66 | //// Uncomment the following to use "1234" directly as the request sample for media type "text/plain" on the controller named "Values" 67 | //// and action named "Put". 68 | //config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put"); 69 | 70 | //// Uncomment the following to use the image on "../images/aspNetHome.png" directly as the response sample for media type "image/png" 71 | //// on the controller named "Values" and action named "Get" with parameter "id". 72 | //config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id"); 73 | 74 | //// Uncomment the following to correct the sample request when the action expects an HttpRequestMessage with ObjectContent. 75 | //// The sample will be generated as if the controller named "Values" and action named "Get" were having string as the body parameter. 76 | //config.SetActualRequestType(typeof(string), "Values", "Get"); 77 | 78 | //// Uncomment the following to correct the sample response when the action returns an HttpResponseMessage with ObjectContent. 79 | //// The sample will be generated as if the controller named "Values" and action named "Post" were returning a string. 80 | //config.SetActualResponseType(typeof(string), "Values", "Post"); 81 | } 82 | 83 | #if Handle_PageResultOfT 84 | private static object GeneratePageResult(HelpPageSampleGenerator sampleGenerator, Type type) 85 | { 86 | if (type.IsGenericType) 87 | { 88 | Type openGenericType = type.GetGenericTypeDefinition(); 89 | if (openGenericType == typeof(PageResult<>)) 90 | { 91 | // Get the T in PageResult 92 | Type[] typeParameters = type.GetGenericArguments(); 93 | Debug.Assert(typeParameters.Length == 1); 94 | 95 | // Create an enumeration to pass as the first parameter to the PageResult constuctor 96 | Type itemsType = typeof(List<>).MakeGenericType(typeParameters); 97 | object items = sampleGenerator.GetSampleObject(itemsType); 98 | 99 | // Fill in the other information needed to invoke the PageResult constuctor 100 | Type[] parameterTypes = new Type[] { itemsType, typeof(Uri), typeof(long?), }; 101 | object[] parameters = new object[] { items, null, (long)ObjectGenerator.DefaultCollectionSize, }; 102 | 103 | // Call PageResult(IEnumerable items, Uri nextPageLink, long? count) constructor 104 | ConstructorInfo constructor = type.GetConstructor(parameterTypes); 105 | return constructor.Invoke(parameters); 106 | } 107 | } 108 | 109 | return null; 110 | } 111 | #endif 112 | } 113 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Controllers/HelpController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Web.Http; 3 | using System.Web.Mvc; 4 | using BookingWeb.Areas.HelpPage.ModelDescriptions; 5 | using BookingWeb.Areas.HelpPage.Models; 6 | 7 | namespace BookingWeb.Areas.HelpPage.Controllers 8 | { 9 | /// 10 | /// The controller that will handle requests for the help page. 11 | /// 12 | public class HelpController : Controller 13 | { 14 | private const string ErrorViewName = "Error"; 15 | 16 | public HelpController() 17 | : this(GlobalConfiguration.Configuration) 18 | { 19 | } 20 | 21 | public HelpController(HttpConfiguration config) 22 | { 23 | Configuration = config; 24 | } 25 | 26 | public HttpConfiguration Configuration { get; private set; } 27 | 28 | public ActionResult Index() 29 | { 30 | ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider(); 31 | return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 32 | } 33 | 34 | public ActionResult Api(string apiId) 35 | { 36 | if (!String.IsNullOrEmpty(apiId)) 37 | { 38 | HelpPageApiModel apiModel = Configuration.GetHelpPageApiModel(apiId); 39 | if (apiModel != null) 40 | { 41 | return View(apiModel); 42 | } 43 | } 44 | 45 | return View(ErrorViewName); 46 | } 47 | 48 | public ActionResult ResourceModel(string modelName) 49 | { 50 | if (!String.IsNullOrEmpty(modelName)) 51 | { 52 | ModelDescriptionGenerator modelDescriptionGenerator = Configuration.GetModelDescriptionGenerator(); 53 | ModelDescription modelDescription; 54 | if (modelDescriptionGenerator.GeneratedModels.TryGetValue(modelName, out modelDescription)) 55 | { 56 | return View(modelDescription); 57 | } 58 | } 59 | 60 | return View(ErrorViewName); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/HelpPage.css: -------------------------------------------------------------------------------- 1 | .help-page h1, 2 | .help-page .h1, 3 | .help-page h2, 4 | .help-page .h2, 5 | .help-page h3, 6 | .help-page .h3, 7 | #body.help-page, 8 | .help-page-table th, 9 | .help-page-table pre, 10 | .help-page-table p { 11 | font-family: "Segoe UI Light", Frutiger, "Frutiger Linotype", "Dejavu Sans", "Helvetica Neue", Arial, sans-serif; 12 | } 13 | 14 | .help-page pre.wrapped { 15 | white-space: -moz-pre-wrap; 16 | white-space: -pre-wrap; 17 | white-space: -o-pre-wrap; 18 | white-space: pre-wrap; 19 | } 20 | 21 | .help-page .warning-message-container { 22 | margin-top: 20px; 23 | padding: 0 10px; 24 | color: #525252; 25 | background: #EFDCA9; 26 | border: 1px solid #CCCCCC; 27 | } 28 | 29 | .help-page-table { 30 | width: 100%; 31 | border-collapse: collapse; 32 | text-align: left; 33 | margin: 0px 0px 20px 0px; 34 | border-top: 1px solid #D4D4D4; 35 | } 36 | 37 | .help-page-table th { 38 | text-align: left; 39 | font-weight: bold; 40 | border-bottom: 1px solid #D4D4D4; 41 | padding: 5px 6px 5px 6px; 42 | } 43 | 44 | .help-page-table td { 45 | border-bottom: 1px solid #D4D4D4; 46 | padding: 10px 8px 10px 8px; 47 | vertical-align: top; 48 | } 49 | 50 | .help-page-table pre, 51 | .help-page-table p { 52 | margin: 0px; 53 | padding: 0px; 54 | font-family: inherit; 55 | font-size: 100%; 56 | } 57 | 58 | .help-page-table tbody tr:hover td { 59 | background-color: #F3F3F3; 60 | } 61 | 62 | .help-page a:hover { 63 | background-color: transparent; 64 | } 65 | 66 | .help-page .sample-header { 67 | border: 2px solid #D4D4D4; 68 | background: #00497E; 69 | color: #FFFFFF; 70 | padding: 8px 15px; 71 | border-bottom: none; 72 | display: inline-block; 73 | margin: 10px 0px 0px 0px; 74 | } 75 | 76 | .help-page .sample-content { 77 | display: block; 78 | border-width: 0; 79 | padding: 15px 20px; 80 | background: #FFFFFF; 81 | border: 2px solid #D4D4D4; 82 | margin: 0px 0px 10px 0px; 83 | } 84 | 85 | .help-page .api-name { 86 | width: 40%; 87 | } 88 | 89 | .help-page .api-documentation { 90 | width: 60%; 91 | } 92 | 93 | .help-page .parameter-name { 94 | width: 20%; 95 | } 96 | 97 | .help-page .parameter-documentation { 98 | width: 40%; 99 | } 100 | 101 | .help-page .parameter-type { 102 | width: 20%; 103 | } 104 | 105 | .help-page .parameter-annotations { 106 | width: 20%; 107 | } 108 | 109 | .help-page h1, 110 | .help-page .h1 { 111 | font-size: 36px; 112 | line-height: normal; 113 | } 114 | 115 | .help-page h2, 116 | .help-page .h2 { 117 | font-size: 24px; 118 | } 119 | 120 | .help-page h3, 121 | .help-page .h3 { 122 | font-size: 20px; 123 | } 124 | 125 | #body.help-page { 126 | font-size: 14px; 127 | line-height: 143%; 128 | color: #333; 129 | } 130 | 131 | .help-page a { 132 | color: #0000EE; 133 | text-decoration: none; 134 | } 135 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/HelpPageAreaRegistration.cs: -------------------------------------------------------------------------------- 1 | using System.Web.Http; 2 | using System.Web.Mvc; 3 | 4 | namespace BookingWeb.Areas.HelpPage 5 | { 6 | public class HelpPageAreaRegistration : AreaRegistration 7 | { 8 | public override string AreaName 9 | { 10 | get 11 | { 12 | return "HelpPage"; 13 | } 14 | } 15 | 16 | public override void RegisterArea(AreaRegistrationContext context) 17 | { 18 | context.MapRoute( 19 | "HelpPage_Default", 20 | "Help/{action}/{apiId}", 21 | new { controller = "Help", action = "Index", apiId = UrlParameter.Optional }); 22 | 23 | HelpPageConfig.Register(GlobalConfiguration.Configuration); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/CollectionModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class CollectionModelDescription : ModelDescription 4 | { 5 | public ModelDescription ElementDescription { get; set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ComplexTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ComplexTypeModelDescription : ModelDescription 6 | { 7 | public ComplexTypeModelDescription() 8 | { 9 | Properties = new Collection(); 10 | } 11 | 12 | public Collection Properties { get; private set; } 13 | } 14 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/DictionaryModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class DictionaryModelDescription : KeyValuePairModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/EnumTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class EnumTypeModelDescription : ModelDescription 7 | { 8 | public EnumTypeModelDescription() 9 | { 10 | Values = new Collection(); 11 | } 12 | 13 | public Collection Values { get; private set; } 14 | } 15 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/EnumValueDescription.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class EnumValueDescription 4 | { 5 | public string Documentation { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string Value { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/IModelDocumentationProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 5 | { 6 | public interface IModelDocumentationProvider 7 | { 8 | string GetDocumentation(MemberInfo member); 9 | 10 | string GetDocumentation(Type type); 11 | } 12 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/KeyValuePairModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class KeyValuePairModelDescription : ModelDescription 4 | { 5 | public ModelDescription KeyModelDescription { get; set; } 6 | 7 | public ModelDescription ValueModelDescription { get; set; } 8 | } 9 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ModelDescription.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Describes a type model. 7 | /// 8 | public abstract class ModelDescription 9 | { 10 | public string Documentation { get; set; } 11 | 12 | public Type ModelType { get; set; } 13 | 14 | public string Name { get; set; } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ModelNameAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 4 | { 5 | /// 6 | /// Use this attribute to change the name of the generated for a type. 7 | /// 8 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum, AllowMultiple = false, Inherited = false)] 9 | public sealed class ModelNameAttribute : Attribute 10 | { 11 | public ModelNameAttribute(string name) 12 | { 13 | Name = name; 14 | } 15 | 16 | public string Name { get; private set; } 17 | } 18 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ModelNameHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Linq; 4 | using System.Reflection; 5 | 6 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 7 | { 8 | internal static class ModelNameHelper 9 | { 10 | // Modify this to provide custom model name mapping. 11 | public static string GetModelName(Type type) 12 | { 13 | ModelNameAttribute modelNameAttribute = type.GetCustomAttribute(); 14 | if (modelNameAttribute != null && !String.IsNullOrEmpty(modelNameAttribute.Name)) 15 | { 16 | return modelNameAttribute.Name; 17 | } 18 | 19 | string modelName = type.Name; 20 | if (type.IsGenericType) 21 | { 22 | // Format the generic type name to something like: GenericOfAgurment1AndArgument2 23 | Type genericType = type.GetGenericTypeDefinition(); 24 | Type[] genericArguments = type.GetGenericArguments(); 25 | string genericTypeName = genericType.Name; 26 | 27 | // Trim the generic parameter counts from the name 28 | genericTypeName = genericTypeName.Substring(0, genericTypeName.IndexOf('`')); 29 | string[] argumentTypeNames = genericArguments.Select(t => GetModelName(t)).ToArray(); 30 | modelName = String.Format(CultureInfo.InvariantCulture, "{0}Of{1}", genericTypeName, String.Join("And", argumentTypeNames)); 31 | } 32 | 33 | return modelName; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ParameterAnnotation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 4 | { 5 | public class ParameterAnnotation 6 | { 7 | public Attribute AnnotationAttribute { get; set; } 8 | 9 | public string Documentation { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/ParameterDescription.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | 4 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 5 | { 6 | public class ParameterDescription 7 | { 8 | public ParameterDescription() 9 | { 10 | Annotations = new Collection(); 11 | } 12 | 13 | public Collection Annotations { get; private set; } 14 | 15 | public string Documentation { get; set; } 16 | 17 | public string Name { get; set; } 18 | 19 | public ModelDescription TypeDescription { get; set; } 20 | } 21 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/ModelDescriptions/SimpleTypeModelDescription.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage.ModelDescriptions 2 | { 3 | public class SimpleTypeModelDescription : ModelDescription 4 | { 5 | } 6 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Models/HelpPageApiModel.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Collections.ObjectModel; 3 | using System.Net.Http.Headers; 4 | using System.Web.Http.Description; 5 | using BookingWeb.Areas.HelpPage.ModelDescriptions; 6 | 7 | namespace BookingWeb.Areas.HelpPage.Models 8 | { 9 | /// 10 | /// The model that represents an API displayed on the help page. 11 | /// 12 | public class HelpPageApiModel 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public HelpPageApiModel() 18 | { 19 | UriParameters = new Collection(); 20 | SampleRequests = new Dictionary(); 21 | SampleResponses = new Dictionary(); 22 | ErrorMessages = new Collection(); 23 | } 24 | 25 | /// 26 | /// Gets or sets the that describes the API. 27 | /// 28 | public ApiDescription ApiDescription { get; set; } 29 | 30 | /// 31 | /// Gets or sets the collection that describes the URI parameters for the API. 32 | /// 33 | public Collection UriParameters { get; private set; } 34 | 35 | /// 36 | /// Gets or sets the documentation for the request. 37 | /// 38 | public string RequestDocumentation { get; set; } 39 | 40 | /// 41 | /// Gets or sets the that describes the request body. 42 | /// 43 | public ModelDescription RequestModelDescription { get; set; } 44 | 45 | /// 46 | /// Gets the request body parameter descriptions. 47 | /// 48 | public IList RequestBodyParameters 49 | { 50 | get 51 | { 52 | return GetParameterDescriptions(RequestModelDescription); 53 | } 54 | } 55 | 56 | /// 57 | /// Gets or sets the that describes the resource. 58 | /// 59 | public ModelDescription ResourceDescription { get; set; } 60 | 61 | /// 62 | /// Gets the resource property descriptions. 63 | /// 64 | public IList ResourceProperties 65 | { 66 | get 67 | { 68 | return GetParameterDescriptions(ResourceDescription); 69 | } 70 | } 71 | 72 | /// 73 | /// Gets the sample requests associated with the API. 74 | /// 75 | public IDictionary SampleRequests { get; private set; } 76 | 77 | /// 78 | /// Gets the sample responses associated with the API. 79 | /// 80 | public IDictionary SampleResponses { get; private set; } 81 | 82 | /// 83 | /// Gets the error messages associated with this model. 84 | /// 85 | public Collection ErrorMessages { get; private set; } 86 | 87 | private static IList GetParameterDescriptions(ModelDescription modelDescription) 88 | { 89 | ComplexTypeModelDescription complexTypeModelDescription = modelDescription as ComplexTypeModelDescription; 90 | if (complexTypeModelDescription != null) 91 | { 92 | return complexTypeModelDescription.Properties; 93 | } 94 | 95 | CollectionModelDescription collectionModelDescription = modelDescription as CollectionModelDescription; 96 | if (collectionModelDescription != null) 97 | { 98 | complexTypeModelDescription = collectionModelDescription.ElementDescription as ComplexTypeModelDescription; 99 | if (complexTypeModelDescription != null) 100 | { 101 | return complexTypeModelDescription.Properties; 102 | } 103 | } 104 | 105 | return null; 106 | } 107 | } 108 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/SampleGeneration/HelpPageSampleKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Net.Http.Headers; 5 | 6 | namespace BookingWeb.Areas.HelpPage 7 | { 8 | /// 9 | /// This is used to identify the place where the sample should be applied. 10 | /// 11 | public class HelpPageSampleKey 12 | { 13 | /// 14 | /// Creates a new based on media type. 15 | /// 16 | /// The media type. 17 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType) 18 | { 19 | if (mediaType == null) 20 | { 21 | throw new ArgumentNullException("mediaType"); 22 | } 23 | 24 | ActionName = String.Empty; 25 | ControllerName = String.Empty; 26 | MediaType = mediaType; 27 | ParameterNames = new HashSet(StringComparer.OrdinalIgnoreCase); 28 | } 29 | 30 | /// 31 | /// Creates a new based on media type and CLR type. 32 | /// 33 | /// The media type. 34 | /// The CLR type. 35 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, Type type) 36 | : this(mediaType) 37 | { 38 | if (type == null) 39 | { 40 | throw new ArgumentNullException("type"); 41 | } 42 | 43 | ParameterType = type; 44 | } 45 | 46 | /// 47 | /// Creates a new based on , controller name, action name and parameter names. 48 | /// 49 | /// The . 50 | /// Name of the controller. 51 | /// Name of the action. 52 | /// The parameter names. 53 | public HelpPageSampleKey(SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 54 | { 55 | if (!Enum.IsDefined(typeof(SampleDirection), sampleDirection)) 56 | { 57 | throw new InvalidEnumArgumentException("sampleDirection", (int)sampleDirection, typeof(SampleDirection)); 58 | } 59 | if (controllerName == null) 60 | { 61 | throw new ArgumentNullException("controllerName"); 62 | } 63 | if (actionName == null) 64 | { 65 | throw new ArgumentNullException("actionName"); 66 | } 67 | if (parameterNames == null) 68 | { 69 | throw new ArgumentNullException("parameterNames"); 70 | } 71 | 72 | ControllerName = controllerName; 73 | ActionName = actionName; 74 | ParameterNames = new HashSet(parameterNames, StringComparer.OrdinalIgnoreCase); 75 | SampleDirection = sampleDirection; 76 | } 77 | 78 | /// 79 | /// Creates a new based on media type, , controller name, action name and parameter names. 80 | /// 81 | /// The media type. 82 | /// The . 83 | /// Name of the controller. 84 | /// Name of the action. 85 | /// The parameter names. 86 | public HelpPageSampleKey(MediaTypeHeaderValue mediaType, SampleDirection sampleDirection, string controllerName, string actionName, IEnumerable parameterNames) 87 | : this(sampleDirection, controllerName, actionName, parameterNames) 88 | { 89 | if (mediaType == null) 90 | { 91 | throw new ArgumentNullException("mediaType"); 92 | } 93 | 94 | MediaType = mediaType; 95 | } 96 | 97 | /// 98 | /// Gets the name of the controller. 99 | /// 100 | /// 101 | /// The name of the controller. 102 | /// 103 | public string ControllerName { get; private set; } 104 | 105 | /// 106 | /// Gets the name of the action. 107 | /// 108 | /// 109 | /// The name of the action. 110 | /// 111 | public string ActionName { get; private set; } 112 | 113 | /// 114 | /// Gets the media type. 115 | /// 116 | /// 117 | /// The media type. 118 | /// 119 | public MediaTypeHeaderValue MediaType { get; private set; } 120 | 121 | /// 122 | /// Gets the parameter names. 123 | /// 124 | public HashSet ParameterNames { get; private set; } 125 | 126 | public Type ParameterType { get; private set; } 127 | 128 | /// 129 | /// Gets the . 130 | /// 131 | public SampleDirection? SampleDirection { get; private set; } 132 | 133 | public override bool Equals(object obj) 134 | { 135 | HelpPageSampleKey otherKey = obj as HelpPageSampleKey; 136 | if (otherKey == null) 137 | { 138 | return false; 139 | } 140 | 141 | return String.Equals(ControllerName, otherKey.ControllerName, StringComparison.OrdinalIgnoreCase) && 142 | String.Equals(ActionName, otherKey.ActionName, StringComparison.OrdinalIgnoreCase) && 143 | (MediaType == otherKey.MediaType || (MediaType != null && MediaType.Equals(otherKey.MediaType))) && 144 | ParameterType == otherKey.ParameterType && 145 | SampleDirection == otherKey.SampleDirection && 146 | ParameterNames.SetEquals(otherKey.ParameterNames); 147 | } 148 | 149 | public override int GetHashCode() 150 | { 151 | int hashCode = ControllerName.ToUpperInvariant().GetHashCode() ^ ActionName.ToUpperInvariant().GetHashCode(); 152 | if (MediaType != null) 153 | { 154 | hashCode ^= MediaType.GetHashCode(); 155 | } 156 | if (SampleDirection != null) 157 | { 158 | hashCode ^= SampleDirection.GetHashCode(); 159 | } 160 | if (ParameterType != null) 161 | { 162 | hashCode ^= ParameterType.GetHashCode(); 163 | } 164 | foreach (string parameterName in ParameterNames) 165 | { 166 | hashCode ^= parameterName.ToUpperInvariant().GetHashCode(); 167 | } 168 | 169 | return hashCode; 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/SampleGeneration/ImageSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an image sample on the help page. There's a display template named ImageSample associated with this class. 7 | /// 8 | public class ImageSample 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The URL of an image. 14 | public ImageSample(string src) 15 | { 16 | if (src == null) 17 | { 18 | throw new ArgumentNullException("src"); 19 | } 20 | Src = src; 21 | } 22 | 23 | public string Src { get; private set; } 24 | 25 | public override bool Equals(object obj) 26 | { 27 | ImageSample other = obj as ImageSample; 28 | return other != null && Src == other.Src; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return Src.GetHashCode(); 34 | } 35 | 36 | public override string ToString() 37 | { 38 | return Src; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/SampleGeneration/InvalidSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents an invalid sample on the help page. There's a display template named InvalidSample associated with this class. 7 | /// 8 | public class InvalidSample 9 | { 10 | public InvalidSample(string errorMessage) 11 | { 12 | if (errorMessage == null) 13 | { 14 | throw new ArgumentNullException("errorMessage"); 15 | } 16 | ErrorMessage = errorMessage; 17 | } 18 | 19 | public string ErrorMessage { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | InvalidSample other = obj as InvalidSample; 24 | return other != null && ErrorMessage == other.ErrorMessage; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return ErrorMessage.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return ErrorMessage; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/SampleGeneration/SampleDirection.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Areas.HelpPage 2 | { 3 | /// 4 | /// Indicates whether the sample is used for request or response 5 | /// 6 | public enum SampleDirection 7 | { 8 | Request = 0, 9 | Response 10 | } 11 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/SampleGeneration/TextSample.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace BookingWeb.Areas.HelpPage 4 | { 5 | /// 6 | /// This represents a preformatted text sample on the help page. There's a display template named TextSample associated with this class. 7 | /// 8 | public class TextSample 9 | { 10 | public TextSample(string text) 11 | { 12 | if (text == null) 13 | { 14 | throw new ArgumentNullException("text"); 15 | } 16 | Text = text; 17 | } 18 | 19 | public string Text { get; private set; } 20 | 21 | public override bool Equals(object obj) 22 | { 23 | TextSample other = obj as TextSample; 24 | return other != null && Text == other.Text; 25 | } 26 | 27 | public override int GetHashCode() 28 | { 29 | return Text.GetHashCode(); 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Text; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/Api.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using BookingWeb.Areas.HelpPage.Models 3 | @model HelpPageApiModel 4 | 5 | @{ 6 | var description = Model.ApiDescription; 7 | ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; 8 | } 9 | 10 | 11 |
12 | 19 |
20 | @Html.DisplayForModel() 21 |
22 |
23 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/ApiGroup.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using BookingWeb.Areas.HelpPage 5 | @using BookingWeb.Areas.HelpPage.Models 6 | @model IGrouping 7 | 8 | @{ 9 | var controllerDocumentation = ViewBag.DocumentationProvider != null ? 10 | ViewBag.DocumentationProvider.GetDocumentation(Model.Key) : 11 | null; 12 | } 13 | 14 |

@Model.Key.ControllerName

15 | @if (!String.IsNullOrEmpty(controllerDocumentation)) 16 | { 17 |

@controllerDocumentation

18 | } 19 | 20 | 21 | 22 | 23 | 24 | @foreach (var api in Model) 25 | { 26 | 27 | 28 | 38 | 39 | } 40 | 41 |
APIDescription
@api.HttpMethod.Method @api.RelativePath 29 | @if (api.Documentation != null) 30 | { 31 |

@api.Documentation

32 | } 33 | else 34 | { 35 |

No documentation available.

36 | } 37 |
-------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/CollectionModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model CollectionModelDescription 3 | @if (Model.ElementDescription is ComplexTypeModelDescription) 4 | { 5 | @Html.DisplayFor(m => m.ElementDescription) 6 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/ComplexTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model ComplexTypeModelDescription 3 | @Html.DisplayFor(m => m.Properties, "Parameters") -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/DictionaryModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model DictionaryModelDescription 3 | Dictionary of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/EnumTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model EnumTypeModelDescription 3 | 4 |

Possible enumeration values:

5 | 6 | 7 | 8 | 9 | 10 | 11 | @foreach (EnumValueDescription value in Model.Values) 12 | { 13 | 14 | 15 | 18 | 21 | 22 | } 23 | 24 |
NameValueDescription
@value.Name 16 |

@value.Value

17 |
19 |

@value.Documentation

20 |
-------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/HelpPageApiModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Description 3 | @using BookingWeb.Areas.HelpPage.Models 4 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 5 | @model HelpPageApiModel 6 | 7 | @{ 8 | ApiDescription description = Model.ApiDescription; 9 | } 10 |

@description.HttpMethod.Method @description.RelativePath

11 |
12 |

@description.Documentation

13 | 14 |

Request Information

15 | 16 |

URI Parameters

17 | @Html.DisplayFor(m => m.UriParameters, "Parameters") 18 | 19 |

Body Parameters

20 | 21 |

@Model.RequestDocumentation

22 | 23 | @if (Model.RequestModelDescription != null) 24 | { 25 | @Html.DisplayFor(m => m.RequestModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.RequestModelDescription }) 26 | if (Model.RequestBodyParameters != null) 27 | { 28 | @Html.DisplayFor(m => m.RequestBodyParameters, "Parameters") 29 | } 30 | } 31 | else 32 | { 33 |

None.

34 | } 35 | 36 | @if (Model.SampleRequests.Count > 0) 37 | { 38 |

Request Formats

39 | @Html.DisplayFor(m => m.SampleRequests, "Samples") 40 | } 41 | 42 |

Response Information

43 | 44 |

Resource Description

45 | 46 |

@description.ResponseDescription.Documentation

47 | 48 | @if (Model.ResourceDescription != null) 49 | { 50 | @Html.DisplayFor(m => m.ResourceDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ResourceDescription }) 51 | if (Model.ResourceProperties != null) 52 | { 53 | @Html.DisplayFor(m => m.ResourceProperties, "Parameters") 54 | } 55 | } 56 | else 57 | { 58 |

None.

59 | } 60 | 61 | @if (Model.SampleResponses.Count > 0) 62 | { 63 |

Response Formats

64 | @Html.DisplayFor(m => m.SampleResponses, "Samples") 65 | } 66 | 67 |
-------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/ImageSample.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage 2 | @model ImageSample 3 | 4 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/InvalidSample.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage 2 | @model InvalidSample 3 | 4 | @if (HttpContext.Current.IsDebuggingEnabled) 5 | { 6 |
7 |

@Model.ErrorMessage

8 |
9 | } 10 | else 11 | { 12 |

Sample not available.

13 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/KeyValuePairModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model KeyValuePairModelDescription 3 | Pair of @Html.DisplayFor(m => Model.KeyModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.KeyModelDescription }) [key] 4 | and @Html.DisplayFor(m => Model.ValueModelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = Model.ValueModelDescription }) [value] -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/ModelDescriptionLink.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model Type 3 | @{ 4 | ModelDescription modelDescription = ViewBag.modelDescription; 5 | if (modelDescription is ComplexTypeModelDescription || modelDescription is EnumTypeModelDescription) 6 | { 7 | if (Model == typeof(Object)) 8 | { 9 | @:Object 10 | } 11 | else 12 | { 13 | @Html.ActionLink(modelDescription.Name, "ResourceModel", "Help", new { modelName = modelDescription.Name }, null) 14 | } 15 | } 16 | else if (modelDescription is CollectionModelDescription) 17 | { 18 | var collectionDescription = modelDescription as CollectionModelDescription; 19 | var elementDescription = collectionDescription.ElementDescription; 20 | @:Collection of @Html.DisplayFor(m => elementDescription.ModelType, "ModelDescriptionLink", new { modelDescription = elementDescription }) 21 | } 22 | else 23 | { 24 | @Html.DisplayFor(m => modelDescription) 25 | } 26 | } -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Collections.Generic 2 | @using System.Collections.ObjectModel 3 | @using System.Web.Http.Description 4 | @using System.Threading 5 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 6 | @model IList 7 | 8 | @if (Model.Count > 0) 9 | { 10 | 11 | 12 | 13 | 14 | 15 | @foreach (ParameterDescription parameter in Model) 16 | { 17 | ModelDescription modelDescription = parameter.TypeDescription; 18 | 19 | 20 | 23 | 26 | 39 | 40 | } 41 | 42 |
NameDescriptionTypeAdditional information
@parameter.Name 21 |

@parameter.Documentation

22 |
24 | @Html.DisplayFor(m => modelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = modelDescription }) 25 | 27 | @if (parameter.Annotations.Count > 0) 28 | { 29 | foreach (var annotation in parameter.Annotations) 30 | { 31 |

@annotation.Documentation

32 | } 33 | } 34 | else 35 | { 36 |

None.

37 | } 38 |
43 | } 44 | else 45 | { 46 |

None.

47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/Samples.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Net.Http.Headers 2 | @model Dictionary 3 | 4 | @{ 5 | // Group the samples into a single tab if they are the same. 6 | Dictionary samples = Model.GroupBy(pair => pair.Value).ToDictionary( 7 | pair => String.Join(", ", pair.Select(m => m.Key.ToString()).ToArray()), 8 | pair => pair.Key); 9 | var mediaTypes = samples.Keys; 10 | } 11 |
12 | @foreach (var mediaType in mediaTypes) 13 | { 14 |

@mediaType

15 |
16 | Sample: 17 | @{ 18 | var sample = samples[mediaType]; 19 | if (sample == null) 20 | { 21 |

Sample not available.

22 | } 23 | else 24 | { 25 | @Html.DisplayFor(s => sample); 26 | } 27 | } 28 |
29 | } 30 |
-------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/SimpleTypeModelDescription.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 2 | @model SimpleTypeModelDescription 3 | @Model.Documentation -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/DisplayTemplates/TextSample.cshtml: -------------------------------------------------------------------------------- 1 | @using BookingWeb.Areas.HelpPage 2 | @model TextSample 3 | 4 |
5 | @Model.Text
6 | 
-------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using System.Web.Http.Controllers 3 | @using System.Web.Http.Description 4 | @using System.Collections.ObjectModel 5 | @using BookingWeb.Areas.HelpPage.Models 6 | @model Collection 7 | 8 | @{ 9 | ViewBag.Title = "ASP.NET Web API Help Page"; 10 | 11 | // Group APIs by controller 12 | ILookup apiGroups = Model.ToLookup(api => api.ActionDescriptor.ControllerDescriptor); 13 | } 14 | 15 | 16 |
17 |
18 |
19 |

@ViewBag.Title

20 |
21 |
22 |
23 |
24 | 32 |
33 | @foreach (var group in apiGroups) 34 | { 35 | @Html.DisplayFor(m => group, "ApiGroup") 36 | } 37 |
38 |
39 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Help/ResourceModel.cshtml: -------------------------------------------------------------------------------- 1 | @using System.Web.Http 2 | @using BookingWeb.Areas.HelpPage.ModelDescriptions 3 | @model ModelDescription 4 | 5 | 6 |
7 | 14 |

@Model.Name

15 |

@Model.Documentation

16 |
17 | @Html.DisplayFor(m => Model) 18 |
19 |
20 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @RenderSection("scripts", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/BookingWeb/Areas/HelpPage/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | // Change the Layout path below to blend the look and feel of the help page with your existing web pages 3 | Layout = "~/Views/Shared/_Layout.cshtml"; 4 | } -------------------------------------------------------------------------------- /src/BookingWeb/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Set width on the form input elements since they're 100% wide by default */ 13 | input, 14 | select, 15 | textarea { 16 | max-width: 280px; 17 | } 18 | -------------------------------------------------------------------------------- /src/BookingWeb/Controllers/AcceptedActionResult.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Controllers 2 | { 3 | using System.Net; 4 | using System.Net.Http; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using System.Web.Http; 8 | 9 | 10 | public class AcceptedActionResult : 11 | IHttpActionResult 12 | { 13 | readonly HttpRequestMessage _request; 14 | readonly T _value; 15 | 16 | public AcceptedActionResult(HttpRequestMessage request, T value) 17 | { 18 | _request = request; 19 | _value = value; 20 | } 21 | 22 | public Task ExecuteAsync(CancellationToken cancellationToken) 23 | { 24 | var response = _request.CreateResponse(HttpStatusCode.Accepted, _value); 25 | 26 | return Task.FromResult(response); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/BookingWeb/Controllers/BookController.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Controllers 2 | { 3 | using System; 4 | using System.Configuration; 5 | using System.Threading.Tasks; 6 | using System.Web.Http; 7 | using Booking.Contracts.Commands; 8 | using MassTransit; 9 | using Models; 10 | 11 | 12 | public class BookController : 13 | EnhancedApiController 14 | { 15 | // POST api/book 16 | public async Task Post(BookingRequestModel model) 17 | { 18 | if (!ModelState.IsValid) 19 | return BadRequest(ModelState); 20 | 21 | if (model.BookingRequestId == Guid.Empty) 22 | model.BookingRequestId = NewId.NextGuid(); 23 | 24 | var address = ConfigurationManager.AppSettings["BookMeetingAddress"]; 25 | 26 | var endpoint = await WebApiApplication.Bus.GetSendEndpoint(new Uri(address)); 27 | 28 | var request = new BookMeetingCommand(model); 29 | 30 | await endpoint.Send(request); 31 | 32 | return Accepted(new BookingRequestResult 33 | { 34 | BookingRequestId = model.BookingRequestId, 35 | Timestamp = request.Timestamp 36 | }); 37 | } 38 | 39 | 40 | class BookMeetingCommand : 41 | BookMeeting 42 | { 43 | readonly BookingRequestModel _model; 44 | 45 | public BookMeetingCommand(BookingRequestModel model) 46 | { 47 | _model = model; 48 | 49 | Timestamp = DateTime.UtcNow; 50 | } 51 | 52 | public Guid BookingRequestId => _model.BookingRequestId; 53 | 54 | public DateTime Timestamp { get; } 55 | 56 | public string EmailAddress => _model.EmailAddress; 57 | public DateTime StartTime => _model.StartTime; 58 | public TimeSpan Duration => _model.Duration; 59 | public int RoomCapacity => _model.RoomCapacity; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /src/BookingWeb/Controllers/EnhancedApiController.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Controllers 2 | { 3 | using System.Web.Http; 4 | 5 | 6 | public abstract class EnhancedApiController : 7 | ApiController 8 | { 9 | protected IHttpActionResult Accepted(T value) 10 | { 11 | return new AcceptedActionResult(Request, value); 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/BookingWeb/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Controllers 2 | { 3 | using System.Web.Mvc; 4 | 5 | 6 | public class HomeController : 7 | Controller 8 | { 9 | public ActionResult Index() 10 | { 11 | ViewBag.Title = "Home Page"; 12 | 13 | return View(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/BookingWeb/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="BookingWeb.WebApiApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /src/BookingWeb/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Http; 6 | using System.Web.Mvc; 7 | using System.Web.Optimization; 8 | using System.Web.Routing; 9 | 10 | namespace BookingWeb 11 | { 12 | using System.Configuration; 13 | using MassTransit; 14 | using MassTransit.Util; 15 | 16 | 17 | public class WebApiApplication : System.Web.HttpApplication 18 | { 19 | static IBusControl _bus; 20 | static BusHandle _busHandle; 21 | 22 | public static IBus Bus 23 | { 24 | get { return _bus; } 25 | } 26 | protected void Application_Start() 27 | { 28 | AreaRegistration.RegisterAllAreas(); 29 | GlobalConfiguration.Configure(WebApiConfig.Register); 30 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 31 | RouteConfig.RegisterRoutes(RouteTable.Routes); 32 | BundleConfig.RegisterBundles(BundleTable.Bundles); 33 | 34 | _bus = MassTransit.Bus.Factory.CreateUsingRabbitMq(x => 35 | { 36 | x.Host(GetHostAddress(), h => 37 | { 38 | h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); 39 | h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); 40 | }); 41 | }); 42 | 43 | _busHandle = _bus.Start(); 44 | 45 | TaskUtil.Await(() => _busHandle.Ready); 46 | } 47 | 48 | protected void Application_End() 49 | { 50 | _busHandle?.Stop(TimeSpan.FromSeconds(30)); 51 | } 52 | 53 | static Uri GetHostAddress() 54 | { 55 | var uriBuilder = new UriBuilder 56 | { 57 | Scheme = "rabbitmq", 58 | Host = ConfigurationManager.AppSettings["RabbitMQHost"] 59 | }; 60 | 61 | return uriBuilder.Uri; 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/BookingWeb/Models/BookingRequestModel.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Models 2 | { 3 | using System; 4 | using System.ComponentModel.DataAnnotations; 5 | 6 | 7 | public class BookingRequestModel 8 | { 9 | public Guid BookingRequestId { get; set; } 10 | 11 | [Required] 12 | public string EmailAddress { get; set; } 13 | 14 | [Required] 15 | public DateTime StartTime { get; set; } 16 | 17 | [Required] 18 | public TimeSpan Duration { get; set; } 19 | 20 | [Required] 21 | public int RoomCapacity { get; set; } 22 | } 23 | } -------------------------------------------------------------------------------- /src/BookingWeb/Models/BookingRequestResult.cs: -------------------------------------------------------------------------------- 1 | namespace BookingWeb.Models 2 | { 3 | using System; 4 | 5 | 6 | public class BookingRequestResult 7 | { 8 | public Guid BookingRequestId { get; set; } 9 | 10 | public DateTime Timestamp { get; set; } 11 | } 12 | } -------------------------------------------------------------------------------- /src/BookingWeb/Project_Readme.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Your ASP.NET application 6 | 95 | 96 | 97 | 98 | 102 | 103 |
104 |
105 |

This application consists of:

106 |
    107 |
  • Help Page for documenting your Web APIs
  • 108 |
  • Theming using Bootstrap
  • 109 |
  • Authentication, if selected, shows how to register and sign in
  • 110 |
  • ASP.NET features managed using NuGet
  • 111 |
112 |
113 | 114 | 130 | 131 |
132 |

Deploy

133 | 138 |
139 | 140 |
141 |

Get help

142 | 146 |
147 |
148 | 149 | 150 | -------------------------------------------------------------------------------- /src/BookingWeb/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("BookingWeb")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("BookingWeb")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6be8bef6-b430-4da2-80c0-0b87ff4d720e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /src/BookingWeb/Results/ChallengeResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Net.Http; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using System.Web.Http; 9 | 10 | namespace BookingWeb.Results 11 | { 12 | public class ChallengeResult : IHttpActionResult 13 | { 14 | public ChallengeResult(string loginProvider, ApiController controller) 15 | { 16 | LoginProvider = loginProvider; 17 | Request = controller.Request; 18 | } 19 | 20 | public string LoginProvider { get; set; } 21 | public HttpRequestMessage Request { get; set; } 22 | 23 | public Task ExecuteAsync(CancellationToken cancellationToken) 24 | { 25 | Request.GetOwinContext().Authentication.Challenge(LoginProvider); 26 | 27 | HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized); 28 | response.RequestMessage = Request; 29 | return Task.FromResult(response); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/BookingWeb/Scripts/_references.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MassTransit/Sample-Booking/0bd25e3211e8c633864ac74e19515edccf42e5bf/src/BookingWeb/Scripts/_references.js -------------------------------------------------------------------------------- /src/BookingWeb/Scripts/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | /* 16 | ** Unobtrusive validation support library for jQuery and jQuery Validate 17 | ** Copyright (C) Microsoft Corporation. All rights reserved. 18 | */ 19 | (function(a){var d=a.validator,b,e="unobtrusiveValidation";function c(a,b,c){a.rules[b]=c;if(a.message)a.messages[b]=a.message}function j(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function f(a){return a.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function h(a){return a.substr(0,a.lastIndexOf(".")+1)}function g(a,b){if(a.indexOf("*.")===0)a=a.replace("*.",b);return a}function m(c,e){var b=a(this).find("[data-valmsg-for='"+f(e[0].name)+"']"),d=b.attr("data-valmsg-replace"),g=d?a.parseJSON(d)!==false:null;b.removeClass("field-validation-valid").addClass("field-validation-error");c.data("unobtrusiveContainer",b);if(g){b.empty();c.removeClass("input-validation-error").appendTo(b)}else c.hide()}function l(e,d){var c=a(this).find("[data-valmsg-summary=true]"),b=c.find("ul");if(b&&b.length&&d.errorList.length){b.empty();c.addClass("validation-summary-errors").removeClass("validation-summary-valid");a.each(d.errorList,function(){a("
  • ").html(this.message).appendTo(b)})}}function k(d){var b=d.data("unobtrusiveContainer"),c=b.attr("data-valmsg-replace"),e=c?a.parseJSON(c):null;if(b){b.addClass("field-validation-valid").removeClass("field-validation-error");d.removeData("unobtrusiveContainer");e&&b.empty()}}function n(){var b=a(this),c="__jquery_unobtrusive_validation_form_reset";if(b.data(c))return;b.data(c,true);try{b.data("validator").resetForm()}finally{b.removeData(c)}b.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors");b.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}function i(b){var c=a(b),f=c.data(e),i=a.proxy(n,b),g=d.unobtrusive.options||{},h=function(e,d){var c=g[e];c&&a.isFunction(c)&&c.apply(b,d)};if(!f){f={options:{errorClass:g.errorClass||"input-validation-error",errorElement:g.errorElement||"span",errorPlacement:function(){m.apply(b,arguments);h("errorPlacement",arguments)},invalidHandler:function(){l.apply(b,arguments);h("invalidHandler",arguments)},messages:{},rules:{},success:function(){k.apply(b,arguments);h("success",arguments)}},attachValidation:function(){c.off("reset."+e,i).on("reset."+e,i).validate(this.options)},validate:function(){c.validate();return c.valid()}};c.data(e,f)}return f}d.unobtrusive={adapters:[],parseElement:function(b,h){var d=a(b),f=d.parents("form")[0],c,e,g;if(!f)return;c=i(f);c.options.rules[b.name]=e={};c.options.messages[b.name]=g={};a.each(this.adapters,function(){var c="data-val-"+this.name,i=d.attr(c),h={};if(i!==undefined){c+="-";a.each(this.params,function(){h[this]=d.attr(c+this)});this.adapt({element:b,form:f,message:i,params:h,rules:e,messages:g})}});a.extend(e,{__dummy__:true});!h&&c.attachValidation()},parse:function(c){var b=a(c),e=b.parents().addBack().filter("form").add(b.find("form")).has("[data-val=true]");b.find("[data-val=true]").each(function(){d.unobtrusive.parseElement(this,true)});e.each(function(){var a=i(this);a&&a.attachValidation()})}};b=d.unobtrusive.adapters;b.add=function(c,a,b){if(!b){b=a;a=[]}this.push({name:c,params:a,adapt:b});return this};b.addBool=function(a,b){return this.add(a,function(d){c(d,b||a,true)})};b.addMinMax=function(e,g,f,a,d,b){return this.add(e,[d||"min",b||"max"],function(b){var e=b.params.min,d=b.params.max;if(e&&d)c(b,a,[e,d]);else if(e)c(b,g,e);else d&&c(b,f,d)})};b.addSingleVal=function(a,b,d){return this.add(a,[b||"val"],function(e){c(e,d||a,e.params[b])})};d.addMethod("__dummy__",function(){return true});d.addMethod("regex",function(b,c,d){var a;if(this.optional(c))return true;a=(new RegExp(d)).exec(b);return a&&a.index===0&&a[0].length===b.length});d.addMethod("nonalphamin",function(c,d,b){var a;if(b){a=c.match(/\W/g);a=a&&a.length>=b}return a});if(d.methods.extension){b.addSingleVal("accept","mimtype");b.addSingleVal("extension","extension")}else b.addSingleVal("extension","extension","accept");b.addSingleVal("regex","pattern");b.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url");b.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range");b.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength");b.add("equalto",["other"],function(b){var i=h(b.element.name),j=b.params.other,d=g(j,i),e=a(b.form).find(":input").filter("[name='"+f(d)+"']")[0];c(b,"equalTo",e)});b.add("required",function(a){(a.element.tagName.toUpperCase()!=="INPUT"||a.element.type.toUpperCase()!=="CHECKBOX")&&c(a,"required",true)});b.add("remote",["url","type","additionalfields"],function(b){var d={url:b.params.url,type:b.params.type||"GET",data:{}},e=h(b.element.name);a.each(j(b.params.additionalfields||b.element.name),function(i,h){var c=g(h,e);d.data[c]=function(){var d=a(b.form).find(":input").filter("[name='"+f(c)+"']");return d.is(":checkbox")?d.filter(":checked").val()||d.filter(":hidden").val()||"":d.is(":radio")?d.filter(":checked").val()||"":d.val()}});c(b,"remote",d)});b.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&c(a,"minlength",a.params.min);a.params.nonalphamin&&c(a,"nonalphamin",a.params.nonalphamin);a.params.regex&&c(a,"regex",a.params.regex)});a(function(){d.unobtrusive.parse(document)})})(jQuery); -------------------------------------------------------------------------------- /src/BookingWeb/Scripts/respond.min.js: -------------------------------------------------------------------------------- 1 | /* NUGET: BEGIN LICENSE TEXT 2 | * 3 | * Microsoft grants you the right to use these script files for the sole 4 | * purpose of either: (i) interacting through your browser with the Microsoft 5 | * website or online service, subject to the applicable licensing or use 6 | * terms; or (ii) using the files as included with a Microsoft product subject 7 | * to that product's license terms. Microsoft reserves all other rights to the 8 | * files not expressly granted by Microsoft, whether by implication, estoppel 9 | * or otherwise. Insofar as a script file is dual licensed under GPL, 10 | * Microsoft neither took the code under GPL nor distributes it thereunder but 11 | * under the terms set out in this paragraph. All notices and licenses 12 | * below are for informational purposes only. 13 | * 14 | * NUGET: END LICENSE TEXT */ 15 | /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ 16 | /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ 17 | window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.style.background="none";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document); 18 | 19 | /*! Respond.js v1.2.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ 20 | (function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var w=e.document,s=w.documentElement,i=[],k=[],q=[],o={},h=30,f=w.getElementsByTagName("head")[0]||s,g=w.getElementsByTagName("base")[0],b=f.getElementsByTagName("link"),d=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,v=function(){var z,A=w.createElement("div"),x=w.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=w.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=w.compatMode==="CSS1Compat"&&B||w.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();if(I&&l&&z-l-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this); -------------------------------------------------------------------------------- /src/BookingWeb/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Microsoft.Owin; 5 | using Owin; 6 | 7 | [assembly: OwinStartup(typeof(BookingWeb.Startup))] 8 | 9 | namespace BookingWeb 10 | { 11 | public partial class Startup 12 | { 13 | public void Configuration(IAppBuilder app) 14 | { 15 | ConfigureAuth(app); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/BookingWeb/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | 
    2 |

    ASP.NET

    3 |

    ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS, and JavaScript.

    4 |

    Learn more »

    5 |
    6 |
    7 |
    8 |

    Getting started

    9 |

    ASP.NET Web API is a framework that makes it easy to build HTTP services that reach 10 | a broad range of clients, including browsers and mobile devices. ASP.NET Web API 11 | is an ideal platform for building RESTful applications on the .NET Framework.

    12 |

    Learn more »

    13 |
    14 |
    15 |

    Get more libraries

    16 |

    NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.

    17 |

    Learn more »

    18 |
    19 |
    20 |

    Web Hosting

    21 |

    You can easily find a web hosting company that offers the right mix of features and price for your applications.

    22 |

    Learn more »

    23 |
    24 |
    25 | -------------------------------------------------------------------------------- /src/BookingWeb/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Error 6 | 7 | 8 |
    9 |

    Error.

    10 |

    An error occurred while processing your request.

    11 |
    12 | 13 | 14 | -------------------------------------------------------------------------------- /src/BookingWeb/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewBag.Title 7 | @Styles.Render("~/Content/css") 8 | @Scripts.Render("~/bundles/modernizr") 9 | 10 | 11 | 29 |
    30 | @RenderBody() 31 |
    32 |
    33 |

    © @DateTime.Now.Year - My ASP.NET Application

    34 |
    35 |
    36 | 37 | @Scripts.Render("~/bundles/jquery") 38 | @Scripts.Render("~/bundles/bootstrap") 39 | @RenderSection("scripts", required: false) 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/BookingWeb/Views/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 |
    7 |
    8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/BookingWeb/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /src/BookingWeb/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/BookingWeb/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/BookingWeb/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 |
    10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/BookingWeb/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MassTransit/Sample-Booking/0bd25e3211e8c633864ac74e19515edccf42e5bf/src/BookingWeb/favicon.ico -------------------------------------------------------------------------------- /src/BookingWeb/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MassTransit/Sample-Booking/0bd25e3211e8c633864ac74e19515edccf42e5bf/src/BookingWeb/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /src/BookingWeb/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MassTransit/Sample-Booking/0bd25e3211e8c633864ac74e19515edccf42e5bf/src/BookingWeb/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /src/BookingWeb/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MassTransit/Sample-Booking/0bd25e3211e8c633864ac74e19515edccf42e5bf/src/BookingWeb/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /src/BookingWeb/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Sample.Booking.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Contracts", "Booking.Contracts\Booking.Contracts.csproj", "{4A3E87BF-2A26-4F41-BB90-F91766B00C53}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Activities", "Booking.Activities\Booking.Activities.csproj", "{D4D28F1D-7A94-485C-94C1-34FA6D1278F4}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Activities.Tests", "Booking.Activities.Tests\Booking.Activities.Tests.csproj", "{02D11FE8-6357-4BB2-A9C9-71763BB7D908}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Tracking", "Booking.Tracking\Booking.Tracking.csproj", "{547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Tracking.Tests", "Booking.Tracking.Tests\Booking.Tracking.Tests.csproj", "{B4487E8B-A0D8-4740-93A2-6DC91245F7C6}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booking.Services", "Booking.Services\Booking.Services.csproj", "{DE2891A8-F54E-43BD-AD00-E38FFEB484AA}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookingService", "BookingService\BookingService.csproj", "{23F088E8-6486-4923-9E77-36EFA1820E27}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrackingService", "TrackingService\TrackingService.csproj", "{B2FFF5F3-40B8-4545-919E-216EB7C04DFC}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BookingWeb", "BookingWeb\BookingWeb.csproj", "{E226A1FB-B6DA-4A77-A3D7-438051498D87}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Release|Any CPU = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {4A3E87BF-2A26-4F41-BB90-F91766B00C53}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {D4D28F1D-7A94-485C-94C1-34FA6D1278F4}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {02D11FE8-6357-4BB2-A9C9-71763BB7D908}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {02D11FE8-6357-4BB2-A9C9-71763BB7D908}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {02D11FE8-6357-4BB2-A9C9-71763BB7D908}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {02D11FE8-6357-4BB2-A9C9-71763BB7D908}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {547191ED-8F53-4CA8-B4BE-AFEA30FD7E1B}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {B4487E8B-A0D8-4740-93A2-6DC91245F7C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {B4487E8B-A0D8-4740-93A2-6DC91245F7C6}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {B4487E8B-A0D8-4740-93A2-6DC91245F7C6}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {B4487E8B-A0D8-4740-93A2-6DC91245F7C6}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {DE2891A8-F54E-43BD-AD00-E38FFEB484AA}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {23F088E8-6486-4923-9E77-36EFA1820E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {23F088E8-6486-4923-9E77-36EFA1820E27}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {23F088E8-6486-4923-9E77-36EFA1820E27}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {23F088E8-6486-4923-9E77-36EFA1820E27}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {B2FFF5F3-40B8-4545-919E-216EB7C04DFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {B2FFF5F3-40B8-4545-919E-216EB7C04DFC}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {B2FFF5F3-40B8-4545-919E-216EB7C04DFC}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {B2FFF5F3-40B8-4545-919E-216EB7C04DFC}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {E226A1FB-B6DA-4A77-A3D7-438051498D87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {E226A1FB-B6DA-4A77-A3D7-438051498D87}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {E226A1FB-B6DA-4A77-A3D7-438051498D87}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {E226A1FB-B6DA-4A77-A3D7-438051498D87}.Release|Any CPU.Build.0 = Release|Any CPU 66 | EndGlobalSection 67 | GlobalSection(SolutionProperties) = preSolution 68 | HideSolutionNode = FALSE 69 | EndGlobalSection 70 | EndGlobal 71 | -------------------------------------------------------------------------------- /src/TrackingService/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
    6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/TrackingService/BookingRequestStateMap.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using Booking.Tracking; 4 | using MassTransit.EntityFrameworkIntegration; 5 | 6 | 7 | class BookingRequestStateMap : 8 | SagaClassMapping 9 | { 10 | public BookingRequestStateMap() 11 | { 12 | Property(x => x.State); 13 | 14 | Property(x => x.CreateTime); 15 | Property(x => x.UpdateTime); 16 | 17 | Property(x => x.ReceiveTime); 18 | 19 | Property(x => x.StartTime); 20 | Property(x => x.Duration); 21 | Property(x => x.RoomCapacity); 22 | Property(x => x.EmailAddress); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/TrackingService/EntityFrameworkTrackingEventWriter.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System; 4 | using System.Data.Entity; 5 | using System.Threading.Tasks; 6 | using Booking.Tracking; 7 | 8 | 9 | public class EntityFrameworkTrackingEventWriter : 10 | ITrackingEventWriter 11 | { 12 | readonly Func _contextFactory; 13 | 14 | public EntityFrameworkTrackingEventWriter(Func contextFactory) 15 | { 16 | _contextFactory = contextFactory; 17 | } 18 | 19 | public async Task Write(TrackingEvent trackingEvent) 20 | { 21 | using (var context = _contextFactory()) 22 | { 23 | context.Set().Add(trackingEvent); 24 | 25 | await context.SaveChangesAsync(); 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/TrackingService/LocalDatabaseSelector.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System; 4 | using System.Data.SqlClient; 5 | 6 | 7 | public static class LocalDatabaseSelector 8 | { 9 | /// 10 | /// This is a list of the connection strings that we will attempt to find what LocalDb versions 11 | /// are on the local pc which we can run the unit tests against 12 | /// 13 | static readonly string[] _candidateConnectionStrings = 14 | { 15 | @"Data Source=(LocalDb)\MSSQLLocalDB;Integrated Security=True;Initial Catalog=Booking;", // the localdb installed with VS 2015 16 | @"Data Source=(LocalDb)\ProjectsV12;Integrated Security=True;Initial Catalog=Booking;", // the localdb with VS 2013 17 | @"Data Source=(LocalDb)\v11.0;Integrated Security=True;Initial Catalog=Booking;" // the older version of localdb 18 | }; 19 | 20 | static readonly Lazy _connectionString = new Lazy(GetConnectionString); 21 | 22 | public static string ConnectionString => _connectionString.Value; 23 | 24 | /// 25 | /// Loops through the array of potential localdb connection strings to find one that we can use for the unit tests 26 | /// 27 | static string GetConnectionString() 28 | { 29 | foreach (var connectionString in _candidateConnectionStrings) 30 | { 31 | try 32 | { 33 | using (new SqlConnection(connectionString)) 34 | { 35 | return connectionString; 36 | } 37 | } 38 | catch (Exception) 39 | { 40 | // Did not find a connection, so try the next one 41 | } 42 | } 43 | 44 | throw new InvalidOperationException( 45 | "Couldn't connect to any of the LocalDB Databases. You might have a version installed that is not in the list. Please check the list and modify as necessary"); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/TrackingService/Program.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System.IO; 4 | using System.Text; 5 | using log4net.Config; 6 | using MassTransit.Log4NetIntegration.Logging; 7 | using Topshelf; 8 | using Topshelf.Logging; 9 | 10 | 11 | class Program 12 | { 13 | static int Main(string[] args) 14 | { 15 | ConfigureLogger(); 16 | 17 | // Topshelf to use Log4Net 18 | Log4NetLogWriterFactory.Use(); 19 | 20 | // MassTransit to use Log4Net 21 | Log4NetLogger.Use(); 22 | 23 | return (int)HostFactory.Run(x => x.Service()); 24 | } 25 | 26 | static void ConfigureLogger() 27 | { 28 | const string logConfig = @" 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | "; 43 | 44 | using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(logConfig))) 45 | { 46 | XmlConfigurator.Configure(stream); 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /src/TrackingService/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TrackingService")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TrackingService")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b2fff5f3-40b8-4545-919e-216eb7c04dfc")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /src/TrackingService/TrackingEventDbContext.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System.Data.Entity; 4 | 5 | 6 | public class TrackingEventDbContext : 7 | DbContext 8 | { 9 | public TrackingEventDbContext(string nameOrConnectionString) 10 | : base(nameOrConnectionString) 11 | { 12 | } 13 | 14 | protected override void OnModelCreating(DbModelBuilder modelBuilder) 15 | { 16 | base.OnModelCreating(modelBuilder); 17 | modelBuilder.Configurations.Add(new TrackingEventMap()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/TrackingService/TrackingEventMap.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Data.Entity.ModelConfiguration; 5 | using Booking.Tracking; 6 | 7 | 8 | public class TrackingEventMap : 9 | EntityTypeConfiguration 10 | { 11 | public TrackingEventMap() 12 | { 13 | HasKey(x => x.MessageId); 14 | Property(x => x.MessageId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None); 15 | 16 | Property(x => x.Timestamp); 17 | Property(x => x.Duration); 18 | 19 | Property(x => x.CorrelationId); 20 | Property(x => x.ConversationId); 21 | Property(x => x.InitiatorId); 22 | 23 | Property(x => x.BookingRequestId); 24 | 25 | Property(x => x.EventType); 26 | Property(x => x.Text).IsOptional(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/TrackingService/TrackingService.cs: -------------------------------------------------------------------------------- 1 | namespace TrackingService 2 | { 3 | using System; 4 | using System.Configuration; 5 | using System.Data.Entity; 6 | using Automatonymous; 7 | using Booking.Tracking; 8 | using MassTransit; 9 | using MassTransit.EntityFrameworkIntegration; 10 | using MassTransit.EntityFrameworkIntegration.Saga; 11 | using MassTransit.Saga; 12 | using MassTransit.Util; 13 | using Topshelf; 14 | using Topshelf.Logging; 15 | 16 | 17 | class TrackingService : 18 | ServiceControl 19 | { 20 | readonly LogWriter _log = HostLogger.Get(); 21 | readonly BookingRequestStateMachine _stateMachine; 22 | 23 | IBusControl _busControl; 24 | BusHandle _busHandle; 25 | SagaDbContextFactory _sagaDbContextFactory; 26 | ISagaRepository _sagaRepository; 27 | 28 | public TrackingService() 29 | { 30 | _stateMachine = new BookingRequestStateMachine(); 31 | } 32 | 33 | public bool Start(HostControl hostControl) 34 | { 35 | _log.Info("Creating bus..."); 36 | 37 | _sagaRepository = GetSagaRepository(); 38 | 39 | ITrackingEventWriter writer = GetTrackingEventWriter(); 40 | 41 | _busControl = Bus.Factory.CreateUsingRabbitMq(x => 42 | { 43 | var host = x.Host(GetHostAddress(), h => 44 | { 45 | h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); 46 | h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); 47 | }); 48 | 49 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookingStateQueueName"], e => 50 | { 51 | e.StateMachineSaga(_stateMachine, _sagaRepository); 52 | }); 53 | 54 | x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["EventTrackingQueueName"], e => 55 | { 56 | e.Consumer(() => new EventTrackingConsumer(writer)); 57 | }); 58 | }); 59 | 60 | _log.Info("Starting bus..."); 61 | 62 | _busHandle = _busControl.Start(); 63 | 64 | TaskUtil.Await(() => _busHandle.Ready); 65 | 66 | return true; 67 | } 68 | 69 | public bool Stop(HostControl hostControl) 70 | { 71 | _log.Info("Stopping bus..."); 72 | 73 | _busHandle?.Stop(TimeSpan.FromSeconds(30)); 74 | 75 | return true; 76 | } 77 | 78 | ISagaRepository GetSagaRepository() 79 | { 80 | _sagaDbContextFactory = () => new SagaDbContext(LocalDatabaseSelector.ConnectionString); 81 | 82 | using (var context = _sagaDbContextFactory()) 83 | { 84 | context.Database.CreateIfNotExists(); 85 | } 86 | 87 | return new EntityFrameworkSagaRepository(_sagaDbContextFactory); 88 | } 89 | 90 | ITrackingEventWriter GetTrackingEventWriter() 91 | { 92 | Func contextProvider = () => new TrackingEventDbContext(LocalDatabaseSelector.ConnectionString); 93 | 94 | using (var context = contextProvider()) 95 | { 96 | context.Database.CreateIfNotExists(); 97 | } 98 | 99 | return new EntityFrameworkTrackingEventWriter(contextProvider); 100 | } 101 | 102 | static Uri GetHostAddress() 103 | { 104 | var uriBuilder = new UriBuilder 105 | { 106 | Scheme = "rabbitmq", 107 | Host = ConfigurationManager.AppSettings["RabbitMQHost"] 108 | }; 109 | 110 | return uriBuilder.Uri; 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/TrackingService/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | --------------------------------------------------------------------------------