Esempio n. 1
0
        private string Execute(string[] args)
        {
            try
            {
                // default to help if no args passed.
                if (args.Length == 0)
                {
                    args = new string[] { "help" }
                }
                ;

                var command = ArgsCommand.Create(args);

                if (command == null)
                {
                    throw new Exception("Invalid command. Use 'cli help' for more information on how to use this service.");
                }

                command.Container = this.Container;
                return(command.Execute());
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Esempio n. 2
0
        public void SetArgsToExecuteParamters(params string[] args)
        {
            var ac = new ArgsCommand();

            ac.Execute(args);

            Assert.True(args.SequenceEqual(ac.Args));
        }
Esempio n. 3
0
 /// <summary>
 /// Creates and sends a WAAPI command to select a Wwise object.
 /// </summary>
 /// <param name="guid">GUID of the object to be selected.</param>
 /// <returns></returns>
 static private async Task SelectObjectInAuthoringAsync(System.Guid guid)
 {
     if (guid == System.Guid.Empty)
     {
         return;
     }
     var args = new ArgsCommand(WaapiKeywords.FIND_IN_PROJECT_EXPLORER, new string[] { guid.ToString("B") });
     await WaapiClient.Call(ak.wwise.ui.commands.execute, args, null);
 }
        public void PassAllParametersExceptCommandIdToCommandExecute(params string[] args)
        {
            var ce = new RouterCommand();
            var ac = new ArgsCommand();

            ce.Register("test", ac);

            ce.Execute(args);

            Assert.True(ac.Args.SequenceEqual(args.Skip(1)));
        }
Esempio n. 5
0
        static string ProcessMessage(string[] args)
        {
            // If no arguments supplied, default to show help.
            if (args.Count() == 0)
            {
                args = new string[] { "help" }
            }
            ;

            // Look to see what local / library commands there are.
            var command = ArgsCommand.Create(args);

            // Generally, the only commands processed locally by the
            // cli are 'api' and 'script'. The API command sets the
            // service end point, and the SCRIPT command runs a
            // script of commands. All other commands are processed
            // on the server
            if (args[0].Equals("api", StringComparison.OrdinalIgnoreCase))
            {
                return(command.Execute());
            }
            else if (args[0].Equals("script", StringComparison.OrdinalIgnoreCase))
            {
                var    script = command.Execute();
                var    lines  = Regex.Split(script, "\r\n|\r|\n");
                string output = "";
                foreach (var line in lines)
                {
                    var l = line.Trim();
                    if (l.Length > 0 && l.Substring(0, 1) != "#")
                    {
                        output += ProcessMessage(line.ParseArgs()) + Environment.NewLine;
                    }
                }
                return(output);
            }
            else
            {
                string result = string.Empty;
                string host   = (string)Properties.Settings.Default["host"];
                int    port   = (int)Properties.Settings.Default["port"];

                // must be processed on server.
                TcpClient client = new TcpClient();
                //client.Client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);

                // Parse the host value. Can be host name or IPv4 address.
                IPAddress addr = null;
                if (!IPAddress.TryParse(host, out addr))
                {
                    // if failed, try dns lookup
                    var hostEntry = Dns.GetHostEntry(host);
                    foreach (var item in hostEntry.AddressList)
                    {
                        // Get the first IPv4 address.
                        if (item.AddressFamily == AddressFamily.InterNetwork)
                        {
                            addr = item;
                            break;
                        }
                    }
                    if (addr == null)
                    {
                        throw new Exception("Invalid host.");
                    }
                }

                IPEndPoint serverEndPoint = new IPEndPoint(addr, port);
                client.Connect(serverEndPoint);

                // Ensure the client does not close when there is
                // still data to be sent to the server.
                client.LingerState = (new LingerOption(true, 0));

                // Request authentication
                NetworkStream   clientStream = client.GetStream();
                NegotiateStream authStream   = new NegotiateStream(clientStream, false);
                // Pass the NegotiateStream as the AsyncState object
                // so that it is available to the callback delegate.
                authStream.AuthenticateAsClient();

                // Convert client arguments to a byte array
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream    ms = new MemoryStream();
                bf.Serialize(ms, args);
                byte[] buffer = new byte[ms.Length];
                buffer = ms.ToArray();

                // Send a message to the server.
                // Encode the test data into a byte array.
                authStream.Write(buffer, 0, buffer.Length);

                // get the response
                byte[] message = new byte[4096];
                int    bytesRead;

                while (true)
                {
                    bytesRead = 0;
                    try
                    {
                        //blocks until a client sends a message
                        bytesRead = authStream.Read(message, 0, 4096);
                    }
                    catch
                    {
                        //a socket error has occured
                        break;
                    }

                    if (bytesRead == 0)
                    {
                        //the client has disconnected from the server
                        break;
                    }

                    ASCIIEncoding encoder = new ASCIIEncoding();
                    result += encoder.GetString(message, 0, bytesRead);
                    if (bytesRead < 4096)
                    {
                        break;
                    }
                }

                // Close the client connection.
                authStream.Close();

                return(result);
            }
        }
    }