public async Task SetBinaries(BinarySet binarySet, string comPort, string?workingDir = null) { if (BinarySet != null) { throw new InvalidOperationException("Binaries have already been set"); } BinarySet = binarySet ?? throw new ArgumentNullException(nameof(binarySet)); this.comPort = comPort; var plan = toolset.GetPlan(BinarySet); if (plan.IsSuccess(out var details)) { Consoles = details.Select((part, index) => { var s = part.Item1.GetStartInfo(BinarySet.TargetPlatform, part.Item2, comPort ?? throw new InvalidOperationException("Couldn't get the port")); s.RedirectStandardOutput = true; s.RedirectStandardError = true; s.RedirectStandardInput = true; s.CreateNoWindow = true; s.WorkingDirectory = workingDir ?? s.WorkingDirectory; return(new StreamingConsoleViewModel($"{BinarySet.Name} ({index + 1} of {details.Count})", s)); }).ToList(); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Consoles))); } else { throw new InvalidOperationException($"Couldn't get a tool for binary {plan.UnflashableBinary?.Path ?? "(unknown)"}"); } foreach (var vm in Consoles) { await vm.Start().WaitForExitAsync(); } Next.RaiseCanExecuteChanged(); }
public ConfigurationViewModel(BinarySet binarySet, string comPort) { Connection = SerialConnection.Open(comPort, binarySet.BaudRate); GetStatus = Command.Create(async() => StatusValue = await Connection.Prompt("?", true)); Verifications = binarySet.Verifications.Select(v => new VerificationViewModel(v, Connection)).ToList(); Parameters = binarySet.ConfigTemplate?.Parameters.Select(p => new ParameterViewModel(p)).ToList() as IReadOnlyCollection <ParameterViewModel> ?? Array.Empty <ParameterViewModel>(); CommitConfig = Command.Create( () => Connection.Prompt($"{binarySet.ConfigTemplate!.SerialCommand} {binarySet.ConfigTemplate!.Build(GetValue)}"), () => (binarySet.ConfigTemplate?.SerialCommand) != null && Parameters.All(p => !p.IsRequired || p.Value != null)); foreach (var parameter in Parameters) { parameter.PropertyChanged += (sender, args) => CommitConfig.RaiseCanExecuteChanged(); } }
internal static FlashPlan GetPlan(BinarySet set, IReadOnlyCollection <ISetTool> tools) { (ISetTool tool, Binaries handled, Binaries remaining)? GetNextTool(string?targetPlatform, Binaries binaries) => tools.Select(tool => { var(handled, remaining) = tool.CanHandle(targetPlatform, binaries); return(tool, handled, remaining); }).SkipWhile(t => !t.handled.Any()) .Take(1) .Cast <(ISetTool, Binaries, Binaries)?>() .FirstOrDefault(); List <(ISetTool, Binaries)> output = new(); Binaries remaining = set.Binaries; while (remaining.Any()) { if (GetNextTool(set.TargetPlatform, remaining) is (ISetTool, Binaries, Binaries)value && value.handled.Any()) { output.Add((value.tool, value.handled)); remaining = value.remaining; }
public override FlashPlan GetPlan(BinarySet set) => GetPlan(set, tools);
public override FlashPlan GetPlan(BinarySet set) => GetPlan(set, new ISetTool[] { espUploaderPyTool });