Exemple #1
0
        public async Task <IHttpActionResult> PostOrder([FromBody] TicketOrder order)
        {
            var error   = "";
            var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService);

            handler.Start(LOG_TAG, "PostOrder", GetServiceProperties());

            try
            {
                TicketOrder.Validate(order);

                ServiceLocationService locator          = new ServiceLocationService();
                UriBuilderService      builder          = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName);
                ITicketOrderService    dispenderService = locator.Create <ITicketOrderService>(builder.ToUri());
                return(Ok(await dispenderService.EnqueueOrder(order)));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(BadRequest(ex.Message));
            }
            finally
            {
                handler.Stop(error);
            }
        }
Exemple #2
0
        public async Task <IHttpActionResult> GetTicketOrderPartitions()
        {
            var error   = "";
            var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService);

            handler.Start(LOG_TAG, "GetTicketOrderPartitions", GetServiceProperties());
            List <TicketOrderServiceInfo> infos = new List <TicketOrderServiceInfo>();

            try
            {
                ServiceLocationService locator = new ServiceLocationService();
                UriBuilderService      builder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName);

                //TODO: Task 4.1 - Use the FabricClient to get the list of partitions for the Ticket Order Service
                ServicePartitionList partitions = await _fabricClient.QueryManager.GetPartitionListAsync(builder.ToUri());

                foreach (Partition p in partitions)
                {
                    long minKey = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                    ITicketOrderService dispenderService = locator.Create <ITicketOrderService>(minKey, builder.ToUri());

                    //TODO: Task 4.2 - Collect the partition info
                    infos.Add(new TicketOrderServiceInfo()
                    {
                        PartitionId     = p.PartitionInformation.Id.ToString(),
                        PartitionKind   = p.PartitionInformation.Kind.ToString(),
                        PartitionStatus = p.PartitionStatus.ToString(),
                        NodeName        = await dispenderService.GetNodeName(),
                        HealthState     = p.HealthState.ToString(),
                        ServiceKind     = p.ServiceKind.ToString(),
                        ItemsInQueue    = await dispenderService.GetOrdersCounter(CancellationToken.None)
                    });
                }

                return(Ok(infos));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(BadRequest(ex.Message));
            }
            finally
            {
                handler.Stop(error);
            }
        }
Exemple #3
0
        public void TestInialize()
        {
            _mockOrderRepository = new Mock <IRepository <TicketOrder> >();

            var orders = new List <TicketOrder>()
            {
                new TicketOrder()
                {
                    Owner = new User()
                    {
                        Email = "*****@*****.**"
                    }, Flight = new Flight()
                    {
                        Name = "M1"
                    }
                },
                new TicketOrder()
                {
                    Owner = new User()
                    {
                        Email = "*****@*****.**"
                    }, Flight = new Flight()
                    {
                        Name = "L1"
                    }
                },
                new TicketOrder()
                {
                    Owner = new User()
                    {
                        Email = "*****@*****.**"
                    }, Flight = new Flight()
                    {
                        Name = "T1"
                    }
                }
            };

            _mockOrderRepository.Setup(x => x.GetAll()).Returns(orders);
            _ticketService = new TicketOrderService(_mockOrderRepository.Object);
        }
        public async Task <IHttpActionResult> UpdateServiceHealthState(UpdateHealthRequest request)
        {
            var error   = "";
            var handler = HandlersFactory.GetProfilerHandler(TheSettingService, TheLoggerService);

            handler.Start(LOG_TAG, "UpdateServiceHealthState", GetServiceProperties());

            try
            {
                UpdateHealthRequest.Validate(request);

                int ticketOrderServices           = 0;
                int ticketOrderActors             = 0;
                int eventActors                   = 0;
                ServiceLocationService locator    = new ServiceLocationService();
                UriBuilderService      builder    = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderServiceName);
                ServicePartitionList   partitions = await _fabricClient.QueryManager.GetPartitionListAsync(builder.ToUri());

                foreach (Partition p in partitions)
                {
                    long minKey = (p.PartitionInformation as Int64RangePartitionInformation).LowKey;
                    ITicketOrderService dispenderService = locator.Create <ITicketOrderService>(builder.ToUri());
                    await dispenderService.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    ticketOrderServices++;
                }

                ActorLocationService actorLocator         = new ActorLocationService();
                UriBuilderService    orderActorBuilder    = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsTicketOrderActorName);
                ServicePartitionList orderActorPartitions = await _fabricClient.QueryManager.GetPartitionListAsync(orderActorBuilder.ToUri());

                foreach (Partition p in orderActorPartitions)
                {
                    string            minKey = (p.PartitionInformation as Int64RangePartitionInformation).Id.ToString();
                    ITicketOrderActor actor  = actorLocator.Create <ITicketOrderActor>(new ActorId(minKey), Constants.ContosoEventsApplicationName);
                    await actor.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    ticketOrderActors++;
                    // May require contiunuation
                }

                IDataStoreService  dataService = ServiceFactory.GetInstance().GetDataStoreService(TheSettingService, TheLoggerService);
                List <TicketEvent> events      = await dataService.GetEvents();

                UriBuilderService eventActorBuilder = new UriBuilderService(Constants.ContosoEventsApplicationInstance, Constants.ContosoEventsEventActorName);
                foreach (var tEvent in events)
                {
                    IEventActor actor = actorLocator.Create <IEventActor>(new ActorId(tEvent.Id), Constants.ContosoEventsApplicationName);
                    await actor.UpdateHealthState(GetHealthStateFromString(request.State), request.Message);

                    eventActors++;
                    // May require contiunuation
                }

                return(Ok("Done: " + ticketOrderServices + "|" + ticketOrderActors + "|" + eventActors));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(BadRequest(ex.Message));
            }
            finally
            {
                handler.Stop(error);
            }
        }
Exemple #5
0
 public HomeController(ITicketOrderService ticketOrderService,
                       IUserService userService)
 {
     _ticketOrderService = ticketOrderService;
     _userService        = userService;
 }
 public OrderController(ITicketOrderService ticketOrderService)
 {
     _ticketOrderService = ticketOrderService;
 }
 public OrderController(ITicketOrderService service)
 {
     _service = service;
 }