Esempio n. 1
0
        static void Main(string[] args)
        {
            //Televisor televisor = new Televisor("Sony", "HRMN-100", "Red", 1000, 42, "1280x960", "CLD");
            //MultimediaAcousticSystem audioSystem = new MultimediaAcousticSystem("SVEN", "CDO-50", "Black", 20, 5.1);
            //Notebook notebook = new Notebook("ASUS", "SX50", "Black", 325, "2x2000GHr", 1000000, 8000, "GeForce NX500", "800x600", 15, true);
            //PC pc = new PC("Pentium", "5", "Black", 550, "5x2000GHr", 1000000, 4000, "GeForce sX8000", "1920x1080", 24, false);
            //Fridge fridge = new Fridge("Atlant", "SX200", "White", 500, 1.9, 0.6, 0.7, true);
            //Washer washer = new Washer("LG", "L5", "Silver", 800, 1.2, 1.0, 0.45, 800, 5);
            //Ketle ketle = new Ketle("Bosh", "S5", "Silver", 550, 1.2);
            //VacuumCleaner vacuumCleaner = new VacuumCleaner("Samsung", "GCRE1800", "Purple", 600, 1800);


            List <ElectricalAppliances> appliences = new List <ElectricalAppliances>();
            var            serializer    = new XmlSerializer();
            JSONSerializer binSerializer = new JSONSerializer();

            //appliences.Add(audioSystem);
            //appliences.Add(televisor);
            //appliences.Add(notebook);
            //appliences.Add(pc);
            //appliences.Add(washer);

            bool appliactionNeverStop = false;

            do
            {
                Console.WriteLine("Home Appliances System is ready to use");
                Console.WriteLine();
                Console.WriteLine("To see a list of Home Appliances please enter LIST and press Enter");
                Console.WriteLine();
                Console.WriteLine("To upload Home Appliances from xml file please enter XML and press Enter");
                Console.WriteLine();
                Console.WriteLine("To upload Home Appliances from data file please enter JSON and press Enter");
                Console.WriteLine();
                Console.WriteLine("To save Home Appliances to xml file please enter SAVEXML and press Enter");
                Console.WriteLine();
                Console.WriteLine("To save Home Appliances to data file please enter SAVEJSON and press Enter");
                Console.WriteLine();


                bool   correctCommand      = false;
                string userChoiceFirstMenu = Console.ReadLine();
                do
                {
                    if (String.Equals(userChoiceFirstMenu, "LIST"))
                    {
                        correctCommand = true;
                    }

                    else if (String.Equals(userChoiceFirstMenu, "XML"))
                    {
                        correctCommand = true;
                    }

                    else if (String.Equals(userChoiceFirstMenu, "JSON"))
                    {
                        correctCommand = true;
                    }

                    else if (String.Equals(userChoiceFirstMenu, "SAVEXML"))
                    {
                        correctCommand = true;
                    }
                    else if (String.Equals(userChoiceFirstMenu, "SAVEJSON"))
                    {
                        correctCommand = true;
                    }
                    else
                    {
                        Console.WriteLine("Wrong command, choose from the following options (LIST, XML, JSON, SAVEXML, SAVEJSON)");

                        userChoiceFirstMenu = Console.ReadLine();
                    }
                } while (correctCommand == false);

                switch (userChoiceFirstMenu)
                {
                case "LIST":
                    try
                    {
                        if (appliences.Count > 0)
                        {
                            for (int i = 1; i < appliences.Count + 1; i++)
                            {
                                Console.WriteLine("ID: {0}", i);
                                appliences[i - 1].PrintSummary();
                            }
                        }
                        else
                        {
                            throw (new CatalogIsEpmtyException("Appliances Catalog is empty. Please, upload appliances first."));
                        }
                    }
                    catch (CatalogIsEpmtyException ex)
                    {
                        Console.WriteLine(ex.Message.ToString());
                        Console.WriteLine();
                    }
                    break;

                case "XML":
                    try
                    {
                        appliences = serializer.Deserialize();
                    }
                    catch (DirectoryNotFoundException directoryNotFound)
                    {
                        Console.WriteLine(directoryNotFound.Message);
                    }
                    catch (FileNotFoundException fileNotFound)
                    {
                        Console.WriteLine(fileNotFound.Message);
                    }
                    catch (PathTooLongException longPath)
                    {
                        Console.WriteLine(longPath.Message);
                    }

                    catch (SecurityException securityException)
                    {
                        Console.WriteLine(securityException.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "JSON":
                    try
                    {
                        appliences = binSerializer.Deserialize();
                    }
                    catch (DirectoryNotFoundException directoryNotFound)
                    {
                        Console.WriteLine(directoryNotFound.Message);
                    }
                    catch (FileNotFoundException fileNotFound)
                    {
                        Console.WriteLine(fileNotFound.Message);
                    }
                    catch (PathTooLongException longPath)
                    {
                        Console.WriteLine(longPath.Message);
                    }

                    catch (SecurityException securityException)
                    {
                        Console.WriteLine(securityException.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    break;

                case "SAVEXML":
                    serializer.Serialize(appliences);
                    break;

                case "SAVEJSON":
                    binSerializer.Serialize(appliences);
                    break;

                default:
                    break;
                }
            } while (appliactionNeverStop == false);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <ElectricalAppliances> appliences = new List <ElectricalAppliances>();
            var            serializer    = new XmlSerializer();
            JSONSerializer binSerializer = new JSONSerializer();

            bool appliactionNeverStop = false;

            do
            {
                Console.WriteLine("Home Appliances System is ready to use");
                Console.WriteLine();
                Console.WriteLine("To see a list of Home Appliances please enter LIST and press Enter");
                Console.WriteLine();
                Console.WriteLine("To upload Home Appliances from xml file please enter XML and press Enter");
                Console.WriteLine();
                Console.WriteLine("To upload Home Appliances from data file please enter JSON and press Enter");
                Console.WriteLine();
                Console.WriteLine("To save Home Appliances to xml file please enter SAVEXML and press Enter");
                Console.WriteLine();
                Console.WriteLine("To save Home Appliances to data file please enter SAVEJSON and press Enter");
                Console.WriteLine();


                bool   correctCommand      = false;
                string userChoiceFirstMenu = Console.ReadLine();
                do
                {
                    if (String.Equals(userChoiceFirstMenu, "LIST"))
                    {
                        correctCommand = true;
                    }

                    else if (String.Equals(userChoiceFirstMenu, "XML"))
                    {
                        correctCommand = true;
                    }

                    else if (String.Equals(userChoiceFirstMenu, "JSON"))
                    {
                        correctCommand = true;
                    }
                    else if (String.Equals(userChoiceFirstMenu, "SAVEXML"))
                    {
                        correctCommand = true;
                    }
                    else if (String.Equals(userChoiceFirstMenu, "SAVEJSON"))
                    {
                        correctCommand = true;
                    }
                    else
                    {
                        Console.WriteLine("Wrong command, choose from the following options (LIST, XML, JSON, SAVEXML, SAVEJSON)");

                        userChoiceFirstMenu = Console.ReadLine();
                    }
                } while (correctCommand == false);

                switch (userChoiceFirstMenu)
                {
                case "LIST":
                    try
                    {
                        if (appliences.Count > 0)
                        {
                            for (int i = 1; i < appliences.Count + 1; i++)
                            {
                                Console.WriteLine("ID: {0}", i);
                                appliences[i - 1].PrintSummary();
                            }
                        }
                        else
                        {
                            throw (new CatalogIsEpmtyException("Appliances Catalog is empty. Please, upload appliances first."));
                        }
                    }
                    catch (CatalogIsEpmtyException ex)
                    {
                        Console.WriteLine(ex.Message.ToString());
                        Console.WriteLine();
                    }
                    break;

                case "XML":
                    try
                    {
                        appliences = serializer.Deserialize();
                    }
                    catch (DirectoryNotFoundException directoryNotFound)
                    {
                        Console.WriteLine(directoryNotFound.Message);
                    }
                    catch (FileNotFoundException fileNotFound)
                    {
                        Console.WriteLine(fileNotFound.Message);
                    }
                    catch (PathTooLongException longPath)
                    {
                        Console.WriteLine(longPath.Message);
                    }

                    catch (SecurityException securityException)
                    {
                        Console.WriteLine(securityException.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case "JSON":
                    try
                    {
                        appliences = binSerializer.Deserialize();
                    }
                    catch (DirectoryNotFoundException directoryNotFound)
                    {
                        Console.WriteLine(directoryNotFound.Message);
                    }
                    catch (FileNotFoundException fileNotFound)
                    {
                        Console.WriteLine(fileNotFound.Message);
                    }
                    catch (PathTooLongException longPath)
                    {
                        Console.WriteLine(longPath.Message);
                    }

                    catch (SecurityException securityException)
                    {
                        Console.WriteLine(securityException.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    break;

                case "SAVEXML":
                    serializer.Serialize(appliences);
                    break;

                case "SAVEJSON":
                    binSerializer.Serialize(appliences);
                    break;

                default:
                    break;
                }
            } while (appliactionNeverStop == false);
        }