public IActionResult Save()
        {
            var formData = this.Request.Form;

            try
            {
                OnlineCosmeticShop onlineCosmeticShop = ObjectConstuctor.constructXMLObject(formData);

                XmlSerializer xmlSerializer = new XmlSerializer(typeof(OnlineCosmeticShop));

                FileStream fileStream = new FileStream(
                    $"C:\\Users\\ksimeonova\\Documents\\ASP\\CozmeticZone\\CozmeticZone\\XML\\G_Products.xml",
                    FileMode.CreateNew);

                using (StreamWriter streamWriter = new StreamWriter(fileStream))
                {
                    xmlSerializer.Serialize(streamWriter, onlineCosmeticShop);
                }

                string name       = "G_Products.xml";
                bool   isValidXML = XMLValidator.isValidXML(name);

                if (isValidXML)
                {
                    DBManipulator.fillDatabase(onlineCosmeticShop);
                }

                ViewBag.ValidXML = isValidXML;
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
                ViewBag.FileExists = true;
            }
            catch (FormatException e)
            {
                Console.WriteLine(e);
                ViewBag.IncorrectFormat = true;
            }

            return(View("Save"));
        }
예제 #2
0
        public IActionResult Save()
        {
            var formData = this.Request.Form;

            try
            {
                SmartphoneCatalog onlineCosmeticShop = ObjectConstuctor.constructXMLObject(formData);

                XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartphoneCatalog));
                FileStream    fileStream    = new FileStream(
                    $"C:\\Users\\Dan4inatora\\Desktop\\Kris_proj\\SmartPhone_Catalog\\SmartPhone_Catalog\\XML\\G_Books.xml",
                    FileMode.CreateNew);

                using (StreamWriter streamWriter = new StreamWriter(fileStream))
                {
                    xmlSerializer.Serialize(streamWriter, onlineCosmeticShop);
                }

                string name       = "G_Books.xml";
                bool   isValidXML = XMLValidator.isValidXML(name);

                if (isValidXML)
                {
                    DBManipulator.fillDatabase(onlineCosmeticShop);
                }

                ViewBag.ValidXML = isValidXML;
            }
            catch (IOException e)
            {
                Console.WriteLine(e);
                ViewBag.FileExists = true;
            }
            catch (FormatException e)
            {
                Console.WriteLine(e);
                ViewBag.IncorrectFormat = true;
            }

            return(View("Save"));
        }
        public IActionResult Serialize()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(OnlineCosmeticShop));

            var filesInfo = new Dictionary <string, bool>();

            for (int index = 1; index <= 20; index++)
            {
                try
                {
                    string fileName = $"Products_{index}.xml";
                    bool   validXML = XMLValidator.isValidXML(fileName);

                    bool isValid = XMLValidator.isValidXML();

                    FileStream fileStream = new FileStream(
                        $"C:\\Users\\ksimeonova\\Documents\\ASP\\CozmeticZone\\CozmeticZone\\XML\\Products_{index}.xml",
                        FileMode.Open);

                    if (validXML)
                    {
                        OnlineCosmeticShop onlineCosmeticShop =
                            (OnlineCosmeticShop)xmlSerializer.Deserialize(fileStream);
                        var success = DBManipulator.fillDatabase(onlineCosmeticShop);
                        ViewBag.Sucess = success;
                    }

                    fileStream.Close();
                    filesInfo.Add(fileName, validXML);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ViewBag.IncorrectFormat = true;
                }
            }

            ViewBag.FilesInfo = filesInfo;

            return(View());
        }
예제 #4
0
        public IActionResult Serialize()
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SmartphoneCatalog));

            var filesInfo = new Dictionary <string, bool>();

            for (int index = 1; index <= 20; index++)
            {
                try
                {
                    string fileName = $"Book_{index}.xml";
                    bool   validXML = XMLValidator.isValidXML(fileName);
                    string path     = Environment.CurrentDirectory;

                    FileStream fileStream = new FileStream(
                        $"C:\\Users\\Dan4inatora\\Desktop\\Kris_proj\\SmartPhone_Catalog\\SmartPhone_Catalog\\XML\\Book_{index}.xml",
                        FileMode.Open);

                    if (validXML)
                    {
                        SmartphoneCatalog smartphoneCatalog =
                            (SmartphoneCatalog)xmlSerializer.Deserialize(fileStream);
                        var success = DBManipulator.fillDatabase(smartphoneCatalog);
                        ViewBag.Sucess = success;
                    }

                    fileStream.Close();
                    filesInfo.Add(fileName, validXML);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ViewBag.IncorrectFormat = true;
                }
            }

            ViewBag.FilesInfo = filesInfo;

            return(View());
        }