async Task <bool> InitializeMeadowDevice(MeadowDeviceExecutionTarget target, CancellationTokenSource cts) { if (cts.IsCancellationRequested) { return(true); } target.Write($"Initializing Meadow {target.meadowSerialDevice.connection.ToString()}\n"); if (target.meadowSerialDevice == null) { target.WriteError("Can't read Meadow device\n"); return(false); } Console.WriteLine("MonoDisable"); MeadowDeviceManager.MonoDisable(target.meadowSerialDevice); if (!(await target.meadowSerialDevice.AwaitStatus(5000, MeadowCLI.DeviceManagement.MeadowSerialDevice.DeviceStatus.PortOpen)).HasValue) { target.Write("The Meadow has failed to restart.\n"); return(false); } return(true); }
//https://stackoverflow.com/questions/29798243/how-to-write-to-the-tool-output-pad-from-within-a-monodevelop-add-in async Task DeployApp(MeadowDeviceExecutionTarget target, string folder, CancellationTokenSource cts) { //ProgressMonitor toolMonitor = MonoDevelop.Ide.IdeApp.Workbench.ProgressMonitors.GetToolOutputProgressMonitor(true, cts); //ProgressMonitor outMonitor = MonoDevelop.Ide.IdeApp.Workbench.ProgressMonitors.GetStatusProgressMonitor("Meadow", IconId.Null, true); //var monitor = new AggregatedProgressMonitor(toolMonitor, new ProgressMonitor[] { outMonitor }); //target.meadowPad.Window.Visible = true; target.meadowPad.Window.Activate(true); target.meadowPad.Window.Sticky = true; target.Write("Deploying to Meadow ...\n"); try { var meadow = target.meadowSerialDevice; if (await InitializeMeadowDevice(target, cts) == false) { throw new Exception($"Failed to initialize Meadow {meadow.connection.ToString()}"); } var meadowFiles = await GetFilesOnDevice(target, cts); var localFiles = await GetLocalFiles(target, cts, folder); await DeleteUnusedFiles(target, cts, meadowFiles, localFiles); await DeployApp(target, cts, folder, meadowFiles, localFiles); await ResetMeadowAndStartMono(target, cts); } catch (Exception ex) { target.WriteError($"Error: {ex.Message}\n"); } }