Example #1
0
 static void StorageInitialization(Storage[] flashStorage, double memory)
 {
     for (int i = 0; i < flashStorage.Length; i++)
     {
         flashStorage[i] = new FlashMemory(memory);
     }
 }
Example #2
0
 static double CopyingTime(FlashMemory flashMemory, double copyMemory)
 {
     return(copyMemory / flashMemory.Speed);
 }
Example #3
0
        static void Main(string[] args)
        {
            double informationMemoryValueInGb = Constants.NULL;

            SetInformationMemory(ref informationMemoryValueInGb);

            double       flashMemory        = SetFlashMemory();
            int          hddSectionCount    = SetSectionCount();
            double       hddSectionMemory   = SetSectionMemory();
            DVDDisckType dvdDisckType       = SetDVDDisckType();
            double       dvdDisckWriteSpeed = SetDVDDisckWriteSpeed();
            double       dvdDisckReadSpeed  = SetDVDDisckReadSpeed();

            int flashCount = StorageCount(flashMemory, informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
            int hddCount   = StorageCount(hddSectionCount * hddSectionMemory, informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
            int dvdCount   = Constants.NULL;

            switch (dvdDisckType)
            {
            case DVDDisckType.Unilateral:
                dvdCount = StorageCount(Constants.UNITARELAL_DVDDISCK_MEMORY, informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
                break;

            case DVDDisckType.Bilateral:
                dvdCount = StorageCount(Constants.BILATERAL_DVDDISCK_MEMORY, informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
                break;
            }

            Storage[] flashStorage    = new FlashMemory[flashCount];
            Storage[] hddStorage      = new HDDStorage[hddCount];
            Storage[] dvdDisckStorage = new DVDDisck[dvdCount];

            StorageInitialization(flashStorage, flashMemory);
            StorageInitialization(hddStorage, hddSectionCount, hddSectionMemory);
            StorageInitialization(dvdDisckStorage, dvdDisckType, dvdDisckReadSpeed, dvdDisckWriteSpeed);

            bool isWantToCopy;

            while (true)
            {
                try
                {
                    Console.WriteLine("Хотите сделать резервную копию(y/n)");

                    string choice = Console.ReadLine().Trim();

                    if (choice == "y" || choice == "Y" || choice == "Yes" || choice == "YES")
                    {
                        isWantToCopy = true;
                        break;
                    }
                    else if (choice == "n" || choice == "N" || choice == "No" || choice == "NO")
                    {
                        isWantToCopy = false;
                        break;
                    }
                    else
                    {
                        throw new ArgumentException("Некоректный ответ");
                    }
                }
                catch (ArgumentException exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            if (isWantToCopy == true)
            {
                for (int i = 0; i < flashStorage.Length; i++)
                {
                    double copyMemory = informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT - (flashStorage[i] as FlashMemory).FreeMemory;
                    (flashStorage[i] as FlashMemory).CopyInStorageInMb(informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
                }
                for (int i = 0; i < hddStorage.Length; i++)
                {
                    double copyMemory = informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT - (hddStorage[i] as HDDStorage).FreeMemory;
                    (hddStorage[i] as HDDStorage).CopyInStorageInMb(informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
                }
                for (int i = 0; i < dvdDisckStorage.Length; i++)
                {
                    double copyMemory = informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT - (dvdDisckStorage[i] as DVDDisck).FreeMemory;
                    (dvdDisckStorage[i] as DVDDisck).CopyInStorageInMb(informationMemoryValueInGb * Constants.IN_GIGABYTE_MEGABYTE_COUNT);
                }
            }

            Console.WriteLine($"Общая память всех устройств\n" +
                              $"Flash: {flashMemory*flashCount}\n" +
                              $"HDD: {hddSectionCount*hddSectionMemory*hddCount}\n" +
                              $"DVDDisck: {dvdDisckStorage[Constants.FIRST_INDEX].GetMemoryValueInMb() * dvdCount}");

            Console.WriteLine($"Кол необходимых носителей\n" +
                              $"Flash: {flashCount}\n" +
                              $"HDD: {hddCount}\n" +
                              $"DVDDisck: {dvdCount}\n");

            Console.WriteLine($"Необходимое время для копирование\n" +
                              $"Flash: {CopyingTime(flashStorage[Constants.FIRST_INDEX] as FlashMemory, informationMemoryValueInGb*Constants.IN_GIGABYTE_MEGABYTE_COUNT) * flashCount}s\n" +
                              $"HDD: {CopyingTime(hddStorage[Constants.FIRST_INDEX] as HDDStorage, informationMemoryValueInGb*Constants.IN_GIGABYTE_MEGABYTE_COUNT)}s\n" +
                              $"DVDDisck: {CopyingTime(dvdDisckStorage[Constants.FIRST_INDEX] as DVDDisck, informationMemoryValueInGb*Constants.IN_GIGABYTE_MEGABYTE_COUNT)}s\n");
        }