示例#1
0
文件: Update.cs 项目: Vla00/alone
        //метод протокола FTP RETR для загрузки файла с FTP-сервера
        public void DownloadFile(string path, string fileName, string output, LoadProgram load)
        {
            ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://" + _Host + path + "/" + fileName);

            ftpRequest.Credentials = new NetworkCredential(_UserName, _Password);
            //команда фтп RETR
            ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
            FtpWebResponse respSize = (FtpWebResponse)ftpRequest.GetResponse();
            long           sizeSrc  = respSize.ContentLength;

            ftpResponse.Close();
            _load = load;
            double proc     = sizeSrc / 1024.0000;
            double one_proc = 100.0000 / proc;
            double summ     = 0.00000;

            ftpRequest = (FtpWebRequest)WebRequest.Create("ftp://" + _Host + path + "/" + fileName);

            ftpRequest.Credentials = new NetworkCredential(_UserName, _Password);
            ftpRequest.Method      = WebRequestMethods.Ftp.DownloadFile;

            ftpRequest.EnableSsl = _UseSSL;
            //Файлы будут копироваться в кталог программы
            FileStream downloadedFile = new FileStream(output + "/" + path + "/" + fileName, FileMode.Create, FileAccess.ReadWrite);

            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            //Получаем входящий поток
            Stream responseStream = ftpResponse.GetResponseStream();

            //Буфер для считываемых данных
            byte[] buffer = new byte[1024];
            int    size   = 0;

            while ((size = responseStream.Read(buffer, 0, 1024)) > 0)
            {
                summ += one_proc;
                downloadedFile.Write(buffer, 0, size);
                _load.SetProgressValue((int)summ);
            }
            ftpResponse.Close();
            downloadedFile.Close();
            responseStream.Close();

            FileInfo file     = new FileInfo(output + "/" + path + "/" + fileName);
            long     sizeDesc = file.Length;

            if (sizeDesc != sizeSrc)
            {
            }
        }
示例#2
0
文件: Main.cs 项目: Andriew/SopOS
        static void Main(string[] args)
        {
            ProcessManager processManager;

            try
            {
                int choice;
                processManager = new ProcessManager(); //utworz manager procesow

                do
                {
                    Console.WriteLine();
                    Console.WriteLine("1. Wyswietl liste wszystkich procesow");
                    Console.WriteLine("2. Wyswietl PCB danego procesu (po nazwie)");
                    Console.WriteLine("3. Wyswietl PCB danego procesu (po PID)");
                    Console.WriteLine("4. Sprawdz czy dany proces istnieje");
                    Console.WriteLine("5. Wczytaj program z dysku");
                    Console.WriteLine("6. Utworz recznie proces");
                    Console.WriteLine("7. Zmien priorytet procesu");
                    Console.WriteLine("8. Zmien stan procesu");
                    Console.WriteLine("9. Usun proces (po PID)");
                    Console.WriteLine("10. Usun proces (po nazwie)");
                    Console.WriteLine("11. Usun wszystkie procesy");
                    Console.WriteLine("0. Zakoncz");
                    Console.WriteLine();

                    choice = int.Parse(Console.ReadLine());
                    try
                    {
                        switch (choice)
                        {
                        case 1:
                        {
                            processManager.displayAllProcess();
                            break;
                        }

                        case 2:
                        {
                            Console.Write("Podaj nazwe procesu: ");
                            string name = Console.ReadLine();
                            processManager.displayProcess(name);
                            break;
                        }

                        case 3:
                        {
                            Console.Write("Podaj PID procesu: ");
                            int pid = int.Parse(Console.ReadLine());
                            processManager.displayProcess(pid);
                            break;
                        }

                        case 4:
                        {
                            Console.Write("Podaj PID procesu: ");
                            int  pid   = int.Parse(Console.ReadLine());
                            bool check = processManager.existProcess(pid);
                            if (check)
                            {
                                processManager.displayProcess(pid);
                            }
                            else
                            {
                                Console.WriteLine("Proces o tym PID nie istnieje!");
                            }

                            break;
                        }

                        case 5:
                        {
                            LoadProgram loadprogram;
                            string      path;

                            Console.WriteLine("1. Wczytaj program");
                            Console.WriteLine("2. Wczytaj program1");
                            //Console.WriteLine("3. Wczytaj program2");
                            Console.WriteLine("3. Wczytaj program3");

                            int program = int.Parse(Console.ReadLine());

                            switch (program)
                            {
                            case 1:
                            {
                                path        = "program.exe";
                                loadprogram = new LoadProgram(path, processManager);
                                //zaladuj program i odrazu utworz procesy
                                Console.WriteLine("Ilosc procesow w kolejce: " + processManager.processList.Count);
                                Process p = processManager.getProcess("program.exe");
                                processManager.setProcessState(1, p);
                                p.displayPCB();
                                break;
                            }

                            case 2:
                            {
                                path        = "program1.exe";
                                loadprogram = new LoadProgram(path, processManager);
                                //zaladuj program i odrazu utworz procesy
                                Console.WriteLine("Ilosc procesow w kolejce: " + processManager.processList.Count);
                                Process p = processManager.getProcess("program1.exe");
                                processManager.setProcessState(1, p);
                                p.displayPCB();
                                break;
                            }

                            /*
                             * case 3:
                             *  {
                             *      path = "program2.exe";
                             *      loadprogram = new LoadProgram(path, processManager);
                             *      //zaladuj program i odrazu utworz procesy
                             *      Console.WriteLine("Ilosc procesow w kolejce: " + processManager.processList.Count);
                             *      Process p = processManager.getProcess("program2.exe");
                             *      processManager.setProcessState(1, p);
                             *      p.displayPCB();
                             *
                             *      break;
                             *  }
                             */

                            case 3:
                            {
                                path        = "program3.exe";
                                loadprogram = new LoadProgram(path, processManager);
                                //zaladuj program i odrazu utworz procesy
                                Console.WriteLine("Ilosc procesow w kolejce: " + processManager.processList.Count);
                                Process p = processManager.getProcess("program3.exe");
                                processManager.setProcessState(1, p);
                                p.displayPCB();
                                break;
                            }


                            default:
                            {
                                Console.WriteLine("Podales zly numer");
                                break;
                            }
                            }
                            break;
                        }

                        case 6:
                        {
                            Console.WriteLine("Podaj nazwe procesu: ");
                            string name = Console.ReadLine();

                            if (processManager.existProcess(name))
                            {
                                Console.WriteLine("Proces o podanej nazwie juz istnieje!");
                                break;
                            }

                            Console.WriteLine("Podaj wielkosc tablicy: ");
                            int tabSize = int.Parse(Console.ReadLine());

                            Console.WriteLine("Podaj priorytet: ");
                            int priority = int.Parse(Console.ReadLine());

                            Console.WriteLine("Podaj ojca procesu (jezeli proces nie ma ojca wpis 0): ");
                            int father = int.Parse(Console.ReadLine());

                            // Process p = processManager.getProcess(father);
                            //if (p.is_parent || p == null)
                            //    Console.WriteLine("Struktura procesow pozwala tylko na jeden poziom potomkow!");
                            // else
                            processManager.addProcess(name, tabSize, priority, father);

                            break;
                        }

                        case 7:
                        {
                            Console.WriteLine("Podaj PID procesu");
                            int pid = int.Parse(Console.ReadLine());

                            if (!processManager.existProcess(pid))
                            {
                                Console.WriteLine("Proces o podanym PID nie istnieje!");
                            }
                            else
                            {
                                Process p = processManager.getProcess(pid);
                                Console.WriteLine("Podaj priorytet: ");
                                short priority = short.Parse(Console.ReadLine());
                                if (priority > 8 || priority < 1)
                                {
                                    Console.WriteLine("Prioryet musi byc wartoscia od 1 do 8!");
                                    break;
                                }
                                p.actual_priority = priority;
                                Console.WriteLine("Prioryet procesu zostal zmieniony");
                            }

                            break;
                        }

                        case 8:
                        {
                            Console.WriteLine("Podaj pid procesu: ");
                            int     pid = int.Parse(Console.ReadLine());
                            Process p   = processManager.getProcess(pid);

                            Console.WriteLine("Podaj stan: ");
                            short state = short.Parse(Console.ReadLine());

                            processManager.setProcessState(state, p);
                            Console.WriteLine("Stan procesu zostal zmieniony: ");

                            break;
                        }

                        case 9:
                        {
                            Console.WriteLine("Podaj PID procesu: ");
                            int pid = int.Parse(Console.ReadLine());
                            processManager.terminateProcess(pid);
                            break;
                        }

                        case 10:
                        {
                            Console.WriteLine("Podaj nazwe procesu: ");
                            string name = Console.ReadLine();
                            processManager.terminateProcess(name);
                            break;
                        }

                        case 11:
                        {
                            processManager.processList.Clear();
                            Console.WriteLine("Lista procesow zostala wyczyszczona");
                            break;
                        }

                        ///////////////

                        case 0:
                        {
                            choice = 0;
                            break;
                        }

                        default:
                        {
                            Console.WriteLine("Podales zly numer");
                            break;
                        }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        Console.ReadKey();
                    }
                } while (choice != 0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }
 private void LoadProgramFile()
 {
     LoadProgram.LoadProgramFromFile();
 }