Exemple #1
0
        /// <summary>
        /// Returns a BatchExportSettingsViewModel object that wraps
        /// the last used BatchExportSettings stored in the
        /// workbookContent's hidden storage area, or the one stored
        /// in the assembly's Properties, or Null if no stored object exists.
        /// </summary>
        /// <param name="workbookContext"></param>
        /// <returns>BatchExportSettingsViewModel object with last
        /// used settings model, or Null if no such object exists.</returns>
        public static BatchExportSettingsViewModel FromLastUsed(Workbook workbookContext)
        {
            BatchExportSettings settings = BatchExportSettings.FromLastUsed(workbookContext);

            if (settings != null)
            {
                Logger.Info("FromLastUsed(workbookContext): Got settings for workbook context, creating view model");
                return(new BatchExportSettingsViewModel(settings));
            }
            else
            {
                Logger.Info("FromLastUsed(workbookContext): Did not get settings for workbook context");
                return(BatchExportSettingsViewModel.FromLastUsed());
            }
        }
Exemple #2
0
        /// <summary>
        /// Returns a BatchExportSettingsViewModel object that wraps
        /// the last used BatchExportSettings stored in the assembly's
        /// Properties, or Null if no stored object exists.
        /// </summary>
        /// <returns>BatchExportSettingsViewModel object with last
        /// used settings model, or Null if no such object exists.</returns>
        public static BatchExportSettingsViewModel FromLastUsed()
        {
            BatchExportSettings settings = BatchExportSettings.FromLastUsed();

            if (settings != null)
            {
                Logger.Info("FromLastUsed(): Got last used settings, creating view model");
                return(new BatchExportSettingsViewModel(settings));
            }
            else
            {
                Logger.Info("FromLastUsed(): Did not get last used settings, returning null");
                return(null);
            }
        }
 public ExportFileName(string template, FileType fileType, BatchExportSettings settings)
 {
     Template  = template;
     Counter   = 0;
     FileType  = fileType;
     _settings = settings;
     _placeholderReplacements = new Dictionary <string, Func <string> >()
     {
         { Strings.Workbook.ToUpper(), () =>
           { return(Path.GetFileNameWithoutExtension(this.CurrentWorkbookName)); } },
         { Strings.Worksheet.ToUpper(), () => { return(this.CurrentWorksheetName); } },
         { Strings.Index.ToUpper(), () => { return(String.Format("{0:000}", Counter)); } },
         { Strings.Name.ToUpper(), () => { return(this.CurrentObjectName); } },
     };
     Directory      = String.Empty;
     _upperTemplate = template.ToUpper();
     _needIndex     = NeedToAddIndex(_upperTemplate);
     SetExtension();
 }
Exemple #4
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);
        }
Exemple #5
0
 public BatchExportSettingsViewModel(BatchExportSettings settings)
     : this(new BatchExporter(settings as BatchExportSettings))
 {
 }
 public BatchExporter(BatchExportSettings settings)
     : base()
 {
     Settings = settings;
 }
 public ExportFileName(string directory, string template, FileType fileType, BatchExportSettings settings)
     : this(template, fileType, settings)
 {
     Directory = directory;
 }
 // TODO: Clean up those constructor signatures
 public ExportFileName(BatchExportSettings settings)
     : this(settings.Path, settings.FileName, settings.Preset.FileType, settings)
 {
 }