public T PutOrGetModel <T>(T model) where T : class, ICacheableModel { CleanReferences(); var getModel = GetModel <T>(model.ModelId); if (getModel != null) { return(getModel); } else { referenceList.Add(model); modelBuffer.Add(new KeyValuePair <DateTime, object>(DateTime.Now, model)); return(model); } }
internal THandler EnsureFeatureRegistered(ISldWorks app, IModelDoc2 model, IFeature feat, out bool isNew) { isNew = false; MacroFeatureDictionary featsDict; if (!m_Register.TryGetValue(model, out featsDict)) { m_Logger.Log($"{model?.GetTitle()} model is not registered in the register"); featsDict = new MacroFeatureDictionary(); m_Register.Add(model, featsDict); var lcm = new MacroFeatureLifecycleManager(model, m_BaseName, m_Logger); lcm.ModelDisposed += OnModelDisposed; lcm.FeatureDeleted += OnFeatureDeleted; m_LifecycleManagers.Add(model, lcm); } THandler handler = null; if (!featsDict.TryGetValue(feat, out handler)) { m_Logger.Log($"{feat?.Name} feature in {model?.GetTitle()} model is not registered in the register"); handler = new THandler(); featsDict.Add(feat, handler); handler.Init(app, model, feat); isNew = true; } return(handler); }
public static int RepoIndex(DirectoryInfo localRepo, FileInfo outputFile, int pageLimit) { if (localRepo == null) { localRepo = new DirectoryInfo(Path.GetFullPath(".")); } if (!localRepo.Exists) { Outputs.WriteError($"Invalid target repository directory: {localRepo.FullName}."); return(ReturnCodes.InvalidArguments); } int currentPageCount = 0; int pageIdentifier = 1; FileInfo currentPageFile = outputFile; var modelDictionary = new ModelDictionary(); var currentLinks = new ModelIndexLinks { Self = currentPageFile.FullName }; foreach (string file in Directory.EnumerateFiles(localRepo.FullName, "*.json", new EnumerationOptions { RecurseSubdirectories = true })) { if (file.ToLower().EndsWith(".expanded.json")) { continue; } // TODO: Debug plumbing. // Outputs.WriteDebug($"Processing: {file}"); try { var modelFile = new FileInfo(file); ModelIndexEntry indexEntry = ParsingUtils.ParseModelFileForIndex(modelFile); modelDictionary.Add(indexEntry.Dtmi, indexEntry); currentPageCount += 1; if (currentPageCount == pageLimit) { var nextPageFile = new FileInfo( Path.Combine( currentPageFile.Directory.FullName, $"index.page.{pageIdentifier}.json")); currentLinks.Next = nextPageFile.FullName; var nextLinks = new ModelIndexLinks { Self = nextPageFile.FullName, Prev = currentLinks.Self }; var modelIndex = new ModelIndex(modelDictionary, currentLinks); IndexPageUtils.WritePage(modelIndex); currentPageCount -= pageLimit; modelDictionary = new ModelDictionary(); currentPageFile = nextPageFile; currentLinks = nextLinks; pageIdentifier += 1; } } catch (Exception e) { Outputs.WriteError($"Failure processing model file: {file}, {e.Message}"); return(ReturnCodes.ProcessingError); } } if (modelDictionary.Count > 0) { var modelIndex = new ModelIndex(modelDictionary, currentLinks); IndexPageUtils.WritePage(modelIndex); } return(ReturnCodes.Success); }