/// <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); }
/// <summary> /// Get system names of installed plugins /// </summary> /// <param name="filePath">Path to the file</param> /// <returns>List of plugin system names</returns> private static IList <string> GetInstalledPluginNames(string 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(GSPluginDefaults.ObsoleteInstalledPluginsFilePath); if (!_fileProvider.FileExists(filePath)) { return(new List <string>()); } //get plugin system names from the old txt file var pluginSystemNames = new List <string>(); using (var reader = new StringReader(_fileProvider.ReadAllText(filePath, Encoding.UTF8))) { string pluginName; while ((pluginName = reader.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(pluginName)) { pluginSystemNames.Add(pluginName.Trim()); } } } //save system names of installed plugins to the new file SaveInstalledPluginNames(pluginSystemNames, _fileProvider.MapPath(GSPluginDefaults.InstalledPluginsFilePath)); //and delete the old one _fileProvider.DeleteFile(filePath); return(pluginSystemNames); } var text = _fileProvider.ReadAllText(filePath, Encoding.UTF8); if (string.IsNullOrEmpty(text)) { return(new List <string>()); } //get plugin system names from the JSON file return(JsonConvert.DeserializeObject <IList <string> >(text)); }
/// <summary> /// Delete the file /// </summary> /// <param name="path">Path to the file</param> /// <returns>A task that represents the completion of the operation</returns> protected virtual async Task DeleteFileAsync(string path) { path = GetFullPath(GetVirtualPath(path)); if (!_fileProvider.FileExists(path)) { throw new Exception(GetLanguageResource("E_DeleteFileInvalidPath")); } try { _fileProvider.DeleteFile(path); await HttpContext.Response.WriteAsync(GetSuccessResponse()); } catch { throw new Exception(GetLanguageResource("E_DeletеFile")); } }
public virtual IActionResult MaintenanceDeleteFiles(MaintenanceModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageMaintenance)) { return(AccessDeniedView()); } var startDateValue = model.DeleteExportedFiles.StartDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteExportedFiles.StartDate.Value, _dateTimeHelper.CurrentTimeZone); var endDateValue = model.DeleteExportedFiles.EndDate == null ? null : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.DeleteExportedFiles.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1); model.DeleteExportedFiles.NumberOfDeletedFiles = 0; foreach (var fullPath in _fileProvider.GetFiles(_fileProvider.GetAbsolutePath(EXPORT_IMPORT_PATH))) { try { var fileName = _fileProvider.GetFileName(fullPath); if (fileName.Equals("index.htm", StringComparison.InvariantCultureIgnoreCase)) { continue; } var info = _fileProvider.GetFileInfo(_fileProvider.Combine(EXPORT_IMPORT_PATH, fileName)); var lastModifiedTimeUtc = info.LastModified.UtcDateTime; if ((!startDateValue.HasValue || startDateValue.Value < lastModifiedTimeUtc) && (!endDateValue.HasValue || lastModifiedTimeUtc < endDateValue.Value)) { _fileProvider.DeleteFile(fullPath); model.DeleteExportedFiles.NumberOfDeletedFiles++; } } catch (Exception exc) { ErrorNotification(exc, false); } } return(View(model)); }
/// <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, IGSFileProvider fileProvider = null) { if (!reloadSettings && Singleton <DataSettings> .Instance != null) { return(Singleton <DataSettings> .Instance); } fileProvider = fileProvider ?? CommonHelper.DefaultFileProvider; filePath = filePath ?? fileProvider.MapPath(GSDataSettingsDefaults.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(GSDataSettingsDefaults.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 = 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); }
void DeleteWorkFileOnDisk(WorkFile item) { var _fileStore = _fileProvider.Combine(_fileProvider.MapPath(GSDataSettingsDefaults.FolderWorkFiles), item.CreatedDate.ToPathFolderStore(), item.FileGuid.ToString() + item.Extension); _fileProvider.DeleteFile(_fileStore, true); }