Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="pUpdater"></param>
        public void RefreshTriggers(Document doc, ProjectUpdater pUpdater)
        {
            try
            {
                var centralPath = FileInfoUtil.GetCentralFilePath(doc);
                var configId    = "";
                if (MissionControlSetup.Configurations.ContainsKey(centralPath))
                {
                    configId = MissionControlSetup.Configurations[centralPath].Id;
                }

                UpdaterRegistry.RemoveDocumentTriggers(_updaterId, doc);

                var elementsToDelete = _reportingElements.Where(x => x.CentralPath == centralPath).ToList();
                if (elementsToDelete.Any())
                {
                    foreach (var eInfo in elementsToDelete)
                    {
                        _reportingElements.Remove(eInfo);
                    }
                }

                foreach (var trigger in pUpdater.CategoryTriggers)
                {
                    if (!trigger.IsEnabled)
                    {
                        continue;
                    }

                    var catFilter = new ElementCategoryFilter(_catDictionary[trigger.CategoryName]);
                    UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeAny());
                    UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeElementAddition());
                    UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeElementDeletion());

                    switch (trigger.CategoryName)
                    {
                    case "Grids":
                    {
                        GridUtils.CollectGridExtents(doc, centralPath);
                        if (GridUtils.gridParameters.ContainsKey(centralPath))
                        {
                            foreach (var paramId in GridUtils.gridParameters[centralPath])
                            {
                                UpdaterRegistry.AddTrigger(_updaterId, catFilter, Element.GetChangeTypeParameter(paramId));
                            }
                        }

                        var elements = new FilteredElementCollector(doc)
                                       .WherePasses(catFilter)
                                       .WhereElementIsNotElementType()
                                       .ToElements();
                        foreach (var element in elements)
                        {
                            var reportingInfo = new ReportingElementInfo(
                                configId,
                                UpdaterGuid.ToString(),
                                centralPath,
                                trigger.CategoryName,
                                trigger.Description,
                                element.Id,
                                element.UniqueId);
                            _reportingElements.Add(reportingInfo);
                        }
                    }
                    break;

                    case "Views":
                    {
                        var viewTemplates = new FilteredElementCollector(doc)
                                            .WherePasses(catFilter)
                                            .WhereElementIsNotElementType()
                                            .Cast <View>()
                                            .Where(x => x.IsTemplate)
                                            .ToList();

                        if (viewTemplates.Any())
                        {
                            foreach (var view in viewTemplates)
                            {
                                var reportingInfo = new ReportingElementInfo(
                                    configId,
                                    UpdaterGuid.ToString(),
                                    centralPath,
                                    trigger.CategoryName,
                                    trigger.Description,
                                    view.Id,
                                    view.UniqueId);
                                _reportingElements.Add(reportingInfo);
                            }
                        }
                    }
                    break;

                    default:
                    {
                        var elements = new FilteredElementCollector(doc)
                                       .WherePasses(catFilter)
                                       .WhereElementIsNotElementType()
                                       .ToElements();
                        foreach (var element in elements)
                        {
                            var reportingInfo = new ReportingElementInfo(
                                configId,
                                UpdaterGuid.ToString(),
                                centralPath,
                                trigger.CategoryName,
                                trigger.Description,
                                element.Id,
                                element.UniqueId);
                            _reportingElements.Add(reportingInfo);
                        }
                    }
                    break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
        public void RefreshTriggers(Document doc, ProjectUpdater pUpdater)
        {
            try
            {
                string centralPath = FileInfoUtil.GetCentralFilePath(doc);
                string configId    = "";
                if (AppCommand.Instance.ConfigDictionary.ContainsKey(centralPath))
                {
                    configId = AppCommand.Instance.ConfigDictionary[centralPath]._id;
                }

                UpdaterRegistry.RemoveDocumentTriggers(updaterId, doc);

                var elementsToDelete = from eInfo in reportingElements where eInfo.CentralPath == centralPath 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());
                        UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeElementAddition());
                        UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeElementDeletion());

                        if (trigger.categoryName == "Grids")
                        {
                            GridUtils.CollectGridExtents(doc, centralPath);
                            if (GridUtils.gridParameters.ContainsKey(centralPath))
                            {
                                foreach (ElementId paramId in GridUtils.gridParameters[centralPath])
                                {
                                    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(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, 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(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, 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(configId, updaterGuid.ToString(), centralPath, trigger.categoryName, trigger.description, element.Id, element.UniqueId);
                                reportingElements.Add(reportingInfo);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                LogUtil.AppendLog("DTMUpdater-RefreshTriggers:" + ex.Message);
            }
        }