/// <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); }
/// <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; }
private void NotifyModuleEvent(IModuleInstance moduleInst, string eventCode, object eventParams) { if (this.ModuleEvent != null) { this.ModuleEvent(this, moduleInst, eventCode, eventParams); } }
/// <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); //} } }
/// <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); //} } }
private IModuleDataModel _GetAsInstanceData(IModuleInstance module) { IModuleDataModel model = null; _dataModels.TryGetValue(Tuple.Create(module.TypeId, module.InstanceId), out model); return(model); }
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 }
public void ProjectTemplateInto(IModuleInstance target) { if (target != null) { ModuleTemplateModuleManagement manager = Modules.GetManager <IModuleTemplateModuleInstance, ModuleTemplateModuleManagement>(); manager.ProjectTemplateInto(target); } }
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"); }
public string GetModulePath(IModuleInstance actor) { if (localModulePath.TryGetValue(actor, out string path)) { return(path); } return(null); }
public void ProjectTemplateInto(IModuleInstance target) { if (target != null) { ModuleTemplateModuleManagement manager = Modules.GetManager<IModuleTemplateModuleInstance, ModuleTemplateModuleManagement>(); manager.ProjectTemplateInto(target); } }
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); }
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 }
private void _RemoveInstanceData(IModuleInstance module) { IModuleDataModel dataModel = _GetAsInstanceData(module); if (dataModel != null) { _dataModels.Remove(dataModel); } }
private void _RemoveInstanceData(IModuleInstance module) { IModuleDataModel dataModel = _GetAsInstanceData(module); if (dataModel != null) { _dataModels.Remove(Tuple.Create(module.TypeId, module.InstanceId)); } }
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); }
protected IModuleDataModel _GetOrCreateAsInstanceData(IModuleInstance module) { IModuleDataModel dataModel = _GetAsInstanceData(module); if (dataModel == null) { dataModel = _CreateDataModel(module); _AddAsInstanceData(dataModel, module); } return(dataModel); }
public static IModuleDataModel CreateModuleDataInstance(IModuleInstance module) { IModuleDataModel dataModel = null; Type moduleDataSetType = _GetModuleDataSetType(module.Descriptor); if (moduleDataSetType != null) { dataModel = _CreateDataModel(moduleDataSetType); } return dataModel; }
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); }
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); }
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); }
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; }
/// <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); }
/// <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); } }
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(); }); } }
/// <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); } }
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); }
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); } }
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); }
/// <summary> /// Retrieves the module type data without assigning it to a module instance. /// </summary> public IModuleDataModel GetTypeData(IModuleInstance module) { return _GetOrCreateAsTypeData(module); }
protected abstract IModuleDataModel _GetDataInstance(IModuleInstance module);
protected IModuleDataModel _CreateDataModel(IModuleInstance module) { Type dataModelType = _GetDataModelType(module.Descriptor); return _CreateDataModel(dataModelType); }
protected override IModuleDataModel _GetDataInstance(IModuleInstance module) { return(module.StaticModuleData); }
protected IModuleDataModel _GetOrCreateAsTypeData(IModuleInstance module) { IModuleDataModel dataModel = _GetAsTypeData(module); if (dataModel == null) { dataModel = _CreateDataModel(module); _AddAsTypeData(dataModel, module); } return dataModel; }
/// <summary> /// Retrieves the module type data without assigning it to a module instance. /// </summary> public IModuleDataModel GetTypeData(IModuleInstance module) { return(_GetOrCreateAsTypeData(module)); }
private void _AddAsTypeData(IModuleDataModel dataModel, IModuleInstance module) { _Add(dataModel, module.Descriptor.TypeId, module.Descriptor.TypeId); }
private IModuleDataModel _GetAsTypeData(IModuleInstance module) { IModuleDataModel model = null; _dataModels.TryGetValue(Tuple.Create(module.Descriptor.TypeId, module.Descriptor.TypeId), out model); return model; }
private void _RemoveTypeData(IModuleInstance module) { IModuleDataModel dataModel = _GetAsTypeData(module); if (dataModel != null) { _dataModels.Remove(Tuple.Create(module.Descriptor.TypeId, module.Descriptor.TypeId)); } }
public void AssignModuleData(IModuleInstance module) { _moduleDataSet.AssignModuleInstanceData(module); }
protected override IModuleDataModel _GetDataInstance(IModuleInstance module) { return module.ModuleData; }
public void RemoveModuleTypeData(IModuleInstance module) { _RemoveTypeData(module); }