예제 #1
0
        private static Employee GetEmployeeFromText(string info, OfficeManagement officeMangement)
        {
            if (string.IsNullOrEmpty(info))
            {
                return(null);
            }
            var lines = info
                        .Replace("\t", string.Empty)
                        .Trim()
                        .Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            if (!lines.Any())
            {
                return(null);
            }

            var name     = GetPropertyValue(nameof(Employee.Name), lines);
            var position = GetPropertyValue(nameof(Employee.Position), lines);
            var capacity = GetPropertyValue(nameof(Employee.Capacity), lines);
            var hobbies  = GetPropertyValue(nameof(Employee.Hobbies), lines).Split(',');

            var positionType = EmployeePosition.Intern;

            if (!Enum.TryParse(position, out positionType))
            {
                Console.WriteLine($"Pentru {name} nu s-a putut stabili position type");
            }

            return(officeMangement.AddEmployee(name, positionType, Convert.ToSingle(capacity, CultureInfo.InvariantCulture), hobbies.ToList()));
        }
예제 #2
0
        static void Main(string[] args)
        {
            var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *
            *  officeManagement.DeleteEmployee(dev);
            *  officeManagement.DisplayAllEmployees();
            *  officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();


            var ds = new DataContractSerializer(typeof(OfficeManagement));
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent              = true;
            settings.OmitXmlDeclaration  = true;
            settings.NewLineOnAttributes = true;
            using (XmlWriter w = XmlWriter.Create("Information.xml", settings))
            {
                ds.WriteObject(w, officeManagement);
            }

            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            OfficeManagement officeManagement = new OfficeManagement();

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();

            var ds = new DataContractSerializer(typeof(OfficeManagement));
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };

            using (XmlWriter w = XmlWriter.Create("office.xml", settings))
                ds.WriteObject(w, officeManagement);

            var office = new OfficeManagement();

            using (Stream s = File.OpenRead("office.xml"))
                office = (OfficeManagement)ds.ReadObject(s);

            //POPULEAZA LISTA DE ANGAJATI SI PROIECTE SI APOI CHEAMA WRITEXML



            //var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *
            *  officeManagement.DeleteEmployee(dev);
            *  officeManagement.DisplayAllEmployees();
            *  officeManagement.DisplayAllProjects();*/



            //XmlWriterSettings settings = new XmlWriterSettings();
            //settings.Indent = true;
            //settings.OmitXmlDeclaration = true;
            //settings.NewLineOnAttributes = true;
            //settings.ConformanceLevel = ConformanceLevel.Auto;
            //using (XmlWriter writer = XmlWriter.Create("temp.xml", settings))
            //{
            //    writer.WriteStartDocument();
            //    officeManagement.WriteXml(writer);
            //    writer.WriteEndDocument();

            //}

            string content = JsonConvert.SerializeObject(officeManagement);

            File.WriteAllText("office.json", content);

            Console.ReadLine();
        }
예제 #4
0
        private static void PopulateEmployeeList(OfficeManagement officeManagement)
        {
            var allInformation = File.ReadAllText(@"C:\Users\Bogdan.roman\source\repos\AccesaEmployee\officeDB.txt");

            var employees = allInformation.Split(new string[] {nameof(Employee),"{", "}"}, StringSplitOptions.RemoveEmptyEntries);
            foreach (var record in employees)
            {
                var trimmedRecord = record.TrimStart(new char[] {'\r', '\n'});
                if (trimmedRecord.StartsWith(nameof(Project)) || trimmedRecord.Equals("\r\n")) continue;
                GetEmployeeFromText(trimmedRecord, officeManagement);
            }
        }
예제 #5
0
        static void Main(string[] args)
        {
            var officeManagement = new OfficeManagement();


            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();


            officeManagement.WriteJSON();

            Console.ReadLine();
        }
예제 #6
0
        static void Main(string[] args)
        {
            var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *
            *  officeManagement.DeleteEmployee(dev);
            *  officeManagement.DisplayAllEmployees();
            *  officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();
            Console.ReadLine();
        }
예제 #7
0
        private static void PopulateEmployeeList(OfficeManagement officeManagement)
        {
            var allInformation = File.ReadAllText(@"c:\Work stuff\Internship\officeDB.txt");

            var employees = allInformation.Split(new string[] { nameof(Employee), "{", "}" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var record in employees)
            {
                var trimmedRecord = record.TrimStart(new char[] { '\r', '\n' });
                if (trimmedRecord.StartsWith(nameof(Project)) || trimmedRecord.Equals("\r\n"))
                {
                    continue;
                }
                GetEmployeeFromText(trimmedRecord, officeManagement);
            }
        }
예제 #8
0
        static void Main(string[] args)
        {
            var officeManagement  = new OfficeManagement();
            var officeManagement1 = new OfficeManagement();
            var officeManagement2 = new OfficeManagement();
            var ds = new DataContractSerializer(typeof(OfficeManagement));

            /*officeManagement.DisplayAllProjects();
            *
            *           officeManagement.DeleteEmployee(dev);
            *           officeManagement.DisplayAllEmployees();
            *           officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent              = true;
            settings.OmitXmlDeclaration  = true;
            settings.NewLineOnAttributes = true;
            using (XmlWriter w = XmlWriter.Create("xmlfile.xml", settings))
            {
                ds.WriteObject(w, officeManagement);
            }
            using (Stream s = File.OpenRead("xmlfile.xml"))
            {
                officeManagement1 = (OfficeManagement)ds.ReadObject(s);
            }
            officeManagement1.DisplayAllEmployees();

            using (StreamWriter file = File.CreateText(@"C:\Users\Catalin.Oant\Downloads\AccesaEmployee\AccesaEmployee\bin\Debug\json.txt"))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, officeManagement);
            }
            //using (Stream s = File.OpenRead(@"C:\Users\Catalin.Oant\Downloads\AccesaEmployee\AccesaEmployee\bin\Debug\json.txt"))
            //{
            //    officeManagement2 = (OfficeManagement)ds.ReadObject(s);
            //}
            //PopulateEmployeeList(officeManagement2);
            //officeManagement2.DisplayAllEmployees();

            Console.ReadLine();
        }
예제 #9
0
        static void Main(string[] args)
        {
            XmlWriter w = XmlWriter.Create(@"C:\Users\andrei.oros\source\repos\xmlexemple.xml");

            w.WriteStartDocument();
            w.WriteStartElement("test");

            var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *
            *  officeManagement.DeleteEmployee(dev);
            *  officeManagement.DisplayAllEmployees();
            *  officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();
            officeManagement.WriteXML(w);
            Console.ReadLine();
        }
예제 #10
0
        static void Main(string[] args)
        {
            var officeManagement= new OfficeManagement();
            /*officeManagement.DisplayAllProjects();

            officeManagement.DeleteEmployee(dev);
            officeManagement.DisplayAllEmployees();
            officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(@"C:\Users\Bogdan.roman\source\repos\AccesaEmployee", settings))
            {
                officeManagement.WriteXml(writer);
            }

            Console.ReadLine();
             //   officeManagement.WriteXml(w);
        }
예제 #11
0
        static void Main(string[] args)
        {
            OfficeManagement officeManagement = new OfficeManagement();

            // using (XmlReader reader = XmlReader.Create("Office.xml")) ;

            //POPULEAZA LISTA DE ANGAJATI SI PROIECTE SI APOI CHEAMA WRITEXML



            //var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *  officeManagement.DeleteEmployee(dev);
            *  officeManagement.DisplayAllEmployees();
            *  officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent              = true;
            settings.OmitXmlDeclaration  = true;
            settings.NewLineOnAttributes = true;
            settings.ConformanceLevel    = ConformanceLevel.Auto;
            using (XmlWriter writer = XmlWriter.Create("temp.xml", settings))
            {
                writer.WriteStartDocument();
                officeManagement.WriteXml(writer);
                writer.WriteEndDocument();
            }

            string content = JsonConvert.SerializeObject(officeManagement);

            File.WriteAllText("office.json", content);



            Console.ReadLine();
        }
예제 #12
0
        static void Main(string[] args)
        {
            // XmlDocument myXml = new XmlDocument();
            //XPathNavigator Xnav = myXml.CreateNavigator();
            //XmlSerializer x = new XmlSerializer (myEmployee)

            var officeManagement = new OfficeManagement();

            /*officeManagement.DisplayAllProjects();
            *
            *           officeManagement.DeleteEmployee(dev);
            *           officeManagement.DisplayAllEmployees();
            *           officeManagement.DisplayAllProjects();*/

            PopulateEmployeeList(officeManagement);
            officeManagement.DisplayAllEmployees();
            // var employee = new Employee();

            // string content = JsonConvert.SerializeObject(officeManagement);
            // File.WriteAllText("office.json", content);

            var ds = new DataContractSerializer(typeof(OfficeManagement));

            //  MemoryStream stream = new MemoryStream();
            //  ds.WriteObject(stream, officeManagement);

            using (XmlWriter a = XmlWriter.Create("siguuur.xml"))
            {
                ds.WriteObject(a, officeManagement);
            }

            using (Stream s = File.OpenRead("siguuur.xml"))
            {
                officeManagement = (OfficeManagement)ds.ReadObject(s);
            }
            officeManagement.DisplayAllEmployees();
            Console.ReadLine();
        }