/// <summary> /// Create XLS file from ifc/xbim files /// </summary> /// <param name="parameters">Params</param> private void GenerateCOBieFile(Params parameters) { var outputFile = Path.ChangeExtension(parameters.ModelFile, ".xls"); var timer = new Stopwatch(); timer.Start(); var builder = GenerateCOBieWorkBook(parameters); timer.Stop(); LogBackground(String.Format("Time to generate COBie data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); // Export LogBackground(String.Format("Formatting as {1} using {0} template...", Path.GetFileName(parameters.TemplateFile), parameters.IsXLSX ? "XLSX" : "XLS")); var serialiser = new COBieXLSXSerialiser(outputFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.IsXlsx = parameters.IsXLSX; builder.Export(serialiser); LogBackground(String.Format("Export Complete: {0}", outputFile)); Process.Start(serialiser.FileName); LogBackground("Finished COBie Generation"); }
/// <summary> /// Validate XLS file for COBie errors, also will swap templates if required /// </summary> /// <param name="parameters">Params</param> /// <param name="validationTemplate"></param> /// <returns>Created file name</returns> private void ValidateXlSfile(Params parameters, ICOBieValidationTemplate validationTemplate = null) { //read xls file LogBackground(String.Format("Reading {0}....", parameters.ModelFile)); var deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile); var workbook = deSerialiser.Deserialise(); //extract pick list from the template sheet and swap into workbook (US / UK) LogBackground("Swapping PickList from template..."); COBieSheet <COBiePickListsRow> cobiePickLists = null; if ((!string.IsNullOrEmpty(parameters.TemplateFile)) && File.Exists(parameters.TemplateFile) ) { //extract the pick list sheet from template var deSerialiserPickList = new COBieXLSDeserialiser(parameters.TemplateFile, Constants.WORKSHEET_PICKLISTS); var wbookPickList = deSerialiserPickList.Deserialise(); if (wbookPickList.Count > 0) { cobiePickLists = (COBieSheet <COBiePickListsRow>)wbookPickList.FirstOrDefault(); } //check the workbook last sheet is a pick list if (workbook.LastOrDefault() is COBieSheet <COBiePickListsRow> ) { //remove original pick list and replace with templates workbook.RemoveAt(workbook.Count - 1); workbook.Add(cobiePickLists); } else { LogBackground("Failed to Swap PickList from template..."); } } var context = new COBieContext(_worker.ReportProgress); var progress = new COBieProgress(context); context.Exclude = UserFilters; //Validate progress.Initialise("Validating Workbooks", workbook.Count, 0); progress.ReportMessage("Building Indices..."); foreach (var item in workbook) { item.BuildIndices(); } progress.ReportMessage("Building Indices...Finished"); // Validate the workbook progress.ReportMessage("Starting Validation..."); workbook.Validate(ErrorRowIndexBase.RowTwo, null, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar progress.IncrementAndUpdate(); }); progress.ReportMessage("Finished Validation"); progress.Finalise(); // Export LogBackground(String.Format("Formatting as {1} using {0} template...", Path.GetFileName(parameters.TemplateFile), parameters.IsXLSX ? "XLSX" : "XLS")); var serialiser = new COBieXLSXSerialiser(parameters.ModelFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.IsXlsx = parameters.IsXLSX; serialiser.Serialise(workbook, validationTemplate); LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile)); Process.Start(serialiser.FileName); LogBackground("Finished COBie Validation"); }