示例#1
0
        public async System.Threading.Tasks.Task DownladRuntimeAsync()
        {
            await m_outputWriter.WriteLineAsync("Downloading Mono Runtime").ConfigureAwait(false);

            string monoFolder = await GetMonoFolderAsync().ConfigureAwait(false);

            string monoFilePath = Path.Combine(monoFolder, MonoZipName);

            if (await m_md5HashCheckerProvider.VerifyMd5Hash(monoFilePath, MonoMd5).ConfigureAwait(false))
            {
                // File already exists and is correct. No need to redownload
                await m_outputWriter.WriteLineAsync("Runtime already downloaded. Skipping...").ConfigureAwait(false);

                return;
            }
            Directory.CreateDirectory(monoFolder);
            string file = Path.Combine(monoFolder, MonoZipName);

            await DownloadToFileAsync(MonoUrl, file).ConfigureAwait(false);

            if (!await m_md5HashCheckerProvider.VerifyMd5Hash(monoFilePath, MonoMd5).ConfigureAwait(false))
            {
                throw m_exceptionThrowerProvider.ThrowException("Mono file not downloaded successfully");
            }
        }
示例#2
0
        public async Task <IEnumerable <string> > GetAllowedImageVersionsAsync()
        {
            string buildLocation = await m_projectInformationProvider.GetProjectBuildDirectoryAsync().ConfigureAwait(false);

            string settingsFile = GetCombinedFilePath(buildLocation);

            string json;

            try
            {
                json = await m_fileReaderProvider.ReadFileAsStringAsync(settingsFile).ConfigureAwait(false);
            }
            catch (IOException)
            {
                throw m_exceptionThrowerProvider.ThrowException($"Failed to read settings file at {settingsFile}");
            }

            try
            {
                return(ParseStringToJson(json));
            }
            catch (JsonSerializationException)
            {
                throw m_exceptionThrowerProvider.ThrowException("Failed to parse image settings file");
            }
            catch (JsonReaderException)
            {
                throw m_exceptionThrowerProvider.ThrowException("Failed to parse image settings file");
            }
        }
示例#3
0
        public async Task BuildCodeAsync()
        {
            await m_outputWriter.WriteLineAsync("Starting code build").ConfigureAwait(false);

            string outputLoc = await m_projectInformationProvider.GetProjectBuildDirectoryAsync().ConfigureAwait(false);

            string projectDir = await m_projectInformationProvider.GetProjectRootDirectoryAsync().ConfigureAwait(false);

            var retVal = await Task.Run(() =>
            {
                string configuration = "Release";
                if (m_buildSettingsProvider.Debug)
                {
                    configuration = "Debug";
                }
                var cmdArgs = new List <string>
                {
                    projectDir,
                    "--configuration", configuration,
                    "-o", outputLoc
                };

                var result = Command.CreateDotNet("build", cmdArgs).Execute();
                return(result);
            }).ConfigureAwait(false);

            if (retVal.ExitCode != 0)
            {
                throw m_exceptionThrowerProvider.ThrowException($"Failed to build code. Error code: {retVal.ExitCode}");
            }
            await m_outputWriter.WriteLineAsync("Successfully built code").ConfigureAwait(false);
        }
示例#4
0
        public async Task DeployRobotCodeAsync()
        {
            await m_outputWriter.WriteLineAsync("Deploying Robot Code Files").ConfigureAwait(false);

            bool   verbose  = m_buildSettingsProvider.Verbose;
            string buildDir = await m_projectInformationProvider.GetProjectBuildDirectoryAsync().ConfigureAwait(false);

            string nativeDir = Path.Combine(buildDir, m_nativePackageDeploymentProvider.NativeDirectory);

            if (verbose)
            {
                await m_outputWriter.WriteLineAsync("Creating Mono Deploy Directory").ConfigureAwait(false);
            }
            // Ensure output directory exists
            await m_fileDeployerProvider.RunCommandAsync($"mkdir -p {DeployProperties.DeployDir}", ConnectionUser.LvUser).ConfigureAwait(false);

            // Ignore User specified ignore files, and the wpinative folder
            List <string>?ignoreFiles = (await m_frcSettingsProvider.GetFrcSettingsAsync()
                                         .ConfigureAwait(false))
                                        ?.DeployIgnoreFiles;

            if (ignoreFiles == null)
            {
                ignoreFiles = new List <string>();
            }
            var files = Directory.GetFiles(buildDir, "*", SearchOption.AllDirectories).Where(x => !x.Contains(nativeDir))
                        .Where(f => !DeployProperties.IgnoreFiles.Any(f.Contains) && !ignoreFiles.Any(f.Contains))
                        .Select(x =>
            {
                var path     = Path.GetDirectoryName(x) ?? x;
                string split = path.Substring(buildDir.Length);
                split        = split.Replace('\\', '/');
                return(x, $"{DeployProperties.DeployDir}{split}");
            });

            // Deploy all files
            if (!await m_fileDeployerProvider.DeployFilesAsync(files, ConnectionUser.LvUser).ConfigureAwait(false))
            {
                throw m_exceptionThrowerProvider.ThrowException("Failed to deploy robot files");
            }
            await m_outputWriter.WriteLineAsync("Successfully deployed robot code files").ConfigureAwait(false);
        }
        public async Task InstallZippedPackagesAsync(string localFile)
        {
            if (!File.Exists(localFile))
            {
                throw m_exceptionThrowerProvider.ThrowException($"Could not find file to deploy: {localFile}");
            }

            await m_outputWriter.WriteLineAsync($"Deploying file: {localFile} to {RoboRioOpgkLocation}").ConfigureAwait(false);

            bool verbose = m_buildSettingsProvider.Verbose;

            var ret = await m_fileDeployerProvider.DeployFilesAsync(new (string, string)[] { (localFile, RoboRioOpgkLocation) },
示例#6
0
        public async Task WriteFrcSettingsAsync(FrcSettings settings)
        {
            await m_outputWriter.WriteLineAsync("Writing settings file").ConfigureAwait(false);

            string serialized = await Task.Run(() => JsonConvert.SerializeObject(settings,
                                                                                 Formatting.Indented)).ConfigureAwait(false);

            if (string.IsNullOrEmpty(serialized))
            {
                m_exceptionThrowerProvider.ThrowException("Failed to serialize settings file");
            }
            string projectDirectory = await m_projectInformationProvider.GetProjectRootDirectoryAsync().ConfigureAwait(false);

            string settingsFile = Path.Combine(projectDirectory, SettingsJsonFileName);

            Directory.CreateDirectory(Path.GetDirectoryName(settingsFile));
            await File.WriteAllTextAsync(settingsFile, serialized);
        }
示例#7
0
        public async Task CheckCorrectImageAsync()
        {
            string currentImage = await GetCurrentRoboRioImageAsync().ConfigureAwait(false);

            IEnumerable <string> allowedImages = await GetAllowedRoboRioImagesAsync().ConfigureAwait(false);

            if (!allowedImages.Contains(currentImage))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("RoboRIO image not correct. Allowed Images:");
                foreach (var item in allowedImages)
                {
                    builder.AppendLine($"    {item}");
                }
                builder.AppendLine($"Current Version: {currentImage}");
                throw m_exceptionThrowerProvider.ThrowException(builder.ToString());
            }
        }
        public async Task <int> GetTeamNumberAsync()
        {
            int teamNumber = -1;

            if (m_inputTeamNumber != null)
            {
                teamNumber = m_inputTeamNumber.Value;
                if (teamNumber < 0)
                {
                    await m_outputWriter.WriteLineAsync("Entered team number is not valid. Attempting to read from settings file").ConfigureAwait(false);
                }
            }
            if (teamNumber < 0)
            {
                var frcSettings = await m_frcSettingsProvider.Value.GetFrcSettingsAsync().ConfigureAwait(false);

                if (frcSettings == null)
                {
                    throw m_exceptionThrowerProvider.ThrowException("Could not find team number. Please either use a -t argument, \nor run dotnet frc settings to set a permanent team number");
                }
                teamNumber = frcSettings.TeamNumber;
            }
            return(teamNumber);
        }
示例#9
0
        private async Task CreateConnectionAsync()
        {
            if (Connected)
            {
                return;
            }

            int teamNumber = await m_teamNumberProvider.GetTeamNumberAsync().ConfigureAwait(false);

            if (teamNumber < 0)
            {
                throw m_exceptionThrowerProvider.ThrowException("Team number cannot be less than 0. Check settings");
            }

            await m_outputWriter.WriteLineAsync($"Connecting to robot for team {teamNumber}").ConfigureAwait(false);

            string roboRioMDNS = string.Format(RoboRioMdnsFormatString, teamNumber);
            string roboRioLan  = string.Format(RoboRioLanFormatString, teamNumber);
            string roboRIOIP   = string.Format(RoboRioIpFormatString, teamNumber / 100, teamNumber % 100);

            bool verbose = m_buildSettingsProvider.Verbose;

            if (verbose)
            {
                await m_outputWriter.WriteLineAsync($"Connecting to the following IP Addresses:").ConfigureAwait(false);

                await m_outputWriter.WriteLineAsync($"    {RoboRioUSBIp}").ConfigureAwait(false);

                await m_outputWriter.WriteLineAsync($"    {roboRioMDNS}").ConfigureAwait(false);

                await m_outputWriter.WriteLineAsync($"    {roboRioLan}").ConfigureAwait(false);

                await m_outputWriter.WriteLineAsync($"    {roboRIOIP}").ConfigureAwait(false);
            }

            using (TcpClient usbClient = new TcpClient(AddressFamily.InterNetwork))
                using (TcpClient mDnsClient = new TcpClient(AddressFamily.InterNetwork))
                    using (TcpClient lanClient = new TcpClient(AddressFamily.InterNetwork))
                        using (TcpClient ipClient = new TcpClient(AddressFamily.InterNetwork))
                        {
                            Task usb       = usbClient.ConnectAsync(RoboRioUSBIp, 80);
                            Task mDns      = mDnsClient.ConnectAsync(roboRioMDNS, 80);
                            Task lan       = lanClient.ConnectAsync(roboRioLan, 80);
                            Task ip        = ipClient.ConnectAsync(roboRIOIP, 80);
                            Task delayTask = Task.Delay(m_sshTimeout);

                            // http://stackoverflow.com/questions/24441474/await-list-of-async-predicates-but-drop-out-on-first-false
                            List <Task> tasks = new List <Task>()
                            {
                                usb, mDns, lan, ip, delayTask
                            };

                            while (tasks.Count != 0)
                            {
                                var finished = await Task.WhenAny(tasks).ConfigureAwait(false);

                                if (finished == delayTask)
                                {
                                    throw m_exceptionThrowerProvider.ThrowException("Connection to robot timed out");
                                }
                                else if (finished.IsCompleted && !finished.IsFaulted && !finished.IsCanceled)
                                {
                                    // A task finished, find our host
                                    TcpClient?foundHost = null;
                                    if (finished == usb)
                                    {
                                        foundHost = usbClient;
                                    }
                                    else if (finished == mDns)
                                    {
                                        foundHost = mDnsClient;
                                    }
                                    else if (finished == lan)
                                    {
                                        foundHost = lanClient;
                                    }
                                    else if (finished == ip)
                                    {
                                        foundHost = ipClient;
                                    }
                                    else
                                    {
                                        // Error
                                        throw m_exceptionThrowerProvider.ThrowException("Unknown task returned");
                                    }

                                    var ep = foundHost.Client.RemoteEndPoint;
                                    if (!(ep is IPEndPoint ipEp))
                                    {
                                        // Continue, we cannot use this one
                                    }
                                    else
                                    {
                                        bool finishedConnect = await OnConnectionFound(ipEp.Address).ConfigureAwait(false);

                                        if (finishedConnect)
                                        {
                                            await m_outputWriter.WriteLineAsync($"Connected to robot at IP Address: {ipEp.Address}").ConfigureAwait(false);

                                            m_remoteIp = ipEp.Address;
                                            return;
                                        }
                                        else
                                        {
                                            throw m_exceptionThrowerProvider.ThrowException("Failed to complete all RoboRio connections");
                                        }
                                    }
                                }
                                tasks.Remove(finished);
                            }
                            // If we have ever gotten here, return false
                            throw m_exceptionThrowerProvider.ThrowException("Ran out of tasks");
                        }