/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> /// <param name="cobie"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("COBie", "COBieXLSSerialiser.Serialise does not accept null as the COBie data parameter."); } if (!File.Exists(TemplateFileName)) throw new Exception("COBie creation error. Could not locate template file " + TemplateFileName); // Load template file FileStream excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); XlsWorkbook = new HSSFWorkbook(excelFile, true); CreateFormats(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, ValidationTemplate); ReportRules(); using (FileStream exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { XlsWorkbook.Write(exportFile); } }
private void PopulateErrors(ICOBieValidationTemplate ValidationTemplate = null) { try { COBieProgress progress = new COBieProgress(Context); progress.Initialise("Validating Workbooks", Workbook.Count, 0); progress.ReportMessage("Building Indices..."); Workbook.CreateIndices(); progress.ReportMessage("Building Indices...Finished"); // Validate the workbook progress.ReportMessage("Starting Validation..."); Workbook.Validate(Context.ErrorRowStartIndex, ValidationTemplate, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar progress.IncrementAndUpdate(); }); progress.ReportMessage("Finished Validation"); progress.Finalise(); } catch (Exception) { // TODO: Handle throw; } }
/// <summary> /// Runs validation rules on each sheet and updates the Errors collection /// on each sheet. /// </summary> ///<param name="errorRowIdx">excel sheet = ErrorRowIndexBase.RowTwo, datasets = ErrorRowIndexBase.RowOne </param> public void Validate(ErrorRowIndexBase errorRowIdx, ICOBieValidationTemplate ValidationTemplate = null, Action <int> progressCallback = null) //default for excel row index's on error rows { // Enumerates the sheets and validates each foreach (var sheet in this) { if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS) //skip validation on pick list { if (ValidationTemplate != null) { sheet.Validate(this, errorRowIdx, ValidationTemplate.Sheet[sheet.SheetName]); } else { sheet.Validate(this, errorRowIdx, null); } } // Progress bar support if (progressCallback != null) { // Call-back with the index of the last processed sheet progressCallback(this.IndexOf(sheet)); } } }
/// <summary> /// Create XLS file from ifc/xbim files /// </summary> /// <param name="parameters">Params</param> /// <param name="validationTemplate"></param> private void GenerateFederatedCOBieFile(Params parameters, ICOBieValidationTemplate validationTemplate = null) { var outputFile = Path.ChangeExtension(parameters.ModelFile, ".xls"); var timer = new Stopwatch(); timer.Start(); var fedWorkBook = GenerateFederatedCOBieWorkBook(parameters); timer.Stop(); LogBackground(String.Format("Time to generate Federated 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; serialiser.Serialise(fedWorkBook, validationTemplate); LogBackground(String.Format("Export Complete: {0}", outputFile)); Process.Start(serialiser.FileName); LogBackground("Finished Federation COBie Generation"); }
/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> /// <param name="workbook"></param> /// <param name="validationTemplate"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("COBie", "COBieXLSXSerialiser.Serialise does not accept null as the COBie data parameter."); } if (!File.Exists(TemplateFileName)) { throw new Exception("COBie creation error. Could not locate template file " + TemplateFileName); } // Load template file FileStream excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); ExcelWorkbook = IsXlsx ? new XSSFWorkbook(excelFile) as IWorkbook : new HSSFWorkbook(excelFile, true) as IWorkbook; CreateCellStyles(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, validationTemplate); ReportRules(); using (FileStream exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { ExcelWorkbook.Write(exportFile); } }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> /// <param name="validationTemplate"></param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { Create(workbook); if (!string.IsNullOrEmpty(FileName)) { Save(); } }
/// <summary> /// Passes this instance of the COBieReader into the provided ICOBieSerialiser /// </summary> /// <param name="serialiser">The object implementing the ICOBieSerialiser interface.</param> public void Export(ICOBieSerialiser serialiser, ICOBieValidationTemplate ValidationTemplate = null) { if (serialiser == null) { throw new ArgumentNullException("formatter", "Parameter passed to COBieReader.Export(ICOBieSerialiser) must not be null."); } serialiser.Serialise(Workbook, ValidationTemplate); }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim"); } BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(_file, FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, workbook); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim"); } BinaryFormatter formatter = new BinaryFormatter(); using (Stream stream = new FileStream(_file, FileMode.Create, FileAccess.Write, FileShare.None)) { formatter.Serialize(stream, workbook); } }
/// <summary> /// Formats the COBie data into an Excel XLS file /// </summary> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "COBieXLSSerialiser.Serialise does not accept null as the COBieWorkbook data parameter."); } if (!File.Exists(TemplateFileName)) { var di = new DirectoryInfo("."); var msg = string.Format( "COBie creation error. Could not locate template file '{0}' from executing folder '{1}'", TemplateFileName, di.FullName); var e = new FileNotFoundException(msg, TemplateFileName); Log.LogError(0, e, "COBie creation error.Could not locate template file '{template}' from executing folder '{folder}'", TemplateFileName, di.FullName); throw e; } // Load template file var excelFile = File.Open(TemplateFileName, FileMode.Open, FileAccess.Read); XlsWorkbook = new HSSFWorkbook(excelFile, true); CreateFormats(); foreach (var sheet in workbook) { WriteSheet(sheet); } UpdateInstructions(); ReportErrors(workbook, validationTemplate); ReportRules(); using (var exportFile = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { XlsWorkbook.Write(exportFile); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim.COBie.Serialisers.COBieJSONSerialiser.Serialise(COBieWorkbook) does not accept null as the workbook parameter"); } FileName += ".json"; using (FileStream stream = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { StreamWriter writer = new StreamWriter(stream); // Serialise Workbook to JSON and write to file stream new Newtonsoft.Json.JsonSerializer().Serialize(writer, workbook); writer.Flush(); writer.Close(); } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate validationTemplate = null) { var errorsSheet = XlsWorkbook.GetSheet(ErrorsSheet) ?? XlsWorkbook.CreateSheet(ErrorsSheet); ICOBieSheetValidationTemplate sheetValidator = null; foreach (var sheet in workbook.OrderBy(w => w.SheetName)) { if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (validationTemplate != null && validationTemplate.Sheet.ContainsKey(sheet.SheetName)) { sheetValidator = validationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, sheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { if (workbook == null) { throw new ArgumentNullException("workbook", "Xbim.COBie.Serialisers.COBieJSONSerialiser.Serialise(COBieWorkbook) does not accept null as the workbook parameter"); } FileName += ".json"; using (FileStream stream = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read)) { StreamWriter writer = new StreamWriter(stream); // Serialise Workbook to JSON and write to file stream new Newtonsoft.Json.JsonSerializer().Serialize(writer, workbook); writer.Flush(); writer.Close(); } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { ISheet errorsSheet = ExcelWorkbook.GetSheet(ErrorsSheet) ?? ExcelWorkbook.CreateSheet(ErrorsSheet); //if we are validating here then ensure we have Indices on each sheet //workbook.CreateIndices(); ICOBieSheetValidationTemplate SheetValidator = null; foreach (var sheet in workbook.OrderBy(w => w.SheetName)) { if (sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (ValidationTemplate != null && ValidationTemplate.Sheet.ContainsKey(sheet.SheetName)) { SheetValidator = ValidationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, SheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
private void ReportErrors(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { ISheet errorsSheet = ExcelWorkbook.GetSheet(ErrorsSheet) ?? ExcelWorkbook.CreateSheet(ErrorsSheet); //if we are validating here then ensure we have Indices on each sheet //workbook.CreateIndices(); ICOBieSheetValidationTemplate SheetValidator = null; foreach(var sheet in workbook.OrderBy(w=>w.SheetName)) { if(sheet.SheetName != Constants.WORKSHEET_PICKLISTS) { if (ValidationTemplate != null && ValidationTemplate.Sheet.ContainsKey(sheet.SheetName)) { SheetValidator = ValidationTemplate.Sheet[sheet.SheetName]; } // Ensure the validation is up to date sheet.Validate(workbook, ErrorRowIndexBase.RowTwo, SheetValidator); } WriteErrors(errorsSheet, sheet.Errors); } }
/// <summary> /// XBim Serialise /// </summary> /// <param name="workbook">COBieWorkbook to Serialise</param> public void Serialise(COBieWorkbook workbook, ICOBieValidationTemplate ValidationTemplate = null) { Create(workbook); if (!string.IsNullOrEmpty(FileName)) { Save(); } }
/// <summary> /// Create XLS file from ifc/xbim files /// </summary> /// <param name="parameters">Params</param> private void GenerateFederatedCOBieFile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null) { string outputFile = Path.ChangeExtension(parameters.ModelFile, ".xls"); Stopwatch timer = new Stopwatch(); timer.Start(); COBieWorkbook fedWorkBook = GenerateFederatedCOBieWorkBook(parameters); timer.Stop(); LogBackground(String.Format("Time to generate Federated COBie data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3"))); // Export LogBackground(String.Format("Formatting as XLS using {0} template...", Path.GetFileName(parameters.TemplateFile))); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.Serialise(fedWorkBook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", outputFile)); Process.Start(outputFile); LogBackground("Finished Federation COBie Generation"); }
/// <summary> /// Validate XLS file for COBie errors, also will swap templates if required /// </summary> /// <param name="parameters">Params</param> /// <returns>Created file name</returns> private void ValidateXLSfile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null) { //read xls file LogBackground(String.Format("Reading {0}....", parameters.ModelFile)); COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile); COBieWorkbook 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 COBieXLSDeserialiser deSerialiserPickList = new COBieXLSDeserialiser(parameters.TemplateFile, Constants.WORKSHEET_PICKLISTS); COBieWorkbook 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..."); } } COBieContext context = new COBieContext(_worker.ReportProgress); COBieProgress progress = new COBieProgress(context); context.Exclude = UserFilters; //Validate progress.Initialise("Validating Workbooks", Workbook.Count, 0); progress.ReportMessage("Building Indices..."); foreach (ICOBieSheet<COBieRow> 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 XLS using {0} template...", Path.GetFileName(parameters.TemplateFile))); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(parameters.ModelFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.Serialise(Workbook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile)); Process.Start(parameters.ModelFile); LogBackground("Finished COBie Validation"); }
private void PopulateErrors(ICOBieValidationTemplate ValidationTemplate = null) { try { COBieProgress progress = new COBieProgress(Context); progress.Initialise("Validating Workbooks", Workbook.Count, 0); progress.ReportMessage("Building Indices..."); Workbook.CreateIndices(); progress.ReportMessage("Building Indices...Finished"); // Validate the workbook progress.ReportMessage("Starting Validation..."); Workbook.Validate(Context.ErrorRowStartIndex, ValidationTemplate, (lastProcessedSheetIndex) => { // When each sheet has been processed, increment the progress bar progress.IncrementAndUpdate(); } ); progress.ReportMessage("Finished Validation"); progress.Finalise(); } catch (Exception) { // TODO: Handle throw; } }
/// <summary> /// Validate XLS file for COBie errors, also will swap templates if required /// </summary> /// <param name="parameters">Params</param> /// <returns>Created file name</returns> private void ValidateXLSfile(Params parameters, ICOBieValidationTemplate ValidationTemplate = null) { //read xls file LogBackground(String.Format("Reading {0}....", parameters.ModelFile)); COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(parameters.ModelFile); COBieWorkbook 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 COBieXLSDeserialiser deSerialiserPickList = new COBieXLSDeserialiser(parameters.TemplateFile, Constants.WORKSHEET_PICKLISTS); COBieWorkbook 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..."); } } COBieContext context = new COBieContext(_worker.ReportProgress); COBieProgress progress = new COBieProgress(context); context.Exclude = UserFilters; //Validate progress.Initialise("Validating Workbooks", Workbook.Count, 0); progress.ReportMessage("Building Indices..."); foreach (ICOBieSheet <COBieRow> 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 XLS using {0} template...", Path.GetFileName(parameters.TemplateFile))); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(parameters.ModelFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; serialiser.Serialise(Workbook, ValidationTemplate); LogBackground(String.Format("Export Complete: {0}", parameters.ModelFile)); Process.Start(parameters.ModelFile); LogBackground("Finished COBie Validation"); }
/// <summary> /// Passes this instance of the COBieReader into the provided ICOBieSerialiser /// </summary> /// <param name="serialiser">The object implementing the ICOBieSerialiser interface.</param> public void Export(ICOBieSerialiser serialiser, ICOBieValidationTemplate ValidationTemplate = null) { if (serialiser == null) { throw new ArgumentNullException("formatter", "Parameter passed to COBieReader.Export(ICOBieSerialiser) must not be null."); } serialiser.Serialise(Workbook, ValidationTemplate); }