示例#1
0
        /// <summary>
        ////Get the default plugin for the asset's file extension by context
        /// </summary>
        public Plugin GetDefaultPluginForAsset(Asset asset)
        {
            string fileExtension = asset.FileExtension;

            if (fileExtension == "flv")
            {
                string rtmpStreamingServer = ConfigurationManager.AppSettings.GetValue("RTMPStreamingServer");
                if (!StringUtils.IsBlank(rtmpStreamingServer))
                {
                    fileExtension += "-streaming";
                }
            }

            AssetTypeFileExtension atfe = AssetTypeFileExtensionCache.Instance.GetByExtension(fileExtension);

            //try and locate the plugin for the file extension
            if (atfe.Plugin != Guid.Empty)
            {
                Plugin plugin = GetValidPluginByKey(atfe.Plugin);
                if (!plugin.IsNull)
                {
                    //check whether plugin support this extension or if force preview set
                    return(plugin);
                }
            }

            //use the system default
            return(GetDefaultPlugin());
        }
示例#2
0
        /// <summary>
        /// Determines whether the specified plugin is currently in use
        /// </summary>
        public bool IsUsed(Plugin plugin)
        {
            bool active = false;

            if (!plugin.IsUnregistered && plugin.RegistrationKey != Guid.Empty)
            {
                //check if any file extensions use it
                AssetTypeFileExtensionFinder atfeFinder = new AssetTypeFileExtensionFinder {
                    Plugin = plugin.RegistrationKey
                };
                AssetTypeFileExtension atfe = AssetTypeFileExtension.FindOne(atfeFinder);
                if (!atfe.IsNull)
                {
                    active = true;
                }
                else
                {
                    //check to see if in use by any assets
                    AssetFinder assetFinder = new AssetFinder {
                        Plugin = plugin.RegistrationKey
                    };
                    Asset asset = Asset.FindOne(assetFinder);
                    active = !asset.IsNull;
                }
            }

            return(active);
        }
        public override void ProcessRequest()
        {
            string token             = GetTokenFromFilename();
            AssetTypeFileExtension o = AssetTypeFileExtensionCache.Instance.GetByExtension(token);

            if (!o.IsNull && o.IconImage != null && o.IconImage.Length > 0)
            {
                SiteUtils.SendFile(o.IconFilename, o.IconImage, false);
                return;
            }

            // Look for an icon for this file extension on disk
            string path = Context.Server.MapPath("~/Images/Icons/File/" + token + ".gif");

            // Finally, resort to generic
            if (!File.Exists(path))
            {
                path = Context.Server.MapPath("~/Images/Icons/File/Generic.gif");
            }

            // Enure icon exists
            if (!File.Exists(path))
            {
                throw new FileNotFoundException(Path.GetFileName(path));
            }

            WriteFileToResponseStream(path, null, false);
            return;
        }
示例#4
0
        public static void Delete(AssetTypeFileExtension atfe)
        {
            // First delete the asset type file extension from the database
            AssetTypeFileExtension.Delete(atfe.AssetTypeFileExtensionId);

            // Invalidate caches
            CacheManager.InvalidateCache("AssetTypeFileExtension", CacheType.All);
            CacheManager.InvalidateCache("AssetType", CacheType.All);
        }
示例#5
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            AssetTypeFileExtension atfe = SaveATFE();

            if (!atfe.IsNull)
            {
                AuditLogManager.LogUserAction(SessionInfo.Current.User, AuditUserAction.ModifyFileExtension, string.Format("File Extension: {0}, ID: {1}", atfe.Extension, atfe.AssetTypeFileExtensionId));
            }
        }
示例#6
0
        protected void DuplicateButton_Click(object sender, EventArgs e)
        {
            AssetTypeFileExtension atfe = SaveATFE();

            if (!atfe.IsNull)
            {
                string ext = atfe.Extension;
                AssetTypeFileExtensionManager.Duplicate(atfe);
                AuditLogManager.LogUserAction(SessionInfo.Current.User, AuditUserAction.DuplicateFileExtension, string.Format("File Extension: {0} (temp ext: {1}), ID: {2}", ext, atfe.Extension, atfe.AssetTypeFileExtensionId));
                Response.Redirect("ManageFileExtensionsForm.aspx?Action=Duplicate&AssetTypeFileExtensionId=" + atfe.AssetTypeFileExtensionId);
            }
        }
示例#7
0
        private static void Validate(AssetTypeFileExtension atfe, BinaryFile iconFile)
        {
            ErrorList errors = new ErrorList();

            if (StringUtils.IsBlank(atfe.Extension))
            {
                errors.Add("Extension is required");
            }
            else if (atfe.Extension.Length > 4)
            {
                errors.Add("Extension cannot exceed 4 characters");
            }
            else if (!Regex.IsMatch(atfe.Extension, "^[0-9a-z]+$"))
            {
                errors.Add("Extension can only contain letters and numbers");
            }
            else
            {
                AssetTypeFileExtension o = AssetTypeFileExtensionCache.Instance.GetByExtension(atfe.Extension);

                if (atfe.IsNew && !o.IsNull)
                {
                    errors.Add("File extension is already assigned to asset type: " + o.AssetType.Name);
                }

                if (!atfe.IsNew && !o.IsNull && !o.AssetTypeFileExtensionId.Equals(atfe.AssetTypeFileExtensionId))
                {
                    errors.Add("File extension is already assigned to asset type: " + o.AssetType.Name);
                }
            }

            if (StringUtils.IsBlank(atfe.Name))
            {
                errors.Add("Name is required");
            }

            if (atfe.AssetTypeId == 0)
            {
                errors.Add("Asset Type is required");
            }

            if (!iconFile.IsEmpty && !GeneralUtils.ValueIsInList(iconFile.FileExtension, "gif", "jpg", "png"))
            {
                errors.Add("Icon must be a GIF, JPG or PNG file");
            }

            if (errors.Count > 0)
            {
                throw new AssetTypeFileExtensionException(errors, atfe);
            }
        }
示例#8
0
        public static void Duplicate(AssetTypeFileExtension atfe)
        {
            // Reset ID to create new record
            atfe.AssetTypeFileExtensionId = null;

            // Set extension to extension prefixed with tilde
            // If we get two people editing extension at same time,
            // this will cause an error as the extension must be unique
            atfe.Extension = "~" + atfe.Extension.Substring(0, 4);

            // Make it invisible for now
            atfe.IsVisible = false;

            // Save it
            AssetTypeFileExtension.Update(atfe);
        }
示例#9
0
        private AssetTypeFileExtension GetATFEFromForm()
        {
            AssetTypeFileExtension atfe = AssetTypeFileExtension.Get(AssetTypeFileExtensionId);

            if (atfe.IsNull)
            {
                atfe = AssetTypeFileExtension.New();
            }

            atfe.Extension   = ExtensionTextBox.Text.Trim().ToLower();
            atfe.Name        = FileTypeNameTextBox.Text.Trim();
            atfe.AssetTypeId = AssetTypeDropDownList.SelectedId;
            atfe.IsVisible   = IsVisibleCheckBox.Checked;
            atfe.Plugin      = PluginManager.GetRegistrationKey(PreviewPluginDropDownList.SelectedId);

            return(atfe);
        }
示例#10
0
        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            // Get the ID of the extension to be deleted
            int id = WebUtils.GetIntRequestParam("AssetTypeFileExtensionId", 0);

            // Get the file extension to be deleted
            AssetTypeFileExtension atfe = AssetTypeFileExtension.Get(id);

            // Now actually delete it
            AssetTypeFileExtensionManager.Delete(atfe);

            // Update audit log
            AuditLogManager.LogUserAction(SessionInfo.Current.User, AuditUserAction.DeleteFileExtension, string.Format("File Extension: {0}, ID: {1}", atfe.Extension, atfe.AssetTypeFileExtensionId));

            // Update UI
            FormPanel.Visible    = false;
            SuccessPanel.Visible = true;
            MessageLabel2.SetSuccessMessage("File extension deleted successfully");
        }
示例#11
0
        public static void Save(AssetTypeFileExtension atfe, BinaryFile iconFile)
        {
            Validate(atfe, iconFile);

            if (iconFile.IsEmpty)
            {
                atfe.IconFilename = string.Empty;
                atfe.IconImage    = ByteArray.Empty.ContentBytes;
            }
            else
            {
                atfe.IconFilename = iconFile.FileName;
                atfe.IconImage    = ByteArray.New(iconFile.InputStream).ContentBytes;
            }

            AssetTypeFileExtension.Update(atfe);

            CacheManager.InvalidateCache("AssetTypeFileExtension", CacheType.All);
            CacheManager.InvalidateCache("AssetType", CacheType.All);
        }
示例#12
0
        private AssetTypeFileExtension SaveATFE()
        {
            AssetTypeFileExtension atfe = GetATFEFromForm();
            BinaryFile             file = new BinaryFile(IconFileUpload.PostedFile);

            try
            {
                AssetTypeFileExtensionManager.Save(atfe, file);
                FormPanel.Visible    = false;
                SuccessPanel.Visible = true;

                return(atfe);
            }
            catch (AssetTypeFileExtensionException ex)
            {
                MessageLabel1.SetErrorMessage("Error saving file extension", ex.Errors);
            }

            return(AssetTypeFileExtension.Empty);
        }
示例#13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int assetTypeId = WebUtils.GetIntRequestParam("AssetTypeId", 0);
                AssetTypeDropDownList.SafeSelectValue(assetTypeId);

                int    id  = WebUtils.GetIntRequestParam("AssetTypeFileExtensionId", 0);
                string ext = WebUtils.GetRequestParam("Extension", string.Empty);

                AssetTypeFileExtension atfe = AssetTypeFileExtensionCache.Instance.GetById(id);

                if (atfe.IsNull && !StringUtils.IsBlank(ext))
                {
                    atfe = AssetTypeFileExtensionCache.Instance.GetByExtension(ext);
                }

                if (!atfe.IsNull)
                {
                    AssetTypeFileExtensionId = atfe.AssetTypeFileExtensionId.GetValueOrDefault();

                    // Populate UI
                    ExtensionTextBox.Text    = atfe.Extension;
                    FileTypeNameTextBox.Text = atfe.Name;
                    IconImage.ImageUrl       = SiteUtils.GetFileTypeImageUrl(atfe.Extension);
                    AssetTypeDropDownList.SafeSelectValue(atfe.AssetTypeId);
                    IsVisibleCheckBox.Checked = atfe.IsVisible;
                    IconImagePanel.Visible    = true;
                    DeleteButton.Visible      = true;


                    string generatedExtension = APSGateway.Instance.GeneratesFileExtension(atfe.Extension);
                    PreviewPluginDropDownList.Extension         = generatedExtension;
                    PreviewFileFormatLabel.Text                 = generatedExtension;
                    PreviewPluginDropDownList.ShowSupportedOnly = ShowSupportedPluginsCheckbox.Checked;
                    PreviewPluginDropDownList.RefreshFromDataSource();

                    if (atfe.Plugin != Guid.Empty)
                    {
                        //try and select the file extensions plugin
                        PreviewPluginDropDownList.SafeSelectValue(PluginManager.GetPluginId(atfe.Plugin));

                        if (PreviewPluginDropDownList.SelectedValue == PreviewPluginDropDownList.BlankValue)
                        {
                            //not found in supported list so try finding the plugin in the unsupported list
                            ShowSupportedPluginsCheckbox.Checked        = false;
                            PreviewPluginDropDownList.ShowSupportedOnly = false;
                            PreviewPluginDropDownList.RefreshFromDataSource();
                            PreviewPluginDropDownList.SafeSelectValue(PluginManager.GetPluginId(atfe.Plugin));
                        }
                    }

                    ProcessingSupportPlaceHolder.Visible = true;
                    ProcessingSupportLabel.Text          = (APSGateway.Instance.CanProcess(atfe.Extension) ? "Yes" : "No");

                    // Duplicate, clear extension
                    if (WebUtils.GetRequestParam("Action", string.Empty) == "Duplicate")
                    {
                        ExtensionTextBox.Text = string.Empty;
                    }
                }
            }
        }