コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: tvelzy/RadstackMedia
    /// <summary>
    /// Destroys the entire document's version history. Called when the "Destroy version history" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool DestroyHistory()
    {
        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)
        {
            VersionManager versionManager = VersionManager.GetInstance(tree);

            // Destroy the version history
            versionManager.DestroyDocumentHistory(node.DocumentID);

            return(true);
        }

        return(false);
    }
コード例 #2
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        TreeProvider   tree             = new TreeProvider(MembershipContext.AuthenticatedUser);
        VersionManager verMan           = VersionManager.GetInstance(tree);
        int            versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);
        TreeNode       doc;

        switch (actionName.ToLowerCSafe())
        {
        case "restore":
        {
            try
            {
                if (IsAuthorizedPerDocument(versionHistoryId, "Create", mCurrentUser, out doc, verMan))
                {
                    verMan.RestoreDocument(versionHistoryId, doc);
                    ShowConfirmation(GetString("Recyclebin.RestorationOK"));
                }
                else
                {
                    ShowError(String.Format(ResHelper.GetString("Recyclebin.RestorationFailedPermissions", mCurrentCulture), HTMLHelper.HTMLEncode(doc.DocumentNamePath)));
                }
            }
            catch (Exception ex)
            {
                LogAndShowError("Content", "RESTOREDOC", ex);
            }
        }
        break;

        case "destroy":
        {
            try
            {
                if (IsAuthorizedPerDocument(versionHistoryId, "Destroy", mCurrentUser, out doc, verMan))
                {
                    verMan.DestroyDocumentHistory(doc.DocumentID);
                    ShowConfirmation(GetString("recyclebin.destroyok"));
                }
                else
                {
                    ShowError(String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", mCurrentCulture), HTMLHelper.HTMLEncode(doc.DocumentNamePath)));
                }
            }
            catch (Exception ex)
            {
                LogAndShowError("Content", "DESTROYDOC", ex);
            }
        }
        break;
        }

        ugRecycleBin.ResetSelection();
    }
コード例 #3
0
ファイル: RecycleBin.ascx.cs プロジェクト: kudutest2/Kentico
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        TreeProvider   tree             = new TreeProvider(CMSContext.CurrentUser);
        VersionManager verMan           = new VersionManager(tree);
        int            versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);
        TreeNode       doc = null;

        if (actionName == "restore")
        {
            try
            {
                if (IsAuthorizedPerDocument(versionHistoryId, "Create", currentUser, out doc, verMan))
                {
                    verMan.RestoreDocument(versionHistoryId, doc);
                    lblInfo.Visible = true;
                    lblInfo.Text    = GetString("Recyclebin.RestorationOK");
                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text    = String.Format(ResHelper.GetString("Recyclebin.RestorationFailedPermissions", currentCulture), doc.DocumentNamePath);
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("recyclebin.errorrestoringdocument") + " " + ex.Message;
            }
        }
        else if (actionName == "destroy")
        {
            if (IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out doc, verMan))
            {
                verMan.DestroyDocumentHistory(doc.DocumentID);
                lblInfo.Visible = true;
                lblInfo.Text    = GetString("recyclebin.destroyok");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", currentCulture), doc.DocumentNamePath);
            }
        }
        ugRecycleBin.ResetSelection();
    }
コード例 #4
0
 private void DestroyDocumentHistory(VersionHistoryInfo versionHistoryInfo, VersionManager versionManager)
 {
     try
     {
         if (IsAuthorizedPerDocument(versionHistoryInfo, "Destroy", mCurrentUser))
         {
             versionManager.DestroyDocumentHistory(versionHistoryInfo.DocumentID);
             ShowConfirmation(GetString("recyclebin.destroyok"));
         }
         else
         {
             ShowError(String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", mCurrentCulture), HTMLHelper.HTMLEncode(versionHistoryInfo.DocumentNamePath)));
         }
     }
     catch (Exception ex)
     {
         LogAndShowError("Content", "DESTROYDOC", ex);
     }
 }
コード例 #5
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        TreeProvider   tree             = new TreeProvider(MembershipContext.AuthenticatedUser);
        VersionManager verMan           = VersionManager.GetInstance(tree);
        int            versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);
        TreeNode       doc = null;

        if (actionName == "restore")
        {
            try
            {
                if (IsAuthorizedPerDocument(versionHistoryId, "Create", currentUser, out doc, verMan))
                {
                    verMan.RestoreDocument(versionHistoryId, doc);
                    ShowConfirmation(GetString("Recyclebin.RestorationOK"));
                }
                else
                {
                    ShowError(String.Format(ResHelper.GetString("Recyclebin.RestorationFailedPermissions", currentCulture), doc.DocumentNamePath));
                }
            }
            catch (Exception ex)
            {
                ShowError(GetString("recyclebin.errorrestoringdocument"), ex.Message, null);
            }
        }
        else if (actionName == "destroy")
        {
            if (IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out doc, verMan))
            {
                verMan.DestroyDocumentHistory(doc.DocumentID);
                ShowConfirmation(GetString("recyclebin.destroyok"));
            }
            else
            {
                ShowError(String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", currentCulture), doc.DocumentNamePath));
            }
        }

        ugRecycleBin.ResetSelection(false);
    }
コード例 #6
0
ファイル: VersionList.ascx.cs プロジェクト: kudutest2/Kentico
    protected void btnDestroy_Click(object sender, EventArgs e)
    {
        if (Node != null)
        {
            // Check permissions
            if (!CanDestroy || (CheckedOutByAnotherUser && !CanCheckIn))
            {
                lblError.Text = GetString("History.ErrorNotAllowedToDestroy");
                return;
            }
            VersionManager.DestroyDocumentHistory(Node.DocumentID);

            EventLogProvider ev = new EventLogProvider();
            ev.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "DESTROYHISTORY", TreeProvider.UserInfo.UserID, TreeProvider.UserInfo.UserName, Node.NodeID, Node.DocumentName, HTTPHelper.UserHostAddress, string.Format(ResHelper.GetAPIString("contentedit.documenthistorydestroyed", "Document history of document '{0}' has been destroyed."), HTMLHelper.HTMLEncode(Node.NodeAliasPath)), Node.NodeSiteID, HTTPHelper.GetAbsoluteUri());

            InvalidateNode();
            ReloadData();
            if (AfterDestroyHistory != null)
            {
                AfterDestroyHistory(sender, e);
            }
        }
    }
コード例 #7
0
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = new VersionManager(Tree);
        TreeNode node = null;
        // Custom logging
        Tree.LogEvents = false;
        Tree.AllowAsyncActions = false;
        CanceledString = ResHelper.GetString("workflowdocuments.removingcanceled", currentCulture);
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("content.preparingdocuments", currentCulture));

            // Get the documents
            DataSet documents = GetDocumentsToProcess();

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(ResHelper.GetString("workflowdocuments.removingwf", currentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName = ValidationHelper.GetString(nodeRow["SiteName"], string.Empty);

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        // Clear workflow
                        DocumentHelper.ClearWorkflowInformation(node);
                        node.Update();

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "REMOVEDOCWORKFLOW", currentUser.UserID,
                             currentUser.UserName, node.NodeID, node.DocumentName,
                             HTTPHelper.GetUserHostAddress(), string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath),
                             node.NodeSiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent());
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(ResHelper.GetString("workflowdocuments.nodocumentstoclear", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
コード例 #8
0
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = ResHelper.GetString("workflowdocuments.removingcanceled", currentCulture);
        try
        {
            // Begin log
            AddLog(ResHelper.GetString("content.preparingdocuments", currentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(ResHelper.GetString("workflowdocuments.removingwf", currentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = ValidationHelper.GetString(nodeRow["SiteName"], string.Empty);

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        // Clear workflow
                        DocumentHelper.ClearWorkflowInformation(node);
                        node.Update();

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEvent(EventLogProvider.EVENT_TYPE_INFORMATION, DateTime.Now, "Content", "REMOVEDOCWORKFLOW", currentUser.UserID,
                                            currentUser.UserName, node.NodeID, node.GetDocumentName(),
                                            HTTPHelper.UserHostAddress, string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath),
                                            node.NodeSiteID, HTTPHelper.GetAbsoluteUri(), HTTPHelper.MachineName, HTTPHelper.GetUrlReferrer(), HTTPHelper.GetUserAgent());
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(ResHelper.GetString("workflowdocuments.nodocumentstoclear", currentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            string state = ValidationHelper.GetString(ex.ExceptionState, string.Empty);
            if (state == CMSThread.ABORT_REASON_STOP)
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : CMSContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
    private void RemoveWorkflow(object parameter)
    {
        VersionManager verMan = VersionManager.GetInstance(Tree);
        TreeNode       node   = null;

        // Custom logging
        Tree.LogEvents         = false;
        Tree.AllowAsyncActions = false;
        CanceledString         = GetString("workflowdocuments.removingcanceled", mCurrentCulture);
        try
        {
            // Begin log
            AddLog(GetString("content.preparingdocuments", mCurrentCulture));

            string where = parameter as string;

            // Get the documents
            DataSet documents = GetDocumentsToProcess(where);

            if (!DataHelper.DataSourceIsEmpty(documents))
            {
                // Begin log
                AddLog(GetString("workflowdocuments.removingwf", mCurrentCulture));

                foreach (DataTable classTable in documents.Tables)
                {
                    foreach (DataRow nodeRow in classTable.Rows)
                    {
                        // Get the current document
                        string className  = ValidationHelper.GetString(nodeRow["ClassName"], string.Empty);
                        string aliasPath  = ValidationHelper.GetString(nodeRow["NodeAliasPath"], string.Empty);
                        string docCulture = ValidationHelper.GetString(nodeRow["DocumentCulture"], string.Empty);
                        string siteName   = SiteInfoProvider.GetSiteName(nodeRow["NodeSiteID"].ToInteger(0));

                        // Get published version
                        node = Tree.SelectSingleNode(siteName, aliasPath, docCulture, false, className, false);
                        string encodedAliasPath = HTMLHelper.HTMLEncode(ValidationHelper.GetString(aliasPath, string.Empty) + " (" + node.GetValue("DocumentCulture") + ")");

                        // Destroy document history
                        verMan.DestroyDocumentHistory(node.DocumentID);

                        using (new CMSActionContext {
                            LogEvents = false
                        })
                        {
                            // Clear workflow
                            DocumentHelper.ClearWorkflowInformation(node);
                            node.Update();
                        }

                        // Add log record
                        AddLog(encodedAliasPath);

                        // Add record to eventlog
                        LogContext.LogEventToCurrent(EventType.INFORMATION, "Content", "REMOVEDOCWORKFLOW", string.Format(GetString("workflowdocuments.removeworkflowsuccess"), encodedAliasPath), RequestContext.RawURL, mCurrentUser.UserID, mCurrentUser.UserName, node.NodeID, node.GetDocumentName(), RequestContext.UserHostAddress, node.NodeSiteID, SystemContext.MachineName, RequestContext.URLReferrer, RequestContext.UserAgent, DateTime.Now);
                    }
                }
                CurrentInfo = GetString("workflowdocuments.removecomplete");
            }
            else
            {
                AddError(GetString("workflowdocuments.nodocumentstoclear", mCurrentCulture));
            }
        }
        catch (ThreadAbortException ex)
        {
            if (CMSThread.Stopped(ex))
            {
                // When canceled
                CurrentInfo = CanceledString;
            }
            else
            {
                int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
                // Log error
                LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
            }
        }
        catch (Exception ex)
        {
            int siteId = (node != null) ? node.NodeSiteID : SiteContext.CurrentSiteID;
            // Log error
            LogExceptionToEventLog("REMOVEDOCWORKFLOW", "workflowdocuments.removefailed", ex, siteId);
        }
    }
コード例 #10
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);
        }
    }
コード例 #11
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);
        }
    }
コード例 #12
0
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that throws event</param>
    /// <param name="actionArgument">ID (value of Primary key) of corresponding data row</param>
    protected void ugRecycleBin_OnAction(string actionName, object actionArgument)
    {
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);
        VersionManager verMan = new VersionManager(tree);
        int versionHistoryId = ValidationHelper.GetInteger(actionArgument, 0);
        TreeNode doc = null;
        if (actionName == "restore")
        {
            try
            {
                if (IsAuthorizedPerDocument(versionHistoryId, "Create", currentUser, out doc, verMan))
                {
                    verMan.RestoreDocument(versionHistoryId, doc);
                    lblInfo.Visible = true;
                    lblInfo.Text = GetString("Recyclebin.RestorationOK");

                }
                else
                {
                    lblError.Visible = true;
                    lblError.Text = String.Format(ResHelper.GetString("Recyclebin.RestorationFailedPermissions", currentCulture), doc.DocumentNamePath);
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text = GetString("recyclebin.errorrestoringdocument") + " " + ex.Message;
            }
        }
        else if (actionName == "destroy")
        {
            if (IsAuthorizedPerDocument(versionHistoryId, "Destroy", currentUser, out doc, verMan))
            {
                verMan.DestroyDocumentHistory(doc.DocumentID);
                lblInfo.Visible = true;
                lblInfo.Text = GetString("recyclebin.destroyok");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text = String.Format(ResHelper.GetString("recyclebin.destructionfailedpermissions", currentCulture), doc.DocumentNamePath);
            }

        }
        ugRecycleBin.ResetSelection();
    }
コード例 #13
0
ファイル: RecycleBin.ascx.cs プロジェクト: kudutest2/Kentico
    /// <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);
        }
    }
コード例 #14
0
ファイル: Default.aspx.cs プロジェクト: KuduApps/Kentico
    /// <summary>
    /// Destroys the entire document's version history. Called when the "Destroy version history" button is pressed.
    /// Expects the "CreateExampleObjects" method to be run first.
    /// </summary>
    private bool DestroyHistory()
    {
        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)
        {
            VersionManager versionManager = new VersionManager(tree);

            // Destroy the version history
            versionManager.DestroyDocumentHistory(node.DocumentID);

            return true;
        }

        return false;
    }