예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <see cref="IAppServer.Initialize(IAppServerInitContext)" />
        public void Initialize(IAppServerInitContext initContext)
        {
            lock (this._SYNC)
            {
                this.ThrowIfDisposed();

                if (initContext == null)
                {
                    throw new ArgumentNullException("initContext");
                }

                if (this.IsInitialized)
                {
                    throw new InvalidOperationException();
                }

                var context = initContext.ServerContext;
                if (context == null)
                {
                    throw new ArgumentException("initContext");
                }

                var isInitialized = true;
                this.OnInitialize(initContext,
                                  ref isInitialized);

                this.Context = isInitialized ? context : null;
            }
        }
예제 #2
0
        // Protected Methods (3) 

        /// <summary>
        ///
        /// </summary>
        /// <see cref="AppServerBase.OnInitialize(IAppServerInitContext, ref bool)" />
        protected override void OnInitialize(IAppServerInitContext initContext, ref bool isInitialized)
        {
            this.Arguments = (initContext.Arguments ?? Enumerable.Empty <string>()).OfType <string>()
                             .ToArray();

            this.WorkingDirectory = initContext.WorkingDirectory;
            if (string.IsNullOrWhiteSpace(this.WorkingDirectory))
            {
                this.WorkingDirectory = Environment.CurrentDirectory;
            }

            this.StartupConfig = new IniFileConfigRepository(Path.Combine(this.WorkingDirectory,
                                                                          "config.ini"),
                                                             false);

            var trustedAssemblyKeys = this.LoadTrustedAssemblyKeyList();

            this.EntityAssemblies = new SynchronizedCollection <Assembly>();
            this.RefreshEntityAssemblyList();

            // service locator
            CompositionContainer   compContainer;
            AggregateCatalog       compCatalog;
            DelegateServiceLocator serviceLocator;
            {
                compCatalog = new AggregateCatalog();
                compCatalog.Catalogs
                .Add(this.TrustedCompositionCatalog = new StrongNamedAssemblyPartCatalog(trustedAssemblyKeys));

                this.ReinitTrustedCompositionCatalog();

                compContainer = new CompositionContainer(compCatalog,
                                                         isThreadSafe: true);

                var mefServiceLocator = new ExportProviderServiceLocator(compContainer);
                serviceLocator = new DelegateServiceLocator(mefServiceLocator);

                serviceLocator.RegisterSingleProvider <global::MarcelJoachimKloubert.CLRToolbox.Templates.Text.Html.IHtmlTemplate>(WebInterfaceHandler.GetHtmlTemplate);
            }

            // logger
            AggregateLogger logger;
            DelegateLogger  loggerFuncs;

            {
                loggerFuncs = new DelegateLogger();

                logger = new AggregateLogger();
                logger.Add(loggerFuncs);

                var outerLogger = initContext.Logger;
                if (outerLogger != null)
                {
                    logger.Add(outerLogger);
                }

                serviceLocator.RegisterMultiProvider(this.GetAllLoggers, false);

                compContainer.ComposeExportedValue <global::MarcelJoachimKloubert.CLRToolbox.Diagnostics.ILoggerFacade>(new AsyncLogger(logger));
            }

            this.LoggerFuncs = loggerFuncs;
            this.Logger      = logger;

            this.GlobalCompositionCatalog   = compCatalog;
            this.GlobalCompositionContainer = compContainer;

            compContainer.ComposeExportedValue <global::MarcelJoachimKloubert.ApplicationServer.ApplicationServer>(this);
            compContainer.ComposeExportedValue <global::MarcelJoachimKloubert.ApplicationServer.IAppServer>(this);

            this.GlobalServiceLocator = serviceLocator;
            ServiceLocator.SetLocatorProvider(this.GetGlobalServiceLocator);
        }
예제 #3
0
 /// <summary>
 /// The logic for the <see cref="AppServerBase.Initialize(IAppServerInitContext)" /> method.
 /// </summary>
 /// <param name="initContext">The context.</param>
 /// <param name="isInitialized">
 /// Defines if initilize operation was successful or not.
 /// Is <see langword="true" /> at the beginning.
 /// </param>
 protected abstract void OnInitialize(IAppServerInitContext initContext,
                                      ref bool isInitialized);