internal static void SetDefaultCategoriesFromJson() { Logger.Info("Setting default categories"); ProblemCategory forProblemCategory = LogCollectorUtils.GetLocalizationForProblemCategory(LogCollectorUtils.sVmName); if (forProblemCategory == null || forProblemCategory.Category == null || forProblemCategory.Category.Count <= 0) { return; } List <Category> categoryList = new List <Category>((IEnumerable <Category>)forProblemCategory.Category); LogCollectorUtils.sProblemCategories = new string[categoryList.Count]; LogCollectorUtils.sCategorySubcategoryMapping = new Dictionary <string, Dictionary <string, string> >(); LogCollectorUtils.sCategorySubcategoryMappingWithDropdown = new Dictionary <string, Dictionary <string, string> >(); for (int index1 = 0; index1 < categoryList.Count; ++index1) { Category category = categoryList[index1]; LogCollectorUtils.sProblemCategories[index1] = category.categoryValue; LogCollectorUtils.sStringConversions.Add((object)category.categoryValue, (object)category.categoryId); LogCollectorUtils.sCategoryShowDropdownMapping.Add(category.categoryId, category.showdropdown); if (category.Subcategory != null && category.Subcategory.Count > 0) { Dictionary <string, string> dictionary1 = new Dictionary <string, string>(); Dictionary <string, string> dictionary2 = new Dictionary <string, string>(); List <Subcategory> subcategoryList = new List <Subcategory>((IEnumerable <Subcategory>)category.Subcategory); for (int index2 = 0; index2 < subcategoryList.Count; ++index2) { dictionary1.Add(subcategoryList[index2].subcategoryId, subcategoryList[index2].subcategoryValue); dictionary2.Add(subcategoryList[index2].subcategoryId, subcategoryList[index2].showdropdown); } LogCollectorUtils.sCategorySubcategoryMapping.Add(category.categoryId, dictionary1); LogCollectorUtils.sCategorySubcategoryMappingWithDropdown.Add(category.categoryId, dictionary2); } } }
public static ProblemCategory GetLocalizationForProblemCategory(string vmName) { ProblemCategory problemCategory = new ProblemCategory(); string str = Thread.CurrentThread.CurrentCulture.Name; string locale = RegistryManager.Instance.Guest[vmName].Locale; if (!string.IsNullOrEmpty(locale)) { str = locale; } if (string.Compare(str, "en-US", StringComparison.Ordinal) != 0 && LogCollectorUtils.PopulateLocaleProblemCategories(str, problemCategory)) { Logger.Info("Successfully populated localized strings for Problem Categories for locale: " + str); } else if (LogCollectorUtils.PopulateLocaleProblemCategories("en-US", problemCategory)) { Logger.Info("Successfully populated English strings for Problem Categories"); } return(problemCategory); }
private static bool PopulateLocaleProblemCategories( string locale, ProblemCategory problemCategory) { try { string path = Path.Combine(Path.Combine(RegistryStrings.UserDefinedDir, "Locales\\ProblemCategories"), string.Format((IFormatProvider)CultureInfo.CurrentCulture, "ReportProblemCategories.{0}.Json", (object)locale)); if (!File.Exists(path)) { Logger.Info(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "File does not exist for Problem Categories: {0}", (object)path)); return(false); } string json = File.ReadAllText(path); if (string.IsNullOrEmpty(json)) { Logger.Info("Invalid json"); return(false); } Logger.Info("Found Json: " + json); foreach (KeyValuePair <string, JArray> serializable in (Dictionary <string, JArray>)JObject.Parse(json).ToSerializableDictionary <JArray>()) { string key = serializable.Key; if (serializable.Value.Count == 0) { Logger.Info("No Categories found in Json"); return(false); } problemCategory.Category.Clear(); foreach (JObject jobject1 in serializable.Value) { Category category = new Category() { categoryId = jobject1["id"].ToString(), categoryValue = jobject1["value"].ToString(), showdropdown = jobject1["showdropdown"].ToString() }; if (jobject1.ContainsKey("subcategory")) { foreach (JObject jobject2 in JArray.Parse(jobject1["subcategory"].ToString())) { Subcategory subcategory = new Subcategory() { subcategoryId = jobject2["id"].ToString(), subcategoryValue = jobject2["value"].ToString(), showdropdown = jobject2["showdropdown"].ToString() }; category.Subcategory.Add(subcategory); } } else { Logger.Info("No Subcategories found in Category: " + category.categoryId); } problemCategory.Category.Add(category); } } return(true); } catch (Exception ex) { Logger.Error("Could not populate localizes strings for Problem Categories. Error: " + ex.ToString()); return(false); } }