public object CreateObject(IObjectSetting setting, params object[] parameters) { if (setting == null) { return(null); } var typeName = ObjectService.GetTypeName(setting.TypeName); var objectType = TypeHelper.CreateType(typeName, false); if (objectType == null) { return(null); } if (!typeof(IEventStorageInternal).IsAssignableFrom(objectType)) { throw new Exception("Create Redis Event Storage Only."); } var storage = (IEventStorageInternal)ObjectService.Current.ObjectBuilder.CreateObject((HTB.DevFx.Core.Config.IObjectSetting)setting, parameters); if (storage == null) { return(null); } storage.ConnectionStringName = setting.Name; return(storage); }
protected override void PublishService(RemotingServiceItemSetting setting) { var typeName = setting.TypeName; if (string.Compare(typeName, ":wcf", true) != 0) { base.PublishService(setting); return; } if (HttpContext.Current != null) //ignore in iis { return; } var serviceTypeName = setting.ServiceTypeName; if (string.IsNullOrEmpty(serviceTypeName)) { throw new RemotingException("serviceType is required in config file"); } serviceTypeName = ObjectService.GetTypeName(setting.ServiceTypeName); var serviceType = TypeHelper.CreateType(serviceTypeName, true); var serviceHost = new ServiceHost(serviceType); serviceHost.Open(); }
protected virtual ServiceHandler CreateHandler(ServiceItemSetting setting) { var contractTypeName = ObjectService.GetTypeName(setting.ContractTypeName); var contractType = TypeHelper.CreateType(contractTypeName, false); if (contractType == null || !contractType.IsInterface) { throw new ArgumentException("ContractType can't be created.", contractTypeName); } setting.ContractType = contractType; return(new ServiceHandler(contractType, this)); }
public void Init(ServiceControllerFactorySetting setting) { var controllerTypeName = ObjectService.GetTypeName(setting.ControllerBaseTypeName); this.services = setting.ServiceControllers.ToDictionary(k => k.Name.ToLower(), v => { v.ControllerBaseTypeName = string.IsNullOrEmpty(v.ControllerBaseTypeName) ? controllerTypeName : ObjectService.GetTypeName(v.ControllerBaseTypeName); return(v); }); var domain = Thread.GetDomain(); var name = new AssemblyName("Octopus.Esb.Server.Mvc.DynamicControllers"); this.assemblyBuilder = domain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); this.moduleBuilder = this.assemblyBuilder.DefineDynamicModule("DynamicModule"); var routeName = this.GetType().Name; RouteTable.Routes.MapRoute( routeName, setting.RouteUrl ).DataTokens[routeName] = true; }
protected virtual void CreateControllerType(ServiceControllerSetting setting) { var contractTypeName = ObjectService.GetTypeName(setting.ContractTypeName); var contractType = TypeHelper.CreateType(contractTypeName, false); if (contractType == null || !contractType.IsInterface) { goto EXIT; } setting.ContractType = contractType; var baseTypeName = setting.ControllerBaseTypeName; var baseType = TypeHelper.CreateType(baseTypeName, typeof(ServiceControllerBase), false); if (baseType == null) { goto EXIT; } var typeBuilder = this.moduleBuilder.DefineType("Octopus.Esb.Server.Mvc.DynamicControllers." + contractType.FullName, TypeAttributes.Public | TypeAttributes.Class, baseType, new Type[] { }); var ctor = typeBuilder.DefineMethod(".ctor", MethodAttributes.Public, CallingConventions.Standard, typeof(void), new[] { typeof(object) }); var ctorBase = baseType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null); var setServiceInstance = baseType.GetMethod("set_ServiceInstance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(object) }, null); var getServiceInstance = baseType.GetMethod("get_ServiceInstance", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null); var il = ctor.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Call, ctorBase); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Callvirt, setServiceInstance); il.Emit(OpCodes.Ret); var methods = contractType.GetMethods(); foreach (var methodInfo in methods) { var parameters = methodInfo.GetParameters(); var resultType = typeof(ActionResult); var resulHandle = baseType.GetMethod("ResultHandle", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(object) }, null); var methodBuilder = typeBuilder.DefineMethod(methodInfo.Name, MethodAttributes.Public | MethodAttributes.Virtual, CallingConventions.Standard, resultType, parameters.Select(parameterInfo => parameterInfo.ParameterType).ToArray()); for (var i = 0; i < parameters.Length; i++) { var parameterInfo = parameters[i]; methodBuilder.DefineParameter(i + 1, ParameterAttributes.None, parameterInfo.Name); } il = methodBuilder.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Call, getServiceInstance); if (parameters.Length > 3) { il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Ldarg_2); il.Emit(OpCodes.Ldarg_3); for (var i = 4; i <= parameters.Length; i++) { il.Emit(OpCodes.Ldarg_S, i); } } else { switch (parameters.Length) { case 1: il.Emit(OpCodes.Ldarg_1); break; case 2: il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Ldarg_2); break; case 3: il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Ldarg_2); il.Emit(OpCodes.Ldarg_3); break; } } il.Emit(OpCodes.Callvirt, methodInfo); if (methodInfo.ReturnType == typeof(void)) { il.Emit(OpCodes.Ldnull); } il.Emit(OpCodes.Callvirt, resulHandle); il.Emit(OpCodes.Ret); } setting.ControllerType = typeBuilder.CreateType(); EXIT: setting.Initialized = true; }
internal override string GetTypeNameInternal(string typeAlias) { return(ObjectService.GetTypeName(typeAlias)); }