示例#1
0
        /// <summary>
        /// Writes all workbooks associated with a workbook creation plugin to the output directory.
        /// </summary>
        /// <param name="outputLocation">The absolute path where plugin output was written.</param>
        /// <param name="plugin">The workbook creation plugin that ran.</param>
        /// <param name="response">The response object, containing information about the results of executing the plugin.</param>
        /// <param name="outputDatabaseName">The name of the Postgres database that the workbook should connect to.</param>
        protected IEnumerable <string> WriteWorkbooksToDisk(string outputLocation, IWorkbookCreationPlugin plugin, IPluginResponse response, string outputDatabaseName)
        {
            var workbookFilePaths = new List <string>();

            // Make sure we have something to do.
            if (!response.SuccessfulExecution)
            {
                return(workbookFilePaths);
            }
            if (response.GeneratedNoData)
            {
                Log.InfoFormat("Skipped saving workbooks for {0} because the plugin did not generate any backing data.", plugin.GetType().Name);
                return(workbookFilePaths);
            }

            // Replace connection information in workbook and flush to disk.
            if (plugin.WorkbookNames != null)
            {
                foreach (var workbookName in plugin.WorkbookNames)
                {
                    var workbookEditor = new WorkbookEditor(outputLocation, postgresConnectionInfo, outputDatabaseName);

                    using (var workbookInputStream = plugin.GetWorkbook(workbookName))
                    {
                        var processedWorkbook = workbookEditor.Process(workbookInputStream, workbookName);
                        workbookFilePaths.Add(processedWorkbook.FullName);
                        Log.InfoFormat("Saved workbook to '{0}'!", processedWorkbook.FullName);
                    }
                }
            }

            return(workbookFilePaths);
        }
示例#2
0
        /// <summary>
        /// Writes all workbooks associated with a workbook creation plugin to the output directory.
        /// </summary>
        /// <param name="plugin">The workbook creation plugin that ran.</param>
        /// <param name="response">The response object, containing information about the results of executing the plugin.</param>
        protected void WriteWorkbooksToDisk(IWorkbookCreationPlugin plugin, IPluginResponse response)
        {
            // Replace connection information in workbook and flush to disk.
            if (response.SuccessfulExecution)
            {
                ICollection <string> workbookNames = plugin.WorkbookNames;

                if (response.GeneratedNoData)
                {
                    Log.InfoFormat("Skipped saving {0} {1} because the plugin did not generate any backing data.", plugin.GetType().Name, "workbook".Pluralize(workbookNames.Count));
                    return;
                }

                foreach (var workbookName in workbookNames)
                {
                    WorkbookEditor workbookEditor = new WorkbookEditor(workbookName, plugin.GetWorkbookXml(workbookName));
                    workbookEditor.ReplacePostgresConnections(logsharkRequest.Configuration.PostgresConnectionInfo, logsharkRequest.PostgresDatabaseName);
                    workbookEditor.RemoveThumbnails();

                    string workbookFilePath = workbookEditor.Save(GetOutputLocation(logsharkRequest.RunId));
                    response.WorkbooksOutput.Add(workbookFilePath);
                    Log.InfoFormat("Saved workbook to '{0}'!", workbookFilePath);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Writes all workbooks associated with a workbook creation plugin to the output directory.
        /// </summary>
        /// <param name="outputLocation">The absolute path where the workbooks should be written.</param>
        /// <param name="plugin">The workbook creation plugin that ran.</param>
        /// <param name="response">The response object, containing information about the results of executing the plugin.</param>
        /// <param name="postgresDatabaseName">The name of the Postgres database that the workbook should connect to.</param>
        protected IEnumerable <string> WriteWorkbooksToDisk(string outputLocation, IWorkbookCreationPlugin plugin, IPluginResponse response, string postgresDatabaseName)
        {
            var workbookFilePaths = new List <string>();

            // Make sure we have something to do.
            if (!response.SuccessfulExecution)
            {
                return(workbookFilePaths);
            }
            if (response.GeneratedNoData)
            {
                Log.InfoFormat("Skipped saving workbooks for {0} because the plugin did not generate any backing data.", plugin.GetType().Name);
                return(workbookFilePaths);
            }

            // Replace connection information in workbook and flush to disk.
            if (plugin.WorkbookNames != null)
            {
                foreach (var workbookName in plugin.WorkbookNames)
                {
                    WorkbookEditor workbookEditor = new WorkbookEditor(workbookName, plugin.GetWorkbookXml(workbookName));
                    workbookEditor.ReplacePostgresConnections(postgresConnectionInfo, postgresDatabaseName);
                    workbookEditor.RemoveThumbnails();

                    string workbookFilePath = workbookEditor.Save(outputLocation);
                    workbookFilePaths.Add(workbookFilePath);
                    Log.InfoFormat("Saved workbook to '{0}'!", workbookFilePath);
                }
            }

            return(workbookFilePaths);
        }
        public void TestNeuterCells()
        {
            WorkbookStream wbs = TestHelpers.GetBuiltinHiddenLblSheet();

            WorkbookEditor wbe = new WorkbookEditor(wbs);

            wbs = wbe.NeuterAutoOpenCells();

            Formula            autoOpenCell     = wbs.GetAllRecordsByType <Formula>().First();
            List <AbstractPtg> openCellPtgStack = autoOpenCell.ptgStack.ToList();

            Assert.AreEqual(typeof(PtgFunc), openCellPtgStack[0].GetType());
            Assert.AreEqual(typeof(PtgConcat), openCellPtgStack.Last().GetType());

            PtgFunc firstItem = (PtgFunc)openCellPtgStack[0];

            Assert.AreEqual(FtabValues.HALT, firstItem.Ftab);

            ExcelDocWriter writer = new ExcelDocWriter();

            writer.WriteDocument(TestHelpers.AssemblyDirectory + Path.DirectorySeparatorChar + "neutered-sheet.xls", wbs.ToBytes());
        }