/// <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 ExportCoBieCmdExecuted(object sender, ExecutedRoutedEventArgs e) { var outputFile = Path.ChangeExtension(Model.DatabaseName, ".xls"); // Build context var context = new COBieContext(); context.TemplateFileName = CoBieTemplate; context.Model = Model; //set filter option context.Exclude = UserFilters; //set the UI language to get correct resource file for template //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-")) //{ try { var ci = new CultureInfo("en-GB"); Thread.CurrentThread.CurrentUICulture = ci; } // ReSharper disable once EmptyGeneralCatchClause catch { //to nothing Default culture will still be used } var builder = new COBieBuilder(context); var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) {Excludes = UserFilters}; builder.Export(serialiser); Process.Start(outputFile); }
/// <summary> /// Create XLS file from ifc/xbim files /// </summary> /// <param name="parameters">Params</param> private void GenerateCOBieFile(Params parameters) { string outputFile = Path.ChangeExtension(parameters.ModelFile, ".xls"); Stopwatch timer = new Stopwatch(); timer.Start(); COBieBuilder 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 XLS using {0} template...", Path.GetFileName(parameters.TemplateFile))); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, parameters.TemplateFile); serialiser.Excludes = UserFilters; builder.Export(serialiser); LogBackground(String.Format("Export Complete: {0}", outputFile)); Process.Start(outputFile); LogBackground("Finished COBie Generation"); }
private void ExportCOBieCmdExecuted(object sender, ExecutedRoutedEventArgs e) { string outputFile = Path.ChangeExtension(Model.DatabaseName, ".xls"); // Build context COBieContext context = new COBieContext(); context.TemplateFileName = COBieTemplate; context.Model = Model; //set filter option context.Exclude = UserFilters; //set the UI language to get correct resource file for template //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-")) //{ try { System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB"); System.Threading.Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception) { //to nothing Default culture will still be used } COBieBuilder builder = new COBieBuilder(context); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName); serialiser.Excludes = UserFilters; builder.Export(serialiser); Process.Start(outputFile); }
private bool ExportCoBie() { if (!Directory.Exists(TxtFolderName.Text)) { try { Directory.CreateDirectory(TxtFolderName.Text); } catch (Exception) { MessageBox.Show("Error creating directory. Select a different location."); return false; } } var f = new FileInfo(Path.ChangeExtension(Model.DatabaseName, ".xls")); var outputFile = Path.Combine(TxtFolderName.Text, f.Name); var context = new COBieContext { TemplateFileName = CoBieTemplate, Model = Model, Exclude = UserFilters }; // setting culture for thread; the current one will be restored later. CultureInfo exisitingCultureInfo = null; try { var ci = new CultureInfo("en-GB"); exisitingCultureInfo = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception ex) { Log.Error("CurrentUICulture could not be set to en-GB.", ex); } // actual export code var builder = new COBieBuilder(context); var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) { Excludes = UserFilters }; builder.Export(serialiser); // restoring culture for thread; try { if (exisitingCultureInfo != null) Thread.CurrentThread.CurrentUICulture = exisitingCultureInfo; } catch (Exception ex) { Log.Error("CurrentUICulture could not restored.", ex); } if (ChkOpenExcel.IsChecked.HasValue && ChkOpenExcel.IsChecked.Value) Process.Start(outputFile); return true; }
public void ExportCOBie(string path, string template) { string outputFile = Path.ChangeExtension(path, ".xls"); //enforce xls FilterValues UserFilters = new FilterValues();//COBie Class filters, set to initial defaults // Build context COBieContext context = new COBieContext(); context.TemplateFileName = template; context.Model = _model; //set filter option context.Exclude = UserFilters; //set the UI language to get correct resource file for template //if (Path.GetFileName(parameters.TemplateFile).Contains("-UK-")) //{ try { System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-GB"); System.Threading.Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception) { //to nothing Default culture will still be used } COBieBuilder builder = new COBieBuilder(context); COBieXLSSerialiser serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName); serialiser.Excludes = UserFilters; builder.Export(serialiser); }
public void Should_Roundtrip_XLSSerialise() { string output = Path.ChangeExtension(SourceBinaryFile, ".xls"); ICOBieSerialiser serialiser = new COBieXLSSerialiser(output, ExcelTemplateFile); serialiser.Serialise(_book, null); Stopwatch timer = new Stopwatch(); timer.Start(); //TEST on COBieXLSDeserialiser COBieXLSDeserialiser deSerialiser = new COBieXLSDeserialiser(output); COBieWorkbook newbook = deSerialiser.Deserialise(); timer.Stop(); Debug.WriteLine(string.Format("COBieXLSDeserialiser Time = {0}", timer.Elapsed.TotalSeconds.ToString())); string newOutputFile = Root + @"\" + "RoundTrip" + Path.ChangeExtension(SourceBinaryFile, ".xls"); ICOBieSerialiser serialiserTest = new COBieXLSSerialiser(newOutputFile, ExcelTemplateFile); // Assert Assert.AreEqual(19, newbook.Count); //with picklist // 19 workbooks. # rows in a selection. }