Пример #1
0
        // 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);
        }
Пример #2
0
 // 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;
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        // 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);
        }
Пример #8
0
        // 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;
                }
            }
        }
Пример #9
0
 // 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"));
 }
Пример #10
0
 // 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"));
 }
Пример #11
0
 // 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"));
 }
Пример #12
0
 private void MenuMailToTimelapseDevelopers_Click(object sender, RoutedEventArgs e)
 {
     ProcessExecution.TryProcessStart(new Uri("mailto:[email protected]"));
 }
Пример #13
0
 // Timelapse mailing list - Send email
 private void MenuMailToTimelapseMailingList_Click(object sender, RoutedEventArgs e)
 {
     ProcessExecution.TryProcessStart(new Uri("mailto:[email protected]"));
 }
Пример #14
0
 // 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"));
 }
Пример #15
0
        // 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);
        }
Пример #16
0
        // 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);
        }
Пример #17
0
        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;
                }
            }
        }
Пример #18
0
 public ProcessExecution CreateExecution(ProcessExecution processExecution)
 {
     _repository.Session.Save(processExecution);
     return(processExecution);
 }
Пример #19
0
        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);
        }
Пример #20
0
 private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     ProcessExecution.TryProcessStart(e.Uri);
     e.Handled = true;
 }
Пример #21
0
 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);
                }
            }
        }