ProgressBar - C#
Формулировка задачи:
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading;
using System.Management;
namespace UpdateDataBaseFtpServer
{
class appStart
{
static void Main(string[] args)
{
string str = "";
string str2 = "";
if (str != str2)
{
Thread.Sleep(5000);
Environment.Exit(0);
}
else if (str == null)
{
Thread.Sleep(3000);
Environment.Exit(0);
}
else if (str == str2)
{
int Length = 2048;
Byte[] buffer = new Byte[Length];
Console.WriteLine(" Start. Please wait... ");
Console.WriteLine(" ");
Thread.Sleep(2000);
try
{
string inputfilepath = @"C:\FTP\sklad.rar";
string ftphost = "123.123.123.123";
string ftpfilepath = "/NA_OSP/sklad.rar";
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
using (WebClient request = new WebClient())
{
request.Credentials = new NetworkCredential("123", "123");
Console.WriteLine(" Logon to FTP OK.. ");
Console.WriteLine(" ");
Thread.Sleep(2000);
Console.WriteLine(" Start download and overwrite files.. ");
Console.WriteLine(" ");
byte[] fileData = request.DownloadData(ftpfullpath);
using (FileStream file = File.Create(inputfilepath))
{
file.Write(fileData, 0, fileData.Length);
Console.CursorVisible = false;
for (int i = 0; i <= fileData.Length; i++)
{
for (int y = 0; y < i; y++)
{
Console.Write("в–€");
}
Console.Write(i + "/100");
}
file.Close();
}
}
ProcessStartInfo ps = new ProcessStartInfo();
ps.FileName = @"C:\Program Files\WinRAR\RAR.exe";
ps.Arguments = @"e -o+ C:\FTP\sklad.rar D:\RAB\SKLAD"; //
Process procCommand = Process.Start(ps);
Thread.Sleep(5000);
procCommand.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine(" Eror: " + ex);
Console.ReadLine();
}
}
}
}
}Решение задачи: «ProgressBar»
textual
Листинг программы
static void Main(string[] args)
{
for (int i = 0; i <= 100; ++i)
{
DrawProgressBar(i, 100, 70, '#');
System.Threading.Thread.Sleep(30);
}
Console.ReadLine();
}
static void DrawProgressBar(long complete, long maxVal, int barSize, char progressCharacter)
{
float perc = (float)complete / (float)maxVal;
DrawProgressBar(perc, barSize, progressCharacter);
}
static void DrawProgressBar(float percent, int barSize, char progressCharacter)
{
Console.CursorVisible = false;
int left = Console.CursorLeft;
int chars = (int)Math.Round(percent / (1.0f / (float)barSize));
string p1 = String.Empty, p2 = String.Empty;
for (int i = 0; i < chars; i++)
p1 += progressCharacter;
for (int i = 0; i < barSize - chars; i++)
p2 += progressCharacter;
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(p1);
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write(p2);
Console.ResetColor();
Console.Write(" {0}%", (percent * 100).ToString("N2"));
Console.CursorLeft = left;
}