Exemplo n.º 1
0
 public void Add(EmployeeRepository rep)
 {
     for (int i = 0; i < rep.employees.Count; i++)
     {
         employees.Add(rep.employees[i]);
     }
 }
Exemplo n.º 2
0
 public void writeXML(EmployeeRepository employee)
 {
     XmlSerializer formatter = new XmlSerializer(typeof(EmployeeRepository));
     using (FileStream fs = new FileStream(xmlName, FileMode.OpenOrCreate))
     {
         formatter.Serialize(fs, employee);
     }
 }
Exemplo n.º 3
0
        public void addEmployeeRepository(EmployeeRepository rep)
        {
            if (rep == null) return;
            DWSaver.repository.Add(rep);

            // выводим подтверждение
            Console.WriteLine("От узла были получены следующие данные:\n");
            Console.WriteLine(rep.ToString());
        }
Exemplo n.º 4
0
        public static string SerializeObject(EmployeeRepository rep)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(rep.GetType());

            using (StringWriter textWriter = new StringWriter())
            {
                xmlSerializer.Serialize(textWriter, rep);
                return textWriter.ToString();
            }
        }
Exemplo n.º 5
0
        public EmployeeRepository sortBy()
        {
            EmployeeRepository sortedEmp = new EmployeeRepository();
            sortedEmp.employees = empRepository.employees;

            sortedEmp.employees.Sort(delegate(Employee x, Employee y)
            {
                if (x.department == null && y.department == null) return 0;
                else if (x.department == null) return -1;
                else if (y.department == null) return 1;
                else return x.department.CompareTo(y.department);
            });
            return sortedEmp;
        }
Exemplo n.º 6
0
        public List<EmployeeRepository> groupBy()
        {
            var groupedDepartmetList = empRepository.employees
                .GroupBy(e => e.department)
                .Select(grp => grp.ToList())
                .ToList();

            List<EmployeeRepository> res = new List<EmployeeRepository>();
            foreach (List<Employee> emp in groupedDepartmetList)
            {
                EmployeeRepository r = new EmployeeRepository();
                r.employees = emp;
                res.Add(r);
            }
            return res;
        }
Exemplo n.º 7
0
        public EmployeeRepository filterBy()
        {
            float avgSalary = 0;
            for (int i = 0; i < empRepository.employees.Count(); i++)
                avgSalary += empRepository.employees[i].salary;
            if (empRepository.employees.Count() > 0)
                avgSalary /= empRepository.employees.Count();


            EmployeeRepository filteredEmp = new EmployeeRepository();
            int count = empRepository.employees.Count();
            if (count <= 0) return filteredEmp;

            for (int i = 0; i < count; i++)
            {
                Employee e = empRepository.Extract(i);
                if (e == null) continue;
                if (e.salary > avgSalary)
                {
                    filteredEmp.Add(e);
                }
            }
            return filteredEmp;
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Я - клиент!\n");

            // получаем данные от сервера
            IMyWCF service = null;
            try
            {
                // подключаемся
                EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8080/"));
                BasicHttpBinding binding = new BasicHttpBinding();
                ChannelFactory<IMyWCF> factory = new ChannelFactory<IMyWCF>(binding, address);
                service = factory.CreateChannel();

                // запрос действия у пользователя
                Console.WriteLine("Выберите действие: 1 - filterBy, 2 - groupBy, 3 - sortBy.");
                ConsoleKeyInfo key = Console.ReadKey();
                Console.WriteLine();
                switch (key.KeyChar)
                {
                    case '1':
                        EmployeeRepository rep1 = service.filterBy();
                        Console.WriteLine(rep1.ToString());

                        string rep1_str = XMLWorker.SerializeObject(rep1);
                        Validator val1 = new Validator(XDocument.Parse(rep1_str));
                        Console.WriteLine(val1.ToString());
                        break;

                    case '2':
                        List <EmployeeRepository> lst = service.groupBy();
                        foreach (EmployeeRepository er in lst)
                            Console.WriteLine(er.ToString());

                        EmployeeRepository rep2 = new EmployeeRepository();
                        rep2.Add(lst);
                        string rep2_str = XMLWorker.SerializeObject(rep2);
                        Validator val2 = new Validator(XDocument.Parse(rep2_str));
                        Console.WriteLine(val2.ToString());
                        break;

                    case '3':
                        EmployeeRepository rep3 = service.sortBy();
                        Console.WriteLine(rep3.ToString());

                        string rep3_str = XMLWorker.SerializeObject(rep3);
                        Validator val3 = new Validator(XDocument.Parse(rep3_str));
                        Console.WriteLine(val3.ToString());
                        break;

                    default:
                        Console.WriteLine("Неверная опция!");
                        break;
                }
            }
            catch
            {
                Console.WriteLine("Не удалось подключиться к серверу!");
            }

            Console.WriteLine("Нажмите любую клавишу для выхода!");
            Console.ReadKey();
        }
Exemplo n.º 9
0
 public void jsonWrite(EmployeeRepository empRep)
 {
     string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(empRep);
     File.WriteAllText(jsonName, json);
 }
Exemplo n.º 10
0
 public Calculator(EmployeeRepository empRepository)
 {
     this.empRepository = empRepository;
 }
Exemplo n.º 11
0
        public void jsonWrite(EmployeeRepository empRep)
        {
            string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(empRep);

            File.WriteAllText(jsonName, json);
        }