Exemplo n.º 1
0
    /// <summary>
    /// Restores documents selected in UniGrid.
    /// </summary>
    private void Restore(object parameter)
    {
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("Recyclebin.RestoringDocuments", currentCulture));
            BinSettingsContainer settings = (BinSettingsContainer)parameter;
            DataSet recycleBin            = null;
            switch (settings.CurrentWhat)
            {
            case What.AllDocuments:
                DateTime modifiedFrom = DateTimeHelper.ZERO_TIME;
                DateTime modifiedTo   = DateTimeHelper.ZERO_TIME;
                SetDocumentAge(ref modifiedFrom, ref modifiedTo);
                recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, GetWhereCondition(filter.WhereCondition), "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName", modifiedFrom, modifiedTo);
                break;

            case What.SelectedDocuments:
                List <string> toRestore = ugRecycleBin.SelectedItems;
                // Restore selected documents
                if (toRestore.Count > 0)
                {
                    string where = SqlHelper.GetWhereCondition("VersionHistoryID", toRestore);
                    recycleBin   = VersionHistoryInfoProvider.GetRecycleBin(0, 0, where, "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName");
                }
                break;
            }

            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                RestoreDataSet(settings.User, recycleBin);
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", currentCulture);
                AddLog(CurrentInfo);
            }
            else
            {
                // Log error
                CurrentError = ResHelper.GetString("Recyclebin.RestorationFailed", currentCulture) + ": " + ex.Message;
                AddLog(CurrentError);
            }
        }
        catch (Exception ex)
        {
            // Log error
            CurrentError = ResHelper.GetString("Recyclebin.RestorationFailed", currentCulture) + ": " + ex.Message;
            AddLog(CurrentError);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Restores documents selected in UniGrid.
    /// </summary>
    private void Restore(object parameter)
    {
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("Recyclebin.RestoringDocuments", mCurrentCulture));
            BinSettingsContainer settings = (BinSettingsContainer)parameter;
            DataSet recycleBin            = null;
            switch (settings.CurrentWhat)
            {
            case What.AllDocuments:
                DateTime modifiedFrom = DateTimeHelper.ZERO_TIME;
                DateTime modifiedTo   = DateTimeHelper.ZERO_TIME;
                SetDocumentAge(ref modifiedFrom, ref modifiedTo);
                recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, GetWhereCondition(filter.WhereCondition), "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName", modifiedFrom, modifiedTo);
                break;

            case What.SelectedDocuments:
                // Restore selected documents
                var toRestore = settings.SelectedItems;
                if ((toRestore != null) && (toRestore.Count > 0))
                {
                    string where = new WhereCondition().WhereIn("VersionHistoryID", toRestore).ToString(true);
                    recycleBin   = VersionHistoryInfoProvider.GetRecycleBin(0, 0, where, "CMS_VersionHistory.DocumentNamePath ASC", -1, "VersionHistoryID, CMS_VersionHistory.DocumentNamePath, CMS_VersionHistory.VersionDocumentName");
                }
                break;
            }

            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                RestoreDataSet(settings.User, recycleBin);
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                CurrentInfo = ResHelper.GetString("Recyclebin.RestorationCanceled", mCurrentCulture);
                AddLog(CurrentInfo);
            }
            else
            {
                // Log error
                LogException("RESTOREDOC", ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogException("RESTOREDOC", ex);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Deletes a specified document version. Called when the "Delete version" button is pressed.
    /// Expects the "CreateExampleObjects" and at least the "EditDocument" method to be run first.
    /// </summary>
    private bool DeleteVersion()
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Prepare parameters
        string siteName  = CMSContext.CurrentSiteName;
        string aliasPath = "/API-Example";
        string culture   = "en-us";
        bool   combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;

        string where = null;
        string orderBy             = null;
        int    maxRelativeLevel    = -1;
        bool   selectOnlyPublished = false;
        string columns             = null;

        // Get the document
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if (node != null)
        {
            // Prepare the WHERE condition for the latest document version
            where   = "DocumentID = " + node.DocumentID;
            orderBy = "ModifiedWhen DESC";
            int topN = 1;

            // Get the version ID
            DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

            if (!DataHelper.DataSourceIsEmpty(versionHistory))
            {
                // Create the Version history info object
                VersionHistoryInfo version = new VersionHistoryInfo(versionHistory.Tables[0].Rows[0]);

                VersionManager versionManager = VersionManager.GetInstance(tree);

                // Delete the version
                versionManager.DestroyDocumentVersion(version.VersionHistoryID);

                return(true);
            }
            else
            {
                apiDeleteVersion.ErrorMessage = "The document's version history is empty.";
            }
        }

        return(false);
    }
Exemplo n.º 4
0
        //Reverting to published version if i am editing a published document and then go for edit it.
        //But i have not changed any thing and click on cancel button.
        //Document should shown as published again
        //It was showing as draft because its creating a new version.So added code here for showing that document as published.
        public static bool RollbackToPreviousVersion(int NodeID)
        {
            TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

            // Prepare parameters
            string siteName = SiteContext.CurrentSiteName;
            string culture  = "en-us";

            string where = null;
            string orderBy = null;
            string columns = null;

            // Get the document
            TreeNode node = DocumentHelper.GetDocument(NodeID, culture, tree);

            if (node != null)
            {
                // Prepare the WHERE condition for the oldest document version
                where   = "DocumentID = " + node.DocumentID;
                orderBy = "ModifiedWhen DESC";
                int topN = 2;

                // Get the version ID
                DataSet versionHistory = VersionHistoryInfoProvider.GetVersionHistories(where, orderBy, topN, columns);

                if (!DataHelper.DataSourceIsEmpty(versionHistory) && node.IsPublished == true)
                {
                    // Create the Version history info object
                    //get the details of previous version of this document
                    VersionHistoryInfo version        = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]);
                    VersionManager     versionManager = VersionManager.GetInstance(tree);
                    //get the workflow stepid of previous version of this document
                    int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID);
                    //move that document to previous version workflow state
                    MoveToWorkflowStep(WorkFlowStepID, tree, node);
                }
                else if (!DataHelper.DataSourceIsEmpty(versionHistory) && versionHistory.Tables[0].Rows.Count > 1)
                {
                    // Create the Version history info object
                    //get the details of previous version of this document
                    VersionHistoryInfo version        = new VersionHistoryInfo(versionHistory.Tables[0].Rows[1]);
                    VersionManager     versionManager = VersionManager.GetInstance(tree);
                    //get the workflow stepid of previous version of this document
                    int WorkFlowStepID = Convert.ToInt32(version.VersionWorkflowStepID);
                    //move that document to previous version workflow state
                    MoveToWorkflowStep(WorkFlowStepID, tree, node);
                }
            }
            return(true);
        }
Exemplo n.º 5
0
    /// <summary>
    /// Restores the document from the recycle bin. Called when the "Restore document" button is pressed.
    /// Expects the "CreateDocumentStructure" and "MoveDocumentToRecycleBin" methods to be run first.
    /// </summary>
    private bool RestoreFromRecycleBin()
    {
        // Prepare the where condition
        string where = "VersionNodeAliasPath LIKE N'/API-Example/Document-1'";

        // Get the recycled document
        DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin(CMSContext.CurrentSiteID, where, null, 0, "VersionHistoryID");

        if (!DataHelper.DataSourceIsEmpty(recycleBin))
        {
            // Create a new version history info object from the data row
            VersionHistoryInfo version = new VersionHistoryInfo(recycleBin.Tables[0].Rows[0]);

            // Create a new version manager instance and restore the document
            VersionManager manager = new VersionManager(new TreeProvider(CMSContext.CurrentUser));
            manager.RestoreDocument(version.VersionHistoryID);

            return(true);
        }

        return(false);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Empties recycle bin.
    /// </summary>
    private void EmptyBin(object parameter)
    {
        // Begin log
        AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", mCurrentCulture));

        BinSettingsContainer settings        = (BinSettingsContainer)parameter;
        CurrentUserInfo      currentUserInfo = settings.User;

        string where = null;
        DateTime modifiedFrom = DateTimeHelper.ZERO_TIME;
        DateTime modifiedTo   = DateTimeHelper.ZERO_TIME;

        switch (settings.CurrentWhat)
        {
        case What.AllDocuments:
            SetDocumentAge(ref modifiedFrom, ref modifiedTo);
            where = GetWhereCondition(filter.WhereCondition);
            break;

        case What.SelectedDocuments:
            // Restore selected documents
            var toRestore = settings.SelectedItems;
            if ((toRestore != null) && (toRestore.Count > 0))
            {
                where = new WhereCondition().WhereIn("VersionHistoryID", toRestore).ToString(true);
            }
            break;
        }

        DataSet recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, @where, "DocumentNamePath ASC", -1, null, modifiedFrom, modifiedTo);

        try
        {
            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                TreeProvider tree = new TreeProvider(currentUserInfo);
                tree.AllowAsyncActions = false;
                VersionManager verMan = VersionManager.GetInstance(tree);

                foreach (DataRow dr in recycleBin.Tables[0].Rows)
                {
                    int    versionHistoryId = Convert.ToInt32(dr["VersionHistoryID"]);
                    string documentNamePath = ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty);
                    // Check permissions
                    TreeNode tn;
                    if (!IsAuthorizedPerDocument(versionHistoryId, "Destroy", mCurrentUser, out tn, verMan))
                    {
                        CurrentError = String.Format(ResHelper.GetString("Recyclebin.DestructionFailedPermissions", mCurrentCulture), documentNamePath);
                        AddLog(CurrentError);
                    }
                    else
                    {
                        AddLog(ResHelper.GetString("general.document", mCurrentCulture) + "'" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty)) + "'");
                        // Destroy the version
                        verMan.DestroyDocumentHistory(ValidationHelper.GetInteger(dr["DocumentID"], 0));
                        LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "DESTROYDOC", string.Format(ResHelper.GetString("Recyclebin.documentdestroyed"), documentNamePath), RequestContext.RawURL, mCurrentUser.UserID, mCurrentUser.UserName, 0, null, RequestContext.UserHostAddress, SiteContext.CurrentSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                if (!String.IsNullOrEmpty(CurrentError))
                {
                    CurrentError = ResHelper.GetString("recyclebin.errorsomenotdestroyed", mCurrentCulture);
                    AddLog(CurrentError);
                }
                else
                {
                    CurrentInfo = ResHelper.GetString("recyclebin.destroyok", mCurrentCulture);
                    AddLog(CurrentInfo);
                }
            }
        }
        catch (ThreadAbortException ex)
        {
            if (!CMSThread.Stopped(ex))
            {
                // Log error
                LogException("DESTROYDOC", ex);
            }
        }
        catch (Exception ex)
        {
            // Log error
            LogException("DESTROYDOC", ex);
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// Empties recycle bin.
    /// </summary>
    private void EmptyBin(object parameter)
    {
        // Begin log
        AddLog(ResHelper.GetString("Recyclebin.EmptyingBin", currentCulture));
        BinSettingsContainer settings        = (BinSettingsContainer)parameter;
        CurrentUserInfo      currentUserInfo = settings.User;

        DataSet recycleBin = null;

        string where = null;
        DateTime modifiedFrom = DateTimeHelper.ZERO_TIME;
        DateTime modifiedTo   = DateTimeHelper.ZERO_TIME;

        switch (settings.CurrentWhat)
        {
        case What.AllDocuments:
            SetDocumentAge(ref modifiedFrom, ref modifiedTo);
            where = GetWhereCondition(string.Empty);
            break;

        case What.SelectedDocuments:
            ArrayList toRestore = ugRecycleBin.SelectedItems;
            // Restore selected documents
            if (toRestore.Count > 0)
            {
                where = SqlHelperClass.GetWhereCondition("VersionHistoryID", (string[])toRestore.ToArray(typeof(string)));
            }
            break;
        }
        recycleBin = VersionHistoryInfoProvider.GetRecycleBin((mSelectedSite != null) ? mSelectedSite.SiteID : 0, 0, where, "DocumentNamePath ASC", -1, null, modifiedFrom, modifiedTo);

        try
        {
            if (!DataHelper.DataSourceIsEmpty(recycleBin))
            {
                TreeProvider tree = new TreeProvider(currentUserInfo);
                tree.AllowAsyncActions = false;
                VersionManager verMan = new VersionManager(tree);

                foreach (DataRow dr in recycleBin.Tables[0].Rows)
                {
                    int    versionHistoryId = Convert.ToInt32(dr["VersionHistoryID"]);
                    string documentNamePath = ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty);
                    // Check permissions
                    TreeNode tn = null;
                    if (!IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out tn, verMan))
                    {
                        CurrentError = String.Format(ResHelper.GetString("Recyclebin.DestructionFailedPermissions", currentCulture), documentNamePath);
                        AddLog(CurrentError);
                    }
                    else
                    {
                        AddLog(ResHelper.GetString("general.document", currentCulture) + "'" + HTMLHelper.HTMLEncode(ValidationHelper.GetString(dr["DocumentNamePath"], string.Empty)) + "'");
                        // Destroy the version
                        verMan.DestroyDocumentHistory(ValidationHelper.GetInteger(dr["DocumentID"], 0));
                        LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DESTROYDOC", currentUser.UserID, currentUser.UserName, 0, null, HTTPHelper.UserHostAddress, string.Format(ResHelper.GetString("Recyclebin.documentdestroyed"), documentNamePath), currentSite.SiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent());
                    }
                }
                if (!String.IsNullOrEmpty(CurrentError))
                {
                    CurrentError = ResHelper.GetString("recyclebin.errorsomenotdestroyed", currentCulture);
                    AddLog(CurrentError);
                }
                else
                {
                    CurrentInfo = ResHelper.GetString("recyclebin.destroyok", currentCulture);
                    AddLog(CurrentInfo);
                }
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state != CMSThread.ABORT_REASON_STOP)
            {
                // Log error
                CurrentError = "Error occurred: " + ex.Message;
                AddLog(CurrentError);
            }
        }
        catch (Exception ex)
        {
            // Log error
            CurrentError = "Error occurred: " + ex.Message;
            AddLog(CurrentError);
        }
    }
Exemplo n.º 8
0
 private static VersionHistoryInfo GetVersionHistoryInfo(int versionHistoryId)
 {
     return(VersionHistoryInfoProvider.GetVersionHistoryInfo(versionHistoryId));
 }