/// <summary> /// Delete a picture on file system /// </summary> /// <param name="picture">Picture</param> protected virtual void DeletePictureOnFileSystem(Picture picture) { if (picture == null) { throw new ArgumentNullException(nameof(picture)); } var lastPart = GetFileExtensionFromMimeType(picture.MimeType); var fileName = $"{picture.Id:0000000}_0.{lastPart}"; var filePath = GetPictureLocalPath(fileName); _fileProvider.DeleteFile(filePath); }
public static DataSettings LoadSettings(string filePath = null, bool reloadSettings = false, IMotelFileProvider fileProvider = null) { if (!reloadSettings && Singleton <DataSettings> .Instance != null) { return(Singleton <DataSettings> .Instance); } fileProvider ??= CommonHelper.DefaultFileProvider; filePath ??= fileProvider.MapPath(MotelDataSettingsDefaults.FilePath); if (!fileProvider.FileExists(filePath)) { filePath = fileProvider.MapPath(MotelDataSettingsDefaults.ObsoleteFilePath); if (!fileProvider.FileExists(filePath)) { return(new DataSettings()); } 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 = Enum.TryParse(value, true, out DataProviderType providerType) ? providerType : DataProviderType.Unknown; continue; case "DataConnectionString": dataSettings.ConnectionString = value; continue; case "SQLCommandTimeout": //If parsing isn't successful, we set a negative timeout, that means the current provider will usе a default value dataSettings.SQLCommandTimeout = int.TryParse(value, out var timeout) ? timeout : -1; continue; default: dataSettings.RawDataSettings.Add(key, value); continue; } } } 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); }