public TableEntity GetRecord(string container, string PartitionKey, string RowKey)
        {
            TableClient tableClient = new TableClient(_connectionString, container);
            TableEntity entity      = tableClient.GetEntity <TableEntity>(PartitionKey, RowKey).Value;

            return(entity);
        }
示例#2
0
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            [Table(HelpTableName)] TableClient client,
            ILogger log)
        {
            HelpMetaData helpMetaData;
            var          refresh = req.Query["refresh"].ToString();

            if (refresh == "true")
            {
                helpMetaData = CalculateMetaData(client, log);
            }
            else
            {
                log.LogInformation("Trying to get HelpMetaData from cache");
                try
                {
                    helpMetaData = client.GetEntity <HelpMetaData>(MetaDataPartitionKey, MetaDataRowKey);
                }
                catch (RequestFailedException)
                {
                    helpMetaData = CalculateMetaData(client, log);
                }
            }

            var json = JsonSerializer.Serialize(helpMetaData);

            return(new OkObjectResult(json));
        }
        private static MediaPublish EnqueuePublish(string accountId, string indexId)
        {
            TableClient  tableClient    = new TableClient();
            string       tableName      = Constant.Storage.Table.InsightPublish;
            string       partitionKey   = accountId;
            string       rowKey         = indexId;
            MediaPublish insightPublish = tableClient.GetEntity <MediaPublish>(tableName, partitionKey, rowKey);

            if (insightPublish != null)
            {
                string      settingKey  = Constant.AppSettingKey.MediaPublishInsightQueue;
                string      queueName   = AppSetting.GetValue(settingKey);
                QueueClient queueClient = new QueueClient();
                queueClient.AddMessage(queueName, insightPublish);
            }
            return(insightPublish);
        }
示例#4
0
        public static HelpMetaData CalculateMetaData(TableClient client, ILogger log)
        {
            log.LogInformation("Calculating meta data on HelpTable");

            string filter   = TableServiceClient.CreateQueryFilter($"PartitionKey eq {CommandHelpPartitionKey}");
            var    select   = new string[] { "CommandName", "ModuleName" };
            var    entities = client.Query <HelpEntity>(filter: filter, select: select);

            var numAbout = entities
                           .Where(r => r
                                  .CommandName
                                  .StartsWith("about_", StringComparison.OrdinalIgnoreCase))
                           .Count();

            var moduleNames = entities
                              .Select(r => r.ModuleName)
                              .Where(moduleName => !string.IsNullOrEmpty(moduleName))
                              .Distinct();

            var helpMetaData = new HelpMetaData()
            {
                PartitionKey          = MetaDataPartitionKey,
                RowKey                = MetaDataRowKey,
                NumberOfAboutArticles = numAbout,
                NumberOfCommands      = entities.Count() - numAbout,
                NumberOfModules       = moduleNames.Count(),
                ModuleNames           = string.Join(',', moduleNames),
                LastPublished         = Helpers.GetBuildDate(Assembly.GetExecutingAssembly()).ToLongDateString()
            };

            var metaDataEntity = new HelpMetaData();

            try
            {
                metaDataEntity = client.GetEntity <HelpMetaData>(MetaDataPartitionKey, MetaDataRowKey);
                _ = client.UpsertEntity(helpMetaData);
            }
            catch (RequestFailedException)
            {
                _ = client.AddEntity(helpMetaData);
            }

            return(helpMetaData);
        }
示例#5
0
        private static MediaPublish EnqueuePublish(MediaJobNotification jobNotification)
        {
            MediaPublish contentPublish = null;

            if (jobNotification.EventType == MediaJobNotificationEvent.JobStateChange &&
                jobNotification.Properties.OldState == MediaJobState.Processing &&
                jobNotification.Properties.NewState == MediaJobState.Finished)
            {
                TableClient tableClient  = new TableClient();
                string      tableName    = Constant.Storage.Table.ContentPublish;
                string      partitionKey = jobNotification.Properties.AccountName;
                string      rowKey       = jobNotification.Properties.JobId;
                contentPublish = tableClient.GetEntity <MediaPublish>(tableName, partitionKey, rowKey);
                if (contentPublish != null)
                {
                    string      settingKey  = Constant.AppSettingKey.MediaPublishContentQueue;
                    string      queueName   = AppSetting.GetValue(settingKey);
                    QueueClient queueClient = new QueueClient();
                    queueClient.AddMessage(queueName, contentPublish);
                }
            }
            return(contentPublish);
        }
示例#6
0
        public void CreateDeleteEntity()
        {
            string storageUri        = StorageUri;
            string accountName       = StorageAccountName;
            string storageAccountKey = PrimaryStorageAccountKey;
            string tableName         = "OfficeSupplies2p1";
            string partitionKey      = "Stationery";
            string rowKey            = "A1";
            string rowKeyStrong      = "B1";

            #region Snippet:TablesSample2CreateTableWithTableClient
            // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />.
            var tableClient = new TableClient(
                new Uri(storageUri),
                tableName,
                new TableSharedKeyCredential(accountName, storageAccountKey));

            // Create the table in the service.
            tableClient.Create();
            #endregion

            #region Snippet:TablesSample2CreateDictionaryEntity
            // Make a dictionary entity by defining a <see cref="TableEntity">.
            var entity = new TableEntity(partitionKey, rowKey)
            {
                { "Product", "Marker Set" },
                { "Price", 5.00 },
                { "Quantity", 21 }
            };

            Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}.");
            #endregion

            #region Snippet:TablesSample2AddEntity
            // Add the newly created entity.
            tableClient.AddEntity(entity);
            #endregion

            #region Snippet:TablesMigrationUpsertEntity
            // Upsert the newly created entity.
            tableClient.UpsertEntity(entity);
            #endregion

            #region Snippet:TablesSample2CreateStronglyTypedEntity
            // Create an instance of the strongly-typed entity and set their properties.
            var strongEntity = new OfficeSupplyEntity
            {
                PartitionKey = partitionKey,
                RowKey       = rowKeyStrong,
                Product      = "Notebook",
                Price        = 3.00,
                Quantity     = 50
            };

            Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}.");
            #endregion

            #region Snippet:TablesMigrationCreateEntity
            // Create an instance of the strongly-typed entity and set their properties.
#if SNIPPET
            var entity = new OfficeSupplyEntity
#else
            var fooEntity = new OfficeSupplyEntity
#endif
            {
                PartitionKey = partitionKey,
                RowKey       = rowKey,
                Product      = "Marker Set",
                Price        = 5.00,
                Quantity     = 21
            };
            #endregion

            // Add the newly created entity.
            tableClient.AddEntity(strongEntity);

            #region Snippet:MigrationGetEntity
            // Get the entity.
            OfficeSupplyEntity marker = tableClient.GetEntity <OfficeSupplyEntity>(partitionKey, rowKey);

            // Display the values.
            Console.WriteLine($"{marker.PartitionKey}, {marker.RowKey}, {marker.Product}, {marker.Price}, {marker.Quantity}");
            #endregion

            #region Snippet:TablesSample2DeleteEntity
            // Delete the entity given the partition and row key.
            tableClient.DeleteEntity(partitionKey, rowKey);
            #endregion

            #region Snippet:TablesSample2DeleteTableWithTableClient
            tableClient.Delete();
            #endregion
        }
示例#7
0
        // as the number of organizations is likely not to reach into the millions, we can stick with a common PartitionKey for now
        public Task <OrganizationEntity> GetOrganization(string orgId)
        {
            var org = _orgTable.GetEntity <OrganizationEntity>(typeof(OrganizationEntity).GetType().Name, Guid.Parse(orgId).ToString());

            return(Task.FromResult(org.Value));
        }
 public Response <T> GetByRowKey(string rowKey) => _tableClient.GetEntity <T>(_partitionKey, rowKey);