Example #1
0
        /// <summary>
        /// it is an helper method for ObjList CURD(Insert, Update, Delete) methods
        /// </summary>
        /// <typeparam name="T">Name of Model Object</typeparam>
        /// <param name="obj"></param>
        /// <param name="ControllerActionName">Name of Controller method to invoke</param>
        /// <returns></returns>
        private static int PerformActionList <T>(List <T> obj, string ControllerActionName)
        {
            try
            {
                string ModelName          = obj[0].GetType().FullName.Split('.').Last();
                string FullControllerName = obj[0].GetType().FullName.Replace(".Entities.", ".DBContexts.") + "Context";
                string Namespace          = FullControllerName.Substring(0, FullControllerName.IndexOf(".DBContexts."));

                if (obj.Count < 1)
                {
                    throw new Exception("Cannot perform operation while no valid " + ModelName + " data provided. Please check provided " + ModelName + "List object and try again.");
                }

                ///----- Referencing Controller Class of same object
                System.Runtime.Remoting.ObjectHandle ControllerWrapper = Activator.CreateInstance(Namespace, FullControllerName);
                var Controller = ControllerWrapper.Unwrap();
                ControllerWrapper = null;

                ///----- Referencing Insert method from Controller Class
                MethodInfo InsertController = Controller.GetType().GetMethods().ToList().Find(x => x.Name == ControllerActionName && x.GetParameters().Count() == 1 && x.GetParameters()[0].Name == "obj" + ModelName + "List");
                if (InsertController == null)
                {
                    throw new Exception("Unable to find " + ControllerActionName + " method in Controller class which accepts " + ModelName + " as parameter.");
                }

                ///----- Invoking Insert and returning the Primary Key of newly inserted object
                return((int)InsertController.Invoke(Controller, new Object[] { obj }));
            }
            catch (Exception ex) { throw ex; }
        }
Example #2
0
        private static string resolveAssemblyDllFromBaseDirectory(string name, string baseDirectory)
        {
            progress("dllFromBase: Resolve  [" + name + "] from " + baseDirectory);
            // Resolve name to the dll as if .exe in baseDirectory was executed
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = baseDirectory;
            setup.DisallowApplicationBaseProbing = false;

            AppDomain dtest = AppDomain.CreateDomain("temp" + Guid.NewGuid(), null, setup);

            progress("dllFromBase: Domain created");
            try
            {
                System.Runtime.Remoting.ObjectHandle v = Activator.CreateInstanceFrom(dtest, Assembly.GetExecutingAssembly().Location, typeof(AppDomainWorker).FullName);
                if (v != null)
                {
                    AppDomainWorker appDomainWorker = v.Unwrap() as AppDomainWorker;
                    progress("dllFromBase: Resolver created");
                    if (appDomainWorker != null)
                    {
                        string s = appDomainWorker.ResolveDllFromAssemblyName(name);
                        progress("dllFromBase: " + name + " >> " + s);
                        return(s);
                    }
                }
                progress("dllFromBase: Resolve  " + name + " failed");
                return(null);
            }
            finally
            {
                AppDomain.Unload(dtest);
            }
        }
Example #3
0
        /// <summary>
        /// 获取需设置的类变更属性
        /// </summary>
        protected void GetShiftProperty()
        {
            Neusoft.FrameWork.WinForms.Classes.Function.ShowWaitForm(Neusoft.FrameWork.Management.Language.Msg("正在载入信息 请稍候..."));
            Application.DoEvents();

            try
            {
                System.Runtime.Remoting.ObjectHandle oHandle = System.Activator.CreateInstance("HISFC.Object", this.txtTypeStr.Text);
                if (oHandle == null)
                {
                    Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                    MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("未能由输入信息获取类型 请检查是否输入正确"));
                    return;
                }
                Type t = oHandle.Unwrap().GetType();
                if (t == null)
                {
                    Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                    MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("未能由输入信息获取类型 请检查是否输入正确"));
                    return;
                }

                if (this.hsExtisClass.ContainsKey(t.ToString()))
                {
                    Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                    MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("该实体信息已存在 请删除原信息后重新添加"));
                    this.txtTypeStr.SelectAll();
                    return;
                }

                List <Neusoft.FrameWork.Models.NeuObject> alProperty = this.GetProperty(t);
                if (alProperty != null)
                {
                    if (alProperty.Count == 0)
                    {
                        Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                        MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("该实体类无满足条件的属性信息"));
                        return;
                    }

                    this.neuSpread1_Sheet1.Rows.Count = 0;
                    foreach (Neusoft.FrameWork.Models.NeuObject info in alProperty)
                    {
                        this.neuSpread1_Sheet1.Rows.Add(0, 1);
                        this.neuSpread1_Sheet1.Cells[0, 0].Text = info.Name;        //属性名称中文描述
                        this.neuSpread1_Sheet1.Cells[0, 1].Text = info.Memo;        //属性描述

                        this.neuSpread1_Sheet1.Rows[0].Tag = info;
                    }
                }
            }
            catch
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("未能由输入信息获取类型 请检查是否输入正确"));
                return;
            }

            Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
        }
Example #4
0
        /// <summary>
        /// Accepts Entity object or its inherited object, delete row(s) from table
        ///
        /// return ObjectId of deleted row(s)
        /// </summary>
        /// <returns>ObjectId of deleted row(s)</returns>
        public static int Delete(this Entity Model)
        {
            try
            {
                ///----- Referencing ValidateThis method from Model Class
                MethodInfo ValidateModel = Model.GetType().GetMethods().ToList().Find(x => x.Name == "Validate");
                if (ValidateModel == null)
                {
                    throw new Exception("Unable to find Validate method in Entity.");
                }

                ///----- Invoking ValidateThis too validate whather the Model is ready to be inserted or not?
                ValidateModel.Invoke(Model, new object[] { SqlOperation.Delete });

                string ModelName          = Model.GetType().FullName.Split('.').Last();
                string FullControllerName = Model.GetType().FullName.Replace(".Entities.", ".DBContexts.") + "Context";
                string Namespace          = FullControllerName.Substring(0, FullControllerName.IndexOf(".DBContexts."));

                ///----- Referencing Controller Class of same object
                System.Runtime.Remoting.ObjectHandle ControllerWrapper = Activator.CreateInstance(Namespace, FullControllerName);
                var Controller = ControllerWrapper.Unwrap();
                ControllerWrapper = null;

                ///----- Referencing Delete method from Controller Class
                MethodInfo deleteController = Controller.GetType().GetMethods().ToList().Find(x => x.Name == "Delete" && x.GetParameters().Count() == 1 && x.GetParameters()[0].Name == "obj" + ModelName);
                if (deleteController == null)
                {
                    throw new Exception("Unable to find Update method in Controller class which accepts " + ModelName + " as parameter.");
                }

                ///----- Invoking Delete and returning the Primary Key of updated object
                return((int)deleteController.Invoke(Controller, new Object[] { Model }));
            }
            catch (Exception ex) { throw ex; }
        }
Example #5
0
        /// <summary>
        /// Dumps everything of a single type into the cache from the filesystem for BackingData
        /// </summary>
        /// <typeparam name="T">the type to get and store</typeparam>
        /// <returns>full or partial success</returns>
        public bool LoadAllCharactersForAccountToCache(string accountHandle)
        {
            string currentBackupDirectory = BaseDirectory + accountHandle + "/" + CurrentDirectoryName;

            //No current directory? WTF
            if (!VerifyDirectory(currentBackupDirectory, false))
            {
                return(false);
            }

            DirectoryInfo charDirectory = new DirectoryInfo(currentBackupDirectory);

            foreach (FileInfo file in charDirectory.EnumerateFiles("*.playertemplate", SearchOption.AllDirectories))
            {
                try
                {
                    byte[] fileData = ReadFile(file);
                    System.Runtime.Remoting.ObjectHandle blankEntity = Activator.CreateInstance("NetMud.Data", "NetMud.Data.Players.PlayerTemplate");

                    IPlayerTemplate objRef = blankEntity.Unwrap() as IPlayerTemplate;

                    IPlayerTemplate newChar = objRef.FromBytes(fileData) as IPlayerTemplate;

                    PlayerDataCache.Add(newChar);
                }
                catch (Exception ex)
                {
                    LoggingUtility.LogError(ex);
                    //Let it keep going
                }
            }

            return(true);
        }
Example #6
0
        private static IVsSingleFileGenerator CreateVBMyResxFileCodeGenerator()
        {
            string className = string.Format(ResxFileCodeGeneratorTypeNameFormatString, "VBMyResXFileCodeGenerator");

            System.Runtime.Remoting.ObjectHandle oh = (System.Runtime.Remoting.ObjectHandle)System.Activator.CreateInstance(ResxFileCodeGeneratorAssemblyName,
                                                                                                                            className);
            return((IVsSingleFileGenerator)oh.Unwrap());
        }
        public static IConfigurationProviderFactory CreateConfigurationFactory()
        {
            string modelAssembly = AspDotNetStorefrontCore.AppLogic.AppConfig("Vortx.OnePageCheckout.ConfigurationFactoryAssembly");
            string modelType     = AspDotNetStorefrontCore.AppLogic.AppConfig("Vortx.OnePageCheckout.ConfigurationFactoryType");

            System.Runtime.Remoting.ObjectHandle handle = System.Activator.CreateInstance(modelAssembly, modelType);
            return((IConfigurationProviderFactory)handle.Unwrap());
        }
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                this.operDept = ((Neusoft.HISFC.Models.Base.Employee) this.drugStoreManager.Operator).Dept;

                this.DataInit();

                #region 反射读取标签格式

                //string dllName = "Report";
                string className = "Neusoft.WinForms.Report.DrugStore.ucRecipeLabel";

                //门诊标签打印接口实现类
                Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam ctrlIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam();
                string labelValue = "Neusoft.WinForms.Report.DrugStore.ucRecipeLabel";  //ctrlIntegrate.GetControlParam<string>(Neusoft.HISFC.BizProcess.Integrate.PharmacyConstant.Clinic_Print_Label, true, "Report.DrugStore.ucRecipeLabel");
                //门诊草药打印接口实现类
                string billValue = "Neusoft.WinForms.Report.DrugStore.ucOutHerbalBill"; // ctrlIntegrate.GetControlParam<string>(Neusoft.HISFC.BizProcess.Integrate.PharmacyConstant.Clinic_Print_Bill, true, "Report.DrugStore.ucOutHerbalBill");

                //默认标签打印
                className = labelValue;
                //读取本地控制参数 判断是否采用草药打印方式
                string    strErr = "";
                ArrayList alParm = Neusoft.FrameWork.WinForms.Classes.Function.GetDefaultValue("ClinicDrug", "PrintList", out strErr);
                if (alParm != null && alParm.Count > 0)
                {
                    if ((alParm[0] as string) == "1")
                    {
                        className          = billValue;
                        this.isHerbalPrint = true;
                    }
                }

                object[] o = new object[] { };

                try
                {
                    System.Runtime.Remoting.ObjectHandle objHandel = System.Activator.CreateInstance("WinForms.Report", className, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);
                    object oLabel = objHandel.Unwrap();

                    // Neusoft.HISFC.Components.DrugStore.Function.IDrugPrint = oLabel as Neusoft.HISFC.BizProcess.Integrate.PharmacyInterface.IDrugPrint;
                    Neusoft.Report.Logistics.DrugStore.Function.IDrugPrint = oLabel as Neusoft.HISFC.BizProcess.Interface.Pharmacy.IDrugPrint;
                }
                catch (System.TypeLoadException ex)
                {
                    Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                    MessageBox.Show(Language.Msg("标签命名空间无效\n" + ex.Message));
                }

                #endregion
            }
            catch
            { }

            base.OnLoad(e);
        }
Example #9
0
        public static object CreateFromXMLNode(System.Xml.XmlNode a_node)
        {
            string sAssembly = a_node.Attributes.GetNamedItem("Assembly").InnerText;
            string sType     = a_node.Attributes.GetNamedItem("Type").InnerText;

            System.Runtime.Remoting.ObjectHandle obj = System.Activator.CreateInstance(sAssembly, sType);
            object o = obj.Unwrap();

            Deserialize(o, a_node);
            return(o);
        }
Example #10
0
        public UserscriptHost(
            byte[] AssemblySerial,
            byte[] AssemblySymbolStoreSerial)
        {
            BeginZait = Bib3.Glob.StopwatchZaitMiliSictInt();

            this.AssemblySerial            = AssemblySerial;
            this.AssemblySymbolStoreSerial = AssemblySymbolStoreSerial;

            if (null == AssemblySerial)
            {
                return;
            }

            if (false)
            {
                //	Weege Probleme mit Debuge (Visual Studio Debugger überspringt Method in Dll) verzict auf AppDomain

                ScriptAppDomain = AppDomain.CreateDomain("UserScript.Instance[" + Ident.ToString() + "]");

                AssemblyLoaded = ScriptAppDomain.Load(AssemblySerial, AssemblySymbolStoreSerial);
            }
            else
            {
                AssemblyLoaded = System.Reflection.Assembly.Load(AssemblySerial, AssemblySymbolStoreSerial);
            }

            var MengeType = AssemblyLoaded.GetTypes();

            ScriptInterfaceType =
                MengeType
                .FirstOrDefaultNullable(PrädikaatTypeIstScriptInterface);

            if (null == ScriptInterfaceType)
            {
                return;
            }

            if (false)
            {
                //	Weege Probleme mit Debuge (Visual Studio Debugger überspringt Method in Dll) verzict auf AppDomain

                ScriptInterfaceWrapped = ScriptAppDomain.CreateInstance(AssemblyLoaded.FullName, ScriptInterfaceType.FullName);

                ScriptInterfaceLease = (System.Runtime.Remoting.Lifetime.ILease)ScriptInterfaceWrapped.InitializeLifetimeService();

                ScriptInterface = (IUserscript)ScriptInterfaceWrapped.Unwrap();
            }
            else
            {
                ScriptInterface = (IUserscript)Activator.CreateInstance(ScriptInterfaceType);
            }
        }
Example #11
0
 public object CreateInstance()
 {
     try
     {
         System.Runtime.Remoting.ObjectHandle oh = System.Activator.CreateInstance(_assemblyName, _typeName);
         return(oh.Unwrap());
     }
     catch (Exception)
     {
     }
     return(null);
 }
Example #12
0
        public static object GetInstance(string sAssmebly, string sClass)
        {
            string sUrl = "";

            sUrl = System.IO.Path.Combine(Application.StartupPath, sAssmebly);

            System.Runtime.Remoting.ObjectHandle handle = Activator.CreateInstanceFrom(sUrl, sClass);

            object obj = handle.Unwrap();

            return(obj);
        }
Example #13
0
 /// <summary>
 /// 从指定程序集加载指定类型对象
 /// </summary>
 /// <param name="assemblyName">程序集名称</param>
 /// <param name="typeName">类名称</param>
 /// <returns></returns>
 public static Object GetPlugin(string assemblyName, string typeName)
 {
     System.Runtime.Remoting.ObjectHandle objHandle = System.Activator.CreateInstance(assemblyName, typeName);
     if (objHandle != null)
     {
         return(objHandle.Unwrap());
     }
     else
     {
         throw new ApplicationException("从程序集" + assemblyName + "反射对象" + typeName + "时,构件对象为NULL");
     }
 }
Example #14
0
        private void LoadPlugins()
        {
            int defaultChecked = 0;

            if (m_Plugins == null)
            {
                ArrayList pluginsKeeper = new ArrayList();

                StreamReader pluginReader = new StreamReader("Agent.dm");
                string       line;
                char[]       separator = { ' ', '\t', '\n' };
                string[]     tokens;

                while ((line = pluginReader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.Length > 0 && line[0] != ';')
                    {
                        tokens = line.Split(separator);
                        if (tokens[0].Equals("Agent1Default"))
                        {
                            defaultChecked = int.Parse(tokens[1]);
                        }
                        else
                        {
                            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstanceFrom(tokens[0], tokens[1]);
                            pluginsKeeper.Add(oh.Unwrap());
                        }
                    }
                }
                pluginReader.Close();

                m_Plugins = new AgentDecisionModule[pluginsKeeper.Count];
                for (int i = 0; i < pluginsKeeper.Count; i++)
                {
                    m_Plugins[i] = ( AgentDecisionModule )pluginsKeeper[i];
                }
            }

            string[] pluginNames = new string[m_Plugins.Length];
            for (int i = 0; i < m_Plugins.Length; i++)
            {
                pluginNames[i] = m_Plugins[i].NameId();
            }

            m_GUI.AddLoadedPlugin(pluginNames);

            if (defaultChecked > 0)
            {
                m_GUI.SelectEvaluator(defaultChecked - 1);
            }
        }
Example #15
0
        /// <summary>
        /// it will select all data from specific table
        /// convert it into Model Object
        /// and overwrite current Instance
        /// </summary>
        /// <typeparam name="T">Name of Model Object</typeparam>
        /// <param name="obj"></param>
        public static void Select <T>(this List <T> obj)
        {
            ///----- Remove all objects from list
            obj.Clear();

            ///----- Internal Variables
            string FullModelName = obj.GetType().FullName.Replace("List", "");
            string ModelName     = FullModelName.Split('.').Last();
            string AssemblyName  = FullModelName.Substring(0, FullModelName.IndexOf(".Entities."));

            System.Runtime.Remoting.ObjectHandle ModelWrapper = Activator.CreateInstance(AssemblyName, FullModelName);
            var Model = ModelWrapper.Unwrap();

            ModelWrapper = null;

            /////----- Gathering method which will select data from DB
            //MethodInfo SelectModel = Model.GetType().GetMethods().ToList().Find(x => x.Name == "Select" && x.GetParameters().Count() == 0);
            //if (SelectModel == null) { return; }

            ///----- Gathering Model's Construct that will parse DataRow into Model Object
            ConstructorInfo cnstrDataRow = Model.GetType().GetConstructors().ToList().Find(x => x.GetParameters().Count() == 1 && x.GetParameters()[0].Name == "Row");

            if (cnstrDataRow == null)
            {
                return;
            }

            ///----- [1].Getting data from DB
            ///----- [2].Parsing into Model Object
            ///----- [3].And adding into collection

            ///----- [1]
            System.Data.DataSet ds = ((Entity)Model).Select();
            if (ds != null && ds.Tables.Count > 0)
            {
                foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                {
                    ///----- [2]
                    T newRow = (T)cnstrDataRow.Invoke(new object[] { row });

                    ///----- [3]
                    obj.Add(newRow);
                }
                ds.Dispose();
            }

            ///----- Clearing up Memory
            Model         = null;
            ModelName     = null;
            FullModelName = null;
        }
Example #16
0
        private IAnimal CreateAnimal(PurchaseAnimalOptions animal, int age)
        {
            //See: https://docs.microsoft.com/en-us/dotnet/api/system.activator?redirectedfrom=MSDN&view=netframework-4.8
            string animalString = "ZooTycoon" + "." + animal.ToString();

            object[] arguments = new object[2] {
                age, _baseCost
            };
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance("ZooTycoon", animalString, false, 0, null, arguments, null, null);
            IAnimal newAnimal = (IAnimal)oh.Unwrap();

            _zoo.Add(newAnimal);
            return(newAnimal);
        }
Example #17
0
        private Control CreateTypedControl_FromPath(String control_guid, String Class_Path)
        {
            Type TypeControl = Type.GetType(Class_Path);

            if (TypeControl == null)
            {
                System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(Class_Path.Substring(0, Class_Path.IndexOf(".")), Class_Path);
                return((Control)oh.Unwrap());
            }
            else
            {
                return((Control)Activator.CreateInstance(TypeControl));
            }
        }
        /// <summary>
        /// Returns a RemoteTestRunner in the target domain. This method
        /// is used in the domain that wants to get a reference to
        /// a RemoteTestRunnner and not in the test domain itself.
        /// </summary>
        /// <param name="targetDomain">AppDomain in which to create the runner</param>
        /// <param name="ID">Id for the new runner to use</param>
        /// <returns></returns>
        public static RemoteTestRunner CreateInstance(AppDomain targetDomain, int ID)
        {
#if CLR_2_0 || CLR_4_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
                targetDomain,
#else
            System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
#endif
                Assembly.GetExecutingAssembly().FullName,
                typeof(RemoteTestRunner).FullName,
                false, BindingFlags.Default, null, new object[] { ID }, null, null, null);

            object obj = oh.Unwrap();
            return((RemoteTestRunner) obj);
        }
        /// <summary>
        /// Factory method used to create a DomainAgent in an AppDomain.
        /// </summary>
        /// <param name="targetDomain">The domain in which to create the agent</param>
        /// <param name="traceLevel">The level of internal tracing to use</param>
        /// <returns>A proxy for the DomainAgent in the other domain</returns>
        static public DomainAgent CreateInstance(AppDomain targetDomain)
        {
#if CLR_2_0 || CLR_4_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstance(
                targetDomain,
#else
            System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstance(
#endif
                Assembly.GetExecutingAssembly().FullName,
                typeof(DomainAgent).FullName,
                false, BindingFlags.Default, null, null, null, null, null);

            object obj = oh.Unwrap();
            return((DomainAgent) obj);
        }
        /// <summary>
        /// Factory method used to create a DomainInitializer in an AppDomain.
        /// </summary>
        /// <param name="targetDomain">The domain in which to create the agent</param>
        /// <param name="traceLevel">The level of internal tracing to use</param>
        /// <returns>A proxy for the DomainAgent in the other domain</returns>
        static public DomainInitializer CreateInstance(AppDomain targetDomain)
        {
#if CLR_2_0 || CLR_4_0
            System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstanceFrom(
                targetDomain,
#else
            System.Runtime.Remoting.ObjectHandle oh = targetDomain.CreateInstanceFrom(
#endif
                typeof(DomainInitializer).Assembly.CodeBase,
                typeof(DomainInitializer).FullName,
                false, BindingFlags.Default, null, null, null, null, null);

            object obj = oh.Unwrap();
            return((DomainInitializer) obj);
        }
//        /// <summary>
//        /// 新建网站站点
//        /// </summary>
//        /// <param name="deployAppInfo">应用部署信息</param>
//        /// <param name="pai"></param>
//        public static bool InstallWinService(DeployAppInfo deployAppInfo, PublishAppInfo pai)
//        {
//            var serviceName = pai.AppSitePoolList.FirstOrDefault();
//            if (String.IsNullOrWhiteSpace(serviceName))
//            {
//                throw new Exception("deploy windows service error,the windows service program dir path is null or empty");
//            }
//            if (String.IsNullOrWhiteSpace(deployAppInfo.winsvr_programfullname))
//            {
//                throw new Exception("deploy windows service error,the windows service program file name is null or empty");
//            }
//            return InstallWinService(serviceName, Path.GetFullPath(Path.Combine(pai.AppPath, deployAppInfo.winsvr_programfullname)), Convert.ToInt32(deployAppInfo.winsvr_starttype));
//        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="serviceProgramFileFullPath"></param>
        /// <param name="windowServiceStartType"></param>
        /// <returns></returns>
        public static bool InstallWinService(string serviceName, string serviceProgramFileFullPath, int windowServiceStartType)
        {
            var app = AppDomain.CreateDomain($"InstallWinService_{serviceName}");

            System.Runtime.Remoting.ObjectHandle objLoader =
                app.CreateComInstanceFrom(System.Reflection.Assembly.GetExecutingAssembly().Location, "Benlai.Application.AutoPublish.Common.Utility.WindowsServiceUtility");

            var loader = objLoader.Unwrap() as WindowsServiceUtility;

            var result = loader?.InstallWinService(serviceName, serviceProgramFileFullPath, windowServiceStartType);

            AppDomain.Unload(app);
            app = null;
            return(result ?? false);
        }
Example #22
0
        public void InitClient()
        {
            Console.Write("loading Battle client library ");
            string battle_gui_fulltypename = string.Format("{0}.{1}",
                                                           this.battle_gui_assembly,
                                                           this.battle_gui_typename);

            Console.WriteLine(battle_gui_fulltypename);
            System.Runtime.Remoting.ObjectHandle oh =
                Activator.CreateInstance(this.battle_gui_assembly,
                                         battle_gui_fulltypename);
            this.battle_gui   = (IBattleGui)oh.Unwrap();
            this.game.Console = (IConsole)this.battle_gui;
            this.battle_gui.Init(this.game);
        }
Example #23
0
        /// <summary>
        /// Creates the object ObjectName object from Assembly Name
        /// </summary>
        /// <param name="assemblyName">The assembry from where to read the object</param>
        /// <param name="objectName">The returned object name</param>
        /// <returns>The object that is read from the specified assembly</returns>
        public static object InstanceOfStringClass(string assemblyName, string objectName)
        {
            object objectToCast;

            try
            {
                System.Runtime.Remoting.ObjectHandle objHandleToCast = Activator.CreateInstance(assemblyName, objectName);
                objectToCast = objHandleToCast.Unwrap();
            }
            catch (Exception)
            {
                objectToCast = null;
            }

            return(objectToCast);
        }
        internal static DataAccessHelper GetDataAccessHelper()
        {
            string assemblyFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Try.DAL.DLL";
            string typeName     = "Try.DAL.SqlDataAccessHelper";

            System.Runtime.Remoting.ObjectHandle obj = Activator.CreateInstanceFrom(assemblyFile, typeName);

            if (obj != null)
            {
                return((DataAccessHelper)obj.Unwrap());
            }
            else
            {
                throw new Exception("Cannot load the DB Helper");
            }
        }
Example #25
0
        /// <summary>
        /// config구조체로 초기화
        /// </summary>
        /// <param name="config"></param>
        private void Setup(TcpServiceConfig config)
        {
            // 콘솔 로거 생성
            if (config.Log != null)
            {
                if (config.Log.Equals("console", StringComparison.OrdinalIgnoreCase))
                {
                    this.Logger = new ConsoleLogger();
                }
                else if (config.Log.Equals("file", StringComparison.OrdinalIgnoreCase))
                {
                    this.Logger = new SimpleFileLogger(@"netservice.log");
                }
                else
                {
                    this.Logger = new NullLogger();
                }
            }
            else
            {
                this.Logger = new ConsoleLogger();
            }

            this.Logger.Level = LogLevel.Error;
            if (config.LogLevel != null)
            {
                this.Logger.Level = (LogLevel)Enum.Parse(typeof(LogLevel), config.LogLevel, true);
            }

            // 16, 128, 256, 1024, 4096 사이즈의 풀을 생성하는 설정
            int[] poolSizes = new int[] { 4096, 16, 128, 256, 1024 };
            this._pooledBufferManager = new PooledBufferManager(poolSizes);

            this.Config = config;
            if (Config.MessageFactoryTypeName != "")
            {
                try
                {
                    System.Runtime.Remoting.ObjectHandle objHandle = Activator.CreateInstance(this.Config.MessageFactoryAssemblyName, this.Config.MessageFactoryTypeName);
                    _messageFactory = (NetService.Message.IMessageFactory)objHandle.Unwrap();
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "메세지 팩토리 생성 실패", e);
                }
            }
        }
Example #26
0
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void initControl()
        {
            this.cmbType.SelectedIndex = 0;
            this.txtAlert.Text         = "0";

            #region 反射读取欠费打印单
            object[] o = new object[] { };
            try
            {
                //入库报表
                Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam ctrlIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam();

                string billValue = ctrlIntegrate.GetControlParam <string>(Neusoft.HISFC.BizProcess.Integrate.Const.RADT_MoneyAlter, true, "Neusoft.WinForms.Report.InpatientFee.ucPatientMoneyAlter");

                System.Runtime.Remoting.ObjectHandle objHande = System.Activator.CreateInstance("WinForms.Report", billValue, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);

                object oLabel = objHande.Unwrap();

                IAlterPrint = oLabel as Neusoft.HISFC.BizProcess.Interface.FeeInterface.IMoneyAlert;
            }
            catch (System.TypeLoadException ex)
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show("命名空间无效\n" + ex.Message);
                return;
            }
            #endregion

            #region {80C40729-D5C1-42ce-96C3-7CF09E562BA7}
            this.repayType = this.ctrlParmMgr.GetControlParam <string>("200309", true, "0");

            if (this.repayType == "2")
            {
                this.neuSpread1_Sheet1.Columns[11].Visible = true;
            }
            else
            {
                this.neuSpread1_Sheet1.Columns[11].Visible = false;
            }
            #endregion

            #region  类别不显示{F7FDA08F-F256-4314-84F1-4C9767242D21}
            //this.neuSpread1_Sheet1.Columns[4].Visible = false;
            AddFeeType();
            #endregion
        }
Example #27
0
        /// <summary>
        /// Creates an instance of the type whose name is specified, using the
        /// named assembly and default constructor.
        /// </summary>
        /// <param name="assemblyName">
        /// The name of the assembly where the type named <paramref name="typeName"/> is sought.
        /// If <paramref name="assemblyName"/> is <c>null</c>, the executing assembly is searched.
        /// </param>
        /// <param name="typeName">
        /// The name of the preferred type.
        /// </param>
        /// <returns>
        /// The created instance.
        /// </returns>
        /// <exception cref="ReflectionException">
        /// An error occurs while attempting to reflect on a type.
        /// </exception>
        public static object CreateObject(string assemblyName, string typeName)
        {
            object returnObject = null;

            try
            {
                System.Runtime.Remoting.ObjectHandle handle =
                    Activator.CreateInstance(assemblyName, typeName);

                returnObject = handle.Unwrap();
            }
            catch (Exception)
            {
                //throw new ReflectionException(ex.Message, ex);
            }

            return(returnObject);
        }
Example #28
0
 public Plugin(string sFile, string sClass, string sData)
 {
     try
     {
         this.sFile = sFile;
         if (_sPluginFileLast != sFile)
         {
             (new Logger()).WriteDebug4("plugin: constructor: before CreateInstanceFrom: [sFile = " + (_sPluginFileLast = sFile) + "]");
         }
         System.Runtime.Remoting.ObjectHandle cHandle = Activator.CreateInstanceFrom(AppDomain.CurrentDomain, sFile, "ingenie.plugins." + sClass);
         _cRemoteInstance = (plugins.IPlugin)cHandle.Unwrap();
         _cRemoteInstance.Create(System.IO.Path.GetDirectoryName(sFile), sData);
         _dtStatusChanged = DateTime.Now;
     }
     catch (Exception ex)
     {
         throw new Exception("указанный тип [" + sClass + "] не реализует API плагина [ingenie.plugins.IPlugin]", ex);                 //TODO LANG
     }
 }
Example #29
0
        /// <summary>
        /// 创建2个打印接口实例,根据需要选择打印入库单还是出库单
        /// </summary>
        protected virtual void SetPrintObject()
        {
            object[] o = new object[] { };

            try
            {
                //反射接口---ModifyBy zj--如果是没有配置打印接口则用默认的实现
                ////入出库报表
                //Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam ctrlIntegrate = new Neusoft.HISFC.BizProcess.Integrate.Common.ControlParam();
                //string billValue = "Neusoft.DongGuan.Report.Material.ucMatInputBill";
                //string billValue1 = "Neusoft.DongGuan.Report.Material.ucMatOutputBill";
                //System.Runtime.Remoting.ObjectHandle objHandel = System.Activator.CreateInstance("DongGuan.Report", billValue, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);
                //System.Runtime.Remoting.ObjectHandle objHandel1 = System.Activator.CreateInstance("DongGuan.Report", billValue1, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);

                //inputInstance = objHandel.Unwrap();
                //outputInstance = objHandel1.Unwrap();
                //---改用接口反射方法
                //
                inputInstance = Neusoft.FrameWork.WinForms.Classes.UtilInterface.CreateObject(typeof(Neusoft.HISFC.Components.Material.In.ucMatIn), typeof(Neusoft.HISFC.BizProcess.Interface.Material.IBillPrint));
                if (inputInstance == null)
                {
                    MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("没有配置物资入库单打印接口,采用默认实现!"));
                    string billValue = "Neusoft.Report.Material.ucMatInputBill";
                    System.Runtime.Remoting.ObjectHandle objHandel = System.Activator.CreateInstance("Report", billValue, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);
                    inputInstance = objHandel.Unwrap();
                }
                outputInstance = Neusoft.FrameWork.WinForms.Classes.UtilInterface.CreateObject(typeof(Neusoft.HISFC.Components.Material.Out.ucMatOut), typeof(Neusoft.HISFC.BizProcess.Interface.Material.IBillPrint));
                if (outputInstance == null)
                {
                    MessageBox.Show(Neusoft.FrameWork.Management.Language.Msg("没有配置物资出库单打印接口,采用默认实现!"));
                    string billValue = "Neusoft.Report.Material.ucMatOutputBill";
                    System.Runtime.Remoting.ObjectHandle objHandel = System.Activator.CreateInstance("Report", billValue, false, System.Reflection.BindingFlags.CreateInstance, null, o, null, null, null);
                    outputInstance = objHandel.Unwrap();
                }
            }
            catch (System.TypeLoadException ex)
            {
                Neusoft.FrameWork.WinForms.Classes.Function.HideWaitForm();
                MessageBox.Show(Language.Msg("命名空间无效\n" + ex.Message));

                return;
            }
        }
Example #30
0
        private static void RecurseCreateSpritesFromXml(XmlNodeList a_xmlNodes, Sprite a_spToAddTo)
        {
            foreach (XmlNode node in a_xmlNodes)
            {
                if (node.NodeType == XmlNodeType.Text)
                {
                    continue;
                }

                if (node.Attributes.Count > 0)
                {
                    XmlNode attrib;
                    attrib = node.Attributes.GetNamedItem("Assembly");
                    if (attrib == null)
                    {
                        continue;
                    }
                    string sAssembly = attrib.InnerText;

                    attrib = node.Attributes.GetNamedItem("Type");
                    if (attrib == null)
                    {
                        continue;
                    }
                    string sType = attrib.InnerText;

                    System.Runtime.Remoting.ObjectHandle obj = System.Activator.CreateInstance(sAssembly, sType);
                    object o  = obj.Unwrap();
                    Sprite sp = (Sprite)o;

                    Endogine.Serialization.Serializer.Deserialize(sp, node);

                    sp.Parent = a_spToAddTo;

                    XmlNode childrenNode = Endogine.Serialization.XmlHelper.GetNthSubNodeByName(node, "ChildSprites", 0);
                    if (childrenNode != null)
                    {
                        RecurseCreateSpritesFromXml(childrenNode.ChildNodes, sp);
                    }
                }
            }
        }