예제 #1
0
        private EmulatorPlatformType GetPlatform()
        {
            EmulatorPlatformType result = EmulatorPlatformType.Mobile;
            int exitCode;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(_selectedDevice,
                                                                 "shell grep TZ_BUILD_PROFILE /etc/tizen-build.conf",
                                                                 (bool isStdOut, string line) =>
            {
                if (line.StartsWith("TZ_BUILD_PROFILE"))
                {
                    if (line.EndsWith("=tv"))
                    {
                        result = EmulatorPlatformType.TV;
                    }
                    return(true);
                }
                return(false);
            },
                                                                 out exitCode, SdbCommandTimeout);

            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                ShowWarning("Failed to determine the target platform type. " + SDBLib.FormatSdbRunResult(sdbResult, exitCode));
            }
            return(result);
        }
예제 #2
0
        private bool IsPreviewerInstalled(EmulatorPlatformType platformType)
        {
            bool isPreviewerInstalled = false;
            int  exitCode;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(_selectedDevice,
                                                                 String.Format(
                                                                     "shell [ -f /opt/usr/home/owner/apps_rw/{0}/tizen-manifest.xml ] && echo 1 || echo 0",
                                                                     (platformType == EmulatorPlatformType.TV) ? AppIdTV : AppIdMobile),
                                                                 (bool isStdOut, string line) =>
            {
                if (line.StartsWith("1"))
                {
                    isPreviewerInstalled = true;
                }
                return(true);    // only one line is needed
            },
                                                                 out exitCode, SdbCommandTimeout);

            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                ShowError("Failed to detect the XAML previewer application. " + SDBLib.FormatSdbRunResult(sdbResult, exitCode));
            }
            return(isPreviewerInstalled);
        }
예제 #3
0
        public static bool PushFile(SDBDeviceInfo device, string sourceFileName, string destinationFileName,
                                    Func <bool, string, bool> onLineRead, out string errorMessage, TimeSpan?timeout = null)
        {
            if (!File.Exists(sourceFileName))
            {
                errorMessage = $"File \"{sourceFileName}\" not found";
                return(false);
            }
            string sdbErr     = null;
            string sdbOutput  = null;
            int    exitResult = 0;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(device,
                                                                 $"push \"{sourceFileName}\" \"{destinationFileName}\"",
                                                                 (bool isStdOut, string line) =>
            {
                bool stop = false;
                if (onLineRead != null)
                {
                    stop = onLineRead(isStdOut, line);
                }
                if (line.Contains("1 file(s) pushed"))
                {
                    stop = true;
                }
                if (line.StartsWith("error:"))
                {
                    sdbErr = line;
                    stop   = true;
                }
                sdbOutput += line;
                return(stop);
            },
                                                                 out exitResult,
                                                                 timeout ?? DefaultTimeout);
            if (sdbResult == SDBLib.SdbRunResult.Success && exitResult == 0)
            {
                if (sdbErr == null)
                {
                    errorMessage = "";
                    return(true);
                }
            }
            errorMessage = $"Cannot push \"{sourceFileName}\" to \"{destinationFileName}\"";
            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                errorMessage = StringHelper.CombineMessages(errorMessage, SDBLib.FormatSdbRunResult(sdbResult));
            }
            if (sdbOutput != null)
            {
                errorMessage = StringHelper.CombineMessages(errorMessage, sdbOutput);
            }
            return(false);
            //if (sdbErr != null)
            //{
            //    errorMessage = StringHelper.CombineMessages(errorMessage, sdbErr);
            //}
            //return false;
        }
예제 #4
0
        protected bool StartRemoteApplication(string sdkCode)
        {
            string appId = _sessionConfiguration.AppId;

            DebugWriteToOutput($"Starting launch_app({appId}; SDK={sdkCode})");
            ProcessProxy launchAppProcess = SDBLib.CreateSdbProcess(true, true);

            if (launchAppProcess == null)
            {
                WriteToOutput(SDBLib.FormatSdbRunResult(SDBLib.SdbRunResult.CreateProcessError));
                return(false);
            }
            launchAppProcess.StartInfo.Arguments = GetSdbLaunchCommand(sdkCode);
            string firstOutputLine = null;

            _launchAppStartedEvent.Reset();
            launchAppProcess.OutputDataReceived += ((sender, e) =>
            {
                if (!String.IsNullOrEmpty(e.Data))
                {
                    firstOutputLine = e.Data;
                    _launchAppStartedEvent.Set();
                    DebugWriteToOutput($"{appId} : {e.Data}");
                }
            });
            launchAppProcess.ErrorDataReceived += ((sender, e) =>
            {
                if (!String.IsNullOrEmpty(e.Data))
                {
                    DebugWriteToOutput($"{appId} [StdErr] {e.Data}");
                }
            });
            launchAppProcess.Exited += (object sender, EventArgs e) =>
            {
                DebugWriteToOutput($"launch_app({appId}) finished");
                launchAppProcess.Dispose();
            };
            Debug.WriteLine("{0} {1} StartRemoteApplication command '{2}'", DateTime.Now, this.ToString(), launchAppProcess.StartInfo.Arguments);
            launchAppProcess.Start();
            DebugWriteProcessToOutput(launchAppProcess);
            try
            {
                launchAppProcess.BeginOutputReadLine();
                launchAppProcess.BeginErrorReadLine();
                if (_launchAppStartedEvent.WaitOne(30000))
                {
                    if (firstOutputLine.EndsWith("launch failed"))
                    {
                        WriteToOutput($"launch_app({appId}) failed");
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            return(true);
        }
예제 #5
0
        public static bool InstallTpk(SDBDeviceInfo device, string tpkFileName,
                                      Func <bool, string, bool> onLineRead, out string errorMessage, TimeSpan?timeout = null)
        {
            if (!File.Exists(tpkFileName))
            {
                errorMessage = $"File \"{tpkFileName}\" not found";
                return(false);
            }
            string sdbErr = null;
            int    exitCode;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(device,
                                                                 $"install \"{tpkFileName}\"",
                                                                 (bool isStdOut, string line) =>
            {
                bool stop = false;
                if (onLineRead != null)
                {
                    stop = onLineRead(isStdOut, line);
                }
                if (line.StartsWith("spend time for pkgcmd is"))
                {
                    stop = true;
                }
                if (line.StartsWith("error:"))
                {
                    sdbErr = line;
                    stop   = true;
                }
                return(stop);
            },
                                                                 out exitCode, timeout ?? DefaultTimeout);
            if (sdbResult == SDBLib.SdbRunResult.Success)
            {
                if (sdbErr == null)
                {
                    errorMessage = "";
                    return(true);
                }
            }
            errorMessage = StringHelper.CombineMessages($"Cannot install TPK", SDBLib.FormatSdbRunResult(sdbResult, exitCode));
            if (sdbErr != null)
            {
                if (!sdbErr.Contains(tpkFileName))
                {
                    errorMessage = StringHelper.CombineMessages(errorMessage, $"Package: \"{tpkFileName}\"");
                }
                errorMessage = StringHelper.CombineMessages(errorMessage, sdbErr);
            }
            return(false);
        }
        private void DisconnectButton_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex = RDMListView.SelectedIndex;

            if (selectedIndex == -1)
            {
                return;
            }

            ItemsData selectedItem     = (ItemsData)RDMListView.Items[selectedIndex];
            string    ip               = selectedItem.IP;
            string    lastNonEmptyLine = "";
            int       exitCode;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(null, "disconnect " + ip,
                                                                 (bool isStdOut, string line) =>
            {
                if (isStdOut)
                {
                    if (line != "")
                    {
                        lastNonEmptyLine = line;
                        return(true);
                    }
                }
                return(false);
            },
                                                                 out exitCode);

            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                MessageBox.Show(SDBLib.FormatSdbRunResult(sdbResult), MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (lastNonEmptyLine.StartsWith("error:"))
            {
                MessageBox.Show(lastNonEmptyLine, MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                this.IsConnect = false;
                MessageBox.Show($"Disconnected from {ip}:{selectedItem.Port}", MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
예제 #7
0
        public static bool RunCommand(SDBDeviceInfo device, string command, out string outputLine, out string errorMessage)
        {
            string s          = "";
            int    exitResult = 0;

            SDBLib.SdbRunResult sdbResult = SDBLib.RunSdbCommand(device, command,
                                                                 (bool isStdOut, string line) =>
            {
                if (line != "")
                {
                    s = line;
                    return(true);    // TODO!! check if it is valid to return 'true' here
                }
                return(false);
            },
                                                                 out exitResult,
                                                                 TimeSpan.FromSeconds(60));
            outputLine = s;
            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                errorMessage = $"Cannot run \"{command}\". {SDBLib.FormatSdbRunResult(sdbResult)}";
                return(false);
            }
            // TODO!! shell command might fail even if sdbResult is Success - check the output
            // (support different commands - vs_sdkinstall, vs_sdkremove, etc.!)
            if (outputLine.StartsWith("/bin/sh:")) // error
            {
                errorMessage = outputLine;
                return(false);
            }
            else if (outputLine.EndsWith("is not installed")) // vs_sdkinstall error
            {
                errorMessage = outputLine;
                return(false);
            }
            if (exitResult != 0)
            {
                errorMessage = outputLine;
                return(false);
            }
            errorMessage = "";
            return(true);
        }
        private void ConnectButton_Click(object sender, RoutedEventArgs e)
        {
            int selectedIndex = RDMListView.SelectedIndex;

            if (selectedIndex == -1)
            {
                return;
            }

            string ip = ((ItemsData)RDMListView.Items[selectedIndex]).IP;
            string lastNonEmptyLine = "";
            bool   connected        = false;
            int    exitCode;

            SDBLib.SdbRunResult sdbResult;

            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
            try
            {
                sdbResult = SDBLib.RunSdbCommand(null, "connect " + ip,
                                                 (bool isStdOut, string line) =>
                {
                    if (isStdOut)
                    {
                        if (line != "")
                        {
                            lastNonEmptyLine = line;
                        }
                        if (line.StartsWith("connected to"))
                        {
                            connected = true;
                            return(true);
                        }
                    }
                    return(false);
                },
                                                 out exitCode);
            }
            finally
            {
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
            }

            if (sdbResult != SDBLib.SdbRunResult.Success)
            {
                MessageBox.Show(SDBLib.FormatSdbRunResult(sdbResult), MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (connected)
            {
                this.IsConnect = true;
                MessageBox.Show($"Completed connection to {ip}");
                this.Close();
            }

            if (lastNonEmptyLine.StartsWith("error:"))
            {
                MessageBox.Show(lastNonEmptyLine, MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                MessageBox.Show($"Got unexpected result while connecting to {ip}.\n{lastNonEmptyLine}",
                                MessageDialogTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }