コード例 #1
0
        /// <summary>
        /// Populates the languages recursive.
        /// </summary>
        /// <param name="folderId">The folder id.</param>
        private void PopulateLanguagesRecursive(int folderId)
        {
            Guid siteId = Guid.Empty;

            DataTable item = FileTreeItem.GetItemByIdDT(folderId);

            // We only care about pages
            if (item != null && item.Rows.Count > 0)
            {
                if ((bool)item.Rows[0]["IsFolder"])
                {
                    DataTable childItems = FileTreeItem.LoadItemByFolderIdDT(folderId);
                    foreach (DataRow childItem in childItems.Rows)
                    {
                        PopulateLanguagesRecursive((int)childItem["PageId"]);
                    }
                }
            }

            siteId = (Guid)item.Rows[0]["SiteId"];
            PageDocument pageDocument = null;

            //GET PUBLISHED VERSION
            int       statusId      = WorkflowStatus.GetLast();
            DataTable versionsTable = PageVersion.GetVersionByStatusIdDT(folderId, statusId);

            // Find page document
            int templateId = 0;
            int stateId    = 0;
            int langId     = 0;

            if (versionsTable != null && versionsTable.Rows.Count > 0)
            {
                foreach (DataRow versionRow in versionsTable.Rows)
                {
                    int versionId = 0;
                    int.TryParse(versionRow["VersionId"].ToString(), out versionId);
                    templateId = Int32.Parse(versionRow["templateid"].ToString());
                    PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider();
                    pageDocument = PageDocument.Open(versionId, OpenMode.View, Guid.Empty);
                    stateId      = Int32.Parse(versionRow["stateid"].ToString());
                    langId       = Int32.Parse(versionRow["LangId"].ToString());

                    // Found a non empty page document
                    if (pageDocument != null)
                    {
                        break;
                    }
                }
            }

            // Get list of languages
            SiteDto siteDto = SiteManager.GetSite(siteId);

            foreach (SiteDto.SiteLanguageRow langRow in siteDto.SiteLanguage)
            {
                IDataReader reader = Language.GetLangByName(langRow.LanguageCode);
                if (reader.Read())
                {
                    int currentLangId = (int)reader["LangId"];

                    // We skip the default page document language
                    if (currentLangId == langId)
                    {
                        reader.Close();
                        continue;
                    }

                    // If we already have a specified language define, skip it
                    IDataReader versionReader = PageVersion.GetVersionByLangId(folderId, langId);
                    if (!versionReader.Read())
                    {
                        versionReader.Close();
                        continue;
                    }

                    int versionId = PageVersion.AddPageVersion(folderId, templateId, currentLangId, ProfileContext.Current.UserId, stateId, String.Empty);
                    PageDocument.PersistentDocumentStorage = new SqlPageDocumentStorageProvider();
                    PageDocument.PersistentDocumentStorage.Save(pageDocument, versionId, ProfileContext.Current.UserId);
                    versionReader.Close();
                }
                reader.Close();
            }
        }
コード例 #2
0
        /// <summary>
        /// Runs the command.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        private void RunCommand(string commandName)
        {
            FileSystemResourceProvider prov = (FileSystemResourceProvider)ResourceHandler.ResourceHandler.ResourceProvider;
            {
                //EXIT FROM DESIGN-MODE
                if (commandName == "Cancel")
                {
                    // delete temp pagedocument
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    CMSContext.Current.IsDesignMode = false;

                    //back to prev page
                    if (Request.QueryString["PrevVersionId"] != null)
                    {
                        NameValueCollection vals = new NameValueCollection();

                        if (Int32.Parse(Request.QueryString["PrevVersionId"]) > 0)
                        {
                            vals.Add("VersionId", Request.QueryString["PrevVersionId"]);
                        }
                        else
                        {
                            vals.Add("VersionId", "");
                        }

                        string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);

                        Response.Redirect(url);
                        //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                //ENTER DESIGN-MODE
                if (commandName == "Edit")
                {
                    //GA: delete temp pagedocument
                    DeleteFromTemp();

                    // Check if we have access to the current version, if not, the new version for a current language will
                    // need to be created for "edit" command
                    if (!PageHelper.HasLanguageVersion(CMSContext.Current.PageId, LanguageId, CMSContext.Current.VersionId))
                    {
                        // add new version
                        _CommandValue.Value = String.Format("{0},{1}", CMSContext.Current.PageId, LanguageId);
                        RunCommand("AddVersion");
                    }

                    //back to prev page
                    if (Request.QueryString["PrevVersionId"] != null)
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("PrevVersionId", Request.QueryString["PrevVersionId"]);
                        string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);
                        Response.Redirect(url);
                        //Response.Redirect("~" + CMSContext.Current.Outline + "?VersionId=" + Request.QueryString["PrevVersionId"]);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                //SAVE AS DRAFT
                if (commandName == "SaveDraft")
                {
                    if (CMSContext.Current.VersionId == -2)
                    {
                        CMSContext.Current.VersionId       = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey);
                        PageDocument.Current.PageVersionId = CMSContext.Current.VersionId;
                        //copy resources
                        DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/"));
                        CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"));
                        if (resDir.Exists)
                        {
                            resDir.Delete(true);
                        }
                    }
                    PageDocument.Current.IsModified = true;

                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int  verId      = -1;
                            bool addVersion = false;
                            using (IDataReader r = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                            {
                                if (r.Read())
                                {
                                    addVersion = (int)r["StatusId"] != -1;
                                    if (!addVersion)
                                    {
                                        verId = CMSContext.Current.VersionId;
                                        PageVersion.UpdatePageVersion(verId, (int)r["TemplateId"], (int)r["LangId"], -1, WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                    }
                                }

                                r.Close();
                            }

                            if (addVersion)
                            {
                                verId = PageVersion.AddPageVersion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                using (IDataReader reader2 = PageVersion.GetVersionById(verId))
                                {
                                    if (reader2.Read())
                                    {
                                        PageVersion.UpdatePageVersion(verId, (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.DraftId, (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                                    }

                                    reader2.Close();
                                }

                                //copy resources
                                //todo: feature suspended, reimplement in the future
                                //CommonHelper.CopyDirectory(MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"), MapPath("~/" + prov.Archive + "/" + verId.ToString() + "/"));

                                CMSContext.Current.VersionId = verId;
                            }
                        }

                        reader.Close();
                    }
                    //SAVE DRAFT TO PERSIST STORAGE
                    PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty);
                    PageDocument.Current.ResetModified();

                    //delete from temporary storage
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    //SWITCH TO VIEW MODE
                    EnableViewMode();

                    RedirectToNewPage();
                }

                //PUBLISH
                if (commandName == "Publish")
                {
                    bool firstVersion = false;
                    if (CMSContext.Current.VersionId == -2)
                    {
                        firstVersion = true;
                        CMSContext.Current.VersionId       = PageVersion.AddDraft(CMSContext.Current.PageId, CMSContext.Current.TemplateId, LanguageId, (Guid)ProfileContext.Current.User.ProviderUserKey);
                        PageDocument.Current.PageVersionId = CMSContext.Current.VersionId;
                        //copy resources
                        DirectoryInfo resDir = new DirectoryInfo(MapPath("~/" + prov.Archive + "/" + ProfileContext.Current.User.UserName + "/"));
                        CommonHelper.CopyDirectory(resDir.FullName, MapPath("~/" + prov.Archive + "/" + CMSContext.Current.VersionId.ToString() + "/"));
                        if (resDir.Exists)
                        {
                            resDir.Delete(true);
                        }
                    }
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int langId = (int)reader["LangId"];
                            if (WorkflowStatus.GetNext((int)reader["StatusId"]) != -1 || (int)reader["StatusId"] == -1)
                            {
                                PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                            }

                            // if we publish version
                            if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])))
                            {
                                //find old published and put to archive
                                using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"])))
                                {
                                    while (reader2.Read())
                                    {
                                        if ((int)reader2["LangId"] == langId)
                                        {
                                            if (CMSContext.Current.VersionId != (int)reader2["VersionId"])
                                            {
                                                PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, "sent to archieve");
                                            }
                                        }
                                    }

                                    reader2.Close();
                                }
                            }
                        }
                        reader.Close();
                    }

                    //SAVE TO PERSIST STORAGE
                    PageDocument.Current.Save(CMSContext.Current.VersionId, SaveMode.PersistentStorage, Guid.Empty);
                    PageDocument.Current.ResetModified();

                    //delete from temporary storage
                    DeleteFromTemp();
                    this.ViewState.Clear();

                    //SWITCH TO VIEW MODE
                    EnableViewMode();

                    // replace VersionId in query string with a new id
                    string url = Request.RawUrl;
                    if (firstVersion)
                    {
                        // if the page has just been created and is being published, need to remove "VersionId=-2" from the queryString to load published version
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("VersionId", String.Empty);
                        url = CommonHelper.FormatQueryString(url, vals);
                    }
                    Response.Redirect(url, true);
                }

                if (commandName == "Approve")
                {
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, /*ddText.TextValue*/ "");
                            int langId = (int)reader["langId"];

                            // if we publish version
                            if (WorkflowStatus.GetLast((int)reader["StatusId"]) == WorkflowAccess.GetMaxStatus(Roles.GetRolesForUser(), WorkflowStatus.GetLast((int)reader["StatusId"])))
                            {
                                //find old publishd and put to archive
                                using (IDataReader reader2 = PageVersion.GetVersionByStatusId((int)reader["PageId"], WorkflowStatus.GetLast((int)reader["StatusId"])))
                                {
                                    while (reader2.Read())
                                    {
                                        if (langId == (int)reader2["LangId"])
                                        {
                                            if (CMSContext.Current.VersionId != (int)reader2["VersionId"])
                                            {
                                                PageVersion.UpdatePageVersion((int)reader2["VersionId"], (int)reader2["TemplateId"], (int)reader2["LangId"], (int)reader2["StatusId"], WorkflowStatus.GetArcStatus((int)reader2["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 1, "Archieved");
                                            }
                                        }
                                    }

                                    reader2.Close();
                                }
                            }
                            //PageVersion.DeletePageVersion(CMSContext.Current.VersionId);
                            //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue);
                        }

                        reader.Close();
                    }

                    Response.Redirect(Request.RawUrl, true);
                    //RedirectToNewPage();
                }

                if (commandName == "Deny")
                {
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, (int)reader["TemplateId"], (int)reader["LangId"], (int)reader["StatusId"], WorkflowStatus.GetPrevious((int)reader["StatusId"]), (Guid)ProfileContext.Current.User.ProviderUserKey, 2, /*ddText.TextValue*/ "");
                            //PageVersion.AddPageVerion((int)reader["PageId"], (int)reader["TemplateId"], (int)reader["LangId"], (Guid)Membership.GetUser(Page.User.Identity.Name).ProviderUserKey, 1, ddText.TextValue);
                        }

                        reader.Close();
                    }
                    string url = Page.Request.Url.ToString();

                    if (!url.Contains("VersionId"))
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("VersionId", CMSContext.Current.VersionId.ToString());
                        url = CommonHelper.FormatQueryString(url, vals);
                        Response.Redirect(url);
                    }
                }

                if (commandName == "ChangeTemplate")
                {
                    // Clear cache
                    CmsCache.Clear();

                    CMSContext mcContext = CMSContext.Current;
                    using (IDataReader reader = PageVersion.GetVersionById(CMSContext.Current.VersionId))
                    {
                        if (reader.Read())
                        {
                            int pageTemplateId;

                            if (Int32.TryParse(_CommandValue.Value, out pageTemplateId))
                            {
                                PageVersion.UpdatePageVersion(CMSContext.Current.VersionId, int.Parse(_CommandValue.Value), this.LanguageId, (int)reader["StatusId"], (int)reader["StatusId"], (Guid)ProfileContext.Current.User.ProviderUserKey, 1, string.Empty);
                            }
                        }

                        reader.Close();
                    }

                    if (mcContext.VersionId == -2)
                    {
                        NameValueCollection vals = new NameValueCollection();
                        vals.Add("TemplateId", _CommandValue.Value);
                        string url = CommonHelper.FormatQueryString(Request.RawUrl, vals);
                        Response.Redirect(url, true);
                    }
                    else
                    {
                        Response.Redirect(Request.RawUrl, true);
                    }
                }

                if (commandName == "AddVersion")
                {
                    string separator      = ",";
                    int    pageId         = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[0]);
                    int    langId         = int.Parse(_CommandValue.Value.Split(separator.ToCharArray())[1]);
                    string currentCulture = "en-us";
                    using (IDataReader reader = Language.LoadLanguage(langId))
                    {
                        if (reader.Read())
                        {
                            currentCulture = (string)reader["LangName"];
                        }

                        reader.Close();
                    }

                    NameValueCollection vals = new NameValueCollection();
                    vals.Add("lang", currentCulture);
                    vals.Add("VersionId", "-2");
                    vals.Add("PrevVersionId", CMSContext.Current.VersionId.ToString());
                    string url = CommonHelper.FormatQueryString(CMSContext.Current.CurrentUrl, vals);
                    Response.Redirect(url);
                }
                return;
            }
        }