Exemplo n.º 1
0
        internal Startup(string appCode)
        {
            try
            {
                CentralData.InitCommonSettings();
                //*ov-
                //EncryptionHelper.Key1 = GlobalConfiguration.GlobalKey2;
                //EncryptionHelper.Key2 = GlobalConfiguration.GlobalKey2;

                var executableDir = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
                _startUpDir = Directory.GetParent(executableDir).ToString();
                _startUpDir = Directory.GetParent(_startUpDir).ToString();
                _startUpDir = Directory.GetParent(_startUpDir).ToString();
                Directory.SetCurrentDirectory(_startUpDir);
                _cfgDir = _startUpDir + "\\Conf";
                var cfgFile = _cfgDir + "\\GlobalSetting";
                if (!ConfigFileHelper.IsFileExisting(cfgFile))
                {
                    throw new ArgumentException(" Must have a \"GlobalSetting\" config file in " + _cfgDir);
                }
                var cfgFileMgr    = new ConfigFileManager(cfgFile);
                var globalSetting = cfgFileMgr.ConvertToGeneric <GlobalSetting>();

                _appCfgDir = _cfgDir + "\\Apps\\" + appCode;
                cfgFile    = _appCfgDir + "\\ApplicationSetting";
                if (!ConfigFileHelper.IsFileExisting(cfgFile))
                {
                    throw new ArgumentException(" Must have a \"ApplicationSetting\" config file in " + _appCfgDir);
                }
                cfgFileMgr = new ConfigFileManager(cfgFile);
                ApplicationStartParamSet = cfgFileMgr.ConvertToGeneric <ApplicationSetting>();

                var appDataDir = "";
                if (ApplicationStartParamSet.ApplicationDataDir.IsNullOrEmpty())
                {
                    appDataDir = _startUpDir + "\\Data\\Apps\\" + appCode;
                }
                else
                {
                    appDataDir = FileHelper.GetFilePath(ApplicationStartParamSet.ApplicationDataDir, _startUpDir + "\\Data" + appCode);
                }
                ApplicationStartParamSet.ApplicationDataDir = appDataDir;

                var appLibDir = "";
                if (ApplicationStartParamSet.ApplicationLibDir.IsNullOrEmpty())
                {
                    appLibDir = _startUpDir + "\\Lib\\Apps\\" + appCode;
                }
                else
                {
                    appLibDir = FileHelper.GetFilePath(ApplicationStartParamSet.ApplicationLibDir, _startUpDir + "\\Lib" + appCode);
                }
                ApplicationStartParamSet.ApplicationLibDir = appLibDir;

                var appTempDir = "";
                if (ApplicationStartParamSet.ApplicationTempDir.IsNullOrEmpty())
                {
                    appTempDir = PathHelper.GetLastDriveName() + "\\tmp\\" + CentralData.ArchitectureCode + "\\" + appCode;
                }
                else
                {
                    appTempDir = FileHelper.GetFilePath(ApplicationStartParamSet.ApplicationTempDir, _startUpDir + "\\Data\\" + appCode + "\\Tmp");
                }
                ApplicationStartParamSet.ApplicationTempDir = appTempDir;



                var cblpDllPath = "";
                if (ApplicationStartParamSet.CblpDllPath.IsNullOrEmpty())
                {
                    cblpDllPath = _startUpDir + "\\Program\\Apps\\" + appCode + "\\Cblp." + appCode + ".dll";
                }
                else if (ApplicationStartParamSet.CblpDllPath.ToLower() == "none" | ApplicationStartParamSet.CblpDllPath.ToLower() == "no")
                {
                    cblpDllPath = "";
                }
                else
                {
                    cblpDllPath = FileHelper.GetFilePath(ApplicationStartParamSet.CblpDllPath, _startUpDir + "\\Program\\Apps\\" + appCode);
                }
                ApplicationStartParamSet.CblpDllPath = cblpDllPath;

                var cblpAdapterFullClassName = "";
                if (ApplicationStartParamSet.CblpAdapterClassFullName.IsNullOrEmpty())
                {
                    cblpAdapterFullClassName = "Ligg.EasyWinApp.Cblp." + appCode + "Adapter";
                }
                ApplicationStartParamSet.CblpAdapterClassFullName = cblpAdapterFullClassName;

                //# following exchange data with globalsetting
                var bootStrapperTasksDllPath = "";
                if (globalSetting.BootStrapperTasksDllPath.IsNullOrEmpty())
                {
                    bootStrapperTasksDllPath = _startUpDir + "\\Program\\BootStrapperTasks\\" + "BootStrapperTasks" + ".dll";
                }
                else
                {
                    bootStrapperTasksDllPath = FileHelper.GetFilePath(globalSetting.BootStrapperTasksDllPath, _startUpDir + "\\Program\\BootStrapperTasks");
                }
                ApplicationStartParamSet.BootStrapperTasksDllPath = bootStrapperTasksDllPath;
                if (globalSetting.BootStrapperTaskNameSpace.IsNullOrEmpty())
                {
                    ApplicationStartParamSet.BootStrapperTaskNameSpace = "Ligg.EasyWinApp.BootStrapperTasks";
                }

                if (!globalSetting.PhythonExePath.IsNullOrEmpty())
                {
                    var defLoc = Directory.GetParent(appLibDir).ToString();
                    defLoc = Directory.GetParent(defLoc).ToString();
                    var phythonExePath = FileHelper.GetFilePath(globalSetting.PhythonExePath, defLoc);
                    ApplicationStartParamSet.PhythonExecPath = phythonExePath;
                    SysProcessHelper.PythonExecPath          = phythonExePath;
                }


                if (ApplicationStartParamSet.DefaultCulture.IsNullOrEmpty())
                {
                    ApplicationStartParamSet.DefaultCulture = globalSetting.DefaultCulture;
                }
                if (ApplicationStartParamSet.HelpdeskEmail.IsNullOrEmpty())
                {
                    ApplicationStartParamSet.HelpdeskEmail = globalSetting.HelpdeskEmail;
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + GetType().FullName + ".Startup Error: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        internal static void Init(ApplicationSetting applicationStartParamSet)
        {
            try
            {
                if (!applicationStartParamSet.RunBootStrapperTasksAtStart & !applicationStartParamSet.HasCblpComponent)
                {
                    return;
                }

                var bootStrapperTasksDllPath = "";
                var cblpDllPath          = "";
                var adapterClassFullName = "";
                Ioc.InitializeWith(new DependencyResolverFactory("Ligg.Infrastructure.Utility.Ioc.AutofacContainer"));

                if (applicationStartParamSet.RunBootStrapperTasksAtStart)
                {
                    var bootStrapperTasksNames = applicationStartParamSet.BootStrapperTasks;
                    bootStrapperTasksDllPath = applicationStartParamSet.BootStrapperTasksDllPath;
                    if (!string.IsNullOrEmpty(bootStrapperTasksNames))
                    {
                        var tmpArry = bootStrapperTasksNames.GetSubParamArray(true, true);
                        foreach (var tmpStr in tmpArry)
                        {
                            var tmpStr1 = tmpStr.Trim();
                            var bootStrapperClassFullName = applicationStartParamSet.BootStrapperTaskNameSpace + "." + tmpStr1;
                            Ioc.Register(bootStrapperTasksDllPath, bootStrapperClassFullName);
                            _bootStrapperTaskClassFullNames.Add(bootStrapperClassFullName);
                        }
                    }
                }
                if (applicationStartParamSet.HasCblpComponent)
                {
                    cblpDllPath          = applicationStartParamSet.CblpDllPath;
                    adapterClassFullName = applicationStartParamSet.CblpAdapterClassFullName;
                    if (!cblpDllPath.IsNullOrEmpty())
                    {
                        Ioc.Register(cblpDllPath, adapterClassFullName);
                    }
                }

                Ioc.SetContainer();

                if (applicationStartParamSet.RunBootStrapperTasksAtStart)
                {
                    if (_bootStrapperTaskClassFullNames.Count > 0)
                    {
                        foreach (var bootStrapperTaskClassFullName in _bootStrapperTaskClassFullNames)
                        {
                            var obj = (IBootStrapperTask)Ioc.Resolve(bootStrapperTasksDllPath, bootStrapperTaskClassFullName);
                            var bootStrapperTask = new BootStrapperTask(obj, bootStrapperTaskClassFullName.GetLastSeparatedString('.'));
                            BootStrapperTaskList.Add(bootStrapperTask);
                        }
                    }
                }

                if (applicationStartParamSet.HasCblpComponent)
                {
                    if (File.Exists(cblpDllPath))
                    {
                        if (!FileHelper.IsFileExisting(cblpDllPath))
                        {
                            return;
                        }
                        Adapter = CreateAdapter(cblpDllPath, adapterClassFullName);
                        Adapter?.Initialize();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("\n>> " + TypeName + ".Init Error: " + ex.Message);
            }
        }