示例#1
0
        /// <summary>
        /// Override to initalize the app with custom values but still call the base!
        /// </summary>
        /// <param name="pPlugInLst">List if ICDEPlugin instances</param>
        /// <param name="ArgList">Additional Parameters of the Application</param>
        /// <returns>True if all went well during startup</returns>
        public virtual bool StartBaseApplication2(List <ICDEPlugin> pPlugInLst, IDictionary <string, string> ArgList)
        {
            if (TheBaseAssets.MasterSwitch)
            {
                return(false);                              //SECURITY REVIEW: do not allow to call StartBaseApplication twice
            }
            TheBaseAssets.MasterSwitch = true;
            if (TheBaseAssets.MyServiceHostInfo == null)
            {
                TheBaseAssets.MasterSwitch = false;
                TheSystemMessageLog.ToCo("MyServiceHostInfo is not set! Exiting...");   //Will becalled because if MyServiceHostInfo==null TOCO will be called
                return(false);
            }
            if (TheBaseAssets.CryptoLoadMessage != null)
            {
                TheBaseAssets.MasterSwitch = false;
                TheSystemMessageLog.ToCo($"Security initialization failed with {TheBaseAssets.CryptoLoadMessage}. Exiting...");
                return(false);
            }
            try
            {
                TheBaseAssets.IsStarting = true;

                //AppDomain.CurrentDomain.UnhandledException += MyUnhandledExceptionHandler;

                if (ArgList == null)
                {
                    ArgList = new Dictionary <string, string>();    //DIC-Allowed!
                }
                if (!TheBaseAssets.MySettings.ReadAllAppSettings(ref ArgList))
                {
                    TheSystemMessageLog.ToCo("Not reading app.config: not supported by platform."); //Will never be called!
                }
                if (!TheBaseAssets.MasterSwitch)
                {
                    return(false);
                }
                TheBaseAssets.MyCmdArgs = ArgList; //MyCmdArgs ONLY contains "public" settings coming from app.config or via the host

                MyUserManager = new TheUserManager();
                TheBaseAssets.InitAssets(this);
                if (!TheBaseAssets.MasterSwitch)
                {
                    return(false);
                }
                TheBaseAssets.MyScopeManager.RegisterScopeChanged(EventScopeChanged);
                TheBaseAssets.MySYSLOG.WriteToLog(4140, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Assets and SystemLog Initialized", eMsgLevel.l3_ImportantMessage));

                int minWorker = -1, minCompletionPort = -1, maxWorker = -1, maxCompletionPort = -1;
                try
                {
                    System.Threading.ThreadPool.GetMinThreads(out minWorker, out minCompletionPort);
                    System.Threading.ThreadPool.GetMaxThreads(out maxWorker, out maxCompletionPort);
                }
                catch { };

#if CDE_STANDARD
                var largeObjectHeapCompactionMode = System.Runtime.GCSettings.LargeObjectHeapCompactionMode;
#else
                const string largeObjectHeapCompactionMode = "n/a";
#endif
                TheBaseAssets.MySYSLOG.WriteToLog(4144, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM(eEngineName.ContentService, $"CLR Info", eMsgLevel.l4_Message, $"Server GC: {System.Runtime.GCSettings.IsServerGC}. GC Latency Mode: {System.Runtime.GCSettings.LatencyMode}. LOHC Mode: {largeObjectHeapCompactionMode}. Bitness: {System.Runtime.InteropServices.Marshal.SizeOf(typeof(IntPtr)) * 8}. Threads Min W/CP, Max W/CP: {minWorker}/{minCompletionPort},{maxWorker}/{maxCompletionPort}. GC TotalMemory: {GC.GetTotalMemory(false)}"));

                if (!TheBaseAssets.MyActivationManager.InitializeLicenses())
                {
                    Shutdown(true);
                    TheBaseAssets.MySYSLOG.WriteToLog(4145, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Licensing error", eMsgLevel.l3_ImportantMessage));
                    return(false);
                }

                //4.304: Workitem #2289 - Removed from OSS Release (as CheckLicense is always returning true in the CoreCrypto Lib
                if (!TheBaseAssets.MyActivationManager.CheckLicense(new Guid("{5737240C-AA66-417C-9B66-3919E18F9F4A}"), "", null, 1, false))
                {
                    if (TheBaseAssets.MyServiceHostInfo.ShutdownOnLicenseFailure)
                    {
                        TheBaseAssets.MySYSLOG.WriteToLog(4146, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Licensing error: no activated license for Thing Service. Shutting down immediately as configured.", eMsgLevel.l2_Warning));
                        return(false);
                    }
                    else
                    {
                        TheBaseAssets.MySYSLOG.WriteToLog(4147, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Licensing error: no activated license for Thing Service. Will shut down in 60 minutes if not activated.", eMsgLevel.l2_Warning));
                        TheCommonUtils.cdeRunAsync("LicenseCheck", true, (o) =>
                        {
                            TheCommonUtils.TaskDelayOneEye(60 * 60 * 1000, 100).ContinueWith((t) =>
                            {
                                if (TheBaseAssets.MasterSwitch)
                                {
                                    if (!TheBaseAssets.MyActivationManager.CheckLicense(new Guid("{5737240C-AA66-417C-9B66-3919E18F9F4A}"), "", null, 1, false))
                                    {
                                        TheBaseAssets.MySYSLOG.WriteToLog(4148, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Licensing error: no activated license for Thing Service. Shutting down.", eMsgLevel.l1_Error));
                                        if (TheBaseAssets.IsInAgentStartup)
                                        {
                                            MyISMRoot?.Restart(true);
                                        }
                                        else
                                        {
                                            Shutdown(true);
                                        }
                                    }
                                }
                            });
                        });
                    }
                }


                TheCommCore.MyHttpService = new TheHttpService();
                TheBaseAssets.MySYSLOG.WriteToLog(4141, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "HttpService created", eMsgLevel.l3_ImportantMessage));

                if (TheBaseAssets.MyServiceHostInfo.StartISM && MyISMRoot == null && !string.IsNullOrEmpty(TheBaseAssets.MyServiceHostInfo.BaseDirectory))
                {
                    MyISMRoot = new TheISMManager {
                        eventShutdownRequired = sinkAppShutdown
                    };
                    MyISMRoot.InitISM("", "", "", TheBaseAssets.MyServiceHostInfo.CurrentVersion, TheBaseAssets.MyServiceHostInfo.ISMScanForUpdatesOnUSB, TheBaseAssets.MyServiceHostInfo.ISMScanOnStartup);
                    TheBaseAssets.MySYSLOG.WriteToLog(4142, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "ISM Started", eMsgLevel.l3_ImportantMessage));
                }
                else
                {
                    TheBaseAssets.MyServiceHostInfo.StartISM = false;
                }
                if (!TheBaseAssets.MasterSwitch)
                {
                    return(false);
                }

                if (MyCommonDisco == null)
                {
                    if (!TheBaseAssets.MyServiceHostInfo.IsIsolated && (TheCommonUtils.IsHostADevice() || TheBaseAssets.MyServiceHostInfo.cdeNodeType == cdeNodeType.Active))
                    {
                        TheBaseAssets.MySettings.SetSetting("DISCO_IsClientOnly", "True");
                    }
                    MyCommonDisco = new TheCommonDisco(); // Initialized the Discovery Service
                }

                TheCDEngines.eventAllEnginesStarted += sinkEnginesStarted;
                if (!TheCDEngines.StartEngines(pPlugInLst, null))                                           //Starts all SubEngines and Plugins. MyCmdArgs is a copy of the tParas sent to the Init Assets Function and can be used to set parameters for each engine during startup
                {
                    Shutdown(true);
                    TheBaseAssets.MySYSLOG.WriteToLog(4149, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheBaseApplication", "Failed to start engines", eMsgLevel.l3_ImportantMessage));
                    return(false);
                }
                return(true);
            }
            finally
            {
                TheBaseAssets.IsStarting = false;
            }
        }