Ejemplo n.º 1
0
        /// <summary>
        /// Parse a connection command.
        /// </summary>
        /// <param name="pCommand"></param>
        private static void Connection(JObject pCommand)
        {
            if (pCommand == null)
            {
                throw new Exception(311, "There doesn't exist a json command");
            }
            var command = JsonConvert.DeserializeObject <ConnectionCommand>(JsonConvert.SerializeObject(pCommand));
            var type    = (ConnectionCommandType)Enum.Parse(typeof(ConnectionCommandType), command.Type);


            switch (type)
            {
            case ConnectionCommandType.Connect:
                //Set the id to the objects
                Client.Identification.Id = command.Identification.Id;
                var app = (FleeAndCatch.Commands.Models.Devices.Apps.App)Client.Device;
                app.Identification.Id = command.Identification.Id;
                return;

            case ConnectionCommandType.Disconnect:
                Client.Disconnect();
                return;

            case ConnectionCommandType.Init:
                //Send a connection command for initialization
                var cmd = new ConnectionCommand(CommandType.Connection.ToString(), ConnectionCommandType.Init.ToString(), Client.Identification, Client.Device);
                Client.SendCmd(cmd.ToJsonString());
                return;

            default:
                throw new Exception(312, "Wrong connection type of json command");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Listen at the current socket and interpret the received commands.
        /// </summary>
        private static async void Listen()
        {
            try
            {
                await tcpSocketClient.ConnectAsync(identification.Address, identification.Port);
            }
            catch (Exception e)
            {
                throw new Exception(301, "The connection could not established");
            }
            if (tcpSocketClient != null)
            {
                connected = true;

                //Send a connection command to transfer the current device
                var command = new ConnectionCommand(CommandType.Connection.ToString(), ConnectionCommandType.Connect.ToString(), identification, Device);
                SendCmd(command.ToJsonString());

                //Receive the packages and put them to the parser
                while (connected)
                {
                    Interpreter.Parse(ReceiveCmd());
                }
                return;
            }
            throw new Exception(302, "The created socket doesn't exist");
        }
Ejemplo n.º 3
0
        public ExternalProcessAction(ConnectionCommand command, params ConnectionOutput[] desiredOutput)
        {
            Command       = command;
            DesiredOutput = desiredOutput;

            if (command.IsStream == null || command.IsStream.Value == false)
            {
                DesiredOutput.Should().NotBeEmpty("If output is empty then the test will hang forever");
            }
        }
Ejemplo n.º 4
0
 public NotConnectedState(Bot bot)
 {
     Value         = StateType.NotConnected;
     Command       = new ConnectionCommand(bot);
     MessagesKnown = new List <MessageType> {
         new MessageType(PrefixMessage.Connection.ReceivedKey),
         new MessageType(PrefixMessage.Connection.DisconnectSomeone),
         new MessageType(PrefixMessage.Connection.ConnectionOk)
     };
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Close the current connection, for start of the closing.
        /// </summary>
        public static void Close()
        {
            if (!Connected)
            {
                throw new Exception(306, "There is no connection to the server");
            }
            //Send connection command to close the connection
            var command = new ConnectionCommand(CommandType.Connection.ToString(), ConnectionCommandType.Disconnect.ToString(), identification, Device);

            SendCmd(command.ToJsonString());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Deserialize a json string into a ConnectionCommand
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static Result <ConnectionCommand, IErrorBuilder> DeserializeConnectionCommand(string json)
        {
            try
            {
                var command1 = JsonConvert.DeserializeObject <ConnectionCommand>(json) !;

                if (command1.Arguments == null)
                {
                    return(command1);
                }

                var newArguments = new Dictionary <string, object>();

                foreach (var(key, value) in command1.Arguments)
                {
                    if (value is JObject jObject)
                    {
                        var entity = JsonConvert.DeserializeObject <Entity>(
                            jObject.ToString() !,
                            EntityJsonConverter.Instance
                            );

                        newArguments.Add(key, entity !);
                    }
                    else if (!(value is string) && value is IEnumerable enumerable)
                    {
                        var newValue = enumerable.OfType <object>().Select(x => x.ToString()).ToList();
                        newArguments.Add(key, newValue);
                    }
                    else
                    {
                        newArguments.Add(key, value);
                    }
                }

                var command2 = new ConnectionCommand
                {
                    Arguments          = newArguments,
                    Command            = command1.Command,
                    FunctionDefinition = command1.FunctionDefinition,
                    IsStream           = command1.IsStream
                };

                return(command2);
            }
            catch (JsonException e)
            {
                return(new ErrorBuilder(e, ErrorCode.ExternalProcessError));
            }
        }
Ejemplo n.º 7
0
 private MigratorOptions Init(ConnectionCommand cmd)
 {
     ConnectionString         = cmd.ConnectionString;
     NoConnection             = cmd.NoConnection;
     ProcessorType            = cmd.ProcessorType;
     ProcessorSwitches        = cmd.ProcessorSwitches;
     Preview                  = cmd.Preview;
     Verbose                  = cmd.Verbose;
     Profile                  = cmd.Profile;
     Context                  = cmd.Context;
     Timeout                  = cmd.Timeout;
     (Output, OutputFileName) = cmd.Output;
     return(Init((MigrationCommand)cmd));
 }
Ejemplo n.º 8
0
    private void ReadLoop(object obj)
    {
        try
        {
            do
            {
                var command = binarySerializer.Deserialize <RpcCommand>(clientStream);
                Debug.Log("收到 Command");

                switch (command.CommandType)
                {
                case CommandType.Connection:
                {
                    var connectionCommand = command.Command as ConnectionCommand;
                    Debug.Log("连接断开直播间" + connectionCommand.Connect + connectionCommand.RoomId);
                    lock (command_lock)
                    {
                        this.connectionCommand = connectionCommand;
                    }
                    break;
                }

                case CommandType.Profile:
                {
                    Debug.Log("收到 profile command");
                    lock (command_lock)
                    {
                        new_profile = (command.Command as ProfileCommand)?.Profile;
                    }
                    break;
                }

                case CommandType.Default:
                default:
                {
                    Debug.Log("收到了一个奇怪的 Command " + command.CommandType);
                    Shutdown();
                    return;
                }
                }
            } while ((clientStream?.IsConnected ?? false) && (clientStream?.CanRead ?? false));
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            Debug.Log("Rpc 错误 退出");
            Shutdown();
        }
    }
Ejemplo n.º 9
0
    private void Update()
    {
        lock (command_lock)
        {
            if (new_profile != null)
            {
                SetProfile(new_profile);
                new_profile = null;
            }

            if (connectionCommand != null)
            {
                if (connectionCommand.Connect)
                {
                    Displayer.Connect(connectionCommand.RoomId);
                }
                else
                {
                    Displayer.Disconnect();
                }
                connectionCommand = null;
            }
        }
    }
Ejemplo n.º 10
0
 public AutoPilotViewModel()
 {
     commandClient  = ConnectionCommand.getInstance;
     text           = "";
     writingStarted = false;
 }
Ejemplo n.º 11
0
 public static void SendCommand(Stream stream, ConnectionCommand command)
 {
     SendInt(stream, (int)command);
 }
Ejemplo n.º 12
0
 public SmartlockWriteRepository(ConnectionCommand connectionCommand)
 {
     this.connectionCommand = connectionCommand;
 }
Ejemplo n.º 13
0
 public void SendCommand(ConnectionCommand command) => _command.OnNext(command);
Ejemplo n.º 14
0
        public void Run(TcpClient client)
        {
            try
            {
                logger.Log(this, String.Format("Godot has been activated. Client IP address is {0}",
                                               LUtils.GetIpAddress(client)));
                godotCounter.IncreaseRunning();

                stream = new SslStream(client.GetStream(), false, CertificateValidation);
                stream.AuthenticateAsServer(serverCert, true, SslProtocols.Tls12, false);

                logger.Log(this, "SSL authentication completed. Starting Handshake.");
                this.connectionInfo = Handshake.Run(stream, Log, config);


                bool running = true;
                while (running)
                {
                    ConnectionCommand command = BinaryEncoder.ReadCommand(stream);
                    switch (command)
                    {
                    case ConnectionCommand.TRUST_CONTACT:
                        Log("TRUST_CONTACT command received.");
                        TrustContact();
                        break;

                    case ConnectionCommand.UNTRUST_CONTACT:
                        Log("UNTRUST_CONTACT command received.");
                        UntrustContact();
                        break;

                    case ConnectionCommand.PULL:
#if (DEBUG)
                        Log("PULL command received.");
#endif
                        Push();
                        break;

                    case ConnectionCommand.PUSH:
#if (DEBUG)
                        Log("PUSH command received.");
#endif
                        Pull();
                        break;

                    case ConnectionCommand.SEARCH_CONTACT:
                        Log("SEARCH_CONTACT command received.");
                        SearchContact();
                        break;

                    case ConnectionCommand.END_CONNECTION:
                        Log("END_CONNECTION command received.");
                        running = false;
                        break;

                    default:
                        throw new Exception("Received unknown command.");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(this, "Godot has crashed.");
                logger.LogException(this, ex);
            }
            finally
            {
                stream.Close();
                client.Close();
                godotCounter.IncreaseDestroyed();
                logger.Log(this, "Godot has died.");
            }
        }
Ejemplo n.º 15
0
        public void Run(TcpClient client)
        {
            try
            {
                logger.Log(this, String.Format("Godot has been activated. Client IP address is {0}",
                                               LUtils.GetIpAddress(client)));
                godotCounter.IncreaseRunning();

                stream = new SslStream(client.GetStream(), false, CertificateValidation);
                stream.AuthenticateAsServer(serverCert, true, SslProtocols.Tls12, false);

                logger.Log(this, "SSL authentication completed. Starting Handshake.");
                this.user = Handshake.Run(stream, Log, config);

                InitSync();

                bool running = true;
                while (running)
                {
                    ConnectionCommand command = TextEncoder.ReadCommand(stream);
                    switch (command)
                    {
                    case ConnectionCommand.TRUST_CONTACT:
                        Log("TRUST_CONTACT command received.");
                        TrustContact();
                        break;

                    case ConnectionCommand.UNTRUST_CONTACT:
                        Log("UNTRUST_CONTACT command received.");
                        UntrustContact();
                        break;

                    case ConnectionCommand.PULL:
#if (DEBUG)
                        Log("PULL command received.");
#endif
                        Push();
                        break;

                    case ConnectionCommand.PUSH:
#if (DEBUG)
                        Log("PUSH command received.");
#endif
                        Pull();
                        break;

                    case ConnectionCommand.CREATE_ONLIVE_TUNNEL:
                        Log("CREATE_ONLIVE_TUNNEL command received.");
                        CreateOnliveTunnel();
                        break;

                    case ConnectionCommand.END_CONNECTION:
                        Log("END_CONNECTION command received.");
                        running = false;
                        break;

                    default:
                        throw new ChatovatkoException(this, "Received unknown command.");
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Log(this, String.Format("Godot has crashed. Exception:\n{0}\n{1}\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace));
            }
            finally
            {
                stream.Close();
                client.Close();
                godotCounter.IncreaseDestroyed();
                logger.Log(this, "Godot has died.");
            }
        }
Ejemplo n.º 16
0
 public SmartlockReadRepository(ConnectionCommand command)
 {
     this.command = command;
 }