public static F.IFilter CreateFilter(FilterDefinition def) { F.IFilter baseFilter = F.CreateFilterOp(def.Condition, def.Value); switch (def.Source) { case Sources.None: return(new None(baseFilter)); case Sources.ClassName: return(new ChildFilter(baseFilter, "ClassName")); case Sources.PathName: return(new ChildFilter(baseFilter, "PathName")); case Sources.LevelName: return(new ChildFilter(baseFilter, "LevelName")); case Sources.FieldName: return(new FieldName(baseFilter)); case Sources.FieldValue: return(new FieldValue(baseFilter)); case Sources.TranslationX: return(new Translation(baseFilter, Translation.Coordinate.X)); case Sources.TranslationY: return(new Translation(baseFilter, Translation.Coordinate.Y)); case Sources.TranslationZ: return(new Translation(baseFilter, Translation.Coordinate.Z)); } return(null); }
public static void Run(Savegame.Savegame savegame, string filename, ExportAction.Writer.Destinations destination_type, List <FilterDefinition> filters, bool deep_traversal, bool recursive_export) { Writer.IWriter writer = Writer.CreateWriter(destination_type, filename, recursive_export); if (writer == null) { string msg = string.Format(Translate._("Unable to create writer for file\n\n{0}"), filename); MessageBox.Show(msg, Translate._("MainWindow.Title"), MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } try { writer.Open(); } catch (Exception exc) { string msg = string.Format(Translate._("Unable to create writer for file\n\n{0}"), filename) + "\n\n" + exc.ToLongString(); MessageBox.Show(msg, Translate._("MainWindow.Title"), MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } var defs = new F.Definitions(filters.Cast <F.Definition>()); F.CreatorCallback creator = (def) => FilterImpl.CreateFilter(def as FilterDefinition); F.FilterChain chain = F.CreateChain(defs, creator); if (chain == null) { string msg = "Internal error!\n\nUnable to create filter chain."; MessageBox.Show(msg, Translate._("MainWindow.Title"), MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } HierarchyRunner.Runner action; if (chain.Count == 0) { action = (prop) => { // Empty "Export all" filter was passed writer.Write(prop); }; // Also remove deep flag deep_traversal = false; } else { action = (prop) => { // Test property against filter(s) given F.IResult result = chain.Test(prop); // If successful, pass to writer if (result.Success) { writer.Write(prop); } } }; try { HierarchyRunner runner = new HierarchyRunner(savegame, deep_traversal); runner.Run(Translate._("Action.Export.Progress.Title"), action); string msg = string.Format(Translate._("Action.Export.Done"), filename); MessageBox.Show(msg, Translate._("MainWindow.Title")); //, MessageBoxButton.OK, MessageBoxImage.Information); } catch { string msg = "Internal error!\n\nFailure within hierarchy runner."; MessageBox.Show(msg, Translate._("MainWindow.Title"), MessageBoxButton.OK, MessageBoxImage.Exclamation); } finally { writer.Close(); } } }