/// <summary> /// Load data settings /// </summary> /// <param name="filePath">File path; pass null to use the default settings file</param> /// <param name="reloadSettings">Whether to reload data, if they already loaded</param> /// <param name="fileProvider">File provider</param> /// <returns>Data settings</returns> public static DataSettings LoadSettings(string filePath = null, bool reloadSettings = false, IResearchFileProvider fileProvider = null) { if (!reloadSettings && Singleton <DataSettings> .Instance != null) { return(Singleton <DataSettings> .Instance); } fileProvider = fileProvider ?? CommonHelper.DefaultFileProvider; filePath = filePath ?? fileProvider.MapPath(ResearchDataSettingsDefaults.FilePath); //check whether file exists if (!fileProvider.FileExists(filePath)) { //if not, try to parse the file that was used in previous nopCommerce versions filePath = fileProvider.MapPath(ResearchDataSettingsDefaults.ObsoleteFilePath); if (!fileProvider.FileExists(filePath)) { return(new DataSettings()); } //get data settings from the old txt file var dataSettings = new DataSettings(); using (var reader = new StringReader(fileProvider.ReadAllText(filePath, Encoding.UTF8))) { string settingsLine; while ((settingsLine = reader.ReadLine()) != null) { var separatorIndex = settingsLine.IndexOf(':'); if (separatorIndex == -1) { continue; } var key = settingsLine.Substring(0, separatorIndex).Trim(); var value = settingsLine.Substring(separatorIndex + 1).Trim(); switch (key) { case "DataProvider": dataSettings.DataProvider = System.Enum.TryParse(value, true, out DataProviderType providerType) ? providerType : DataProviderType.Unknown; continue; case "DataConnectionString": dataSettings.DataConnectionString = value; continue; default: dataSettings.RawDataSettings.Add(key, value); continue; } } } //save data settings to the new file SaveSettings(dataSettings, fileProvider); //and delete the old one fileProvider.DeleteFile(filePath); Singleton <DataSettings> .Instance = dataSettings; return(Singleton <DataSettings> .Instance); } var text = fileProvider.ReadAllText(filePath, Encoding.UTF8); if (string.IsNullOrEmpty(text)) { return(new DataSettings()); } //get data settings from the JSON file Singleton <DataSettings> .Instance = JsonConvert.DeserializeObject <DataSettings>(text); return(Singleton <DataSettings> .Instance); }