예제 #1
0
        /// <summary>
        /// Execute an Azure Table Query Filter filter against the Azure Storage account and Table name specified in the settings file of the calling executable
        /// </summary>
        /// <param name="filter">Azure Table Query Filter</param>
        /// <returns>Entities matching the query in the target table</returns>
        private static List <DynamicTableEntity> ExecuteAzureTableStorageQuery(string filter)
        {
            var tableQuery = new TableQuery <DynamicTableEntity>().Where(filter);
            var table      =
                AzureTablesHelper.GetAzureTablesTableObject(
                    CloudConfigurationManager.GetSetting(telemetryStorageConnectionStringSettingName),
                    AzureTableStorageTableName);

            TableContinuationToken token = null;
            var entities = new List <DynamicTableEntity>();

            do
            {
                var queryResult = table.ExecuteQuerySegmented(tableQuery, token);
                entities.AddRange(queryResult.Results);
                token = queryResult.ContinuationToken;
            }while (token != null);
            return(entities);
        }
예제 #2
0
        /// <summary>
        /// Store the given LogMessage object an Azure Table Storage table called "SystemLogs" in the Azure Storage account pointed to by the "AzureStorageConnectionString"
        /// </summary>
        /// <param name="logMessage">Message object to log</param>
        public static void LogMessageToTableStorage(LogMessage logMessage)
        {
            try
            {
                // Convert message to Azure Table Entity
                var logAzureTableEntity = new LogAzureTableEntity(logMessage);

                var connectionString = CloudConfigurationManager.GetSetting(telemetryStorageConnectionStringSettingName);
                var table            = AzureTablesHelper.GetAzureTablesTableObject(connectionString, AzureTableStorageTableName);
                table.CreateIfNotExists();

                // Create the TableOperation object that inserts the entity.
                var insertOperation = TableOperation.Insert(logAzureTableEntity);

                // Execute the insert operation.
                table.Execute(insertOperation);
            }
            catch (Exception e)
            {
                // ignored
            }
        }