| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- using Ionic.Utils.Zip;
- using Newtonsoft.Json;
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Net;
- using System.Net.Http;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace Fuel01
- {
- partial class f_about : Form
- {
- string runApp = "";
- public f_about()
- {
- InitializeComponent();
- this.Text = String.Format("À propos de {0}", AssemblyTitle);
- this.labelProductName.Text = AssemblyProduct;
- string[] strVersion = AssemblyVersion.Split('.');
- double version = Convert.ToDouble(strVersion[0]) * 100000 + Convert.ToDouble(strVersion[1]) * 1000 + Convert.ToDouble(strVersion[2]) + Convert.ToDouble(strVersion[3]) / 10000;
- double baseVersion = 0;
- WebRequest request = WebRequest.Create(Properties.Settings.Default.server_adress_datas);
- try
- {
- WebResponse response = request.GetResponse();
- StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
- string retour = sr.ReadToEnd();
- sr.Close();
- if (double.TryParse(retour, out baseVersion) && baseVersion > version)
- {
- bt_maj.BackColor = Color.LightGreen;
- }
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
- this.labelVersion.Text = String.Format("Version {0}-{1}-{2}", AssemblyVersion, version, baseVersion);
- this.labelCopyright.Text = AssemblyCopyright;
- this.labelCompanyName.Text = AssemblyCompany;
- this.textBoxDescription.Text = AssemblyDescription + "\r\n" + this.textBoxDescription.Text;
- this.textBoxDescription.Text += "\r\n" + Program.folder;
- this.textBoxDescription.Text += "\r\n" + Program.subfolder;
- textSrvDatas.Text = Properties.Settings.Default.server_adress_datas;
- textSrvBin.Text = Properties.Settings.Default.server_adress_bin;
- textSignalR.Text = Properties.Settings.Default.server_signalr;
- textCopieLocal.Text = Properties.Settings.Default.chemin_copie_locale;
- checkBoxLocale.Checked = Properties.Settings.Default.use_locale;
- textCopieAPI.Text = Properties.Settings.Default.adresse_copie_api;
- bt_send.Enabled = File.Exists(Program.subfolder + @"\station.json");
- }
- #region Accesseurs d'attribut de l'assembly
- public static string AssemblyTitle
- {
- get
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
- if (attributes.Length > 0)
- {
- AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
- if (titleAttribute.Title != "")
- {
- return titleAttribute.Title;
- }
- }
- return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
- }
- }
- public static string AssemblyVersion
- {
- get
- {
- return Assembly.GetExecutingAssembly().GetName().Version.ToString();
- }
- }
- public static string AssemblyDescription
- {
- get
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
- if (attributes.Length == 0)
- {
- return "";
- }
- return ((AssemblyDescriptionAttribute)attributes[0]).Description;
- }
- }
- public static string AssemblyProduct
- {
- get
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
- if (attributes.Length == 0)
- {
- return "";
- }
- return ((AssemblyProductAttribute)attributes[0]).Product;
- }
- }
- public static string AssemblyCopyright
- {
- get
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
- if (attributes.Length == 0)
- {
- return "";
- }
- return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
- }
- }
- public static string AssemblyCompany
- {
- get
- {
- object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
- if (attributes.Length == 0)
- {
- return "";
- }
- return ((AssemblyCompanyAttribute)attributes[0]).Company;
- }
- }
- #endregion
- private void button2_Click(object sender, EventArgs e)
- {
- DialogResult dr = opfile.ShowDialog();
- if (dr == DialogResult.OK)
- {
- string filename = opfile.FileName;
- f_extract res = new f_extract(filename);
- res.ShowDialog();
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- fold.Description = "Sélectionnez le répertoire où sera enregistrée l'archive";
- DialogResult dr = fold.ShowDialog();
- if (dr == DialogResult.OK)
- {
- DateTime dt = DateTime.Now;
- string filename = fold.SelectedPath + @"\Result_" + dt.ToString("yy_MM_dd_hh_mm_ss") + ".txt";
- StreamWriter writer = File.CreateText(filename);
- var zip = new ZipFile(fold.SelectedPath + @"\Backup_" + dt.ToString("yy_MM_dd_hh_mm_ss") + ".zip", writer);
- string tmpDir = Path.GetTempPath();
- if (!Directory.Exists(tmpDir))
- tmpDir = Environment.GetEnvironmentVariable("temp");
- if (!Directory.Exists(tmpDir))
- tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
- zip.TempFileFolder = tmpDir;
- zip.AddDirectory(Program.folder, "AsoFuel");
- zip.Save();
- writer.Close();
- f_result res = new f_result(filename, zip.Name);
- res.ShowDialog();
- }
- }
- private void bt_send_Click(object sender, EventArgs e)
- {
- label1.Visible = true;
- this.Cursor = Cursors.WaitCursor;
- System.Windows.Forms.Application.DoEvents();
- Properties.Settings.Default.chemin_copie_locale = textCopieLocal.Text;
- if (Properties.Settings.Default.use_locale)
- {
- File.Copy(Program.subfolder + @"\station.json", Properties.Settings.Default.chemin_copie_locale + @"\station.json", true);
- File.Copy(Program.subfolder + @"\presta.json", Properties.Settings.Default.chemin_copie_locale + @"\presta.json", true);
- File.Copy(Program.subfolder + @"\vehicule.json", Properties.Settings.Default.chemin_copie_locale + @"\vehicule.json", true);
- File.Copy(Program.folder + @"\param\produit.json", Properties.Settings.Default.chemin_copie_locale + @"\produit.json", true);
- SendFile(Program.subfolder + @"\station.json").Wait();
- SendFile(Program.subfolder + @"\presta.json").Wait();
- SendFile(Program.subfolder + @"\vehicule.json").Wait() ;
- SendFile(Program.folder + @"\param\produit.json").Wait();
- }
- else
- {
- SendFile(Program.subfolder + @"\station.json").Wait();
- SendFile(Program.subfolder + @"\presta.json").Wait();
- SendFile(Program.subfolder + @"\vehicule.json").Wait();
- SendFile(Program.folder + @"\param\produit.json").Wait();
- }
- Thread.Sleep(5000);
- label1.Visible = false;
- this.Cursor = Cursors.Default;
- System.Windows.Forms.Application.DoEvents();
- }
- private async Task SendFile(string fileName)
- {
- var file = new TdfFile
- {
- Name = Path.GetFileName(fileName),
- Data = Encoding.UTF8.GetBytes(File.ReadAllText(fileName))
- };
- try
- {
- var client = new HttpClient();
- var request = new HttpRequestMessage(HttpMethod.Post, $"{Properties.Settings.Default.adresse_copie_api}GetFile");
- var content = new StringContent(JsonConvert.SerializeObject(file), null, "application/json");
- request.Content = content;
- var response = await client.SendAsync(request);
- response.EnsureSuccessStatusCode();
- Console.WriteLine(await response.Content.ReadAsStringAsync());
- }
- catch (Exception ex)
- {
- Console.WriteLine("ERRRRRRRRRRRRRRRREUUUUUUUUUURRRRRRRRRRR POST :" + ex.ToString());
- }
- }
- private void Client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
- {
- double bytesIn = double.Parse(e.BytesSent.ToString());
- double totalBytes = double.Parse(e.TotalBytesToSend.ToString());
- double percentage = bytesIn / totalBytes * 100;
- progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
- }
- private void bt_clean_Click(object sender, EventArgs e)
- {
- f_clean fclean = new f_clean();
- fclean.ShowDialog();
- }
- private void button2_Click_1(object sender, EventArgs e)
- {
- string appName = Properties.Settings.Default.server_adress_bin.Substring(Properties.Settings.Default.server_adress_bin.LastIndexOf('/') + 1);
- string chaine = Properties.Settings.Default.server_adress_bin;
- string tmpDir = Path.GetTempPath();
- if (!Directory.Exists(tmpDir))
- tmpDir = Environment.GetEnvironmentVariable("temp");
- if (!Directory.Exists(tmpDir))
- tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
- WebClient client = new WebClient();
- client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
- client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
- client.Dispose();
- try
- {
- runApp = tmpDir + appName;
- if (File.Exists(runApp))
- File.Delete(runApp);
- client.DownloadFileAsync(new Uri(chaine), tmpDir + appName);
- }
- catch
- {
- runApp = "";
- MessageBox.Show("Le téléchargement a échoué");
- }
- bt_maj.Text = "En cours..";
- bt_maj.Enabled = false;
- }
- void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
- {
- double bytesIn = double.Parse(e.BytesReceived.ToString());
- double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
- double percentage = bytesIn / totalBytes * 100;
- progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
- }
- void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
- {
- if (MessageBox.Show("L'application va se terminer et l'installation de la nouvelle commencer!!", "Téléchargement Terminé", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
- {
- ProcessStartInfo myprocessStartInfo = new ProcessStartInfo(runApp);
- Process install = new Process();
- install.StartInfo = myprocessStartInfo;
- install.Start();
- System.Windows.Forms.Application.Exit();
- }
- bt_maj.Text = "MAJ";
- bt_maj.Enabled = true;
- bt_maj.BackColor = Color.Transparent;
- }
- private void bt_check_Click(object sender, EventArgs e)
- {
- TextBox from = null;
- CheckBox chk = null;
- if ((Button)sender == bt_checkBin)
- {
- from = textSrvBin;
- chk = checkBoxBin;
- }
- if ((Button)sender == bt_checkDatas)
- {
- from = textSrvDatas;
- chk = checkBoxDatas;
- }
- if ((Button)sender == bt_checkR)
- {
- from = textSignalR;
- chk = checkBoxSignalR;
- }
- if ((Button)sender == bt_chekAPI)
- {
- from = textCopieAPI;
- chk = checkBoxAPI;
- }
- lblRes.Text = "....";
- bool result = checkUrl(from.Text + ((Button)sender == bt_chekAPI ? "test" : ""));
- chk.CheckState = result ? CheckState.Checked : CheckState.Unchecked;
- lblRes.Text = result.ToString();
- }
- private static bool checkUrl(string url)
- {
- bool ret = false;
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Timeout = 5000;
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- ret = true;
- response.Dispose();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- return ret;
- }
- private void bt_sav_Click(object sender, EventArgs e)
- {
- if (checkBoxDatas.CheckState == CheckState.Checked || checkAll.Checked)
- Properties.Settings.Default.server_adress_datas = textSrvDatas.Text;
- if (checkBoxBin.CheckState == CheckState.Checked || checkAll.Checked)
- Properties.Settings.Default.server_adress_bin = textSrvBin.Text;
- if (checkBoxSignalR.CheckState == CheckState.Checked || checkAll.Checked)
- Properties.Settings.Default.server_signalr = textSignalR.Text;
- Properties.Settings.Default.chemin_copie_locale = textCopieLocal.Text;
- Properties.Settings.Default.use_locale = checkBoxLocale.Checked;
- if (checkBoxAPI.CheckState == CheckState.Checked || checkAll.Checked)
- Properties.Settings.Default.adresse_copie_api = textCopieAPI.Text;
- Properties.Settings.Default.Save();
- }
- private void bt_fold_Click(object sender, EventArgs e)
- {
- fold2.SelectedPath = textCopieLocal.Text;
- DialogResult res = fold2.ShowDialog();
- if (res == DialogResult.OK)
- textCopieLocal.Text = fold2.SelectedPath;
- }
- }
- }
|