using Ionic.Utils.Zip; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace Fuel01 { partial class f_about : Form { string runApp = ""; Boolean isSending = false; 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_bin+".txt"); 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)) if (baseVersion > version) bt_maj.BackColor = Color.LightGreen; } catch (Exception e) {; } 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 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 string AssemblyVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } public string AssemblyDescription { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyDescriptionAttribute)attributes[0]).Description; } } public string AssemblyProduct { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyProductAttribute)attributes[0]).Product; } } public string AssemblyCopyright { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } } public string AssemblyCompany { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCompanyAttribute)attributes[0]).Company; } } #endregion private void tableLayoutPanel_Paint(object sender, PaintEventArgs e) { } 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(); DateTime deb = DateTime.Now; 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", 2); sendFile(Program.subfolder + @"\presta.json", 2); sendFile(Program.subfolder + @"\vehicule.json", 2); sendFile(Program.folder + @"\param\produit.json", 2); } else { sendFile(Program.subfolder + @"\station.json",3); sendFile(Program.subfolder + @"\presta.json",3); sendFile(Program.subfolder + @"\vehicule.json",3); sendFile(Program.folder + @"\param\produit.json",3); } Thread.Sleep(5000); label1.Visible = false; this.Cursor = Cursors.Default; System.Windows.Forms.Application.DoEvents(); } private void sendFile(string fileName,int mode) { isSending = true; if ( (mode & 1)==1) { string chaine = Properties.Settings.Default.adresse_copie_api; WebClient client = new WebClient(); client.UploadProgressChanged += new UploadProgressChangedEventHandler(Client_UploadProgressChanged); client.UploadFileCompleted += new UploadFileCompletedEventHandler(Client_UploadFileCompleted); client.UploadFileAsync(new Uri(chaine), "POST", fileName); } if ((mode & 2) == 2) { string chaine2 = @"http://www.aformatix.com/ASOStationService/api/FileUpLoad/upLoadFiles"; WebClient clientAfo = new WebClient(); clientAfo.UploadFileAsync(new Uri(chaine2), "POST", fileName); } } private void Client_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e) { isSending = false; } 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 f_about_Load(object sender, EventArgs e) { } private void okButton_Click(object sender, EventArgs e) { } 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); 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 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; } } }