예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <see cref="ServiceBase.OnStop()" />
 protected override void OnStop()
 {
     using (var server = this.Server)
     {
         this.Server = null;
     }
 }
        internal AppServerDataConnection(AppServerImpl server)
        {
            this._SERVER = server;

            string dbProvider;

            this._INNER_CONNECTION = this._SERVER
                                     .TryGetServerDbConnectionDataByConfig(out dbProvider);

            if (this._INNER_CONNECTION == null)
            {
                throw new NotSupportedException(string.Format("'{0}' provider is NOT supported!",
                                                              dbProvider));
            }
        }
        internal AppServerEntityRepository(AppServerImpl server)
        {
            this._SERVER = server;

            // define DbConnection
            string dbProvider;

            this._CONNECTION = this._SERVER.TryGetServerDbConnectionByConfig(out dbProvider);

            if (this._CONNECTION == null)
            {
                throw new NotSupportedException(string.Format("'{0}' provider is NOT supported!",
                                                              dbProvider));
            }

            this._CONNECTION.Open();
        }
예제 #4
0
        internal PasswordHasher(AppServerImpl server)
        {
            byte[] pwdSalt = null;
            {
                IEnumerable <char> salt;
                server.StartupConfig.TryGetValue(category: "security",
                                                 name: "password_salt",
                                                 value: out salt,
                                                 defaultVal: null);

                var strSalt = salt.AsString();
                if (!string.IsNullOrEmpty(strSalt))
                {
                    pwdSalt = Encoding.UTF8.GetBytes(strSalt);
                }
            }

            this._INNER_HASHER = new GeneralPasswordHasher(pwdSalt);
        }
예제 #5
0
        internal NHAppServerDatabase(AppServerImpl server,
                                     IAppServerDataConnection conn)
        {
            // configure
            {
                var newCfg = new Configuration();
                newCfg.DataBaseIntegration(c =>
                {
                    c.Dialect <MsSql2008Dialect>();
                    c.ConnectionString   = conn.ConnectionString;
                    c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                    c.SchemaAction       = SchemaAutoAction.Create;
                });

                // entity types
                {
                    var mapper = new ModelMapper();

                    var entityTypes = server.EntityAssemblies
                                      .SelectMany(asm => asm.GetTypes())
                                      .Where(t => t.IsClass &&
                                             !t.IsAbstract && t.GetInterfaces()
                                             .Any(it => it.Equals(typeof(global::MarcelJoachimKloubert.ApplicationServer.Data.Entities.IAppServerEntity))));

                    foreach (var et in entityTypes)
                    {
                        var entityMapperType = typeof(AppServerEntityMapper <>).MakeGenericType(et);

                        var entityMapper = (IConformistHoldersProvider)Activator.CreateInstance(entityMapperType,
                                                                                                nonPublic: true);
                        mapper.AddMapping(entityMapper);
                    }

                    newCfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
                }

                this._CONF = newCfg;
            }

            // this._SESSION_FACTORY = this._CONF.BuildSessionFactory();
        }
예제 #6
0
 internal FunctionLocator(AppServerImpl server)
 {
     this._SERVER = server;
 }
예제 #7
0
 internal JavaScriptEngine(AppServerImpl server)
 {
     this._SERVER = server;
 }
 internal SqliteDatabaseFactory(AppServerImpl server)
 {
     this._SERVER = server;
 }
예제 #9
0
 internal HttpModuleLocator(AppServerImpl server)
 {
     this._SERVER = server;
 }
예제 #10
0
        // Protected Methods (2) 

        /// <summary>
        ///
        /// </summary>
        /// <see cref="ServiceBase.OnStart(string[])" />
        protected override void OnStart(string[] args)
        {
            var      asmDir     = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            TimeSpan?startDelay = null;

            var workDir = asmDir;

            foreach (var a in args)
            {
                if (a.ToLower().Trim().StartsWith("/rootdir:"))
                {
                    // custom root/working directory
                    var dir = new DirectoryInfo(a.Substring(a.IndexOf(':') + 1)
                                                .TrimStart()).FullName;

                    if (Path.IsPathRooted(dir))
                    {
                        workDir = new DirectoryInfo(dir).CreateDirectoryDeep().FullName;
                    }
                    else
                    {
                        workDir = new DirectoryInfo(Path.Combine(asmDir,
                                                                 dir)).CreateDirectoryDeep().FullName;
                    }
                }
                else if (a.ToLower().Trim().StartsWith("/startdelay:"))
                {
                    var seconds = a.Substring(a.IndexOf(':') + 1)
                                  .Trim();
                    if (seconds == string.Empty)
                    {
                        seconds = "15";
                    }

                    startDelay = TimeSpan.FromSeconds(double.Parse(seconds,
                                                                   CultureInfo.InvariantCulture));
                }
            }

            if (startDelay.HasValue)
            {
                Thread.Sleep(startDelay.Value);
            }

            this.EventLog
            .WriteEntry(string.Format("Root directory is: {0}",
                                      workDir),
                        EventLogEntryType.Information);

            this.LogDirectory = new DirectoryInfo(Path.Combine(workDir,
                                                               "logs")).CreateDirectoryDeep()
                                .FullName;

            this.EventLog
            .WriteEntry(string.Format("Log directory is: {0}",
                                      this.LogDirectory),
                        EventLogEntryType.Information);

            GlobalConsole.SetConsole(new ServiceConsole(this));

            var loggerFuncs = new DelegateLogger();

            loggerFuncs.Add(this.WriteEventLogMessage);

            var logger = new AggregateLogger();

            logger.Add(new AsyncLogger(loggerFuncs));

            var server = new ApplicationServer();

            try
            {
                if (!server.IsInitialized)
                {
                    var srvCtx = new SimpleAppServerContext(server);

                    var initCtx = new SimpleAppServerInitContext();
                    initCtx.Arguments        = args;
                    initCtx.Logger           = logger;
                    initCtx.ServerContext    = srvCtx;
                    initCtx.WorkingDirectory = workDir;

                    try
                    {
                        server.Initialize(initCtx);

                        this.EventLog
                        .WriteEntry("Server has been initialized.",
                                    EventLogEntryType.Information);
                    }
                    catch (Exception ex)
                    {
                        this.EventLog
                        .WriteEntry(string.Format("Server could not be initialized!{0}{0}{1}",
                                                  Environment.NewLine,
                                                  ex.GetBaseException() ?? ex),
                                    EventLogEntryType.Error);

                        throw;
                    }

                    srvCtx.InnerServiceLocator = server.GlobalServiceLocator;
                }

                try
                {
                    server.Start();

                    this.EventLog
                    .WriteEntry("Server has been started.",
                                EventLogEntryType.Information);
                }
                catch (Exception ex)
                {
                    this.EventLog
                    .WriteEntry(string.Format("Server could not be started!{0}{0}{1}",
                                              Environment.NewLine,
                                              ex.GetBaseException() ?? ex),
                                EventLogEntryType.Error);

                    throw;
                }

                this.Server = server;
            }
            catch
            {
                server.Dispose();

                throw;
            }
        }