Exemplo n.º 1
0
        private static async void InsertOrMergeEntityAsync(CloudTable table, CraneEntity entity)
        {
            try
            {
                // Create the InsertOrReplace table operation
                TableOperation insertOrMergeOperation = TableOperation.InsertOrMerge(entity);

                // Execute the operation.
                TableResult result = await table.ExecuteAsync(insertOrMergeOperation);

                CraneEntity insertedCrane = result.Result as CraneEntity;
            }
            catch (StorageException)
            {
            }
        }
Exemplo n.º 2
0
        public static async System.Threading.Tasks.Task RunAsync([QueueTrigger("transformed", Connection = "storageconnectionstring")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");

            CraneEntity entity = JsonConvert.DeserializeObject <CraneEntity>(myQueueItem);

            entity.json = myQueueItem;

            Console.WriteLine(entity.json);

            /*CraneEntity entity = new CraneEntity()
             * {
             *  GeoPositionLongitude = "",
             *  GeoPositionLatitude = "6 * 3",
             *  MachineSerialNumber = "",
             *  CraneID = ""
             * };
             */

            //Get Connectionstring from app settings
            string storageConnectionString = Environment.GetEnvironmentVariable("storageconnectionstring");

            // Retrieve storage account information from connection string.
            CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(storageConnectionString);

            // Create a table client for interacting with the table service
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            Console.WriteLine("Create a Table for the demo");

            // Create a table client for interacting with the table service
            CloudTable table = tableClient.GetTableReference("transformed");

            if (await table.CreateIfNotExistsAsync())
            {
                Console.WriteLine("Created Table named: {0}", "transformed");
            }
            else
            {
                Console.WriteLine("Table {0} already exists", "transformed");
            }

            InsertOrMergeEntityAsync(table, entity);
        }