Пример #1
0
        /*
        /// <summary>
        /// Associates the given image with the Pristine image
        /// specified with the ID value.
        /// DANGEROUS FUNCTION
        /// Do NOT use this to derive an image.  This is only for use when
        /// a newly added image is loaded.
        /// Use DeriveImage() to derive a new image.
        /// </summary>
        /// <param name="strPhysicalImagePath">ID of the Pristine Image</param>
        /// <param name="m_pristineImageId">Optional:  If empty then a new image is created.
        /// if a value</param>
        /// <returns></returns>
        /// <remarks>The scenario is such:
        /// Upload a new image
        /// Add the new image as Pristine
        /// Use the uploaded image (as a shortcut) as the original derived image
        /// Add the image to the DB as a derived image
        /// Edit the image.
        ///</remarks>
        private int AssociateModImage(int pristineImageId, string physicalImagePath)
        {
            Ektron.Cms.API.Content.Content objContent = new Ektron.Cms.API.Content.Content();
            LibraryImageFoundationData imagePristineData = new LibraryImageFoundationData();

            imagePristineData.Id = pristineImageId;
            InitGlobalRefs();
            if (null != m_Library)
            {
                m_Library.RetrieveFoundationImage(ref imagePristineData);

                if (null != m_imageModifyData)
                {
                    //m_imageModifyData.ImageId  // set when image is stored
                    m_imageModifyData.LanguageId = objContent.DefaultContentLanguage;
                    m_imageModifyData.PristineId = imagePristineData.Id;
                    m_imageModifyData.LibraryId = 0;
                    m_imageModifyData.DerivedFromId = 0;
                    m_imageModifyData.PristineCheckSumVal = imagePristineData.CheckSum;
                    m_imageModifyData.WorkbenchURL = "";  // TODO
                    m_imageModifyData.PublishURL = "";  // TODO
                    m_imageModifyData.PhysicalPath = physicalImagePath;
                    m_imageModifyData.MimeType = imagePristineData.MimeType;
                    m_imageModifyData.LastUserId = objContent.UserId;
                    m_imageModifyData.CurrentUndoStepId = 0;
                    m_imageModifyData.DeriveStepId = 0;

                    m_modifyImageId = m_Library.AddModifiedImage(ref m_imageModifyData);
                }
            }

            return m_modifyImageId;
        }

        /// <summary>
        /// This adds the Pristine Original to the database.
        /// All modifications have their origins to this image.
        /// </summary>
        /// <param name="strPhysicalImagePath"></param>
        /// <returns>The ID of the added Pristine Original.
        /// A -1 is an error.</returns>
        private int AddPristineImage(string physicalImagePath)
        {
            string strPristinePath = CreatePristineImagePath(physicalImagePath);
            Ektron.Cms.API.Content.Content objContent = new Ektron.Cms.API.Content.Content();
            // Add the pristine image
            //LibraryNewImageFoundationData imageAddData = new LibraryNewImageFoundationData();

            if (null == m_imageTool)
            {
                m_imageTool = new ImageTool(strPristinePath);
            }

            imageAddData.DepthPx = m_imageTool.Depth;
            imageAddData.Height = m_imageTool.Height;
            imageAddData.LanguageId = objContent.DefaultContentLanguage;
            imageAddData.Width = m_imageTool.Height;
            imageAddData.MimeType = FileMimeType(physicalImagePath);
            imageAddData.FileProperName = System.IO.Path.GetFileName(physicalImagePath);
            imageAddData.PathAndFile = strPristinePath;

            // NOTE:  A return value of -1 means no ID was assigned.
            //m_pristineImageId = m_Library.StoreFoundationImage(ref imageAddData);

            return m_pristineImageId;
        }
         */
        private static string CreatePristineImagePath(string imagePath)
        {
            string strDestPath = imagePath;

            // For now, use the asset path.
            Ektron.Cms.SiteAPI siteAPI = new Ektron.Cms.SiteAPI();

            // There is a problem in the unit tests where the HttpContext is
            // NOT always available.  This is a bad situation, since the module
            // needs to know where the location is.  So, if this is the case
            // use the current folder as the location.
            // So, this has to break from the FXCop standard and eat the
            // error, since it only pertains to this particular instance.
            //strDestPath = System.IO.Path.Combine(System.Web.HttpContext.Current.Request.MapPath(siteAPI.SitePath.ToString()), "assets");
            string strSiteLocation;
            try
            {
                strSiteLocation = System.Web.HttpContext.Current.Request.MapPath(siteAPI.SitePath.ToString());
            }
            catch
            {
                strSiteLocation = Directory.GetCurrentDirectory();  // @"C:\Inetpub\wwwroot\400WorkareaR2\WorkArea\";
            }

            strDestPath = System.IO.Path.Combine(strSiteLocation, "assets");
            strDestPath = System.IO.Path.Combine(strDestPath, mc_defaultPristineSubFolder);

            // Make sure it exists
            System.IO.Directory.CreateDirectory(strDestPath);

            strDestPath = System.IO.Path.Combine(strDestPath,
                System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()) + System.IO.Path.GetExtension(imagePath));

            // Now, copy over.
            System.IO.File.Copy(imagePath, strDestPath);

            return strDestPath;
        }
Пример #2
0
    private void DeleteTemplate()
    {
        long template_id = System.Convert.ToInt64(Request.QueryString["id"]);
        Ektron.Cms.PageBuilder.WireframeModel wireframeModel = new Ektron.Cms.PageBuilder.WireframeModel();
        Ektron.Cms.PageBuilder.WireframeData wireframe = wireframeModel.FindByTemplateID(template_id);

        SetTitleBarToMessage("lbl delete template");
        AddBackButton("template_config.aspx?view=list");
        AddHelpButton("template_delete");
        long[] folders = m_refContentApi.EkContentRef.GetTemplateDefaultFolderUsage(template_id);
        Collection contentBlockInfo = m_refContentApi.EkContentRef.GetTemplateContentBlockUsage(template_id);
        StringBuilder str = new StringBuilder();
        str.Append("<div class=\"ektronPageContainer\">");
        if (folders.Length > 0)
        {
            str.Append(m_refMsg.GetMessage("lbl folders with") + " " + "\'<i>" + m_refContentApi.EkContentRef.GetTemplateNameByID(template_id) + "</i>\'" + " " + m_refMsg.GetMessage("lbl as their default template") + ":");
            str.Append("<div class=\"ektronTopSpace\"></div>");
            str.Append("<table width=\"100%\" class=\"ektronGrid ektronBorder\">");
            str.Append("<tbody>");
            str.Append("<tr class=\"title-header\">");
            str.Append("<th>Folder Path</th>");
            str.Append("</tr>");
            int i = 0;
            for (i = 0; i <= folders.Length - 1; i++)
            {
                str.Append("<tr>");
                str.Append("<td>" + m_refContentApi.GetFolderById(folders[i]).NameWithPath + "</td>");
                str.Append("</tr>");
            }
            str.Append("</tbody>");
            str.Append("</table>");
            str.Append("<div class=\"ektronTopSpace\"></div>");
            str.Append(m_refMsg.GetMessage("alert msg set folders") + " " + "\'<i>" + m_refContentApi.EkContentRef.GetTemplateNameByID(template_id) + "</i>\'.");

        }
        else
        {
            if (contentBlockInfo.Count == 0 || !(Request.Form["deleteTemplate"] == null))
            {
                bool messageadded = false;
                if (wireframe != null)
                {
                    if (wireframe.Template.SubType == Ektron.Cms.Common.EkEnumeration.TemplateSubType.MasterLayout)
                    {
                        //delete the layout as well
                        Ektron.Cms.PageBuilder.TemplateModel templmodel = new Ektron.Cms.PageBuilder.TemplateModel();
                        string status = string.Empty;
                        Ektron.Cms.SiteAPI siteApi = new Ektron.Cms.SiteAPI();
                        Ektron.Cms.LanguageData[] langData = siteApi.GetAllActiveLanguages();
                        int j = 0;
                        for (j = 0; j <= langData.Length - 1; j++)
                        {
                            long contType = this.ContentAPIRef.EkContentRef.GetContentType(wireframe.Template.MasterLayoutID, langData[j].Id);
                            if (contType != 0)
                            {
                                int tempLang = System.Convert.ToInt32(ContentAPIRef.ContentLanguage);
                                ContentAPIRef.ContentLanguage = langData[j].Id;
                                status = (string)(this.ContentAPIRef.EkContentRef.GetContentStatev2_0(wireframe.Template.MasterLayoutID)["ContentStatus"]);
                                if (status == "O" || status == "S")
                                {
                                    Collection permissions = ContentAPIRef.EkContentRef.CanIv2_0(wireframe.Template.MasterLayoutID, "content");
                                    if (permissions.Contains("CanIApprove") && System.Convert.ToBoolean(permissions["CanIApprove"]))
                                    {
                                        ContentAPIRef.EkContentRef.TakeOwnership(wireframe.Template.MasterLayoutID);
                                    }
                                }
                                if (status == "S")
                                {
                                    ContentAPIRef.EkContentRef.CheckContentOutv2_0(wireframe.Template.MasterLayoutID);
                                }
                                status = (string)(this.ContentAPIRef.EkContentRef.GetContentStatev2_0(wireframe.Template.MasterLayoutID)["ContentStatus"]);
                                if (status == "O")
                                {
                                    ContentAPIRef.EkContentRef.CheckIn(wireframe.Template.MasterLayoutID, "");
                                }
                                Ektron.Cms.Content.Behaviors.DeleteContentBehavior deletebehavior = new Ektron.Cms.Content.Behaviors.DeleteContentBehavior(ContentAPIRef.RequestInformationRef);
                                deletebehavior.Delete(wireframe.Template.MasterLayoutID, null);
                                ContentAPIRef.ContentLanguage = tempLang;
                                //if content exists and status is now M then show tell user that layout has been marked for delete
                                if (!messageadded)
                                {
                                    Collection cont = ContentAPIRef.EkContentRef.GetContentByIDv2_0(wireframe.Template.MasterLayoutID);
                                    if (cont.Contains("ContentStatus"))
                                    {
                                        if ((string)cont["ContentStatus"] == "M")
                                        {
                                            str.Append("Template <i>" + wireframe.Template.FileName + "</i> is a Master Layout and has been marked for delete. When an approver approves this delete it will be removed from the templates list.");
                                            messageadded = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        wireframeModel.Remove(wireframe.ID);
                        Response.Redirect("template_config.aspx", false);
                    }
                }
                try
                {
                    m_refContentApi.EkContentRef.PurgeTemplate(template_id);
                }
                catch (Exception ex)
                {
                    string _error = ex.Message;
                }
                if (!messageadded)
                {
                    Response.Redirect("template_config.aspx", false);
                }
            }
            else
            {
                LocalizationAPI objLocalizationApi = new LocalizationAPI();
                str.Append(m_refMsg.GetMessage("lbl content with") + " " + "\'<i>" + m_refContentApi.EkContentRef.GetTemplateNameByID(template_id) + "</i>\'" + " " + m_refMsg.GetMessage("lbl as a template") + ":");
                str.Append("<div class=\"ektronTopSpace\"></div>");
                str.Append("<table width=\"100%\" class=\"ektronGrid ektronBorder\">");
                str.Append("<tbody>");
                str.Append("<tr class=\"title-header\">");
                str.Append("<th width=\"70%\" align=\"center\">Title</th>");
                str.Append("<th width=\"15%\" align=\"center\">ID</th>");
                str.Append("<th width=\"15%\" align=\"center\">Language</th>");
                str.Append("</tr>");
                int i = 0;

                foreach (Collection col in contentBlockInfo)
                {
                    str.Append("<tr>");
                    m_refContentApi.ContentLanguage = Convert.ToInt32(col["language_id"]);
                    ContentData content_data = m_refContentApi.EkContentRef.GetContentById(Convert.ToInt64(col["content_id"]), Ektron.Cms.Content.EkContent.ContentResultType.Published);
                    str.Append("<td>" + content_data.Title + "</td>");
                    str.Append("<td align=\"center\">" + content_data.Id + "</td>");
                    str.Append("<td align=\"center\"><img src=\"" + objLocalizationApi.GetFlagUrlByLanguageID(content_data.LanguageId) + "\" /></td>");
                    str.Append("</tr>");
                    i++;
                }
                str.Append("</tbody>");
                str.Append("</table>");

                if (wireframe == null || wireframe.Template.SubType != Ektron.Cms.Common.EkEnumeration.TemplateSubType.MasterLayout)
                {
                    str.Append("<div class=\"ektronTopSpace\"></div>");
                    str.Append(m_refMsg.GetMessage("alert msg del template"));
                    str.Append(" <input type=\"submit\" id=\"deleteTemplate\" name=\"deleteTemplate\" value=\"Delete\" />&nbsp;&nbsp;");
                    str.Append("<input type=\"button\" id=\"cancelDelete\" name=\"cancelDelete\" value=\"Cancel\" onclick=\"window.location.replace(\'template_config.aspx\')\" />");
                }
                else
                {
                    str.Append("<div class=\"ektronTopSpace\"></div>");
                    str.Append(m_refMsg.GetMessage("alert msg set layout") + " " + "\'<i>" + wireframe.Template.FileName + "</i>\'.");
                }
            }
        }
        str.Append("</div>");
        MainBody.Text = str.ToString();
    }