Exemple #1
0
        public void SetUp()
        {
            SetupEvent.WaitOne();

            adminService = CreateAdminService(storeType);

            IServiceConnector connector = CreateConnector();

            NetworkConfigSource config = new NetworkConfigSource();

            Config(config);
            adminService.Config    = config;
            adminService.Connector = connector;
            adminService.Start();
            networkProfile = new NetworkProfile(connector);

            NetworkConfigSource netConfig = new NetworkConfigSource();

            netConfig.AddNetworkNode(LocalAddress);
            networkProfile.Configuration = netConfig;

            OnSetUp();

            SetupEvent.Set();
        }
Exemple #2
0
        public void StartBlock()
        {
            StartManager();

            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsFalse(machine.IsBlock);
            NetworkProfile.StartService(LocalAddress, ServiceType.Block);
            NetworkProfile.RegisterBlock(LocalAddress);
        }
Exemple #3
0
        protected override void OnTearDown()
        {
            client.Disconnect();

            NetworkProfile.DeregisterBlock(LocalAddress);
            NetworkProfile.StopService(LocalAddress, ServiceType.Block);
            NetworkProfile.DeregisterRoot(LocalAddress);
            NetworkProfile.StopService(LocalAddress, ServiceType.Root);
            NetworkProfile.DeregisterManager(LocalAddress);
            NetworkProfile.StopService(LocalAddress, ServiceType.Manager);
        }
Exemple #4
0
        protected override void OnSetUp()
        {
            SetupAppDomain();
            NetworkProfile.StartService(LocalAddress, ServiceType.Manager);
            NetworkProfile.RegisterManager(LocalAddress);
            NetworkProfile.StartService(LocalAddress, ServiceType.Root);
            NetworkProfile.RegisterRoot(LocalAddress);
            NetworkProfile.StartService(LocalAddress, ServiceType.Block);
            NetworkProfile.RegisterBlock(LocalAddress);

            NetworkProfile.AddPathToNetwork(PathName, PathType, LocalAddress, new IServiceAddress[] { LocalAddress });

            client = new NetworkClient(LocalAddress, new FakeServiceConnector((FakeAdminService)AdminService));
            client.ConnectNetwork();
        }
Exemple #5
0
        public void StartAndStopRoot()
        {
            StartRoot();

            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsTrue(machine.IsRoot);

            NetworkProfile.StopService(LocalAddress, ServiceType.Root);
            NetworkProfile.Refresh();

            machine = NetworkProfile.GetMachineProfile(LocalAddress);
            Assert.IsNotNull(machine);
            Assert.IsFalse(machine.IsRoot);
        }
Exemple #6
0
        public void StartManager()
        {
            MachineProfile machine = NetworkProfile.GetMachineProfile(LocalAddress);

            Assert.IsNotNull(machine);
            Assert.IsEmpty(NetworkProfile.GetManagerServers());
            Assert.IsFalse(machine.IsManager);
            NetworkProfile.StartService(LocalAddress, ServiceType.Manager);
            NetworkProfile.RegisterManager(LocalAddress);

            NetworkProfile.Refresh();

            machine = NetworkProfile.GetMachineProfile(LocalAddress);
            Assert.IsNotNull(machine);
            Assert.IsNotNull(NetworkProfile.GetManagerServers());
            Assert.IsTrue(machine.IsManager);
        }
Exemple #7
0
        public void SetUp()
        {
            SetupEvent.WaitOne();

            IServiceConnector connector = CreateConnector();

            adminService = CreateAdminService(storeType);
            NetworkConfigSource config = new NetworkConfigSource();
            Config(config);
            adminService.Config = config;
            adminService.Connector = connector;
            adminService.Start();
            networkProfile = new NetworkProfile(connector);

            NetworkConfigSource netConfig = new NetworkConfigSource();
            netConfig.AddNetworkNode(LocalAddress);
            networkProfile.Configuration = netConfig;

            SetupEvent.Set();
        }
 public NetworkContext(NetworkProfile netProfile)
 {
     this.netProfile = netProfile;
 }
Exemple #9
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated) {
                Error.WriteLine("a context is already opened: try to disconnect first");
                Error.WriteLine();
                return CommandResultCode.ExecutionFailed;
            }

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            if (args.Current != "to")
                return CommandResultCode.SyntaxError;

            if (!args.MoveNext())
                return CommandResultCode.SyntaxError;

            string address = args.Current;
            IServiceAddress serviceAddress;

            try {
                serviceAddress = ServiceAddresses.ParseString(address);
            } catch(Exception) {
                Error.WriteLine("Invalid service address specified: {0}", address);
                return CommandResultCode.ExecutionFailed;
            }

            NetworkConfigSource configSource = new NetworkConfigSource();

            try {
                configSource.AddNetworkNode(serviceAddress);
            } catch(Exception e) {
                Error.WriteLine("The address '" + address + "' is invalid: " + e.Message);
                return CommandResultCode.ExecutionFailed;
            }

            string protocol = "tcp";
            string credentials = String.Empty;
            string format = "binary";

            if (args.MoveNext()) {
                if (args.Current == "identified") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;
                    if (args.Current != "by")
                        return CommandResultCode.SyntaxError;
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    credentials = args.Current;

                    if (args.MoveNext()) {
                        if (args.Current != "on")
                            return CommandResultCode.SyntaxError;

                        protocol = args.Current;

                        if (args.MoveNext()) {
                            if (args.Current != "with")
                                return CommandResultCode.SyntaxError;

                            format = args.Current;
                        }
                    }
                } else if (args.Current == "on") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    protocol = args.Current;

                    if (args.MoveNext()) {
                        if (args.Current != "with")
                            return CommandResultCode.SyntaxError;

                        format = args.Current;
                    }
                } else if (args.Current == "with") {
                    if (!args.MoveNext())
                        return CommandResultCode.SyntaxError;

                    format = args.Current;
                } else {
                    return CommandResultCode.SyntaxError;
                }
            }

            IServiceConnector connector;
            if (protocol == "tcp") {
                if (String.IsNullOrEmpty(credentials)) {
                    while(String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }
                    Out.WriteLine();
                }
                connector = new TcpServiceConnector(credentials);
            } else if (protocol == "http") {
                string userName = credentials;
                string password = null;
                int index = credentials.IndexOf(':');
                if (index != -1) {
                    password = credentials.Substring(index + 1);
                    userName = credentials.Substring(0, index);
                }

                if (String.IsNullOrEmpty(password)) {
                    while(String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }

                    Out.WriteLine();
                }

                connector = new HttpServiceConnector(userName, password);
            } else {
                return CommandResultCode.SyntaxError;
            }

            IMessageSerializer serializer;

            if (format == "binary") {
                serializer = new BinaryRpcMessageSerializer();
            } else if (format == "xml") {
                serializer = new XmlRpcMessageSerializer();
            } else if (format == "json") {
                if (JsonRpcMessageSerializer == null) {
                    Error.WriteLine("JSON serializer was not installed.");
                    Error.WriteLine();
                    return CommandResultCode.ExecutionFailed;
                }
                serializer = JsonRpcMessageSerializer;
            } else {
                return CommandResultCode.SyntaxError;
            }

            connector.MessageSerializer = serializer;

            NetworkProfile networkProfile = new NetworkProfile(connector);
            networkProfile.Configuration = configSource;

            //TODO: test the connection is correct ...

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));

            Out.WriteLine("connected successfully to {0}" , address);
            Out.WriteLine();

            return CommandResultCode.Success;
        }
Exemple #10
0
        public override bool HandleCommandLine(CommandLine commandLine)
        {
            string protocol = commandLine.GetOptionValue("protocol", "tcp");
            string address = commandLine.GetOptionValue("address", null);
            string format = commandLine.GetOptionValue("format", "binary");

            if (String.IsNullOrEmpty(address))
                return false;

            IServiceConnector connector;
            if (protocol.Equals("tcp", StringComparison.InvariantCultureIgnoreCase)) {
                string netPassword = commandLine.GetOptionValue("password");
                if (String.IsNullOrEmpty(netPassword))
                    throw new ArgumentException("Netwrok password required for TCP/IP protocol.");

                connector = new TcpServiceConnector(netPassword);
            } else if (protocol.Equals("http", StringComparison.InvariantCultureIgnoreCase)) {
                string user = commandLine.GetOptionValue("user");
                string password = commandLine.GetOptionValue("password");
                if (String.IsNullOrEmpty(user))
                    throw new ArgumentException("User name not specified. for HTTP connection.");
                if (String.IsNullOrEmpty(password))
                    throw new ArgumentException("Password not specofoed for HTTP connection.");
                connector = new HttpServiceConnector(user, password);
            } else {
                throw new ArgumentException("Invalid protocol '" + protocol + "'.");
            }

            IMessageSerializer serializer;
            if (format.Equals("xml", StringComparison.InvariantCultureIgnoreCase)) {
                serializer = new XmlRpcMessageSerializer();
            } else if (format.Equals("binary", StringComparison.InvariantCultureIgnoreCase)) {
                serializer = new BinaryRpcMessageSerializer();
            } else if (format.Equals("json", StringComparison.InvariantCultureIgnoreCase)) {
                if (JsonRpcMessageSerializer == null)
                    throw new ApplicationException("The JSON serializer was not installed.");
                serializer = JsonRpcMessageSerializer;
            } else {
                throw new ArgumentException("Invalid message format.");
            }

            connector.MessageSerializer = serializer;
            NetworkProfile networkProfile = new NetworkProfile(connector);

            NetworkConfigSource configSource = new NetworkConfigSource();
            configSource.AddNetworkNode(address);
            networkProfile.Configuration = configSource;

            ((CloudAdmin) Application).SetNetworkContext(new NetworkContext(networkProfile));
            return true;
        }
Exemple #11
0
 public NetworkContext(NetworkProfile netProfile)
 {
     this.netProfile = netProfile;
 }
Exemple #12
0
        public override CommandResultCode Execute(IExecutionContext context, CommandArguments args)
        {
            if (Application.ActiveContext != null && Application.ActiveContext.IsIsolated)
            {
                Error.WriteLine("a context is already opened: try to disconnect first");
                Error.WriteLine();
                return(CommandResultCode.ExecutionFailed);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            if (args.Current != "to")
            {
                return(CommandResultCode.SyntaxError);
            }

            if (!args.MoveNext())
            {
                return(CommandResultCode.SyntaxError);
            }

            string          address = args.Current;
            IServiceAddress serviceAddress;

            try {
                serviceAddress = ServiceAddresses.ParseString(address);
            } catch (Exception) {
                Error.WriteLine("Invalid service address specified: {0}", address);
                return(CommandResultCode.ExecutionFailed);
            }

            NetworkConfigSource configSource = new NetworkConfigSource();

            try {
                configSource.AddNetworkNode(serviceAddress);
            } catch (Exception e) {
                Error.WriteLine("The address '" + address + "' is invalid: " + e.Message);
                return(CommandResultCode.ExecutionFailed);
            }

            string protocol    = "tcp";
            string credentials = String.Empty;
            string format      = "binary";

            if (args.MoveNext())
            {
                if (args.Current == "identified")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (args.Current != "by")
                    {
                        return(CommandResultCode.SyntaxError);
                    }
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    credentials = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "on")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        protocol = args.Current;

                        if (args.MoveNext())
                        {
                            if (args.Current != "with")
                            {
                                return(CommandResultCode.SyntaxError);
                            }

                            format = args.Current;
                        }
                    }
                }
                else if (args.Current == "on")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    protocol = args.Current;

                    if (args.MoveNext())
                    {
                        if (args.Current != "with")
                        {
                            return(CommandResultCode.SyntaxError);
                        }

                        format = args.Current;
                    }
                }
                else if (args.Current == "with")
                {
                    if (!args.MoveNext())
                    {
                        return(CommandResultCode.SyntaxError);
                    }

                    format = args.Current;
                }
                else
                {
                    return(CommandResultCode.SyntaxError);
                }
            }

            IServiceConnector connector;

            if (protocol == "tcp")
            {
                if (String.IsNullOrEmpty(credentials))
                {
                    while (String.IsNullOrEmpty(credentials = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }
                    Out.WriteLine();
                }
                connector = new TcpServiceConnector(credentials);
            }
            else if (protocol == "http")
            {
                string userName = credentials;
                string password = null;
                int    index    = credentials.IndexOf(':');
                if (index != -1)
                {
                    password = credentials.Substring(index + 1);
                    userName = credentials.Substring(0, index);
                }

                if (String.IsNullOrEmpty(password))
                {
                    while (String.IsNullOrEmpty(password = Readline.ReadPassword("password: "******"please provide a valid password...");
                    }

                    Out.WriteLine();
                }

                // TODO: connector = new HttpServiceConnector(userName, password);
                Out.WriteLine("Not supported yet.");
                return(CommandResultCode.ExecutionFailed);
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            IMessageSerializer serializer;

            if (format == "binary")
            {
                serializer = new BinaryRpcMessageSerializer();
            }
            else if (format == "xml")
            {
                //TODO: serializer = new XmlRpcMessageSerializer();
                return(CommandResultCode.ExecutionFailed);
            }
            else if (format == "json")
            {
                if (JsonRpcMessageSerializer == null)
                {
                    Error.WriteLine("JSON serializer was not installed.");
                    Error.WriteLine();
                    return(CommandResultCode.ExecutionFailed);
                }
                serializer = JsonRpcMessageSerializer;
            }
            else
            {
                return(CommandResultCode.SyntaxError);
            }

            connector.MessageSerializer = serializer;

            NetworkProfile networkProfile = new NetworkProfile(connector);

            networkProfile.Configuration = configSource;

            //TODO: test the connection is correct ...

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));

            Out.WriteLine("connected successfully to {0}", address);
            Out.WriteLine();

            return(CommandResultCode.Success);
        }
Exemple #13
0
        public override bool HandleCommandLine(CommandLine commandLine)
        {
            string protocol = commandLine.GetOptionValue("protocol", "tcp");
            string address  = commandLine.GetOptionValue("address", null);
            string format   = commandLine.GetOptionValue("format", "binary");

            if (String.IsNullOrEmpty(address))
            {
                return(false);
            }

            IServiceConnector connector;

            if (protocol.Equals("tcp", StringComparison.InvariantCultureIgnoreCase))
            {
                string netPassword = commandLine.GetOptionValue("password");
                if (String.IsNullOrEmpty(netPassword))
                {
                    throw new ArgumentException("Netwrok password required for TCP/IP protocol.");
                }

                connector = new TcpServiceConnector(netPassword);
            }
            else if (protocol.Equals("http", StringComparison.InvariantCultureIgnoreCase))
            {
                string user     = commandLine.GetOptionValue("user");
                string password = commandLine.GetOptionValue("password");
                if (String.IsNullOrEmpty(user))
                {
                    throw new ArgumentException("User name not specified. for HTTP connection.");
                }
                if (String.IsNullOrEmpty(password))
                {
                    throw new ArgumentException("Password not specofoed for HTTP connection.");
                }
                //TODO: connector = new HttpServiceConnector(user, password);
                throw new NotSupportedException("HTTP not supported yet.");
            }
            else
            {
                throw new ArgumentException("Invalid protocol '" + protocol + "'.");
            }

            IMessageSerializer serializer;

            if (format.Equals("xml", StringComparison.InvariantCultureIgnoreCase))
            {
                //TODO: serializer = new XmlRpcMessageSerializer();
                throw new NotSupportedException("XML format not supported yet.");
            }
            else if (format.Equals("binary", StringComparison.InvariantCultureIgnoreCase))
            {
                serializer = new BinaryRpcMessageSerializer();
            }
            else if (format.Equals("json", StringComparison.InvariantCultureIgnoreCase))
            {
                if (JsonRpcMessageSerializer == null)
                {
                    throw new ApplicationException("The JSON serializer was not installed.");
                }
                serializer = JsonRpcMessageSerializer;
            }
            else
            {
                throw new ArgumentException("Invalid message format.");
            }

            connector.MessageSerializer = serializer;
            NetworkProfile networkProfile = new NetworkProfile(connector);

            NetworkConfigSource configSource = new NetworkConfigSource();

            configSource.AddNetworkNode(address);
            networkProfile.Configuration = configSource;

            ((CloudAdmin)Application).SetNetworkContext(new NetworkContext(networkProfile));
            return(true);
        }