/// <summary> /// Validate and save the asset file path to the database /// Also create require subfolders if necessary /// </summary> private static void Save(AssetFilePath assetFilePath) { ValidateAssetFilePathWithException(assetFilePath); AssetFilePath.Update(assetFilePath); foreach (string subfolder in m_RequiredSubFolders) { string fullpath = Path.Combine(assetFilePath.Path, subfolder); if (!Directory.Exists(fullpath)) { try { Directory.CreateDirectory(fullpath); m_Logger.InfoFormat("Created directory: {0}", fullpath); } catch (Exception ex) { m_Logger.Warn(string.Format("Unable to create folder: {0}. Error : {1}", fullpath, ex.Message), ex); } } } CacheManager.InvalidateCache("AssetFilePath", CacheType.All); }
private static ErrorList ValidateAssetFilePath(AssetFilePath assetFilePath) { ErrorList errors = new ErrorList(); if (assetFilePath.Path.Trim() == string.Empty) { errors.Add("Path cannot be empty"); } else if (!Directory.Exists(assetFilePath.Path)) { errors.Add("Path does not exist"); } else { AssetFilePathFinder finder = new AssetFilePathFinder { Path = assetFilePath.Path.Trim() }; AssetFilePath afp = AssetFilePath.FindOne(finder); if (afp.Path == assetFilePath.Path && afp.AssetFilePathId.GetValueOrDefault(-1) != assetFilePath.AssetFilePathId.GetValueOrDefault(0)) { errors.Add("The specified path already has already been entered"); } } return(errors); }
/// <summary> /// Creates a new asset file path with the specified path /// </summary> public static void CreateNew(string path) { AssetFilePath afp = AssetFilePath.New(); afp.Path = path; afp.IsDefault = false; Save(afp); }
private static void ValidateAssetFilePathWithException(AssetFilePath assetFilePath) { ErrorList errors = ValidateAssetFilePath(assetFilePath); if (errors.Count > 0) { throw new InvalidAssetFilePathException(errors, assetFilePath); } }
/// <summary> /// Set the default asset file path to that with the specified id /// All other asset file paths are marked as not default as there can only be one /// default asset file path at any time /// </summary> public static void SetDefault(int assetFilePathId) { foreach (var afp in GetList()) { afp.IsDefault = (afp.AssetFilePathId == assetFilePathId); AssetFilePath.Update(afp); } CacheManager.InvalidateCache("AssetFilePath", CacheType.All); }
/// <summary> /// Get the default asset file path /// </summary> public static AssetFilePath GetDefault() { AssetFilePath afp = AssetFilePathCache.Instance.GetList().Find(o => o.IsDefault) ?? AssetFilePath.Empty; if (afp.IsNull) { throw new SystemException("No default asset file path specified. Please ensure that the default asset file path in the database has 'IsDefault' set to true"); } return(afp); }
/// <summary> /// Gets the absolute folder where files of the specified type should be saved for the specified asset /// </summary> internal static string GetFolder(AssetFilePath path, AssetFileType fileType) { if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AssetFile, AssetFileType.AssetPreview, AssetFileType.AssetThumbnail)) { return(Path.Combine(path.Path, fileType + "s")); } if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AssetFileZipped)) { return(Path.Combine(path.Path, "AssetFilesZipped")); } if (GeneralUtils.ValueIsInList(fileType, AssetFileType.AttachedFile)) { throw new SystemException("Attached files are not stored on disk"); } throw new SystemException("Unknown file type: " + fileType); }
protected void AssetFilePathsDataGrid_OnItemDataBound(object sender, DataGridItemEventArgs e) { switch (e.Item.ItemType) { case (ListItemType.Item): case (ListItemType.AlternatingItem): AssetFilePath assetFilePath = (AssetFilePath)e.Item.DataItem; HiddenField AssetFilePathIdHiddenField = (HiddenField)e.Item.FindControl("AssetFilePathIdHiddenField"); Label PathLabel = (Label)e.Item.FindControl("PathLabel"); Label AssetCountLabel = (Label)e.Item.FindControl("AssetCountLabel"); RadioButton IsDefaultRadioButton = (RadioButton)e.Item.FindControl("IsDefaultRadioButton"); AssetFilePathIdHiddenField.Value = assetFilePath.AssetFilePathId.ToString(); PathLabel.Text = assetFilePath.Path; AssetCountLabel.Text = assetFilePath.AssetCount.ToString(); IsDefaultRadioButton.Checked = assetFilePath.IsDefault; IsDefaultRadioButton.Attributes.Add("onClick", "selectRadio(this)"); break; } }
/// <summary> /// Gets list of asset file paths /// </summary> public static EntityList <AssetFilePath> GetList() { AssetFilePathFinder finder = new AssetFilePathFinder(); return(AssetFilePath.FindMany(finder)); }