Ejemplo n.º 1
0
        public static CloudTableClient GetTableClient(string connectionStringOrKey = null)
        {
            var key = AzureUtilities.FromConfiguration(connectionStringOrKey ?? "StorageConnectionString");

            if (key == null)
            {
                // NOTE: In the real world, you'd want to remove this, so you didn't log keys.
                Trace.TraceInformation("Couldn't find '{0}' as setting, assuming it's the actual key.", connectionStringOrKey);
                key = connectionStringOrKey;
            }

            var storageAccount = CloudStorageAccount.Parse(key);

            return(storageAccount.CreateCloudTableClient());
        }
Ejemplo n.º 2
0
        public async Task StartAsync()
        {
            var ehConnStr = AzureUtilities.ServiceBusConnectionString(
                AzureUtilities.FromConfiguration("MappyServiceBusNamespace"),
                AzureUtilities.FromConfiguration("MappyEventHubSASName"),
                AzureUtilities.FromConfiguration("MappyEventHubSASKey"));
            var storageConnStr = AzureUtilities.StorageConnectionString(
                AzureUtilities.FromConfiguration("MappyStorageName"),
                AzureUtilities.FromConfiguration("MappyStorageKey"));
            var eventHubName  = AzureUtilities.FromConfiguration("MappyEventHubName");
            var consumerGroup = AzureUtilities.FromConfiguration("MappyConsumerGroupName") ?? "$Default";

            Trace.TraceInformation("Connecting to {0}/{1}/{2}, storing in {3}", ehConnStr, eventHubName, consumerGroup, storageConnStr);

            var factory = new RoutePointProcessorFactory(item =>
            {
                Trace.TraceInformation("From EH: {0} @ ({1}, {2})", item.UserID, item.Latitude, item.Longitude);
                this._onPoint(item);
            });
            await AzureUtilities.AttachProcessorForHub("mappy", ehConnStr, storageConnStr, eventHubName, consumerGroup, factory);
        }
Ejemplo n.º 3
0
        public void Start()
        {
            var quanta = 10000;

            Task.Run(async() =>
            {
                while (true)
                {
                    await Task.Delay(1000);
                    foreach (var item in AzureUtilities.GetRoutePointsFromTo(this.RouteItemTable, this.LastCheck, this.LastCheck.AddSeconds(quanta)))
                    {
                        Trace.TraceInformation("Sending point ({0}, {1}, {2})", item.UserID, item.Latitude, item.Longitude);
                        this._onPoint(item);
                    }
                    this.LastCheck = this.LastCheck.AddSeconds(quanta);
                    if (this.LastCheck > DateTime.UtcNow)
                    {
                        this.LastCheck = DateTime.UtcNow;
                    }
                }
            });
        }
Ejemplo n.º 4
0
        public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            foreach (var message in messages)
            {
                var routeItem = AzureUtilities.DeserializeMessage <RoutePointEH>(message);
                try
                {
                    this.onItemCB(routeItem);
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failed to process {0}: {1}", routeItem, e);
                    throw;
                }
                this.untilCheckpoint--;
                if (this.untilCheckpoint == 0)
                {
                    await context.CheckpointAsync();

                    this.untilCheckpoint = MessagesBetweenCheckpoints;
                }
            }
        }
Ejemplo n.º 5
0
 public TableStorageRoutePointSource(Action <IRoutePoint> onNewPoint)
 {
     this.RouteItemTable = AzureUtilities.GetRoutePointsTable();
     this.LastCheck      = DateTime.UtcNow.AddHours(-24);
     this._onPoint       = onNewPoint;
 }