public void SaveTranslations() { OrderTranslations(); //var fileData = JsonConvert.SerializeObject(_translationFile[_cultureCode], Formatting.Indented); lock (_lockObject) { //using (var resFile = File.Create(_resourceFilePath)) //{ // var data = Encoding.UTF8.GetBytes(fileData); // resFile.Write(data, 0, data.Length); // resFile.Flush(); //} foreach (var item in SupportedCultures.Cultures) { if (item.TwoLetterISOLanguageName == "en") { continue; } var file = TranslationFile.GetTranslationFilePath(item.TwoLetterISOLanguageName); NccFileHelper.WriteObject(file.FullName, _translationFile[item.TwoLetterISOLanguageName]); } } }
public bool InactivateTheme(string themeId) { try { var infoFileLocation = Path.Combine(GlobalContext.ContentRootPath, NccInfo.ThemeFolder, themeId, ThemeInfoFileName); if (File.Exists(infoFileLocation)) { var theme = NccFileHelper.LoadObject <Theme>(infoFileLocation); if (theme.IsActive == true) { theme.IsActive = false; NccFileHelper.WriteObject <Theme>(infoFileLocation, theme); } return(true); } else { RegisterErrorMessage("Theme config file Theme.json not found"); } } catch (Exception ex) { return(false); } return(false); }
public bool ActivateDefaultTheme() { try { var infoFileLocation = Path.Combine(GlobalContext.ContentRootPath, NccInfo.ThemeFolder, Constants.DefaultThemeId, ThemeInfoFileName); if (File.Exists(infoFileLocation)) { var theme = NccFileHelper.LoadObject <Theme>(infoFileLocation); theme.ThemeId = Constants.DefaultThemeId; theme.IsActive = true; NccFileHelper.WriteObject <Theme>(infoFileLocation, theme); var defaultTheme = GlobalContext.Themes.Where(x => x.ThemeId == Constants.DefaultThemeId).FirstOrDefault(); if (defaultTheme != null) { defaultTheme.IsActive = true; } ThemeHelper.ActiveTheme = theme; return(true); } else { RegisterErrorMessage("Theme config file Theme.json not found"); } } catch (Exception ex) { RegisterErrorMessage(ex.Message); throw ex; } return(false); }
private static void WriteMessagesToStorage() { var task = new Task(() => { try { var messageDbFilePath = GetMessageDbFilePath(); if (File.Exists(messageDbFilePath) == false) { using (File.Open(messageDbFilePath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite)) { } } if (_messageCache.Count > 0) { NccFileHelper.WriteObject(messageDbFilePath, _messageCache); } else { using (var originalFileStream = File.Open(messageDbFilePath, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite)) { } } } catch (Exception ex) { //TODO: have to improve this. } }); task.Start(); task.Wait(); }
public List <Theme> ScanThemeDirectory(string path) { var themes = new List <Theme>(); var directoryInfo = new DirectoryInfo(path); bool isThemeActivated = false; foreach (var themeDir in directoryInfo.EnumerateDirectories()) { try { if (themeDir.Name == "ChildThemes") { continue; } var configFileLocation = Path.Combine(themeDir.FullName, ThemeInfoFileName); if (File.Exists(configFileLocation)) { var theme = NccFileHelper.LoadObject <Theme>(configFileLocation); theme.ThemeId = themeDir.Name; theme.Folder = themeDir.Name; theme.ConfigFilePath = configFileLocation; if (Directory.Exists(themeDir.FullName + "\\Bin\\Debug\\netcoreapp2.0")) { theme.ResourceFolder = themeDir.FullName + "\\Bin\\Debug\\netcoreapp2.0\\Resources"; theme.AssemblyPath = themeDir.FullName + "\\Bin\\Debug\\netcoreapp2.0\\" + theme.ThemeId + ".dll"; } else if (Directory.Exists(themeDir.FullName + "\\Bin\\Release\\netcoreapp2.0")) { theme.AssemblyPath = themeDir.FullName + "\\Bin\\Release\\netcoreapp2.0\\" + theme.ThemeId + ".dll"; theme.ResourceFolder = themeDir.FullName + "\\Bin\\Release\\netcoreapp2.0\\Resources"; } if (string.IsNullOrEmpty(theme.AssemblyPath) == false && File.Exists(theme.AssemblyPath)) { var themeAssembly = Assembly.LoadFile(theme.AssemblyPath); themes.Add(theme); if (isThemeActivated == false && theme.IsActive) { isThemeActivated = true; ThemeHelper.ActiveTheme = theme; } else { if (theme.IsActive) { theme.IsActive = false; NccFileHelper.WriteObject <Theme>(configFileLocation, theme); } } GlobalContext.Themes.Add(theme); } } else { //RegisterErrorMessage("Theme config file Theme.json not found"); } } catch (Exception ex) { RegisterErrorMessage(ex.Message); throw ex; } } if (ThemeHelper.ActiveTheme == null) { ActivateDefaultTheme(); } return(themes); }