public void UpdateModel(StoredObjectInfo newModel, object modelToBeUpdated) { if (modelToBeUpdated is IProcess process) { RWLock.EnterWriteLock(); try { var toBeReplaced = Processes.FirstOrDefault(p => p.Language == newModel.Language && p.Type == newModel.ModelType && p.Tag == newModel.Tag && p.Version < newModel.Version); if (toBeReplaced is object) { var index = Processes.IndexOf(toBeReplaced); if (index >= 0) { Processes[index] = process; } } } finally { RWLock.ExitWriteLock(); } } else { throw new InvalidOperationException("Invalid model to update"); } }
public bool HasModelToUpdate(StoredObjectInfo newModel) { RWLock.EnterReadLock(); try { return(Processes.Any(p => p.Language == newModel.Language && p.Type == newModel.ModelType && p.Tag == newModel.Tag && p.Version < newModel.Version)); } finally { RWLock.ExitReadLock(); } }
public bool HasModel(StoredObjectInfo model, bool matchVersion = true) { RWLock.EnterReadLock(); try { return(Processes.Any(p => p.Language == model.Language && p.Type == model.ModelType && p. Tag == model.Tag && (!matchVersion || p.Version == model.Version))); } finally { RWLock.ExitReadLock(); } }
public bool RemoveModel(StoredObjectInfo model) { //Removes any model matching the description, independent of the version RWLock.EnterReadLock(); try { return(Processes.RemoveAll(p => p.Language == model.Language && p.Type == model.ModelType && p.Tag == model.Tag) > 0); } finally { RWLock.ExitReadLock(); } }
private void UpdateProcessData() { Data.Processes = new List <StoredObjectInfo>(); var set = new HashSet <string>(); foreach (var p in Processes) { var md = new StoredObjectInfo(p.Type, p.Language, p.Version, p.Tag); if (set.Add(md.ToStringWithoutVersion())) { Data.Processes.Add(md); } } }
public override async Task StoreAsync() { Data.Processes = new List <StoredObjectInfo>(); var set = new HashSet <string>(); foreach (var p in Processes) { var md = new StoredObjectInfo(p.Type, p.Language, p.Version, p.Tag); if (set.Add(md.ToStringWithoutVersion())) { Data.Processes.Add(md); } } await base.StoreAsync(); }
public IEnumerable <(StoredObjectInfo Model, string[] EntityTypes)> GetPossibleEntityTypes() { RWLock.EnterReadLock(); try { foreach (var p in Processes) { if (p is IEntityRecognizer ire) { var md = new StoredObjectInfo(ire); yield return(md, ire.Produces()); } } } finally { RWLock.ExitReadLock(); } }
public IReadOnlyList <(StoredObjectInfo Model, string[] EntityTypes)> GetPossibleEntityTypes() { RWLock.EnterReadLock(); try { var list = new List <(StoredObjectInfo Model, string[] EntityTypes)>(); foreach (var p in Processes) { if (p is IEntityRecognizer ire) { var md = new StoredObjectInfo(ire); list.Add((md, ire.Produces())); } } return(list); } finally { RWLock.ExitReadLock(); } }
public static async Task <bool> CheckIfHasModelAsync(Language language, int version, string tag, StoredObjectInfo model, bool matchVersion = true) { var a = new Pipeline(language, version, tag); await a.LoadDataAsync(); return(a.Data.Processes.Any(p => p.Language == model.Language && p.ModelType == model.ModelType && p.Tag == model.Tag && (!matchVersion || p.Version == model.Version))); }