/// <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"); }
/// <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> /// Performs the export /// </summary> /// <returns>True on success, false on error.</returns> 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 fName = Model.FileName; if (string.IsNullOrEmpty(fName)) { fName = "Unnamed"; } var f = new FileInfo(Path.ChangeExtension(fName, ".xls")); var outputFile = Path.Combine(TxtFolderName.Text, f.Name); // configure settings for exporter var ass = System.Reflection.Assembly.GetAssembly(GetType()); if (_parentWindow == null) { Log.LogError("attempt to locate DiskLess assembly without a valid IXbimXplorerPluginMasterWindow."); return(false); } var assemblyFile = _parentWindow.GetAssemblyLocation(ass); var pluginDir = new FileInfo(assemblyFile).Directory; if (pluginDir == null) { Log.LogError("Failed to determine plugin folder under IXbimXplorerPluginMasterWindow."); return(false); } var templateFileName = Path.Combine( pluginDir.FullName, CoBieTemplate); var context = new COBieContext { TemplateFileName = templateFileName, 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.LogError(0, ex, "CurrentUICulture could not be set to en-GB."); } // 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.LogError(0, ex, "CurrentUICulture could not restored."); } if (ChkOpenExcel.IsChecked.HasValue && ChkOpenExcel.IsChecked.Value) { Process.Start(outputFile); } return(true); }
/// <summary> /// Performs the export /// </summary> /// <returns>True on success, false on error.</returns> 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.FileName, ".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); }