示例#1
0
        private static void StartManufacturing(NotificationServiceClient notificationClient)
        {
            BackendServiceClient client = new BackendServiceClient();

            WriteConsole("Start Manufactoring Triggered!");
            List <FactoryStatistic> stats = client.GetFactoryStats(null, null).ToList();

            WriteConsole("**************************Current Statistics***************");
            stats.ForEach(stat => WriteConsole(string.Format("{0}:{1}", stat.Status, stat.Count)));
            WriteConsole("*************************************************************");
            Request request = client.GetNextRequest();

            if (stats.First(s => s.Status.ToLower() == "inprogress").Count > 0)
            {
                notificationClient.PublishMachineChange(0, 0, 0, "Error-AlreadyInProgress");
                WriteConsole("There is an Item already in production");
                WriteConsole("Enter C  clear production or Q to exit:");
                string c = Console.ReadLine();
                if (c.ToLower() == "c" || c.ToLower() == "clear")
                {
                    client.ClearInProgress();
                }
                else
                {
                    return;
                }
            }
            if (stats.First(s => s.Status.ToLower() == "done").Count > 300)
            {
                notificationClient.PublishMachineChange(0, 0, 0, "DailyLimit");

                WriteConsole("Maximuim number of items to produce per day exceeded");
                return;
            }
            if (request != null)
            {
                WriteConsole("Will start processing Request Number: " + request.Id.ToString());
                RequestStatus currentStatus = Statuses.First(s => s.Id == request.StatusId);
                WriteConsole("Current Status of the request is " + currentStatus.Name);
                notificationClient.PublishMachineChange(request.Id.Value, request.StatusId.Value, 0, "Manufacturing");

                TransitionRequest(request, currentStatus);
                StartManufacturing(notificationClient);
            }
            else
            {
                WriteConsole("No more requests!");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            /////////////////////////////////Set up Publish Events
            InstanceContext           site   = new InstanceContext(new Program());
            NotificationServiceClient client = new NotificationServiceClient(site);

            ////////////////////////////////End Setup

            BackendServiceClient backendClient = new BackendServiceClient();

            Statuses = backendClient.GetRequestStatuses().ToList();
            WriteConsole("Launching the Microship Machine.. Hold on");
            WriteConsole("Hi... I'm you Microship manufacturing machine.");
            WriteConsole("I can only process one request at a time. No multiThreading required here!");
            client.PublishMachineChange(0, 0, 0, "StartManufacturing");

            StartManufacturing(client);
            Console.ReadLine();
        }