public static void LoadVersionsSettings() { string fullPath = GlobalSettings.MainDirectory + "\\" + Constants.FILENAME_SETTINGS_VERSIONS; string folderPath = fullPath.Substring(0, fullPath.LastIndexOf('\\')); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); SaveVersionsSettings(); } else if (!File.Exists(fullPath)) { SaveVersionsSettings(); } else if (File.Exists(fullPath)) { try { using (FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateTextReader(fileStream, Encoding.UTF8, new XmlDictionaryReaderQuotas(), null)) { xmlVersionsSettings = (RootSettingsVersions)xmlSerializer.ReadObject(dictionaryReader); } } } catch (Exception ex) { MessageBox.Show(Messages.ERROR_LOAD_SETTINGS_VERSION + ex.Message, Messages.CAPTION_COMMON); } } }
private static void CheckDictionaryState() { if (xmlVersionsSettings == null) { xmlVersionsSettings = new RootSettingsVersions(); } if (xmlVersionsSettings.VersionsSettings == null) { xmlVersionsSettings.VersionsSettings = new Dictionary <string, VersionSettings>(); } if (!string.IsNullOrWhiteSpace(CurrentVersion) && !xmlVersionsSettings.VersionsSettings.ContainsKey(CurrentVersion)) { ResetCurrentVersionSettings(); } }
static VersionsSettings() { xmlVersionsSettings = new RootSettingsVersions(); xmlSerializer = new DataContractSerializer(typeof(RootSettingsVersions)); }