public IResponse Execute(SessionContext sessionContext, string parameter) { if (string.IsNullOrWhiteSpace(parameter) || !ValidateFIO(parameter)) { return(new Response(ResponseType.BadParameters)); } var profile = profileRepository.FindByID(parameter); if (profile == null) { return(new Response(ResponseType.NoSessionContent)); } // сериализуем в строки EntityTextFormatter <Profile> etf = new EntityTextFormatter <Profile>(); using (var ms = new MemoryStream()) { etf.Serialize(ms, profile); using (StreamReader sr = new StreamReader(ms)) { Console.Write(sr.ReadToEnd()); } } return(new Response(ResponseType.Ok)); }
private Profile ReadFileProfile(string fileName) { using (var fr = new StreamReader(fileName, Encoding.UTF8)) { EntityTextFormatter <Profile> textFormatter = new EntityTextFormatter <Profile>(); return(textFormatter.Deserialize(fr.BaseStream) as Profile); } }
public void SaveOrUpdate(Profile profile) { var fileName = Path.Combine(PATH_TO_SAVE, profile.FIO + DefaultExtension); using (var fs = new StreamWriter(fileName, false, Encoding.UTF8)) { EntityTextFormatter <Profile> textFormatter = new EntityTextFormatter <Profile>(); textFormatter.Serialize(fs.BaseStream, profile); } }
public void SerializableProfile() { var mokProfile = MokProfile.GetSomeProfile(); var fileName = Path.Combine(Config.PATH_TO_FILE, mokProfile.FIO + ".txt"); using (var fs = new StreamWriter(fileName, false, Encoding.UTF8)) { EntityTextFormatter <Profile> textFormatter = new EntityTextFormatter <Profile>(); textFormatter.Serialize(fs.BaseStream, mokProfile); } Assert.IsTrue(System.IO.File.Exists(fileName)); }
public void Execute() { var conf = new Configuration(); conf.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test"); var etf = new EntityTextFormatter <Profile>(); var repo = new ProfileRepository(conf, etf); var cmd = new ListProfiles(repo); var res = cmd.Execute(null, null); Assert.IsNotNull(res); }
public void Execute() { var conf = new Configuration(); conf.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test"); var etf = new EntityTextFormatter <Profile>(); var repo = new ProfileRepository(conf, etf); var cmd = new Find(repo); var profile = MokProfile.GetSomeProfile().FIO; var res = cmd.Execute(null, profile + ".txt"); Assert.IsNotNull(res); }
public void DeserializableProfile() { var mokProfile = MokProfile.GetSomeProfile(); var fileName = Path.Combine(Config.PATH_TO_FILE, mokProfile.FIO + ".txt"); Profile result; using (var fr = new StreamReader(fileName, Encoding.UTF8)) { EntityTextFormatter <Profile> textFormatter = new EntityTextFormatter <Profile>(); result = textFormatter.Deserialize(fr.BaseStream) as Profile; } Assert.IsNotNull(result); Assert.AreEqual <Profile>(mokProfile, result); }
public void Execute() { var conf = new Configuration(); conf.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test"); var etf = new EntityTextFormatter <Profile>(); var repo = new ProfileRepository(conf, etf); var cmd = new Delete(repo); var profile = MokProfile.GetSomeProfile().FIO; var filename = profile + ".txt"; var res = cmd.Execute(null, filename); Assert.IsNotNull(res); Assert.IsFalse(System.IO.File.Exists(Path.Combine(conf.WorkingDirectory, filename))); }
public void Execute() { var conf = new Configuration(); conf.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test"); var etf = new EntityTextFormatter <Profile>(); var repo = new ProfileRepository(conf, etf); IList <IReport> repoDict = new List <IReport>(); repoDict.Add(new AverageYearReport()); repoDict.Add(new PopularLanguageReport()); repoDict.Add(new PopularProgrammerReport()); var cmd = new Statistics(repo, repoDict); var res = cmd.Execute(null, null); Assert.IsNotNull(res); }
public ProfileRepository(Configuration path, EntityTextFormatter <Profile> entityTextFormatter) { this.PATH_TO_SAVE = path.WorkingDirectory; this.entityTextFormatter = entityTextFormatter; }