// Based on https://stackoverflow.com/questions/285760/how-to-spawn-a-process-and-capture-its-stdout-in-net public ProcessExecution Run(string exePath, string arguments) { ProcessStartInfo startInfo = new ProcessStartInfo(); Process p = new Process(); startInfo.CreateNoWindow = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardError = true; startInfo.UseShellExecute = false; startInfo.Arguments = arguments; startInfo.FileName = exePath; p.StartInfo = startInfo; p.Start(); p.WaitForExit(); StringBuilder output = new StringBuilder(); output.Append(p.StandardOutput.ReadToEnd()); output.Append(p.StandardError.ReadToEnd()); var result = new ProcessExecution() { ExitCode = p.ExitCode, Log = output.ToString() }; return(result); }
// Open the currently displayed video in an external player private void OpenExternalPlayer_Click(object sender, RoutedEventArgs e) { // Open the currently displayed video in an external player if (File.Exists(Uri.UnescapeDataString(this.Video.Source.AbsolutePath))) { Uri uri = new Uri(Uri.UnescapeDataString(this.Video.Source.AbsolutePath)); ProcessExecution.TryProcessStart(uri); } }
public Task ExecuteProcessAsync(ProcessExecution request) { return (this .GetClient() .PostAsync <ProcessExecution>( "executeProcess", request)); }
// Start an email private void MailButton_Click(object sender, RoutedEventArgs e) { Uri uri = new Uri(String.Format("mailto:{0}?subject={1}&body={2}", to, subject, Uri.EscapeUriString(body))); if (ProcessExecution.TryProcessStart(uri) == false) { this.MailButton.Content = "Mailing failed - See 'alternate' instructions above, or press Cancel."; this.MailButton.IsEnabled = false; } }
private ServiceResponse GetStepExecutionForView(ProcessExecution processExe, int currentUserID) { ServiceResponse res = new ServiceResponse(); var stepExe = processExe.StepExecutions.OrderByDescending(x => x.ProcessStep.SortOrder).First(); if (stepExe != null) { if (processExe.CurrentStep != null) { processExe.CurrentStep.ProcessExecutions = null; } var listStepExe = new List <StepExecution>(); foreach (var item in processExe.StepExecutions) { item.ProcessExecution = null; if (item.CurrentAssignee != null) { item.CurrentAssignee.ProcessExecutions = null; } if (item.NextAssigneeId != null && item.NextAssigneeId != -999) { listStepExe.Add(item); } } var result = new StepExecutionHandel() { CurrentStep = stepExe.ProcessStep, ListStep = listStepExe, IsHandle = false, Status = processExe.Status, ProcessName = processExe.ProcessExecutionName }; res.OnSuccess(result); return(res); } else { res.OnError("Not permittion"); return(res); } }
private ServiceResponse GetStepExecutionForHandle(ProcessExecution processExe, int currentUserID) { ServiceResponse res = new ServiceResponse(); // kiem tra xem dung nguoi nay duoc giao hay khong var lastProcess = processExe.StepExecutions.OrderByDescending(x => x.ProcessStep.SortOrder).First(); if (lastProcess.CurrentAssigneeId == currentUserID) { if (processExe.CurrentStep != null) { processExe.CurrentStep.ProcessExecutions = null; } var listStepExe = new List <StepExecution>(); foreach (var item in processExe.StepExecutions) { item.ProcessExecution = null; if (item.CurrentAssignee != null) { item.CurrentAssignee.ProcessExecutions = null; } if (item.NextAssigneeId != null && item.NextAssigneeId != -999) { listStepExe.Add(item); } } var result = new StepExecutionHandel() { CurrentStep = processExe.CurrentStep, ListStep = listStepExe, IsHandle = true, Status = processExe.Status, ProcessName = processExe.ProcessExecutionName }; res.OnSuccess(result); return(res); } else { res = GetStepExecutionForView(processExe, currentUserID); return(res); } }
// Receive an event containing new image processing parameters. // Store these parameters and then try to update the image public async void AdjustImage_EventHandler(object sender, ImageAdjusterEventArgs e) { if (e == null) { // Shouldn't happen, but... return; } string path = DataEntryHandler.TryGetFilePathFromGlobalDataHandler(); if (String.IsNullOrEmpty(path)) { // The file cannot be opened or is not displayable. // Signal change in image state, which essentially says there is no displayable image to adjust (consumed by ImageAdjuster) this.OnImageStateChanged(new ImageStateEventArgs(false)); // Signal change in image state (consumed by ImageAdjuster) return; } if (e.OpenExternalViewer) { // The event says to open an external photo viewer. Try to do so. // Note that we don't do any image processing on this event if if this is the case. if (ProcessExecution.TryProcessStart(path) == false) { // Can't open the image file with an external view. Note that file must exist at this point as we checked for that above. Dialogs.MarkableCanvasCantOpenExternalPhotoViewerDialog(Util.GlobalReferences.MainWindow, Path.GetExtension(path)); } return; } // Process the image based on the current image processing arguments. if (e.ForceUpdate == false && (e.Contrast == this.lastContrast && e.Brightness == this.lastBrightness && e.DetectEdges == this.lastDetectEdges && e.Sharpen == this.lastSharpen && e.UseGamma == this.lastUseGamma && e.GammaValue == this.lastGammaValue)) { // If there is no change from the last time we processed an image, abort as it would not make any difference to what the user sees return; } this.contrast = e.Contrast; this.brightness = e.Brightness; this.detectEdges = e.DetectEdges; this.sharpen = e.Sharpen; this.useGamma = e.UseGamma; this.gammaValue = e.GammaValue; this.timerImageProcessingUpdate.Start(); await UpdateAndProcessImage().ConfigureAwait(true); }
// Tutorial guides (via your browser) private void MenuItemGuidesAndManuals_Click(object sender, RoutedEventArgs e) { string prefix = "https://saul.cpsc.ucalgary.ca/timelapse/uploads/Guides/"; if (sender is MenuItem mi) { switch (mi.Name) { case "MenuItemGoToManualsPage": ProcessExecution.TryProcessStart(new Uri("https://saul.cpsc.ucalgary.ca/timelapse/pmwiki.php?n=Main.UserGuide")); break; case "MenuItemQuickStartGuide": ProcessExecution.TryProcessStart(new Uri(prefix + "TimelapseQuickStartGuide.pdf")); break; case "MenuItemReferenceGuide": ProcessExecution.TryProcessStart(new Uri(prefix + "TimelapseReferenceGuide.pdf")); break; case "MenuItemTemplateGuide": ProcessExecution.TryProcessStart(new Uri(prefix + "TimelapseTemplateGuide.pdf")); break; case "MenuItemImageRecognitionGuide": ProcessExecution.TryProcessStart(new Uri(prefix + "TimelapseImageRecognitionGuide.pdf")); break; case "MenuItemDatabaseGuide": ProcessExecution.TryProcessStart(new Uri(prefix + "TimelapseDatabaseGuide.pdf")); break; default: break; } } }
// Download tutorial sample images (via your web browser) private void MenuDownloadSampleImages_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("http://saul.cpsc.ucalgary.ca/timelapse/pmwiki.php?n=Main.UserGuide")); }
// Tutorial manual (via your browser) private void MenuTutorialManual_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("http://saul.cpsc.ucalgary.ca/timelapse/uploads/Installs/Timelapse2/Timelapse2Manual.pdf")); }
// Timelapse web page (via your browser): Timelapse home page private void MenuTimelapseWebPage_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("http://saul.cpsc.ucalgary.ca/timelapse")); }
private void MenuMailToTimelapseDevelopers_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("mailto:[email protected]")); }
// Timelapse mailing list - Send email private void MenuMailToTimelapseMailingList_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("mailto:[email protected]")); }
// Timelapse mailing list - Join it(via your web browser) private void MenuJoinTimelapseMailingList_Click(object sender, RoutedEventArgs e) { ProcessExecution.TryProcessStart(new Uri("http://mailman.ucalgary.ca/mailman/listinfo/timelapse-l")); }
// Export data for this image set as a .csv file // Export data for this image set as a .csv file and preview in Excel private void MenuItemExportCsv_Click(object sender, RoutedEventArgs e) { if (this.State.SuppressSelectedCsvExportPrompt == false && this.DataHandler.FileDatabase.ImageSet.FileSelection != FileSelectionEnum.All) { // Export data for this image set as a.csv file, but confirm, as only a subset will be exported since a selection is active if (Dialogs.MenuFileExportCSVOnSelectionDialog(this) == false) { return; } } // Generate the file names/path string csvFileName = Path.GetFileNameWithoutExtension(this.DataHandler.FileDatabase.FileName) + ".csv"; string csvFilePath = Path.Combine(this.FolderPath, csvFileName); // Backup the csv file if it exists, as the export will overwrite it. if (FileBackup.TryCreateBackup(this.FolderPath, csvFileName)) { this.StatusBar.SetMessage("Backup of csv file made."); } else { this.StatusBar.SetMessage("No csv file backup was made."); } try { CsvReaderWriter.ExportToCsv(this.DataHandler.FileDatabase, csvFilePath, this.excludeDateTimeAndUTCOffsetWhenExporting); } catch (IOException exception) { // Can't write the spreadsheet file Dialogs.MenuFileCantWriteSpreadsheetFileDialog(this, csvFilePath, exception.GetType().FullName, exception.Message); return; } MenuItem mi = (MenuItem)sender; if (mi == this.MenuItemExportAsCsvAndPreview) { // Show the file in excel // Create a process that will try to show the file ProcessStartInfo processStartInfo = new ProcessStartInfo { UseShellExecute = true, RedirectStandardOutput = false, FileName = csvFilePath }; if (ProcessExecution.TryProcessStart(processStartInfo) == false) { // Can't open excel Dialogs.MenuFileCantOpenExcelDialog(this, csvFilePath); return; } } else if (this.State.SuppressCsvExportDialog == false) { Dialogs.MenuFileCSVDataExportedDialog(this, csvFileName); } this.StatusBar.SetMessage("Data exported to " + csvFileName); }
// Export data for this image set as a .csv file // Export data for this image set as a .csv file and preview in Excel private async void MenuItemExportCsv_Click(object sender, RoutedEventArgs e) { if (this.State.SuppressSelectedCsvExportPrompt == false && this.DataHandler.FileDatabase.ImageSet.FileSelection != FileSelectionEnum.All) { // Export data for this image set as a.csv file, but confirm, as only a subset will be exported since a selection is active if (Dialogs.MenuFileExportCSVOnSelectionDialog(this) == false) { return; } } // Generate the candidate file name/path string csvFileName = Path.GetFileNameWithoutExtension(this.DataHandler.FileDatabase.FileName) + ".csv"; // Get the selected filepath from the user if (false == Dialogs.TryGetFileFromUserUsingSaveFileDialog( "Export and save your data as a CSV file", csvFileName, String.Format("CSV files (*{0})|*{0}", Constant.File.CsvFileExtension), Constant.File.CsvFileExtension, out string selectedCSVFilePath)) { // Abort, as file selection is cancelled this.StatusBar.SetMessage("Csv file export cancelled."); return; } if (File.Exists(selectedCSVFilePath) && new System.IO.FileInfo(selectedCSVFilePath).Attributes.HasFlag(System.IO.FileAttributes.ReadOnly)) { // The file exists but its read only... Dialogs.FileCantOpen(GlobalReferences.MainWindow, selectedCSVFilePath, true); this.StatusBar.SetMessage("Csv file export cancelled."); return; } // Backup the csv file if it exists, as the export will overwrite it. if (FileBackup.TryCreateBackup(this.FolderPath, selectedCSVFilePath)) { this.StatusBar.SetMessage("Backup of csv file made."); } else { this.StatusBar.SetMessage("No csv file backup was made."); } try { // Show the Busy indicator this.BusyCancelIndicator.IsBusy = true; if (false == await CsvReaderWriter.ExportToCsv(this.DataHandler.FileDatabase, selectedCSVFilePath, this.State.CSVDateTimeOptions, this.State.CSVInsertSpaceBeforeDates)) { Dialogs.FileCantOpen(GlobalReferences.MainWindow, selectedCSVFilePath, true); return; } // Hide the Busy indicator this.BusyCancelIndicator.IsBusy = false; } catch (Exception exception) { // Can't write the spreadsheet file Dialogs.MenuFileCantWriteSpreadsheetFileDialog(this, selectedCSVFilePath, exception.GetType().FullName, exception.Message); return; } MenuItem mi = (MenuItem)sender; if (mi == this.MenuItemExportAsCsvAndPreview) { // Show the file in excel // Create a process that will try to show the file ProcessStartInfo processStartInfo = new ProcessStartInfo { UseShellExecute = true, RedirectStandardOutput = false, FileName = selectedCSVFilePath }; if (ProcessExecution.TryProcessStart(processStartInfo) == false) { // Can't open excel Dialogs.MenuFileCantOpenExcelDialog(this, selectedCSVFilePath); return; } } else if (this.State.SuppressCsvExportDialog == false) { Dialogs.MenuFileCSVDataExportedDialog(this, selectedCSVFilePath); } this.StatusBar.SetMessage("Data exported to " + selectedCSVFilePath); }
public void MenuVideoPlay_Click(object sender, RoutedEventArgs e) { string prefix = "https://saul.cpsc.ucalgary.ca/timelapse/uploads/Videos/"; if (sender is MenuItem mi) { switch (mi.Name) { case "MenuItemVideoWhirlwindTour": ProcessExecution.TryProcessStart(new Uri(prefix + "WhirlwindTourOfTimelapse.mp4")); break; case "MenuItemVideoImageRecognition": ProcessExecution.TryProcessStart(new Uri("http://grouplab.cpsc.ucalgary.ca/grouplab/uploads/Publications/Publications/2021-05-ImageRecognition-Video.mp4")); break; case "MenuItemVideoTemplateEditor": ProcessExecution.TryProcessStart(new Uri(prefix + "TemplateEditor.mp4")); break; case "MenuItemVideoPlayer": ProcessExecution.TryProcessStart(new Uri(prefix + "UsingVideo.mp4")); break; case "MenuItemVideoClassifyingDarkImages": ProcessExecution.TryProcessStart(new Uri(prefix + "Options-DarkThresholds.mp4")); break; case "MenuItemVideoRepositionDataEntryPanel": ProcessExecution.TryProcessStart(new Uri(prefix + "RepositioningTabsAndPanels.mp4")); break; case "MenuItemVideoUsingOverview": ProcessExecution.TryProcessStart(new Uri(prefix + "UsingTheOverview.mp4")); break; case "MenuItemVideoPopulateEpisodeData": ProcessExecution.TryProcessStart(new Uri(prefix + "PopulateEpisodeData.mp4")); break; case "MenuItemVideoViewingPopups": ProcessExecution.TryProcessStart(new Uri(prefix + "EpisodePopups.mp4")); break; case "MenuItemVideoRandomSampling": ProcessExecution.TryProcessStart(new Uri(prefix + "RandomSample.mp4")); break; case "MenuItemVideoDuplicatingRecords": ProcessExecution.TryProcessStart(new Uri(prefix + "DuplicateThisRecord.mp4")); break; case "MenuItemVideoCompanionImageRecognition": ProcessExecution.TryProcessStart(new Uri(prefix + "Video-TimelapseImageRecognitionGuide.mp4")); break; case "MenuItemVideoCompanionQuickStart": ProcessExecution.TryProcessStart(new Uri(prefix + "Video-TimelapseQuickStartGuide.mp4")); break; default: break; } } }
public ProcessExecution CreateExecution(ProcessExecution processExecution) { _repository.Session.Save(processExecution); return(processExecution); }
public ServiceResponse InitProcessExe(DataInitProcessExe data, int currentUserID) { DateTime now = DateTime.Now; ServiceResponse res = new ServiceResponse(); if (data == null) { res.OnError("Data empty"); return(res); } var process = _processRepository.GetSingleById(data.ProcessSettingId); var stepExe = new StepExecution(); stepExe.StepExecutionData = data.StepExecutionData; stepExe.NextAssigneeId = data.AssigneeId; stepExe.CurrentAssigneeId = currentUserID; stepExe.CreatedDate = now; stepExe.CompletedDate = now; stepExe.ProcessStepId = data.ProcessStepId; var nextStepExe = new StepExecution(); nextStepExe.CurrentAssigneeId = data.AssigneeId; nextStepExe.CreatedDate = now; var processExe = new ProcessExecution(); processExe.ProcessExecutionName = process.ProcessName; processExe.ProcessSettingId = process.ProcessId; processExe.CurrentStepId = data.ProcessStepId; processExe.OwnerId = currentUserID; processExe.Status = 1; processExe.CreatedDate = now; processExe.StepExecutions = new List <StepExecution>() { stepExe }; var nextStep = GetNextStep(data.ProcessStepId, process.ProcessId); if (nextStep != null) { processExe.CurrentStepId = nextStep.ProcessStepId; nextStepExe.ProcessStepId = nextStep.ProcessStepId; processExe.StepExecutions.Add(nextStepExe); } else { processExe.CurrentStepId = -999; } _processExeRepository.Add(processExe); this.Save(); res.OnSuccess(processExe); return(res); }
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) { ProcessExecution.TryProcessStart(e.Uri); e.Handled = true; }
public ProcessExecution UpdateExecution(ProcessExecution processExecution) { _repository.Session.Update(processExecution); return(processExecution); }
// Load the Uri provided in a web browser private void Link_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) { ProcessExecution.TryProcessStart(e.Uri); e.Handled = true; }
public static void DemoMethod() { _processService = new ProcessService(new Repository <Process>(new UnitOfWork())); Process processJob = _processService.GetByCode(JOB_CODE); bool CAN_EXECUTE = processJob != null && processJob.Status && !processJob.Running; //Esta habilitado y no está corriendo (validacion BD) ProcessExecution processExecution = new ProcessExecution { Process = processJob, StartAt = DateUtil.GetDateTimeNow(), Status = true }; _processService.CreateExecution(processExecution); Boolean.TryParse(System.Configuration.ConfigurationManager.AppSettings["Jobs.EnabledJobs"], out bool NotificationProcessEnabled); StringBuilder strResult = new StringBuilder(); if (Monitor.TryEnter(thisLock)) { try { if (!executing && NotificationProcessEnabled && CAN_EXECUTE) { processJob.Running = true; _processService.Update(processJob); //TODO: Implementar logica de negocio especifica System.Diagnostics.Trace.TraceInformation(string.Format("[DemoJob.DemoMethod] Executing at {0}", DateTime.Now)); strResult.Append(string.Format("Executing at {0}", DateUtil.GetDateTimeNow())); Thread.Sleep(5000); strResult.Append(string.Format("| End at {0}", DateUtil.GetDateTimeNow())); //UPDATE JOB DATABASE processExecution.EndAt = DateUtil.GetDateTimeNow(); processExecution.Status = false; processExecution.Success = true; processExecution.Result = strResult.ToString(); _processService.UpdateExecution(processExecution); processJob.Running = false; processJob.Result = strResult.ToString(); processJob.LastExecutionAt = DateUtil.GetDateTimeNow(); _processService.Update(processJob); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Trace.TraceInformation(ex.Message); if (processJob != null) { strResult.Append(string.Format("ERROR: {0}", ex.Message)); processExecution.EndAt = DateUtil.GetDateTimeNow(); processExecution.Status = false; processExecution.Success = false; processExecution.Result = strResult.ToString(); _processService.UpdateExecution(processExecution); processJob.Running = false; processJob.Result = strResult.ToString(); processJob.LastExecutionAt = DateUtil.GetDateTimeNow(); _processService.Update(processJob); } } finally { executing = false; Monitor.Exit(thisLock); } } }