Exemplo n.º 1
0
        public Logger(IArguments args)
            : base(args)
        {
            if (args.ContainsKey("logConfigPath") && File.Exists(args["logConfigPath"]))
            {
                XmlConfigurator.Configure(new FileInfo(args["logConfigPath"]));
                _log = LogManager.GetLogger("KonfDB");
            }
            else
            {
                _log = LogManager.GetLogger("KonfDB");
                var appenders = new List<IAppender> {CreateFileAppender("FileAppender", @"Logs\KonfDB.log")};

                if (args.GetValue("ShowOnConsole", "false")
                    .Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase))
                    appenders.Add(CreateConsoleAppender());

                BasicConfigurator.Configure(appenders.ToArray());
            }
        }
Exemplo n.º 2
0
        public Logger(IArguments args)
            : base(args)
        {
            if (args.ContainsKey("logConfigPath") && File.Exists(args["logConfigPath"]))
            {
                XmlConfigurator.Configure(new FileInfo(args["logConfigPath"]));
                _log = LogManager.GetLogger("KonfDB");
            }
            else
            {
                _log = LogManager.GetLogger("KonfDB");
                var appenders = new List <IAppender> {
                    CreateFileAppender("FileAppender", @"Logs\KonfDB.log")
                };

                if (args.GetValue("ShowOnConsole", "false")
                    .Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase))
                {
                    appenders.Add(CreateConsoleAppender());
                }

                BasicConfigurator.Configure(appenders.ToArray());
            }
        }
Exemplo n.º 3
0
        protected override void OnStart(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            var contextSettings = new ContextSettings
            {
                CommandFactory = new CommandFactory()
            };

            HostContext.CreateFrom(_arguments.GetValue("configPath", "konfdb.json"), contextSettings);
            CurrentHostContext.Default.Log.Info("Agent Started: DataManagement");

            #region Run Command Service

            ServiceFacade = new ServiceCore();
            string internalSessionId = Guid.NewGuid().ToString();
            // Ensure that the super user admin exists
            ServiceFacade.ExecuteCommand(new ServiceRequestContext
            {
                Command = String.Format("NewUser /name:{0} /pwd:{1} /cpwd:{1} /role:admin /silent",
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Username,
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Password),
                SessionId = internalSessionId
            });

            // Ensure that the super user readonly exists
            ServiceFacade.ExecuteCommand(new ServiceRequestContext
            {
                Command = String.Format("NewUser /name:{0}_ro /pwd:{1} /cpwd:{1} /role:readonly /silent",
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Username,
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Password),
                SessionId = internalSessionId
            });

            var serviceConfig = CurrentHostContext.Default.Config.Runtime.Server;
            _serviceHostNative = new WcfService <ICommandService <object>, NativeCommandService>("localhost",
                                                                                                 "CommandService");
            _serviceHostJson = new WcfService <ICommandService <string>, JsonCommandService>("localhost", "CommandService");

            for (int i = 0; i < serviceConfig.Count; i++)
            {
                var configuration = new BindingConfiguration
                {
                    Port        = serviceConfig[i].Port.ToString(CultureInfo.InvariantCulture),
                    ServiceType = serviceConfig[i].GetWcfServiceType()
                };

                var binding = BindingFactory.Create(configuration);
                if (binding.DataTypes.IsSet(DataTypeSupport.Native))
                {
                    _serviceHostNative.AddBinding(binding);
                }
                else if (binding.DataTypes.IsSet(DataTypeSupport.Json))
                {
                    _serviceHostJson.AddBinding(binding);
                }
            }

            if (CurrentHostContext.Default.Config.Runtime.ServiceSecurity == ServiceSecurityMode.BasicSSL)
            {
                var serviceSecurity = new ServiceSecurity
                {
                    CertificateConfiguration = CurrentHostContext.Default.Config.Certificate.Default,
                    SecurityMode             = CurrentHostContext.Default.Config.Runtime.ServiceSecurity
                };

                _serviceHostJson.SetSecured(serviceSecurity);
                _serviceHostNative.SetSecured(serviceSecurity);
            }

            _serviceHostNative.Host();
            _serviceHostJson.Host();

            var authOutput = ServiceFacade.ExecuteCommand(new ServiceRequestContext
            {
                Command = String.Format("UserAuth /name:{0} /pwd:{1}",
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Username,
                                        CurrentHostContext.Default.Config.Runtime.SuperUser.Password),
                SessionId = internalSessionId
            });

            var authenticationOutput = authOutput.Data as AuthenticationOutput;
            if (authenticationOutput == null)
            {
                throw new InvalidOperationException(
                          "Could not authenticate server user: "******"GetSettings",
                SessionId = internalSessionId
            });
            if (settingsOutput != null && settingsOutput.Data != null)
            {
                var settings = (Dictionary <string, string>)settingsOutput.Data;
                foreach (var setting in settings)
                {
                    CurrentHostContext.Default.ApplicationParams.Add(setting.Key, setting.Value);
                }
            }

            //AppContext.Current.Log.Info("Agent Started: " + _serviceHostNative);
            //AppContext.Current.Log.Info("Agent Started: " + _serviceHostJson);

            #endregion

            _thread = new Thread(RunInBackground)
            {
                Name         = "ShellService",
                IsBackground = true
            };

            _shutdownEvent = new ManualResetEvent(false);
            _thread.Start();
        }