Ejemplo n.º 1
0
        public static IServiceCollection AddCde(this IServiceCollection collection, Action <CdeConfiguration> configure)
        {
            var config = new CdeConfiguration();

            configure?.Invoke(config);

            return(collection.AddSingleton(sp => config)
                   .AddSingleton(sp =>
            {
                var cdeApp = new CdeApplication(sp.GetService <ILogger <CdeApplication> >(), sp.GetRequiredService <CdeConfiguration>());
                cdeApp.Start();
                return cdeApp;
            }));
        }
Ejemplo n.º 2
0
        private async Task <TheBaseApplication> StartCde(CdeConfiguration config)
        {
            try
            {
                LoadAlternateCryptoLib(config.CryptoLibConfig);

                TheScopeManager.SetApplicationID(config.ApplicationId);

                TheBaseAssets.MyServiceHostInfo = new TheServiceHostInfo(cdeHostType.Application)
                {
                    Title             = config.ApplicationTitle,
                    ApplicationName   = config.ApplicationName,
                    ApplicationTitle  = config.PortalTitle,
                    DebugLevel        = GetDebugLevel(config.DebugLevel, eDEBUG_LEVELS.ESSENTIALS),
                    MyStationPort     = config.HttpPort,
                    MyStationWSPort   = config.WsPort,
                    cdeMID            = TheCommonUtils.CGuid(config.StorageId),
                    FailOnAdminCheck  = config.FailOnAdminCheck,
                    CloudServiceRoute = config.CloudServiceRoutes,
                    LocalServiceRoute = config.LocalServiceRoutes,
                    IsCloudService    = config.IsCloudService,
                    ISMMainExecutable = Assembly.GetEntryAssembly()?.GetName().Name,
                    CurrentVersion    = config.ApplicationVersion,
                    AllowLocalHost    = config.AllowLocalHost,
                    PreShutDownDelay  = config.PreShutdownDelay
                };

                TheBaseAssets.MyServiceHostInfo.IgnoredEngines.AddRange(config.LogIgnore.Split(';'));
                IDictionary <string, string> arguments = new Dictionary <string, string>
                {
                    { "DontVerifyTrust", $"{config.DontVerifyTrust}" },
                    { "UseUserMapper", $"{config.UseUserMapper}" },
                    { "UseRandomDeviceID", $"{config.UseRandomDeviceId}" },
                    { "AROLE", eEngineName.NMIService + ";" + eEngineName.ContentService },
                    { "SROLE", eEngineName.NMIService + ";" + eEngineName.ContentService }
                };

                if (!string.IsNullOrEmpty(config.ScopeId))
                {
                    arguments["EasyScope"] = config.ScopeId;
                }

                arguments = MergeDictionaries(arguments, config.AdditionalArguments);

                var app       = new TheBaseApplication();
                var startTime = DateTimeOffset.UtcNow;
                if (!app.StartBaseApplication(null, arguments))
                {
                    throw new InvalidOperationException("Failed to start CDE base application!");
                }

                if (config.UseRandomScopeId && string.IsNullOrEmpty(TheScopeManager.GetScrambledScopeID()))
                {
                    if (!TheScopeManager.SetScopeIDFromEasyID(TheScopeManager.GenerateNewScopeID()))
                    {
                        throw new InvalidOperationException("Failed to apply random scope!");
                    }
                }

                _log.LogDebug("Started CDE Base application after {milliseconds} ms", DateTimeOffset.UtcNow.Subtract(startTime).TotalMilliseconds);
                startTime = DateTimeOffset.UtcNow;

                await TheBaseEngine.WaitForEnginesStartedAsync();

                _log.LogDebug("Started CDE engines after {milliseconds} ms", DateTimeOffset.UtcNow.Subtract(startTime).TotalMilliseconds);
                startTime = DateTimeOffset.UtcNow;

                await TheBaseEngine.WaitForStorageReadinessAsync(true);

                _log.LogDebug("Started CDE Storage after {milliseconds} ms", DateTimeOffset.UtcNow.Subtract(startTime).TotalMilliseconds);

                return(app);
            }
            catch (Exception ex)
            {
                _log.LogCritical(ex, "Failed to start CDE");
                throw;
            }
        }
Ejemplo n.º 3
0
 public CdeApplication(ILogger <CdeApplication> log, CdeConfiguration config)
 {
     _log    = log ?? NullLogger <CdeApplication> .Instance;
     _config = config;
 }