示例#1
0
        //Uploads code to the robot and then runs it.
        public async Task <bool> DeployCodeAsync(string teamNumber, bool debug, Project robotProject)
        {
            var writer = OutputWriter.Instance;

            if (robotProject == null)
            {
                await writer.WriteLineAsync("Robot Project not valid. Contact RobotDotNet for support.").ConfigureAwait(false);

                return(false);
            }

            //Connect to Robot Async
            await OutputWriter.Instance.WriteLineAsync("Attempting to Connect to RoboRIO").ConfigureAwait(false);

            Task <RoboRioConnection> rioConnectionTask = RoboRioConnection.StartConnectionTaskAsync(teamNumber);

            CodeReturnStruct codeReturn = await BuildAndPrepareCodeAsync(debug, robotProject).ConfigureAwait(false);

            if (codeReturn == null)
            {
                return(false);
            }

            await writer.WriteLineAsync("Waiting for Connection to Finish").ConfigureAwait(false);

            // Kill our connection if we have already ran once with this same object.
            m_roboRioConnection?.Dispose();
            m_roboRioConnection = await rioConnectionTask.ConfigureAwait(false);

            if (m_roboRioConnection.Connected)
            {
                //Connected successfully
                await OutputWriter.Instance.WriteLineAsync("Successfully Connected to RoboRIO.").ConfigureAwait(false);

                if (!await CheckMonoInstallAsync().ConfigureAwait(false))
                {
                    //TODO: Make this error message better
                    await OutputWriter.Instance.WriteLineAsync("Mono not properly installed. Please try reinstalling to Mono Runtime.").ConfigureAwait(false);

                    return(false);
                }
                await OutputWriter.Instance.WriteLineAsync("Mono correctly installed").ConfigureAwait(false);

                await OutputWriter.Instance.WriteLineAsync("Checking RoboRIO Image").ConfigureAwait(false);

                if (!await CheckRoboRioImageAsync().ConfigureAwait(false))
                {
                    // Ignore image requirement on selected option
                    if (!SettingsProvider.ExtensionSettingsPage.IgnoreImageRequirements)
                    {
                        await OutputWriter.Instance.WriteLineAsync(
                            "RoboRIO Image does not match plugin, allowed image versions: " +
                            string.Join(", ", DeployProperties.RoboRioAllowedImages.ToArray())).ConfigureAwait(false);

                        await OutputWriter.Instance.WriteLineAsync(
                            "Please follow FIRST's instructions on imaging your RoboRIO, and try again.").ConfigureAwait(false);

                        return(false);
                    }
                }
                await OutputWriter.Instance.WriteLineAsync("RoboRIO Image Correct").ConfigureAwait(false);

                //Force making mono directory
                await CreateMonoDirectoryAsync().ConfigureAwait(false);

                bool nativeDeploy =
                    await
                    CachedFileHelper.CheckAndDeployNativeLibrariesAsync(DeployProperties.UserLibraryDir, "WPI_Native_Libraries",
                                                                        await GetProjectPathAsync(robotProject).ConfigureAwait(false) + "wpinative" + Path.DirectorySeparatorChar,
                                                                        new List <string>(), m_roboRioConnection).ConfigureAwait(false);

                if (!nativeDeploy)
                {
                    await OutputWriter.Instance.WriteLineAsync("Failed to deploy native files.").ConfigureAwait(false);

                    return(false);
                }

                //DeployAllFiles
                bool retVal = await DeployRobotFilesAsync(codeReturn.RobotFiles).ConfigureAwait(false);

                if (!retVal)
                {
                    await OutputWriter.Instance.WriteLineAsync("File deploy failed.").ConfigureAwait(false);

                    return(false);
                }
                await OutputWriter.Instance.WriteLineAsync("Successfully Deployed Files. Starting Code.").ConfigureAwait(false);
                await StartRobotCodeAsync(codeReturn.RobotExe, debug, robotProject).ConfigureAwait(false);

                await OutputWriter.Instance.WriteLineAsync("Successfully started robot code.").ConfigureAwait(false);

                return(true);
            }
            else
            {
                //Failed to connect
                await writer.WriteLineAsync("Failed to Connect to RoboRIO. Exiting.").ConfigureAwait(false);

                return(false);
            }
        }