예제 #1
0
        private static void RegisterDocument(Document document)
        {
            // If the document has an existing GUID saved to ExtensibleStorage we retrieve this, otherwise we register it with a new GUID
            string documentGuid = DocumentGuidUtils.GetDocumentGuidFromExtensibleStorage(document) ??
                                  DocumentGuidUtils.RegisterDocumentGuidToExtensibleStorage(document);

            // Creates an accessible, stable reference to the Revit document
            DocumentCacheService.AddDocument(documentGuid, document);

            // Setting a static, accessible reference to the Revit application just this once, for everything to use
            if (RevitApplication == null)
            {
                RevitApplication = document.Application;
            }

            // Getting all of the saved rules in the document
            ObservableCollection <RegexRule> existingRegexRules = ExtensibleStorageUtils.GetAllRegexRulesInExtensibleStorage(documentGuid);

            // If there are no saved rules we return, otherwise we establish the updaters
            if (existingRegexRules == null || existingRegexRules.Count < 1)
            {
                return;
            }

            // If we found rules, load them into the rules cache
            foreach (RegexRule existingRegexRule in existingRegexRules)
            {
                RegexRuleCacheService.AddRule(documentGuid, existingRegexRule);
            }
        }
예제 #2
0
        private static void DeRegisterDocument(Document document)
        {
            string documentGuid = DocumentGuidUtils.GetDocumentGuidFromExtensibleStorage(document) ?? DocumentGuidUtils.RegisterDocumentGuidToExtensibleStorage(document);

            // If there are any saved rules in the application-wide cache, we can remove them
            RegexRuleCacheService.ClearDocumentRules(documentGuid);

            DocumentCacheService.RemoveDocument(documentGuid);
        }