Exemple #1
0
        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");
            }
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
        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();
        }
Exemple #7
0
 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();
     }
 }
Exemple #8
0
 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();
     }
 }
Exemple #9
0
        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)));
        }