Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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)));
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
 public ProfileRepository(Configuration path, EntityTextFormatter <Profile> entityTextFormatter)
 {
     this.PATH_TO_SAVE        = path.WorkingDirectory;
     this.entityTextFormatter = entityTextFormatter;
 }