Exemple #1
0
        private void ReloadMultimediaPanel(List <MultimediaLink> data)
        {
            JobExecutor.QueueJob(() => {
                _model = new ObservableCollection <MultimediaLinkViewModel>(data.ConvertAll((item) => {
                    MultimediaLinkViewModel viewmodel = null;
                    this.InvokeIfRequired(() => {
                        viewmodel              = new MultimediaLinkViewModel(item);
                        viewmodel.DataChanged += new DataChangedHandler((m) => {
                            RegisterUniquePendingChange(new UpdateMultimediaLinkCommand(viewmodel.Model, CategoryType));
                        });
                    });
                    return(viewmodel);
                }));
                this.InvokeIfRequired(() => {
                    this.thumbList.ItemsSource = _model;
                });

                foreach (MultimediaLinkViewModel item in _model)
                {
                    this.BackgroundInvoke(() => {
                        GenerateThumbnail(item, THUMB_SIZE);
                    });
                }
            });
        }
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            btnCancel.IsEnabled = false;
            btnOK.IsEnabled     = false;
            lblStatus.Content   = "Generating points...";
            this.Cursor         = Cursors.Wait;

            var user = PluginManager.Instance.User;

            Config.SetUser <int>(user, "PointSetOptionWindow.PreviousPointSize", shapeOptions.Size);
            Config.SetUser(user, "PointSetOptionWindow.PreviousColor", shapeOptions.Color);
            Config.SetUser(user, "PointSetOptionWindow.PreviousShape", shapeOptions.Shape);

            JobExecutor.QueueJob(() => {
                if (Generator != null)
                {
                    Points = Generator();
                    this.InvokeIfRequired(() => {
                        Points.PointColor  = shapeOptions.Color;
                        Points.PointShape  = shapeOptions.Shape;
                        Points.Size        = shapeOptions.Size;
                        Points.DrawOutline = shapeOptions.DrawOutline;
                    });
                }
                this.InvokeIfRequired(() => {
                    lblStatus.Content = "";
                    this.DialogResult = true;
                    this.Close();
                    this.Cursor = Cursors.Arrow;
                });
            });
        }
Exemple #3
0
        public void Export(Window parentWindow, DataMatrix matrix, String datasetName, IProgressObserver progress)
        {
            this.ProgressObserver = progress;
            object options = GetOptions(parentWindow, matrix, datasetName);

            JobExecutor.QueueJob(() => {
                this.ExportImpl(parentWindow, matrix, datasetName, options);
                ProgressEnd("");
            });
        }
 private void ExecuteReport()
 {
     JobExecutor.QueueJob(() => {
         try {
             this.WaitCursor();
             btnRerun.InvokeIfRequired(() => btnRerun.IsEnabled = false);
             StatusMessage("Running report...");
             this.InvokeIfRequired(() => { DisplayLoading(); });
             DataMatrix data = Report.ExtractReportData(this);
             this.InvokeIfRequired(() => { DisplayReportResults(data); });
         } catch (Exception ex) {
             this.NormalCursor();
             this.ProgressEnd("An error occured executing the report");
             this.InvokeIfRequired(() => { DisplayException(ex); });
         } finally {
             btnRerun.InvokeIfRequired(() => btnRerun.IsEnabled = true);
             this.NormalCursor();
         }
     });
 }
Exemple #5
0
        private void SaveAll()
        {
            var dlg = new System.Windows.Forms.FolderBrowserDialog();

            dlg.ShowNewFolderButton = true;
            var result = dlg.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                JobExecutor.QueueJob(() => {
                    if (Progress != null)
                    {
                        Progress.ProgressStart("Exporting files...");
                    }
                    int count = 0;
                    foreach (MultimediaLinkViewModel vm in _model)
                    {
                        var destFile = string.Format("{0}\\{1}.{2}", dlg.SelectedPath, vm.Name, vm.Extension);
                        var filename = _tempFileManager.GetContentFileName(vm.MultimediaID, vm.Extension);
                        try {
                            File.Copy(filename, destFile, true);
                            count++;
                            if (Progress != null)
                            {
                                double percent = (((double)count) / ((double)_model.Count)) * 100.0;
                                Progress.ProgressMessage(string.Format("Exporting files ({0} of {1})", count, _model.Count), percent);
                            }
                        } catch (Exception ex) {
                            GlobalExceptionHandler.Handle(ex);
                        }
                    }
                    if (Progress != null)
                    {
                        Progress.ProgressEnd(string.Format("{0} files exported.", count));
                    }
                });
            }
        }
 private void DisplayMultimedia(MultimediaLinkViewModel selected)
 {
     if (selected != null)
     {
         JobExecutor.QueueJob(() => {
             string filename = _tempFileManager.GetContentFileName(selected.MultimediaID, selected.Extension);
             var image       = GraphicsUtils.LoadImageFromFile(filename);
             imgPreview.InvokeIfRequired(() => {
                 imgPreview.Stretch          = Stretch.Uniform;
                 imgPreview.StretchDirection = StretchDirection.DownOnly;
                 imgPreview.Source           = image;
                 gridInfo.DataContext        = image;
                 FileInfo f           = new FileInfo(filename);
                 lblImageInfo.Content = string.Format("{0}x{1}  {2} DPI  {3}", image.PixelWidth, image.PixelHeight, image.DpiX, ByteLengthConverter.FormatBytes(f.Length));
             });
         });
     }
     else
     {
         imgPreview.Source    = null;
         lblImageInfo.Content = "";
     }
 }
Exemple #7
0
        void MultimediaThumbnailViewer_Loaded(object sender, RoutedEventArgs e)
        {
            var service = new SupportService(PluginManager.Instance.User);

            if (_model == null)
            {
                using (new OverrideCursor(Cursors.Wait)) {
                    if (ReportData != null && ReportData.ContainsColumn("MultimediaLink"))
                    {
                        int index = ReportData.IndexOf("MultimediaLink");
                        _model = new ObservableCollection <MultimediaLinkViewModel>();
                        foreach (MatrixRow row in ReportData)
                        {
                            var link = row[index] as MultimediaLink;
                            if (link != null)
                            {
                                _model.Add(new MultimediaLinkViewModel(link));
                            }
                        }
                        this.thumbList.ItemsSource = _model;
                    }
                }

                lock (_model) {
                    if (!_threadRunning)
                    {
                        _threadRunning = true;
                        JobExecutor.QueueJob(() => {
                            if (_model != null)
                            {
                                if (Progress != null)
                                {
                                    Progress.ProgressStart("Generating thumbnails...");
                                }

                                int count = 0;
                                foreach (MultimediaLinkViewModel vm in _model)
                                {
                                    bool generate = false;

                                    vm.InvokeIfRequired(() => {
                                        generate = vm.Thumbnail == null;
                                    });

                                    if (generate)
                                    {
                                        GenerateThumbnail(vm, THUMB_SIZE);
                                    }

                                    count++;
                                    if (Progress != null)
                                    {
                                        double percent = (((double)count) / ((double)_model.Count)) * 100.0;
                                        Progress.ProgressMessage(string.Format("Generating thumbnails ({0} of {1})", count, _model.Count), percent);
                                    }
                                }

                                if (Progress != null)
                                {
                                    Progress.ProgressEnd(string.Format("{0} thumbnails generated", count));
                                }
                            }
                            _threadRunning = false;
                        });
                    }
                }
            }
        }
        public void CommitPendingChanges(Action successAction = null)
        {
            if (User == null)
            {
                throw new Exception("User object has not been set on the Control Host Window");
            }
#if DEBUG
            Logger.Debug("About to commit the following changes:");
            foreach (DatabaseCommand command in _pendingChanges)
            {
                Logger.Debug("{0}", command);
            }
#endif


            // First validate each command...Commands can produce messages if they are not valid.
            var errorMessages   = new List <string>();
            var warningMessages = new List <string>();

            var messages = new ValidationMessages();

            foreach (DatabaseCommand command in _pendingChanges)
            {
                command.Validate(messages);
            }

            if (messages != null && messages.Messages.Count > 0)
            {
                foreach (ValidationMessage message in messages.Messages)
                {
                    switch (message.ValidationType)
                    {
                    case ValidationType.Error:
                        errorMessages.Add(message.Message);
                        break;

                    case ValidationType.Warning:
                        warningMessages.Add(message.Message);
                        break;
                    }
                }
            }

            if (errorMessages.Count > 0)
            {
                ErrorMessage.Show("One or more validation errors occured:\n\n{0}\n\nOperation aborted.", errorMessages.Join("\n\n"));
                return;
            }

            if (warningMessages.Count > 0)
            {
                if (!WarningMessage.Show("Please acknowledge the following warning(s) by clicking 'yes' to continue this operation, or 'no' to cancel this operation:\n\n{0}\n\nDo you wish to continue?", warningMessages.Join("\n\n")))
                {
                    return;
                }
            }

            // It may be that this control is aggregated as part of a larger control. This means that, come save time, there
            // may already be a transaction pending. If so, don't create a new one, just piggy back on the existing
            bool commitTrans = false;  // flag to let us know if we are responsible for the transaction...

            if (!User.InTransaction)
            {
                User.BeginTransaction();
                commitTrans = true;
            }
            try {
                foreach (DatabaseCommand command in _pendingChanges)
                {
                    command.Process(User);
                }

                if (commitTrans)
                {
                    User.CommitTransaction();
                }

                if (successAction != null)
                {
                    successAction();
                }

                foreach (IChangeContainerObserver observer in _observers)
                {
                    observer.OnChangesCommitted();
                }

                if (ChangesCommitted != null)
                {
                    ChangesCommitted(this);
                }

                _observers.Clear();
                _pendingChanges.Clear();

                // Reload the pinboard...
                JobExecutor.QueueJob(() => {
                    PluginManager.Instance.RefreshPinBoard();
                });
            } catch (Exception ex) {
                if (commitTrans)
                {
                    User.RollbackTransaction();
                }
                GlobalExceptionHandler.Handle(ex);
            }
        }