ExecuteCommand() private méthode

private ExecuteCommand ( ServiceRequestContext context ) : CommandOutput
context KonfDB.Infrastructure.Services.ServiceRequestContext
Résultat KonfDB.Infrastructure.Services.CommandOutput
Exemple #1
0
        public ServiceCommandOutput <string> ExecuteCommand(string command, string token)
        {
            ServiceRequestContext context = new ServiceRequestContext
            {
                SessionId = token,
                Token     = token,
                Command   = command
            };
            var commandOutput = _core.ExecuteCommand(context);

            return(commandOutput.ConvertForJson());
        }
        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();
        }
Exemple #3
0
        private void RunCommandService()
        {
            _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",
                    AzureContext.Current.Config.Runtime.SuperUser.Username,
                    AzureContext.Current.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",
                    AzureContext.Current.Config.Runtime.SuperUser.Username,
                    AzureContext.Current.Config.Runtime.SuperUser.Password),
                SessionId = internalSessionId
            });

            var serviceConfig = AzureContext.Current.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 (AzureContext.Current.Config.Runtime.ServiceSecurity == ServiceSecurityMode.BasicSSL)
            {
                var serviceSecurity = new ServiceSecurity
                {
                    CertificateConfiguration = AzureContext.Current.Config.Certificate.Default,
                    SecurityMode = AzureContext.Current.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}",
                    AzureContext.Current.Config.Runtime.SuperUser.Username,
                    AzureContext.Current.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)
                {
                    CurrentContext.Default.ApplicationParams.Add(setting.Key, setting.Value);
                }
            }

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