Exemple #1
0
        public MetaOutput Clone()
        {
            var output = new MetaOutput(Guid.NewGuid(), Name, OpPart);

            if (Name != null)
            {
                output.Name = string.Copy(Name);
            }
            return(output);
        }
Exemple #2
0
        public void LoadMetaOperators()
        {
            var coreAssembly = (from asm in AppDomain.CurrentDomain.GetAssemblies()
                                where asm.GetName().Name == "Core"
                                select asm).First();

            Logger.Info("Loading operator definition parts...");
            var watch = new Stopwatch();

            watch.Start();
            try {
                Type[] t = coreAssembly.GetTypes();
            }
            catch (Exception e)
            {
                Logger.Info("e.Message");
                if (e is System.Reflection.ReflectionTypeLoadException)
                {
                    var typeLoadException = e as ReflectionTypeLoadException;
                    var loaderExceptions  = typeLoadException.LoaderExceptions;
                }
            }
            var metaOpPartTypes = (from type in coreAssembly.GetTypes()
                                   let properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static)
                                                    from p in properties
                                                    where p.PropertyType == typeof(MetaOperatorPart)
                                                    select new { Type = type, PropInfo = p }).ToList();

            metaOpPartTypes.ForEach(metaType =>
            {
                AddMetaOperatorPart((MetaOperatorPart)(metaType.PropInfo.GetValue(metaType.Type, null)));
                Logger.Debug("loaded: '{0}'", metaType.PropInfo.Name);
            });

            AppDomain.CurrentDomain.AssemblyResolve += ResolveEventHandler;

            Logger.Info("Loading operator types...");
            if (Directory.Exists(MetaPath) && ReadMetaOpsOnInit)
            {
                var metaFiles = Directory.EnumerateFiles(MetaPath, "*.mop");
                _numOps = metaFiles.Count() - 1;
                foreach (var metaFile in metaFiles)
                {
                    var id = new Guid(Path.GetFileNameWithoutExtension(metaFile));

                    if (!MetaOperators.ContainsKey(id))
                    {
                        var metaOp = LoadMetaOperator(id);
                        AddMetaOperator(id, metaOp);
                    }
                    TriggerInitializeCallback();
                }
                watch.Stop();
                Logger.Debug("Loading took {0}s", (float)watch.ElapsedMilliseconds / 1000.0f);
            }
            else
            {
                Logger.Warn("No meta operators found. Is your operator database empty or corrupted?");
            }

            // try to load main op
            _homeOperator = LoadMetaOperatorFromFile(@"Config/Home.mop");
            if (_homeOperator == null)
            {
                _homeOperator = new MetaOperator(HomeOperatorGuid)
                {
                    Name = "Home"
                };
                var output = new MetaOutput(HomeOutputGuid, "Output", BasicMetaTypes.GenericMeta);
                _homeOperator.AddOutput(output);
            }

            CheckForInconsistencies();
        }