Ejemplo n.º 1
0
        public override void Process(object sender, MessageReceivedArgs argument)
        {
            var request = argument.Request;

            Console.WriteLine($"Part Number Request Processing - {request.Tracker}");
            try
            {
                var status = _statusTableProvider.Get("ServiceRequestCommand", request.Tracker.ToString());
                if (status == null)
                {
                    var statusInfo = new StatusInfo()
                    {
                        Client       = request.ClientName,
                        CreatedTime  = DateTime.UtcNow,
                        Status       = "Created",
                        TrackingGuid = request.Tracker
                    };
                    status = new StatusTableEntity(statusInfo);
                }
                status.Status = "Processing";
                _statusTableProvider.Update(status);

                Thread.Sleep(3000);

                var random      = new Random();
                var errorNumber = random.Next(0, 3);
                if (errorNumber == 2)
                {
                    throw new Exception($"Failed to create Part Number for {request.Tracker}");
                }

                request.Sku = "PNR-" + random.Next(10000, 99999);
                _serviceRequestTableProvider.Update(new ServiceRequestEntity(request));

                status.Status        = "Completed";
                status.ProcessedTime = DateTime.UtcNow;
                status.Result        = request.Sku;

                _statusTableProvider.Update(status);
            }
            catch (Exception exception)
            {
                var status = _statusTableProvider.Get("ServiceRequestCommand", request.Tracker.ToString());
                if (status == null)
                {
                    var statusInfo = new StatusInfo()
                    {
                        Client       = request.ClientName,
                        CreatedTime  = DateTime.UtcNow,
                        Status       = "Created",
                        TrackingGuid = request.Tracker
                    };
                    status = new StatusTableEntity(statusInfo);
                }
                status.Status = "Failed";
                _statusTableProvider.Update(status);
                Console.WriteLine($"Part Number Request Processing has failed- {request.Tracker}");
                throw;
            }
        }
Ejemplo n.º 2
0
        public override void Process(object sender, MessageReceivedArgs argument)
        {
            var request = argument.Request;
            var status  = _statusTableProvider.Get("ServiceRequestCommand", request.Tracker.ToString());

            if (status == null)
            {
                var statusInfo = new StatusInfo()
                {
                    Client       = request.ClientName,
                    CreatedTime  = DateTime.UtcNow,
                    Status       = "Created",
                    TrackingGuid = request.Tracker
                };
                status = new StatusTableEntity(statusInfo);
            }
            status.Status = "Processing";
            _statusTableProvider.Update(status);

            Thread.Sleep(3000);
            var random = new Random();

            request.Sku = "CSR-" + random.Next(10000, 99999);
            _serviceRequestTableProvider.Update(new ServiceRequestEntity(request));

            status.Status        = "Completed";
            status.ProcessedTime = DateTime.UtcNow;
            status.Result        = request.Sku;

            _statusTableProvider.Update(status);
            Console.WriteLine($"Cost Rate Request Processing Complete - {request.Tracker}");
        }
Ejemplo n.º 3
0
        public void SendRequest(ServiceRequest serviceRequest)
        {
            var currentDate = DateTime.UtcNow;
            var json        = JsonConvert.SerializeObject(serviceRequest);
            var message     = new BrokeredMessage(json)
            {
                CorrelationId = serviceRequest.Type,
                ContentType   = "application/json",
            };

            message.Properties.Add("Time", currentDate);

            _topicClient.Send(message);

            var status = new StatusInfo()
            {
                Client       = serviceRequest.ClientName,
                CreatedTime  = currentDate,
                Status       = "Created",
                TrackingGuid = serviceRequest.Tracker
            };

            _statusTableProvider.Update(new StatusTableEntity(status));
        }