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); }
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; }
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); }
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); }