Esempio n. 1
0
        /// <summary>
        /// Creates a new untyped instance of the module.  This should only be called by repositories.
        /// </summary>
        static public IModuleInstance GetById(Guid moduleTypeId)
        {
            Type            instanceType;
            IModuleInstance instance = null;

            if (_activators.TryGetValue(moduleTypeId, out instanceType))
            {
                instance            = (IModuleInstance)Activator.CreateInstance(instanceType);
                instance.Descriptor = GetDescriptorById(moduleTypeId);

                try {
                    instance.StaticModuleData = _GetModuleStaticData(instance);
                } catch (Exception ex) {
                    VixenSystem.Logging.Error("Error when assigning module static data.", ex);
                }

                try {
                    instance.ModuleData = _GetModuleData(instance);
                } catch (Exception ex) {
                    VixenSystem.Logging.Error("Error when assigning module data.", ex);
                }

                // See if there are any templates to apply to the instance.
                ModuleTemplateService.Instance.ProjectTemplateInto(instance);
            }
            else
            {
                VixenSystem.Logging.Warning("Attempt to instantiate non-existent module " + moduleTypeId);
            }
            return(instance);
        }
Esempio n. 2
0
 /// <summary>
 /// Initialize using the definition, instance, and settings.
 /// </summary>
 /// <param name="def"></param>
 /// <param name="instance"></param>
 /// <param name="settings"></param>
 public Module(string id, IModuleDefinition def, IModuleInstance instance, IModuleSettings settings)
 {
     Definition = def;
     Instance   = instance;
     Settings   = settings;
     Id         = id;
 }
Esempio n. 3
0
 private void NotifyModuleEvent(IModuleInstance moduleInst, string eventCode, object eventParams)
 {
     if (this.ModuleEvent != null)
     {
         this.ModuleEvent(this, moduleInst, eventCode, eventParams);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Instantiates the data model for the module from the data in this data set.
 /// Accounts for the module's instance id so there can be multiple instances
 /// of a module type in the dataset.
 /// </summary>
 /// <param name="module"></param>
 public void AssignModuleInstanceData(IModuleInstance module)
 {
     if (module != null)
     {
         // 1. Module has a data object, we don't.
         //    - Add the module's data object
         // 2. Module has no data object, we do.
         //    - Get our data object and assign it in the module
         // 3. We and the module have a data object.
         //    - Get our data object and assign it in the module
         // 4. Neither has a data object.
         //    - We create one within ourselves and assign it in the module.
         IModuleDataModel dataModel = _GetDataInstance(module);
         if (!_ContainsInstanceData(module.Descriptor.TypeId, module.InstanceId) && dataModel != null)
         {
             // We have no data, but the module does.  Add it.
             _AddAsInstanceData(dataModel, module);
         }
         else
         {
             // In every other case, we have or can create data.
             module.ModuleData = _GetOrCreateAsInstanceData(module);
         }
         //* This behavior was put in for a reason now lost to history.
         //* KEEP THIS CODE, in case the reason is discovered.
         //// If the module already has data, add it, don't overwrite it.
         //IModuleDataModel dataModel = _GetDataInstance(module);
         //if(dataModel == null) {
         //    module.ModuleData = RetrieveInstanceData(module);
         //} else {
         //    _Add(this, module.Descriptor.TypeId, module.InstanceId, dataModel);
         //}
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Instantiates the data model for the module from the data in this data set.
 /// Accounts for the module's instance id so there can be multiple instances
 /// of a module type in the dataset.
 /// </summary>
 /// <param name="module"></param>
 public void AssignModuleInstanceData(IModuleInstance module)
 {
     if (module != null) {
         // 1. Module has a data object, we don't.
         //    - Add the module's data object
         // 2. Module has no data object, we do.
         //    - Get our data object and assign it in the module
         // 3. We and the module have a data object.
         //    - Get our data object and assign it in the module
         // 4. Neither has a data object.
         //    - We create one within ourselves and assign it in the module.
         IModuleDataModel dataModel = _GetDataInstance(module);
         if (!_ContainsInstanceData(module.Descriptor.TypeId, module.InstanceId) && dataModel != null) {
             // We have no data, but the module does.  Add it.
             _AddAsInstanceData(dataModel, module);
         }
         else {
             // In every other case, we have or can create data.
             module.ModuleData = _GetOrCreateAsInstanceData(module);
         }
         //* This behavior was put in for a reason now lost to history.
         //* KEEP THIS CODE, in case the reason is discovered.
         //// If the module already has data, add it, don't overwrite it.
         //IModuleDataModel dataModel = _GetDataInstance(module);
         //if(dataModel == null) {
         //    module.ModuleData = RetrieveInstanceData(module);
         //} else {
         //    _Add(this, module.Descriptor.TypeId, module.InstanceId, dataModel);
         //}
     }
 }
Esempio n. 6
0
        private IModuleDataModel _GetAsInstanceData(IModuleInstance module)
        {
            IModuleDataModel model = null;

            _dataModels.TryGetValue(Tuple.Create(module.TypeId, module.InstanceId), out model);
            return(model);
        }
Esempio n. 7
0
 public static bool IsType(this IModuleInstance module)
 {
     return(module.Identifiers[key : "type"] is IModuleInstance typeModule &&
            typeModule.Identifiers[key : "size"] is IVariableInstance sizeVariable &&
            sizeVariable.Type.Name == "u64");
     // TODO: read compile time value & check for != 0
 }
Esempio n. 8
0
 public void ProjectTemplateInto(IModuleInstance target)
 {
     if (target != null)
     {
         ModuleTemplateModuleManagement manager = Modules.GetManager <IModuleTemplateModuleInstance, ModuleTemplateModuleManagement>();
         manager.ProjectTemplateInto(target);
     }
 }
Esempio n. 9
0
 static ITypedValue ImplicitCast(INamedExpressionTuple tuple, IModuleInstance type)
 {
     if (tuple.Tuple.Count == 1)
     {
         return(ImplicitCast((dynamic)tuple.Tuple.First().Expression, type));
     }
     throw new ArgumentException(message: "Invalid argument tuple");
 }
Esempio n. 10
0
 public string GetModulePath(IModuleInstance actor)
 {
     if (localModulePath.TryGetValue(actor, out string path))
     {
         return(path);
     }
     return(null);
 }
Esempio n. 11
0
 public void ProjectTemplateInto(IModuleInstance target)
 {
     if (target != null) {
         ModuleTemplateModuleManagement manager =
             Modules.GetManager<IModuleTemplateModuleInstance, ModuleTemplateModuleManagement>();
         manager.ProjectTemplateInto(target);
     }
 }
Esempio n. 12
0
        static ITypedValue ImplicitCast(ILiteral literal, IModuleInstance type)
        {
            // TODO: make fromLiteral implementable in Rebuild
            var fromLiteral = type.GetFromLiteral();
            var value       = CreateValue(type);

            fromLiteral(value.Data, literal);
            return(value);
        }
Esempio n. 13
0
 public static ulong GetTypeSize(this IModuleInstance module)
 {
     return(module.Identifiers[key : "type"] is IModuleInstance typeModule &&
            typeModule.Identifiers[key : "size"] is IVariableInstance sizeVariable &&
            sizeVariable.Type.Name == "u64"
             ? 8u
            : 0u);
     // TODO extract the real value
 }
Esempio n. 14
0
        private void _RemoveInstanceData(IModuleInstance module)
        {
            IModuleDataModel dataModel = _GetAsInstanceData(module);

            if (dataModel != null)
            {
                _dataModels.Remove(dataModel);
            }
        }
Esempio n. 15
0
        private void _RemoveInstanceData(IModuleInstance module)
        {
            IModuleDataModel dataModel = _GetAsInstanceData(module);

            if (dataModel != null)
            {
                _dataModels.Remove(Tuple.Create(module.TypeId, module.InstanceId));
            }
        }
Esempio n. 16
0
        static ITypedValue CreateValue(IModuleInstance type)
        {
            var result = new TypedValue {
                Data = new byte[type.GetTypeSize()],
                Type = type
            };

            //var constructor = type.GetConstructor();
            // TODO: invoke constructor
            return(result);
        }
Esempio n. 17
0
        protected IModuleDataModel _GetOrCreateAsInstanceData(IModuleInstance module)
        {
            IModuleDataModel dataModel = _GetAsInstanceData(module);

            if (dataModel == null)
            {
                dataModel = _CreateDataModel(module);
                _AddAsInstanceData(dataModel, module);
            }
            return(dataModel);
        }
Esempio n. 18
0
        public static IModuleDataModel CreateModuleDataInstance(IModuleInstance module)
        {
            IModuleDataModel dataModel = null;

            Type moduleDataSetType = _GetModuleDataSetType(module.Descriptor);
            if (moduleDataSetType != null) {
                dataModel = _CreateDataModel(moduleDataSetType);
            }

            return dataModel;
        }
Esempio n. 19
0
 static ITypedValue ImplicitCast(ITypedValue value, IModuleInstance type)
 {
     if (null == value)
     {
         return(null);
     }
     if (value.Type == type)
     {
         return(value);
     }
     // TODO: call the cast
     return(null);
 }
        public static IModuleDataModel CreateModuleDataInstance(IModuleInstance module)
        {
            IModuleDataModel dataModel = null;

            Type moduleDataSetType = _GetModuleDataSetType(module.Descriptor);

            if (moduleDataSetType != null)
            {
                dataModel = _CreateDataModel(moduleDataSetType);
            }

            return(dataModel);
        }
Esempio n. 21
0
        public IModulePipeline GetPipeline(IModuleInstance user, string path)
        {
            var pipestr = this.Remote.ToString() + "/" + path + "_" + user.path;

            if (this.refPipelines.TryGetValue(pipestr, out IModulePipeline pipe))
            {
                return(pipe);
            }
            PipelineRefRemote _pipe = new PipelineRefRemote(_System.refSystemThis, user.path, this, path);

            this.refPipelines[pipestr] = _pipe;

            return(_pipe);
        }
Esempio n. 22
0
        public IModulePipeline GetPipeLineByFrom(IModulePipeline from, IModuleInstance to)
        {
            var fromstr = from.IsLocal ? from.path : (from.system.Remote.ToString() + "/" + from.path);
            var pipestr = to.path + "_" + fromstr;

            if (this.refPipelines.TryGetValue(pipestr, out IModulePipeline pipe))
            {
                return(pipe);
            }
            PipelineRefLocal _pipe = new PipelineRefLocal(_System, to);

            this.refPipelines[pipestr] = _pipe;

            _pipe.SetFromPipeline(from);
            return(_pipe);
        }
Esempio n. 23
0
        public PipelineRefLocal(PipelineSystemV1 _System, IModuleInstance module)
        {
            this._System = _System;
            this.system  = _System.refSystemThis;
            //if (string.IsNullOrEmpty(userPath))
            //    this.userUrl = null;
            //else if (userPath[0] == '@')
            //    this.userUrl = userPath;
            //else
            //    this.userUrl = "this/" + userPath;



            this.path         = module.path;
            this.targetModule = module;
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a default data object for the module without adding it to any dataset.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        static private IModuleDataModel _GetModuleData(IModuleInstance instance)
        {
            // Remember, the data is orphaned initially!
            IModuleDataModel dataModel = null;

            if (instance.Descriptor.ModuleDataClass != null)
            {
                dataModel = ModuleLocalDataSet.CreateModuleDataInstance(instance);
                if (dataModel == null)
                {
                    VixenSystem.Logging.Error("Module \"" + instance.Descriptor.TypeName + "\" in " + instance.Descriptor.FileName + " has a reference to type " + instance.Descriptor.ModuleDataClass.Name + " for its module data class, but it's not an implementation of " + typeof(IModuleDataModel).Name + ".");
                }
            }

            return(dataModel);
        }
Esempio n. 25
0
        /// <summary>
        /// Creates a default data object for the module without adding it to any dataset.
        /// </summary>
        /// <param name="instance"></param>
        /// <returns></returns>
        private static IModuleDataModel _GetModuleData(IModuleInstance instance)
        {
            // Remember, the data is orphaned initially!
            IModuleDataModel dataModel = null;

            if (instance.Descriptor.ModuleDataClass != null)
            {
                dataModel = ModuleLocalDataSet.CreateModuleDataInstance(instance);
                if (dataModel == null)
                {
                    Logging.Error(string.Format("Module \"{0}\" in {1} has a reference to type {2} for its module data class, but it's not an implementation of {3}.", instance.Descriptor.TypeName, instance.Descriptor.FileName, instance.Descriptor.ModuleDataClass.Name, typeof(IModuleDataModel).Name));
                }
            }

            return(dataModel);
        }
        public void ProjectTemplateInto(IModuleInstance target)
        {
            // Get all template module descriptors.
            IEnumerable <IModuleTemplateModuleDescriptor> templateDescriptors = Modules.GetDescriptors <IModuleTemplateModuleInstance, IModuleTemplateModuleDescriptor>();
            // Find the one for the module type.
            // (i.e. Has the module type as a dependency.)
            IModuleTemplateModuleDescriptor descriptor = templateDescriptors.FirstOrDefault(x => x.Dependencies.Contains(target.Descriptor.TypeId));

            if (descriptor != null)
            {
                // Get an instance of the template module.
                IModuleTemplateModuleInstance instance = Get(descriptor.TypeId);
                // Project the template into the target instance.
                instance.Project(target);
            }
        }
Esempio n. 27
0
        public void RegistModule(string path, IModuleInstance actor)
        {
            if (localModules.ContainsKey(path) == true)
            {
                throw new Exception("already have that path.");
            }

            localModules[path]     = actor;
            localModulePath[actor] = path;
            actor.OnRegistered(this, path);

            if (bStarted)
            {
                System.Threading.ThreadPool.QueueUserWorkItem((e) =>
                {
                    actor.OnStart();
                    actor.OnStarted();
                });
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 删除并释放某个模块
        /// </summary>
        /// <param name="moduleID"></param>
        public void RemoveModule(string moduleID)
        {
            IModuleInstance moduleInst = this.ModuleList.FirstOrDefault(v => v.ID == moduleID);

            if (moduleInst == null)
            {
                return;
            }

            try
            {
                moduleInst.PublishEvent -= this.ModuleInstance_PublishEvent;
                moduleInst.Release();
                this.ModuleList.Remove(moduleInst);
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("卸载模块异常, {0}", moduleID), ex);
            }
        }
Esempio n. 29
0
        static void AddTypeSizeDeclaration(ulong typeIntrinsicTypeSize, IModuleInstance module, IParentedIdentifierScope scope)
        {
            var sizeType = module.Name == SizeTypeName
                ? module
                : (scope[SizeTypeName] as IModuleInstance);
            var sizeDefine = new VariableDeclaration {
                Name  = "size",
                Type  = sizeType,
                Value = new TypedValue {
                    Type = sizeType,
                    Data = BitConverter.GetBytes(typeIntrinsicTypeSize)
                }
            };
            var typeModule = new ModuleInstance(name: "type");

            typeModule.Identifiers.Add(new VariableInstance {
                Variable = sizeDefine
            });

            module.Identifiers.Add(typeModule);
        }
Esempio n. 30
0
        public IModulePipeline GetPipeLineByFrom(IModulePipeline from, IModuleInstance to)
        {
            var fromstr = from.IsLocal ? from.path : (from.system.Remote.ToString() + "/" + from.path);
            var pipestr = to.path + "_" + fromstr;
            var isExist = this.refPipelines.TryGetValue(pipestr, out IModulePipeline pipe);

            if (isExist)
            {
                //现有的pipe可能是一个已经关闭的,但是传进来的from始终是对,所以获取后再重新设置下
                (pipe as PipelineRefLocal)?.SetFromPipeline(from);
                return(pipe);
            }
            else
            {
                PipelineRefLocal _pipe = new PipelineRefLocal(_System, to);
                this.refPipelines[pipestr] = _pipe;

                _pipe.SetFromPipeline(from);
                return(_pipe);
            }
        }
Esempio n. 31
0
        public IModulePipeline GetPipeline(IModuleInstance user, string path)
        {
            var pipestr = path + "_";

            if (user != null)
            {
                pipestr += user.path;
            }
            if (this.refPipelines.TryGetValue(pipestr, out IModulePipeline pipe))
            {
                return(pipe);
            }
            IModuleInstance module = this._System.GetModule(path);

            PipelineRefLocal _pipe = new PipelineRefLocal(_System, module);

            this.refPipelines[pipestr] = _pipe;

            var userpipe = user == null ? null : _System.GetPipeline(module, "this/" + user.path);

            _pipe.SetFromPipeline(userpipe);
            return(_pipe);
        }
Esempio n. 32
0
 /// <summary>
 /// Retrieves the module type data without assigning it to a module instance.
 /// </summary>
 public IModuleDataModel GetTypeData(IModuleInstance module)
 {
     return _GetOrCreateAsTypeData(module);
 }
Esempio n. 33
0
 protected abstract IModuleDataModel _GetDataInstance(IModuleInstance module);
Esempio n. 34
0
 protected IModuleDataModel _CreateDataModel(IModuleInstance module)
 {
     Type dataModelType = _GetDataModelType(module.Descriptor);
     return _CreateDataModel(dataModelType);
 }
Esempio n. 35
0
 protected override IModuleDataModel _GetDataInstance(IModuleInstance module)
 {
     return(module.StaticModuleData);
 }
Esempio n. 36
0
 protected IModuleDataModel _GetOrCreateAsTypeData(IModuleInstance module)
 {
     IModuleDataModel dataModel = _GetAsTypeData(module);
     if (dataModel == null) {
         dataModel = _CreateDataModel(module);
         _AddAsTypeData(dataModel, module);
     }
     return dataModel;
 }
Esempio n. 37
0
 /// <summary>
 /// Retrieves the module type data without assigning it to a module instance.
 /// </summary>
 public IModuleDataModel GetTypeData(IModuleInstance module)
 {
     return(_GetOrCreateAsTypeData(module));
 }
Esempio n. 38
0
 private void _AddAsTypeData(IModuleDataModel dataModel, IModuleInstance module)
 {
     _Add(dataModel, module.Descriptor.TypeId, module.Descriptor.TypeId);
 }
Esempio n. 39
0
 private IModuleDataModel _GetAsTypeData(IModuleInstance module)
 {
     IModuleDataModel model = null;
     _dataModels.TryGetValue(Tuple.Create(module.Descriptor.TypeId, module.Descriptor.TypeId), out model);
     return model;
 }
Esempio n. 40
0
 private void _RemoveTypeData(IModuleInstance module)
 {
     IModuleDataModel dataModel = _GetAsTypeData(module);
     if (dataModel != null) {
         _dataModels.Remove(Tuple.Create(module.Descriptor.TypeId, module.Descriptor.TypeId));
     }
 }
Esempio n. 41
0
 public void AssignModuleData(IModuleInstance module)
 {
     _moduleDataSet.AssignModuleInstanceData(module);
 }
Esempio n. 42
0
 protected override IModuleDataModel _GetDataInstance(IModuleInstance module)
 {
     return module.ModuleData;
 }
Esempio n. 43
0
 public void RemoveModuleTypeData(IModuleInstance module)
 {
     _RemoveTypeData(module);
 }