예제 #1
0
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("$projectname$ entry point called", "Information");

            while (true)
            {
                //Thread.Sleep(200);
                // Make the simulation process a long running calculation ~200ms
                // (If it is too quick, you do not see the difference when adding new worker processes)
                //Trace.WriteLine("Working", "Information");

                // Pick up a message from the "simulation" message queue.
                // Create a TaskAggregator and call GenerateAggregatedDuration
                // Save the simulation result (project name, run number, calculated duration)
                // to Azure table storage
                using (CalculatorDataSource dataSource = new CalculatorDataSource("simulation"))
                {
                    Project project = dataSource.GetProjectFromQueueMessage();

                    if (project != null)
                    {
                        // Create a random number generator
                        Distribution randomNumberGenerator = new FisherTippettDistribution();

                        // Create a TaskAggregator, passing in the RNG and the project
                        TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator);
                        double aggregatedDuration = taskAggregator.GenerateAggregatedDuration();
                        dataSource.AddEntry(
                            new ProjectCalculationEntry {Duration = aggregatedDuration, ProjectName = project.Name},
                            project.Name);
                    }
                }

                // Don't bother sending back a "done" message
            }
        }
예제 #2
0
        public override void Run()
        {
            while (!IsStopped)
            {
                Project project = null;
                if (UseMessageBus)
                {
                    try
                    {
                        // Receive the message
                        BrokeredMessage receivedMessage = null;
                        receivedMessage = QueueClient.Receive();

                        if (receivedMessage != null)
                        {
                            // Process the message
                            Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());

                            project = receivedMessage.GetBody<Project>();

                            receivedMessage.Complete();
                        }
                    }
                    catch (MessagingException e)
                    {
                        if (!e.IsTransient)
                        {
                            Trace.WriteLine(e.Message);
                            throw;
                        }

                        Thread.Sleep(10000);
                    }
                    catch (OperationCanceledException e)
                    {
                        if (!IsStopped)
                        {
                            Trace.WriteLine(e.Message);
                            throw;
                        }
                    }
                }
                else
                {
                    //------------------------------------
                    // Pick up a message from the "simulation" message queue.
                    // Create a TaskAggregator and call GenerateAggregatedDuration
                    // Save the simulation result (project name, run number, calculated duration)
                    // to Azure table storage
                    //using (CalculatorDataSource dataSource = new CalculatorDataSource("simulation"))
                    //{
                        project = dataSource.GetProjectFromQueueMessage();
                    //}

                    //------------------------------------
                }

                if (project != null)
                    {
                        // Create a random number generator
                        Distribution randomNumberGenerator = new FisherTippettDistribution();

                        // Create a TaskAggregator, passing in the RNG and the project
                        TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator);
                        double aggregatedDuration = taskAggregator.GenerateAggregatedDuration();
                        dataSource.AddEntry(
                            new ProjectCalculationEntry { Duration = aggregatedDuration, ProjectName = project.Name },
                            project.Name);
                    }
            }
        }