Esempio n. 1
0
        /// <summary>
        /// Event handler method for DocumentSaving and DocumentSavingAs events.
        /// This method will check whether "Project Status" has been updated, and reserve current value as original value.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void CheckProjectStatusUpdate(Object sender, RevitAPIPreDocEventArgs args)
        {
            // The document associated with the event. Here means which document is about to save / save as.
            Document doc = args.Document;

            // Project information is unavailable for Family document.
            if (doc.IsFamilyDocument)
            {
                return;
            }

            // write log file.
            LogManager.WriteLog(args, doc);

            // retrieve the current value of "Project Status".
            string currentProjectStatus = RetrieveProjectCurrentStatus(args.Document);

            // get the old value of "Project Status" for one dictionary.
            string originalProjectStatus = documentOriginalStatusDic[doc.GetHashCode()];

            // write log file.
            LogManager.WriteLog("   Current Project Status: " + currentProjectStatus + "; Original Project Status: " + originalProjectStatus);

            // project status has not been updated.
            if ((string.IsNullOrEmpty(currentProjectStatus) && string.IsNullOrEmpty(originalProjectStatus)) ||
                (0 == string.Compare(currentProjectStatus, originalProjectStatus, true)))
            {
                DealNotUpdate(args);
                return;
            }

            // update "Project Status" value reserved in the dictionary.
            documentOriginalStatusDic.Remove(doc.GetHashCode());
            documentOriginalStatusDic.Add(doc.GetHashCode(), currentProjectStatus);
        }
        /// <summary>
        /// Event handler method for DocumentSaving and DocumentSavingAs events.
        /// 此方法将检查“项目状态”是否已更新,并保留当前值作为原始值。
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void CheckProjectStatusUpdate(Object sender, RevitAPIPreDocEventArgs args)
        {
            Document doc = args.Document;

            if (doc.IsFamilyDocument)
            {
                return;
            }

            // write log file.
            LogManager.WriteLog(args, doc);

            // retrieve the current value of "Project Status".
            string currentProjectStatus = RetrieveProjectCurrentStatus(args.Document);

            // get the old value of "Project Status" for one dictionary.
            string originalProjectStatus = documentOriginalStatusDic[doc.GetHashCode()];

            // write log file.
            LogManager.WriteLog("   Current Project Status: " + currentProjectStatus + "; Original Project Status: " + originalProjectStatus);

            // project status has not been updated.
            if ((string.IsNullOrEmpty(currentProjectStatus) && string.IsNullOrEmpty(originalProjectStatus)) ||
                (0 == string.Compare(currentProjectStatus, originalProjectStatus, true)))
            {
                DealNotUpdate(args);//处理项目状态未更新的情况
                return;
            }

            // update "Project Status" value reserved in the dictionary.
            documentOriginalStatusDic.Remove(doc.GetHashCode());
            documentOriginalStatusDic.Add(doc.GetHashCode(), currentProjectStatus);
        }
Esempio n. 3
0
        /// <summary>
        /// Deal with the case that the project status wasn't updated.
        /// If the event is Cancellable, cancel it and inform user else just inform user the status.
        /// </summary>
        /// <param name="args">Event arguments that contains the event data.</param>
        private static void DealNotUpdate(RevitAPIPreDocEventArgs args)
        {
            string     mainMessage;
            string     additionalText;
            TaskDialog taskDialog = new TaskDialog("CancelSave Sample");

            if (args.Cancellable)
            {
                args.Cancel();                                                                                                                                  // cancel this event if it is cancellable.

                mainMessage = "CancelSave sample detected that the Project Status parameter on Project Info has not been updated. The file will not be saved."; // prompt to user.
            }
            else
            {
                // will not cancel this event since it isn't cancellable.
                mainMessage = "The file is about to save. But CancelSave sample detected that the Project Status parameter on Project Info has not been updated."; // prompt to user.
            }

            // taskDialog will not show when do regression test.
            if (!LogManager.RegressionTestNow)
            {
                additionalText = "You can disable this permanently by uninstaling the CancelSave sample from Revit. Remove or rename CancelSave.addin from the addins directory.";

                // use one taskDialog to inform user current situation.
                taskDialog.MainInstruction = mainMessage;
                taskDialog.MainContent     = additionalText;
                taskDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Open the addins directory");
                taskDialog.CommonButtons = TaskDialogCommonButtons.Close;
                taskDialog.DefaultButton = TaskDialogResult.Close;
                TaskDialogResult tResult = taskDialog.Show();
                if (TaskDialogResult.CommandLink1 == tResult)
                {
                    System.Diagnostics.Process.Start("explorer.exe", DetectAddinFileLocation(args.Document.Application));
                }
            }

            // write log file.
            LogManager.WriteLog("   Project Status is not updated, taskDialog informs user: " + mainMessage);
        }
Esempio n. 4
0
        /// <summary>
        /// Event handler method for DocumentSaving and DocumentSavingAs events.
        /// This method will check whether "Project Status" has been updated, and reserve current value as original value.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Event arguments that contains the event data.</param>
        private void CheckProjectStatusUpdate(Object sender, RevitAPIPreDocEventArgs args)
        {
            // The document associated with the event. Here means which document is about to save / save as.
            Document doc = args.Document;

            // Project information is unavailable for Family document.
            if (doc.IsFamilyDocument)
            {
                return;
            }

            // write log file.
            LogManager.WriteLog(args, doc);

            // retrieve the current value of "Project Status".
            string currentProjectStatus = RetrieveProjectCurrentStatus(args.Document);

            // get the old value of "Project Status" for one dictionary.
            string originalProjectStatus = documentOriginalStatusDic[doc.GetHashCode()];

            // write log file.
            LogManager.WriteLog("   Current Project Status: " + currentProjectStatus + "; Original Project Status: " + originalProjectStatus);

            // project status has not been updated.
            if ((string.IsNullOrEmpty(currentProjectStatus) && string.IsNullOrEmpty(originalProjectStatus)) ||
                (0 == string.Compare(currentProjectStatus, originalProjectStatus,true)))
            {
                DealNotUpdate(args);
                return;
            }

            // update "Project Status" value reserved in the dictionary.
            documentOriginalStatusDic.Remove(doc.GetHashCode());
            documentOriginalStatusDic.Add(doc.GetHashCode(), currentProjectStatus);
        }
Esempio n. 5
0
        /// <summary>
        /// Deal with the case that the project status wasn't updated.
        /// If the event is Cancellable, cancel it and inform user else just inform user the status.
        /// </summary>
        /// <param name="args">Event arguments that contains the event data.</param>
        private static void DealNotUpdate(RevitAPIPreDocEventArgs args)
        {
            string mainMessage;
            string additionalText;
            TaskDialog taskDialog = new TaskDialog("CancelSave Sample");

            if (args.Cancellable)
            {
                args.Cancel(); // cancel this event if it is cancellable.

                mainMessage = "CancelSave sample detected that the Project Status parameter on Project Info has not been updated. The file will not be saved."; // prompt to user.
            }
            else
            {
                // will not cancel this event since it isn't cancellable.
               mainMessage = "The file is about to save. But CancelSave sample detected that the Project Status parameter on Project Info has not been updated."; // prompt to user.
            }

            // taskDialog will not show when do regression test.
            if (!LogManager.RegressionTestNow)
            {
               additionalText = "You can disable this permanently by uninstaling the CancelSave sample from Revit. Remove or rename CancelSave.addin from the addins directory.";

               // use one taskDialog to inform user current situation.
               taskDialog.MainInstruction = mainMessage;
               taskDialog.MainContent     = additionalText;
               taskDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Open the addins directory");
               taskDialog.CommonButtons = TaskDialogCommonButtons.Close;
               taskDialog.DefaultButton = TaskDialogResult.Close;
               TaskDialogResult tResult = taskDialog.Show();
               if (TaskDialogResult.CommandLink1 == tResult)
               {
                  System.Diagnostics.Process.Start("explorer.exe", DetectAddinFileLocation(args.Document.Application));
               }
            }

            // write log file.
            LogManager.WriteLog("   Project Status is not updated, taskDialog informs user: " + mainMessage);
        }