예제 #1
0
        /// <summary>
        /// Serialize department menu.
        /// </summary>
        /// <param name="dep">Department instance.</param>
        public static void SerializeDepartmentMenu(Department dep)
        {
            int sMode = 0;

            while (sMode < 1 || sMode > 2)
            {
                Console.WriteLine("1 - Json.");
                Console.WriteLine("2 - XML.");
                Int32.TryParse(Console.ReadLine(), out sMode);
            }

            if (sMode == 1)
            {
                Console.WriteLine("Введите путь: ");
                string    path = Console.ReadLine();
                ParseJson json = new ParseJson();
                json.SerializeDepartment(dep, path);
                Console.WriteLine("Готово!");
            }

            else if (sMode == 2)
            {
                Console.WriteLine("Введите путь: ");
                string   path = Console.ReadLine();
                ParseXML xml  = new ParseXML();
                xml.SerializeDepartment(dep, path);
                Console.WriteLine("Готово!");
            }
        }
예제 #2
0
        public static void DebMain()
        {
            Department dep  = new Department();
            ParseJson  json = new ParseJson();

            dep = json.DeserializeDepartment("_jsonExample.json");
            Console.WriteLine(dep.PrintDepartment());
        }
예제 #3
0
 /// <summary>
 /// Deserialize worker from Json/Xml file to Worker instance.
 /// </summary>
 /// <param name="path">Path to file.</param>
 /// <returns></returns>
 public static Worker DeserializeWokerJX(string path)
 {
     if (path.Contains(".xml"))
     {
         ParseXML xml       = new ParseXML();
         Worker   newWorker = xml.DeserializeWorker(path);
         return(newWorker);
     }
     else if (path.Contains(".json"))
     {
         ParseJson json      = new ParseJson();
         Worker    newWorker = json.DeserializeWorker(path);
         return(newWorker);
     }
     return(null);
 }
예제 #4
0
        /// <summary>
        /// Serealize worker console menu.
        /// </summary>
        /// <param name="dep"></param>
        public static void SerizalizeWorkerMenu(Department dep)
        {
            Console.Clear();
            int wID = -1;

            Console.WriteLine(dep.PrintDepartment());

            while (wID < 0)
            {
                Console.WriteLine("Введите ID работника для сериализации: ");
                int.TryParse(Console.ReadLine(), out wID);
            }
            int wIndex = GetWorkerIndex(dep, wID);

            if (wIndex == -1)
            {
                Console.WriteLine("Указанного работника не существует!");
            }
            else
            {
                int sMode = 0;
                while (sMode < 1 || sMode > 2)
                {
                    Console.WriteLine("1 - Json.");
                    Console.WriteLine("2 - XML.");
                    Int32.TryParse(Console.ReadLine(), out sMode);
                }

                if (sMode == 1)
                {
                    Console.WriteLine("Введите путь: ");
                    string    path = Console.ReadLine();
                    ParseJson json = new ParseJson();
                    json.SerializeWorker(path, dep.WorkerList[wIndex]);
                    Console.WriteLine("Готово!");
                }

                else if (sMode == 2)
                {
                    Console.WriteLine("Введите путь: ");
                    string   path = Console.ReadLine();
                    ParseXML xml  = new ParseXML();
                    xml.SerializeWorker(dep.WorkerList[wIndex], path);
                    Console.WriteLine("Готово!");
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Deserialize department from Json/Xml file to Department instance.
        /// </summary>
        /// <param name="path">Path to file.</param>
        /// <returns></returns>
        public static Department DeserializeDepartmentJX(string path)
        {
            //todo: check
            Department tempDep = new Department();

            if (path.Contains(".xml"))
            {
                ParseXML xml = new ParseXML();
                tempDep = xml.DeserializeDepartment(path);
                return(tempDep);
            }
            if (path.Contains(".json"))
            {
                ParseJson json = new ParseJson();
                tempDep = json.DeserializeDepartment(path);
                return(tempDep);
            }

            return(null);
        }