public void Dump(IDump dumper) { if (ReferenceEquals(dumper, null)) { var ex = new ArgumentNullException($"{nameof(dumper)} is null"); this.logger?.Error(ex, ex.Message); throw ex; } try { dumper.Save(this.storage); this.logger?.Info($"Dumped {this.storage.Count} users"); } catch (IOException exception) { var ex = new UserServiceException("Can't save Users", exception); this.logger?.Error(ex, ex.Message); throw ex; } catch (InvalidOperationException exception) { var ex = new UserServiceException("Can't save Users", exception); this.logger?.Error(ex, ex.Message); throw ex; } }
/// <summary> /// /// </summary> /// <param name="dumper"></param> public void GetDump(IDump dumper) { if (ReferenceEquals(dumper, null)) { var ex = new ArgumentNullException($"{nameof(dumper)} is null"); this.logger?.Error(ex, ex.Message); throw ex; } try { this.storage = new HashSet <User>(dumper.Load(), this.userEqualityComparer); this.logger?.Info($"Requested {this.storage.Count} users from dump file"); } catch (IOException exception) { var ex = new UserServiceException("Can't load Users", exception); this.logger?.Error(ex, ex.Message); throw ex; } catch (InvalidOperationException exception) { var ex = new UserServiceException("Can't load Users", exception); this.logger?.Error(ex, ex.Message); throw ex; } }
public static string GetDumpString(this IDump instance) { StringBuilder result = new StringBuilder(); instance.AddDumpString(result, 0); return(result.ToString()); }
public static void Dump <T>(Grammar grammar, FileRef file, IDump <T> dump, T subject) { if (dump == null) { throw new ArgumentNullException(nameof(dump)); } var writer = new IndentWriter(); dump.Dump(grammar, writer, subject); writer.Persist(file); }
public void DumpToXml(IDump dumper, string path) { if (ReferenceEquals(dumper, null)) { dumper = new XmlDump(); } if (ReferenceEquals(path, null)) { dumper.Dump(_userRepository.GetUsers(), null); } dumper.Dump(_userRepository.GetUsers(), path); }
public static string GetDumpString(this IDump instance, bool?includeTypeHeader) { includeTypeHeader = includeTypeHeader ?? true; StringBuilder result = new StringBuilder(); if (includeTypeHeader.Value && instance != null) { result.AppendLine(string.Format("[{0}]", instance.GetType())); } instance.AddDumpString(result, includeTypeHeader.Value ? 1 : 0); return(result.ToString()); }
static void Main(string[] args) { Client client = new Client(); IPhoneFactory phoneFactory = client.GetInstance(FactoryName.SAMSUNG); IDump dump = phoneFactory.Dump(); string name = dump.GetName("Hey this is SAMSUNG S8"); ISmart smart = phoneFactory.Smart(); string modelNumber = smart.GetModelNumber("XT672K"); System.Console.WriteLine(name + Environment.NewLine); System.Console.WriteLine(modelNumber + Environment.NewLine); Console.WriteLine("Hello World!"); }
private void AppendToOutput(IDump dump) { AppendToOutput(dump.GetDumpString()); }
public static void AddDumpString(this IDump instance, StringBuilder output, int depth) { AddDumpString(output, depth, instance); }
public static string GetDumpString(this IDump instance) { return(GetDumpString(instance, null)); }
private void AppendToOutput(IDump dump) { AppendToOutput(dump.GetDumpString()); }