Exemplo n.º 1
0
        public async Task <string> GetSelfHelpBySupportTopicAsync(string pesId, string supportTopicId, string path)
        {
            var supportTopicsSelfHelp = SelfHelpCache.TryGetValue(pesId, out ConcurrentDictionary <string, string> resourceSelfHelp);

            if (supportTopicsSelfHelp && resourceSelfHelp.TryGetValue(supportTopicId, out string selfHelpContent))
            {
                return(selfHelpContent);
            }
            else
            {
                return(await GetSelfHelpBySupportTopicFromGitAsync(pesId, supportTopicId, path));
            }
        }
Exemplo n.º 2
0
        public async Task <string> PullSelfHelpContent(string pesId, string supportTopicId, string path)
        {
            HttpRequestMessage  request  = new HttpRequestMessage(HttpMethod.Get, path);
            HttpResponseMessage response = await HttpClient.SendAsync(request);

            var selfHelpStr = string.Empty;

            if (response != null)
            {
                string content = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    var     tasks       = new List <Task <HttpResponseMessage> >();
                    dynamic metaDataSet = JsonConvert.DeserializeObject(content);

                    foreach (var fileData in metaDataSet)
                    {
                        if (!fileData.name.ToString().Contains("-scoping-"))
                        {
                            string fileDataUrl = fileData.download_url;
                            tasks.Add(Task.Run(() => GetFileContent(fileDataUrl)));
                        }
                    }

                    var staticFiles = await Task.WhenAll(tasks);

                    var cacheValue = SelfHelpCache.TryGetValue(pesId, out ConcurrentDictionary <string, string> supportTopicsSelfHelp);

                    if (!cacheValue || !supportTopicsSelfHelp.TryGetValue(supportTopicId, out selfHelpStr))
                    {
                        var selfHelpMapping = new ConcurrentDictionary <string, string>();
                        for (int i = 0; i < staticFiles.Length; i++)
                        {
                            if (staticFiles[i].IsSuccessStatusCode)
                            {
                                string fileContent = await staticFiles[i].Content.ReadAsStringAsync();

                                string[] separators = { "supportTopicIds=", "productPesIds=" };

                                string[] substrs = fileContent.Split(separators, StringSplitOptions.RemoveEmptyEntries);

                                string supportTopicIds = string.Empty;
                                string productId       = string.Empty;

                                if (substrs.Length >= 3)
                                {
                                    supportTopicIds = substrs[1].Split('"', StringSplitOptions.RemoveEmptyEntries)[0];
                                    productId       = substrs[2].Split('"', StringSplitOptions.RemoveEmptyEntries)[0];

                                    if (supportTopicIds.Contains(supportTopicId))
                                    {
                                        selfHelpStr = fileContent;
                                    }

                                    selfHelpMapping.AddOrUpdate(supportTopicIds, fileContent, (key, oldvalue) => fileContent);
                                }
                            }
                        }

                        SelfHelpCache.AddOrUpdate(pesId, selfHelpMapping, (key, oldvalue) => selfHelpMapping);
                    }
                }
            }

            return(selfHelpStr);
        }