Exemplo n.º 1
0
        /// <summary>
        /// Send sdb command and get string result of the sdb command.
        /// </summary>
        /// <param name="serialNumber">Serial number to specify target device. Refer to the 1st column of "$sdb devices".</param>
        /// <param name="protocol">Command type of sdb. ex) appcmd, etc</param>
        /// <param name="cmd">Command to be executed. ex)install, appinfo etc.</param>
        /// <param name="args">Command to be executed. ex)App ID, package ID etc.</param>
        /// <returns>Instant which stores returned output and exit value of the sdb command.</returns>
        public static List <string> RequestToTargetSync(string serialNumber, string protocol, string cmd, params string[] args)
        {
            SDBConnection sdbConnection = EstablishConnection(serialNumber);

            if (sdbConnection == null || !SendMsg(sdbConnection, protocol, cmd, args))
            {
                return(null);
            }

            List <string> responsedMsg = new List <string>();

            while (true)
            {
                string responsedLine = string.Empty;
                string ch            = string.Empty;

                while ((ch) != SDBProtocol.terminator)
                {
                    ch             = sdbConnection.ReadData(new byte[1]);
                    responsedLine += ch;
                }

                if (responsedLine == SDBProtocol.terminator)
                {
                    break;
                }

                responsedMsg.Add(responsedLine);
            }

            sdbConnection.Close();
            return(responsedMsg);
        }
Exemplo n.º 2
0
        private static void ConsumeMsgInBG(SDBConnection sdbConnection, MessageHandler msgCharHandler, LastWorkExecutor lastWorker)
        {
            string responsedMsg;

            try
            {
                while ((responsedMsg = sdbConnection.ReadData(new byte[1])) != string.Empty && responsedMsg != "\0")
                {
                    msgCharHandler(responsedMsg);
                }

                lastWorker?.Invoke();

                sdbConnection.Close();
            }
            catch (ThreadAbortException abortException)
            {
                Debug.WriteLine($"Message consumer aborted. {abortException.Message}");
                sdbConnection.Close();
            }
        }