Ejemplo n.º 1
0
 private Binding(BindingConfiguration config, System.ServiceModel.Channels.Binding wcfBinding,
     Type endpointType, DataTypeSupport dataTypes)
 {
     Configuration = config;
     WcfBinding = wcfBinding;
     EndPointType = endpointType;
     DataTypes = dataTypes;
 }
Ejemplo n.º 2
0
 private Binding(BindingConfiguration config, System.ServiceModel.Channels.Binding wcfBinding,
                 Type endpointType, DataTypeSupport dataTypes)
 {
     Configuration = config;
     WcfBinding    = wcfBinding;
     EndPointType  = endpointType;
     DataTypes     = dataTypes;
 }
Ejemplo n.º 3
0
        public static IBinding Create(BindingConfiguration config)
        {
            switch (config.ServiceType)
            {
                case ServiceType.HTTP:
                    return Binding.Create(config, new HttpBinding(), typeof (HttpEndpoint), DataTypeSupport.Native);
                case ServiceType.TCP:
                    return Binding.Create(config, new TcpBinding(), typeof (NetTcpEndpoint), DataTypeSupport.Native);
                case ServiceType.REST:
                    return Binding.Create(config, new RestBinding(), typeof (RestEndpoint), DataTypeSupport.Json);
                case ServiceType.WSHTTP:
                    return Binding.Create(config, new WsHttpBinding(), typeof (WsHttpEndpoint), DataTypeSupport.Native);
            }

            throw new NotImplementedException("Unknown Binding");
        }
Ejemplo n.º 4
0
        public static IBinding Create(BindingConfiguration config)
        {
            switch (config.ServiceType)
            {
            case ServiceType.HTTP:
                return(Binding.Create(config, new HttpBinding(), typeof(HttpEndpoint), DataTypeSupport.Native));

            case ServiceType.TCP:
                return(Binding.Create(config, new TcpBinding(), typeof(NetTcpEndpoint), DataTypeSupport.Native));

            case ServiceType.REST:
                return(Binding.Create(config, new RestBinding(), typeof(RestEndpoint), DataTypeSupport.Json));

            case ServiceType.WSHTTP:
                return(Binding.Create(config, new WsHttpBinding(), typeof(WsHttpEndpoint), DataTypeSupport.Native));
            }

            throw new NotImplementedException("Unknown Binding");
        }
Ejemplo n.º 5
0
 internal static IBinding Create(BindingConfiguration config, System.ServiceModel.Channels.Binding wcfBinding,
     Type endpointType, DataTypeSupport dataTypes)
 {
     return new Binding(config, wcfBinding, endpointType, dataTypes);
 }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
 internal static IBinding Create(BindingConfiguration config, System.ServiceModel.Channels.Binding wcfBinding,
                                 Type endpointType, DataTypeSupport dataTypes)
 {
     return(new Binding(config, wcfBinding, endpointType, dataTypes));
 }
Ejemplo n.º 8
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);
        }