// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //services.AddSingleton<ServiceBusConfiguration>(Configuration.GetValue<ServiceBusConfiguration>("OrderPlacedSubscription")); //services.AddSingleton<SubscriptionConfiguration>(Configuration.GetSection("ServiceBusConfiguration").Get<ServiceBusConfiguration>()); // services.AddMvc(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1.0", new Info { Title = "SearchManager", Version = "1.0" }); c.OperationFilter <HeaderFilter>(); }); var mapperConfig = new MapperConfiguration(mc => { mc.AddProfile(new CommonEntitiyProfile()); }); IMapper mapper = mapperConfig.CreateMapper(); services.AddSingleton(mapper); services.AddDbContext <RestaurantManagementContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnectionString"), b => b.MigrationsAssembly("MT.OnlineRestaurant.DataLayer"))); services.AddMvc() .AddMvcOptions(options => { options.Filters.Add(new Authorization()); //options.Filters.Add(new LoggingFilter(Configuration["ConnectionString:DatabaseConnectionString"])); //options.Filters.Add(new ErrorHandlingFilter(Configuration["ConnectionString:DatabaseConnectionString"])); options.Filters.Add(new LoggingFilter(Configuration.GetConnectionString("DatabaseConnectionString"))); options.Filters.Add(new ErrorHandlingFilter(Configuration.GetConnectionString("DatabaseConnectionString"))); }); services.AddTransient <IRestaurantBusiness, RestaurantBusiness>(); services.AddTransient <ISearchRepository, SearchRepository>(); services.AddTransient <IListener, OrderListener>((service) => { var orderPlacedSubscription = Configuration.GetSection("OrderPlacedSubscription").Get <SubscriptionConfiguration>(); RestaurantManagementContext restaurantManagementContext = service.GetService <RestaurantManagementContext>(); TopicConfiguration itemOutOfStockTopicConfiguration = Configuration.GetSection("ItemOutOfStockTopic").Get <TopicConfiguration>();; var orderListener = new OrderListener(orderPlacedSubscription, itemOutOfStockTopicConfiguration, restaurantManagementContext, mapper); return(orderListener); }); MessageListenerRegistrar.RegisterListners(services.BuildServiceProvider().GetService <IListener>()); }
}// ProcessCreateBook() // // // ********************************************* // **** ProcessServiceStateChange() **** // ********************************************* /// <summary> /// Called when someone (us or external user) wants to /// change our current ServiceState. /// Notes: /// 1) The states are processed in reverse order so that if/when other states are included /// in the enum, we will consider ourselves in that state if its higher or equal to the ones implemented. /// </summary> /// <param name="request"></param> private void ProcessServiceStateChange(RequestEventArg <RequestCode> request) { ServiceStates nextState = m_ServiceState; // change this if you want to move to a new state. ServiceStates requestedState = (ServiceStates)request.Data[0]; Log.NewEntry(LogLevel.Warning, "ProcessStateChange: [{1}] Processing {0}.", request, m_ServiceState); if (m_ServiceState >= ServiceStates.Stopped) { // Ok. We must shut down now. m_Requests.Recycle(request); base.Stop(); } else if (m_ServiceState >= ServiceStates.Stopping) { // We are trying to stop. But havent stopped yet. // Check that we can stop now. bool isReadyToStop = true; // todo: do the needed checks here. if (isReadyToStop) { m_Listener.Dispose(); nextState = ServiceStates.Stopped; // Okay. We can stop - set my state. this.HubEventEnqueue(request); // pulse this request again immediately. } else { m_PendingQueue.AddPending(request, 1); // wait, then try to stop again. } } else if (m_ServiceState >= ServiceStates.Running) { // Here we are in Running state or better. if (requestedState >= ServiceStates.Stopping) { // user wants to stop now. nextState = ServiceStates.Stopping; this.HubEventEnqueue(m_Requests.Get(RequestCode.ServiceStateChange, ServiceStates.Stopped)); } else { // Right now this is the only active state. // However, we could go onto other states.. like paused, if desired in future. Log.NewEntry(LogLevel.Warning, "ProcessStateChange: Ignoring request {0}", request); m_Requests.Recycle(request); } } else if (m_ServiceState >= ServiceStates.Started) { // We are atleast started now. if (requestedState >= ServiceStates.Stopping) { // User wants to stop. Thats okay. nextState = ServiceStates.Stopping; this.HubEventEnqueue(m_Requests.Get(RequestCode.ServiceStateChange, ServiceStates.Stopped)); } else if (requestedState >= ServiceStates.Running) { // Try to connect all services we need to be running. // Locate services now. List <IService> iServices; if (m_TTService == null) { iServices = m_Services.GetServices(typeof(TTApiService)); if (iServices.Count > 0) { Log.NewEntry(LogLevel.Major, "ProcessStateChange: Starting. Found TTAPI service. "); m_TTService = (TTApiService)iServices[0]; } else { Log.NewEntry(LogLevel.Error, "ProcessStateChange: Failed to locate TTAPI Service."); } } if (m_Market == null) { Log.NewEntry(LogLevel.Major, "ProcessStateChange: Starting. Found TT Market. "); iServices = m_Services.GetServices(typeof(MarketTTAPI)); if (iServices.Count > 0) { m_Market = (MarketTTAPI)iServices[0]; m_Market.FoundResource += new EventHandler(HubEventEnqueue); // subscribe to found resources. } else { Log.NewEntry(LogLevel.Error, "ProcessStateChange: Failed to locate TTAPI Market hub."); } } // TODO: Continue to do connections here. if (m_Market != null && m_TTService != null) { if (m_Listener == null) { m_Listener = new OrderListener("Listener", this); m_Listener.Start(); } } // Try to connect. bool isReadyToRun = true; isReadyToRun = (m_TTService != null && m_TTService.IsRunning) && isReadyToRun; // non-Lazy isReadyToRun = (m_Market != null) && isReadyToRun; if (isReadyToRun) { // Transition to Running state! nextState = ServiceStates.Running; if (requestedState > ServiceStates.Running) { HubEventEnqueue(request); // resubmit request since its more than Running. } else { m_Requests.Recycle(request); } } else { Log.NewEntry(LogLevel.Major, "ProcessStateChange: Cannot proceed to state {0}. Not connected. Wait and try again.", requestedState); m_PendingQueue.AddPending(request, 2); } } else { } } else if (m_ServiceState >= ServiceStates.Unstarted) { // We are marked as unstarted, but since we are here, we must at least be started. nextState = ServiceStates.Started; if (requestedState > ServiceStates.Started) { this.HubEventEnqueue(request); // resubmit this request since user requested more. } else { m_Requests.Recycle(request); } } else { Log.NewEntry(LogLevel.Warning, "ProcessStateChange: Unknown service state {0}", m_ServiceState);// This should never happen } // Exit - report service state change if any. if (m_ServiceState != nextState) { // Our service state has changed. ServiceStates prevState = m_ServiceState; // save previous state. m_ServiceState = nextState; // accept new state. OnServiceStateChanged(prevState, m_ServiceState); } }//ProcessServiceStateChange()
public void addOrderListener(OrderListener orderListener) { orderListenerMgr.addListener(orderListener); }