Esempio n. 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            try
            {
                m_app = commandData.Application;
                m_doc = m_app.ActiveUIDocument.Document;

                UserWindow userWindow = new UserWindow();
                if ((bool)userWindow.ShowDialog())
                {
                    string projectFileId = DataStorageUtil.GetProjectFileId(m_doc).ToString();
                    if (AppCommand.Instance.Configurations.ContainsKey(projectFileId))
                    {
                        DTMConfigurations config = AppCommand.Instance.Configurations[projectFileId];

                        AdminViewModel viewModel   = new AdminViewModel(config);
                        AdminWindow    adminWindow = new AdminWindow();
                        adminWindow.DataContext = viewModel;
                        if ((bool)adminWindow.ShowDialog())
                        {
                            config = adminWindow.ViewModel.Configuration;
                            AppCommand.Instance.Configurations.Remove(projectFileId);
                            AppCommand.Instance.Configurations.Add(projectFileId, config);
                            AppCommand.Instance.ApplyConfiguration(m_doc, config);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string exMessage = ex.Message;
                MessageBox.Show("Failed to execute Admin Command.\n" + ex.Message, "Admin Command", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(Result.Succeeded);
        }
Esempio n. 2
0
        public void Execute(UpdaterData data)
        {
            try
            {
                Document doc   = data.GetDocument();
                Guid     docId = DataStorageUtil.GetProjectFileId(doc);

                List <ElementId> addedElementIds = data.GetAddedElementIds().ToList();
                foreach (ElementId id in addedElementIds)
                {
                    Element element = doc.GetElement(id);
                    if (null != element)
                    {
                        AddCategoryCache(docId, element);
                    }
                }

                List <ElementId> modifiedElementIds = data.GetModifiedElementIds().ToList();
                foreach (ElementId id in modifiedElementIds)
                {
                    Element element = doc.GetElement(id);
                    if (null != element)
                    {
                        RunCategoryActionItems(docId, data, element);
                    }
                }

                List <ElementId> deletedElementIds = data.GetDeletedElementIds().ToList();
                foreach (ElementId id in deletedElementIds)
                {
                    //Process Failure
                    var infoFound = from info in reportingElements where info.DocId == docId && info.ReportingElementId == id select info;
                    if (infoFound.Count() > 0)
                    {
                        ReportFailure(infoFound.First());
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show("Failed to execute updater.\n" + ex.Message, "DTM Updater", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 3
0
        public void UnregisterDTMUpdaterOnClose(object source, DocumentClosingEventArgs args)
        {
            try
            {
                if (null != args.Document)
                {
                    Document doc = args.Document;
                    dtmUpdater.Unregister(doc);

                    Guid projectFileId = DataStorageUtil.GetProjectFileId(doc);
                    if (configurations.ContainsKey(projectFileId.ToString()))
                    {
                        configurations.Remove(projectFileId.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show("Failed to unregister on close.\n" + ex.Message, "Unregister DTM Updater", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 4
0
        private DTMConfigurations GetConfiguration(Document doc)
        {
            DTMConfigurations config = new DTMConfigurations();

            try
            {
                string projectFileId = DataStorageUtil.GetProjectFileId(doc).ToString();
                string centralPath   = FileInfoUtil.GetCentralFilePath(doc);
                if (projectFileId == Guid.Empty.ToString())
                {
                    //first time use
                    List <ProjectFile> items = ServerUtil.GetProjectFiles("centralpath/" + centralPath);
                    if (items.Count > 0)
                    {
                        //import file info by central path
                        ProjectFile projectFile = items.First();
                        bool        found       = ServerUtil.GetConfiguration(projectFile._id, out config);
                        projectFileId = projectFile._id;
                    }
                    else
                    {
                        //create file info
                        projectFileId = Guid.NewGuid().ToString();

                        Project        projectInfo  = FileInfoUtil.GetProjectInfo(centralPath);
                        List <Project> projects     = ServerUtil.GetProjects("");
                        var            projectFound = from p in projects where p.ProjectNumber == projectInfo.ProjectNumber && p.ProjectName == projectInfo.ProjectName select p;
                        if (projectFound.Count() > 0)
                        {
                            projectInfo = projectFound.First();
                        }
                        else
                        {
                            projectInfo._id = Guid.NewGuid().ToString();
                        }

                        ProjectFile pFile = new ProjectFile(projectFileId, centralPath, projectInfo._id, projectInfo);
                        config.ProjectFileInfo = pFile;

                        ProjectUpdater pUpdater = new ProjectUpdater(Guid.NewGuid().ToString(), DTMUpdater.updaterGuid.ToString(), dtmUpdater.GetUpdaterName(), addInGuid.ToString(), addInName, false, pFile._id);
                        foreach (string categoryName in updaterCategories)
                        {
                            CategoryTrigger catTrigger = new CategoryTrigger(Guid.NewGuid().ToString(), categoryName, pUpdater._id, false, Environment.UserName, DateTime.Now);
                            pUpdater.CategoryTriggers.Add(catTrigger);
                        }
                        config.ProjectUpdaters.Add(pUpdater);

                        string         content = "";
                        string         errMsg  = "";
                        HttpStatusCode status  = ServerUtil.PostConfiguration(out content, out errMsg, config);
                    }

                    bool stored = DataStorageUtil.StoreProjectFileId(doc, new Guid(projectFileId));
                }
                else
                {
                    bool found = ServerUtil.GetConfiguration(projectFileId, out config);
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show("Failed to get configuration.\n" + ex.Message, "Get Configuration from Database", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(config);
        }
Esempio n. 5
0
        internal void RefreshTriggers(Document doc, ProjectUpdater pUpdater)
        {
            try
            {
                Guid docId = DataStorageUtil.GetProjectFileId(doc);
                UpdaterRegistry.RemoveDocumentTriggers(updaterId, doc);

                var elementsToDelete = from eInfo in reportingElements where eInfo.DocId == docId select eInfo;
                if (elementsToDelete.Count() > 0)
                {
                    List <ReportingElementInfo> elementsInfo = elementsToDelete.ToList();
                    foreach (ReportingElementInfo eInfo in elementsInfo)
                    {
                        reportingElements.Remove(eInfo);
                    }
                }

                foreach (CategoryTrigger trigger in pUpdater.CategoryTriggers)
                {
                    if (trigger.IsEnabled)
                    {
                        ElementCategoryFilter catFilter = new ElementCategoryFilter(catDictionary[trigger.CategoryName]);
                        UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeAny());

                        if (trigger.CategoryName == "Grids")
                        {
                            GridUtils.CollectGridExtents(doc, docId);
                            if (GridUtils.gridParameters.ContainsKey(docId))
                            {
                                foreach (ElementId paramId in GridUtils.gridParameters[docId])
                                {
                                    UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeParameter(paramId));
                                }
                            }

                            FilteredElementCollector collector = new FilteredElementCollector(doc);
                            List <Element>           elements  = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList();
                            foreach (Element element in elements)
                            {
                                ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, element.Id, element.UniqueId);
                                reportingElements.Add(reportingInfo);
                            }
                        }
                        else if (trigger.CategoryName == "Views")
                        {
                            FilteredElementCollector collector = new FilteredElementCollector(doc);
                            List <View> views         = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().Cast <View>().ToList();
                            var         viewTemplates = from view in views where view.IsTemplate select view;
                            if (viewTemplates.Count() > 0)
                            {
                                foreach (Element view in viewTemplates)
                                {
                                    ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, view.Id, view.UniqueId);
                                    reportingElements.Add(reportingInfo);
                                }
                            }
                        }
                        else
                        {
                            FilteredElementCollector collector = new FilteredElementCollector(doc);
                            List <Element>           elements  = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList();
                            foreach (Element element in elements)
                            {
                                ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, element.Id, element.UniqueId);
                                reportingElements.Add(reportingInfo);
                            }
                        }
                    }
                }

                if (registeredUpdaters.ContainsKey(docId))
                {
                    registeredUpdaters.Remove(docId);
                }
                registeredUpdaters.Add(docId, pUpdater);
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                MessageBox.Show("Failed to refresh triggers\n" + ex.Message, "DTM Updater", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }