Beispiel #1
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);
        }