예제 #1
0
        public override void Run()
        {
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            //Initialize
            var storageAccount = CloudStorageAccount.FromConfigurationSetting("ConnectionString");
            var queueClient    = storageAccount.CreateCloudQueueClient();
            var EventsQueue    = queueClient.GetQueueReference("earthquakes");
            var StationsQueue  = queueClient.GetQueueReference("stations");
            var ReducerQueue   = queueClient.GetQueueReference("reducer");

            while (true)
            {
                Thread.Sleep(10000);
                CloudQueueMessage EventMessage = EventsQueue.GetMessage(TimeSpan.FromMinutes(2));
                if (EventMessage != null)
                {
                    QuakeMessage quake = DeserialeMessage(EventMessage);
                    quake.CalculateGeometry();

                    quake.CalculateCenter();
                    var service = storageAccount.CreateCloudTableClient().GetDataServiceContext();
                    service.IgnoreResourceNotFoundException = true;
                    service.IgnoreMissingProperties         = true;
                    IQueryable <StationsInfo> StationsList;
                    if (!String.IsNullOrEmpty(quake.StationsGroup))
                    {
                        StationsList = (from c in service.CreateQuery <StationsInfo>("Stations").AsTableServiceQuery()
                                        where c.PartitionKey == quake.StationsGroup
                                        select c);
                    }
                    else
                    {
                        StationsList = CalculateGrid(quake);
                    }
                    int Counter = 0;
                    foreach (var item in StationsList)
                    {
                        quake.StationCode = item.Code;
                        quake.Station     = item;
                        CloudQueueMessage StationMessage = new CloudQueueMessage(quake.ToXml());
                        StationsQueue.AddMessage(StationMessage);
                        Counter++;
                    }
                    CloudQueueMessage ReducerMessage = new CloudQueueMessage(String.Format("{0};{1};{2}", quake.EventID.ToLower(), Counter, quake.DeleteMe.ToString()));
                    ReducerQueue.AddMessage(ReducerMessage);

                    EventsQueue.DeleteMessage(EventMessage);
                }
            }
        }
예제 #2
0
 public QuakeMessage CalculateGeometry(QuakeMessage q)
 {
     q.CalculateGeometry();
     q.CalculateCenter();
     return(q);
 }