public override F.IResult Test(object value) { if (value is P.Property) { P.Property prop = value as P.Property; var childs = prop.GetChilds(); if (childs.ContainsKey(_name)) { F.IResult result = _filter.Test(childs[_name].ToString()); if (result.Success) { return(new F.Result(childs[_name])); } } } return(F.EMPTY_RESULT); }
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(); } } }