Beispiel #1
0
        private static void Main(string[] args)
        {
            //StrategyInit
            var om = new OrdersManager(new AnalyticStrategy());

            om.PrintAnalitics();
            om.analyticStrategy = new CostSumAnalyticStrategy();
            om.PrintAnalitics();
            om.analyticStrategy = new AverageAnalyticStrategy();
            om.PrintAnalitics();
            //AbstractFactoryInin
            var manageFile = new AbstractFactory.UserManager(new FileFactory());
            var manageJson = new AbstractFactory.UserManager(new JsonFactory());

            manageFile.Add("Steve", 1, "NewYork");
            manageJson.Add("Steve", 2, "Lviv");
            var usersJson = manageJson.GetAll();
            var usersFile = manageFile.GetAll();

            foreach (var u in usersFile)
            {
                Console.WriteLine("Name:{0},Age:{1},City:{2}", u.Name, u.Age, u.City);
            }
            foreach (var u in usersJson)
            {
                Console.WriteLine("Name:{0},Age:{1},City:{2}", u.Name, u.Age, u.City);
            }

            //AdapterInit
            var provider    = new UsersFileReader();
            var userManager = new Services.UserManager(provider, "");

            foreach (var u in provider.FromFile())
            {
                Console.WriteLine("Name:{0} Age:{1}", u.Name, u.Age);
            }

            //ProxyInit
            UsersFileReaderProxy dpProxy = new UsersFileReaderProxy();

            dpProxy.AddUser(new UserInfo());
            dpProxy.ReadUsers();
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            string source = @"C:\Users\msemeniu\Desktop\UserAdapter.txt";
            UsersFileReaderProxy proxy           = new UsersFileReaderProxy();
            UsersInfoFileReader  fileReader      = new UsersInfoFileReader();
            UsersFileReader      usersFileReader = new UsersFileReader();
            UserManagerAdapter   userManager     = new UserManagerAdapter(usersFileReader, source);
            UserManagerAdapter   userManager2    = new UserManagerAdapter(proxy, source);
            var users  = userManager.GetAll();
            var users2 = userManager2.GetAll();

            //var testUser = new UserInfoAdapterProxy()
            //{
            //    Age = 20,
            //    Name="Petika"
            //};
            //userManager2.AddUser(testUser);

            foreach (var user in users2)
            {
                Console.WriteLine(user.Age + " " + user.Name);
            }

            Console.ReadKey();

            /////////////////////////////////////////////////////////////////////////

            //string source2 = @"C:\Users\msemeniu\Desktop\UsersInfo.txt";
            //FileFactory fileFactory = new FileFactory(source2);
            //UserManagerFactory userManagerFactory = new UserManagerFactory(fileFactory);
            //var userList = userManagerFactory.ByCity("Beijing");
            //foreach (var user in userList)
            //{
            //    Console.WriteLine($"{user.Name},{user.Age},{user.City}");
            //}
            ////userManagerFactory.Add("Vasya", 18, "Beijing");
            //userManagerFactory.Delete(new Guid("8ff8cec0-5930-47f4-913a-17bb613739bc"));

            //Console.ReadKey();

            /////////////////////////////////////////////////////////////////////////////////

            string             jsonSource      = @"C:\Users\msemeniu\Desktop\UsersJson.txt";
            JSONFactory        jsonFactory     = new JSONFactory(jsonSource);
            UserManagerFactory userManagerJson = new UserManagerFactory(jsonFactory);
            //userManagerJson.Add("Vasya", 18, "Beijing");
            //userManagerJson.Add("Kolya", 20, "Tokyo");
            var usersJson = userManagerJson.ByCity("Tokyo");

            foreach (var user in usersJson)
            {
                Console.WriteLine(user.Name + " " + user.Age + " " + user.City);
            }
            userManagerJson.Delete(new Guid("2f638806-9fcf-49f3-ab88-247ff481955d"));
            /////
            Console.ReadLine();

            OrdersReader             reader        = new OrdersReader(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            CostSumAnalyticsStrategy strategy      = new CostSumAnalyticsStrategy();
            OrdersManager            ordersManager = new OrdersManager(strategy);

            ordersManager.Import(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            ordersManager.PrintAnalitycs();

            Console.WriteLine("///////////////////////////////////////");

            AnalyticsStrategy avgStrategy      = new AverageAnalyticStrategy();
            OrdersManager     ordersManagerAvg = new OrdersManager(avgStrategy);

            ordersManagerAvg.Import(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            ordersManagerAvg.PrintAnalitycs();


            Console.ReadKey();
        }