コード例 #1
0
        /// <summary>
        /// Performs a batch export using the last used settings, if available.
        /// </summary>
        public void ExportBatch()
        {
            Logger.Info("ExportBatch");
            BatchExportSettingsViewModel bvm = BatchExportSettingsViewModel.FromLastUsed(
                Instance.Default.ActiveWorkbook);

            Logger.Info("BatchExportSettingsViewModel.FromLastUsed: {0}", bvm);
            if ((bvm != null) && bvm.ChooseFolderCommand.CanExecute(null))
            {
                bvm.ChooseFolderMessage.Sent    += ChooseFolderMessage_Sent;
                bvm.ShowProgressMessage.Sent    += Dispatcher.Exporter_ShowProgress_Sent;
                bvm.ProcessFinishedMessage.Sent += Dispatcher.Exporter_ProcessFinished_Sent;
                bvm.ChooseFolderCommand.Execute(null);
            }
            else
            {
                // We did get a view model, but its ChooseFolderCommand is disabled,
                // which means that the selected batch export options are invalid
                // in the current context.
                if (bvm != null)
                {
                    bvm = new BatchExportSettingsViewModel();
                    // Do not 'sanitize' the export options, so that the user
                    // can see the selected, but disabled options.
                    bvm.ShowProgressMessage.Sent    += Dispatcher.Exporter_ShowProgress_Sent;
                    bvm.ProcessFinishedMessage.Sent += Dispatcher.Exporter_ProcessFinished_Sent;
                    bvm.InjectInto <Views.BatchExportSettingsView>().ShowDialogInForm();
                }
                else
                {
                    Dispatcher.Execute(Command.BatchExport);
                }
            }
        }
コード例 #2
0
ファイル: Dispatcher.cs プロジェクト: treasureboy/XLToolbox
        static void BatchExport()
        {
            BatchExportSettingsViewModel vm = BatchExportSettingsViewModel.FromLastUsed(
                Instance.Default.ActiveWorkbook);

            if (vm == null)
            {
                vm = new BatchExportSettingsViewModel();
            }
            vm.SanitizeOptions();
            vm.ShowProgressMessage.Sent    += Exporter_ShowProgress_Sent;
            vm.ProcessFinishedMessage.Sent += Exporter_ProcessFinished_Sent;
            vm.InjectInto <Export.Views.BatchExportSettingsView>().ShowDialogInForm();
            // NotificationAction a = new NotificationAction();
            // a.Caption = Strings.ScreenshotExport;
            // a.Message = Strings.GraphicHasNoCopyMethod;
            // a.Invoke();
        }
コード例 #3
0
        public void BatchExport(
            BatchExportScope scope, BatchExportObjects objects,
            BatchExportLayout layout, int expectedNumberOfFiles)
        {
            // ExcelInstance.Application.Visible = true;
            Workbook wb = Instance.Default.CreateWorkbook(3);

            Helpers.CreateSomeCharts(wb.Worksheets[1], 1);
            Helpers.CreateSomeCharts(wb.Worksheets[2], 2);
            Helpers.CreateSomeCharts(wb.Worksheets[3], 3);
            Helpers.CreateSomeShapes(wb.Worksheets[1], 3);
            Helpers.CreateSomeShapes(wb.Worksheets[2], 2);
            Helpers.CreateSomeShapes(wb.Worksheets[3], 1);
            wb.Charts.Add(After: wb.Sheets[wb.Sheets.Count]);
            wb.Sheets[1].Activate();
            BatchExportSettings settings = new BatchExportSettings();

            settings.Path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            Directory.CreateDirectory(settings.Path);
            settings.FileName = "{workbook}_{worksheet}_{index}";
            settings.Preset   = new Preset(FileType.Png, 300, ColorSpace.Rgb);
            settings.Layout   = layout;
            settings.Objects  = objects;
            settings.Scope    = scope;
            BatchExporter exporter          = new BatchExporter(settings);
            BatchExportSettingsViewModel vm = new BatchExportSettingsViewModel(exporter);
            bool finished = false;
            bool abort    = false;

            vm.ProcessFinishedMessage.Sent += (sender, args) => { finished = true; };
            vm.StartProcess();
            Timer t = new Timer((obj) => abort = true, null, 8000, Timeout.Infinite);

            while (!finished && !abort)
            {
                ;
            }
            t.Dispose();
            Assert.IsFalse(abort, "Export progress did not finish, timeout reached.");
            Assert.AreEqual(expectedNumberOfFiles,
                            Directory.GetFiles(settings.Path).Length);
            Directory.Delete(settings.Path, true);
        }