f_about.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. using Ionic.Utils.Zip;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Fuel01
  17. {
  18. partial class f_about : Form
  19. {
  20. string runApp = "";
  21. Boolean isSending = false;
  22. public f_about()
  23. {
  24. InitializeComponent();
  25. this.Text = String.Format("À propos de {0}", AssemblyTitle);
  26. this.labelProductName.Text = AssemblyProduct;
  27. string[] strVersion = AssemblyVersion.Split('.');
  28. double version = Convert.ToDouble(strVersion[0]) * 100000 + Convert.ToDouble(strVersion[1]) * 1000 + Convert.ToDouble(strVersion[2])+ Convert.ToDouble(strVersion[3])/10000;
  29. double baseVersion = 0;
  30. WebRequest request = WebRequest.Create(Properties.Settings.Default.server_adress_bin+".txt");
  31. try
  32. {
  33. WebResponse response = request.GetResponse();
  34. StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.ASCII);
  35. string retour = sr.ReadToEnd();
  36. sr.Close();
  37. if (double.TryParse(retour, out baseVersion))
  38. if (baseVersion > version)
  39. bt_maj.BackColor = Color.LightGreen;
  40. }
  41. catch (Exception e) {; }
  42. this.labelVersion.Text = String.Format("Version {0}-{1}-{2}", AssemblyVersion,version,baseVersion);
  43. this.labelCopyright.Text = AssemblyCopyright;
  44. this.labelCompanyName.Text = AssemblyCompany;
  45. this.textBoxDescription.Text = AssemblyDescription+"\r\n"+ this.textBoxDescription.Text;
  46. this.textBoxDescription.Text += "\r\n" + Program.folder;
  47. this.textBoxDescription.Text += "\r\n" + Program.subfolder;
  48. textSrvDatas.Text = Properties.Settings.Default.server_adress_datas;
  49. textSrvBin.Text = Properties.Settings.Default.server_adress_bin;
  50. textSignalR.Text = Properties.Settings.Default.server_signalr;
  51. textCopieLocal.Text = Properties.Settings.Default.chemin_copie_locale;
  52. checkBoxLocale.Checked = Properties.Settings.Default.use_locale;
  53. textCopieAPI.Text = Properties.Settings.Default.adresse_copie_api;
  54. bt_send.Enabled = File.Exists(Program.subfolder + @"\station.json");
  55. }
  56. #region Accesseurs d'attribut de l'assembly
  57. public string AssemblyTitle
  58. {
  59. get
  60. {
  61. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
  62. if (attributes.Length > 0)
  63. {
  64. AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
  65. if (titleAttribute.Title != "")
  66. {
  67. return titleAttribute.Title;
  68. }
  69. }
  70. return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
  71. }
  72. }
  73. public string AssemblyVersion
  74. {
  75. get
  76. {
  77. return Assembly.GetExecutingAssembly().GetName().Version.ToString();
  78. }
  79. }
  80. public string AssemblyDescription
  81. {
  82. get
  83. {
  84. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
  85. if (attributes.Length == 0)
  86. {
  87. return "";
  88. }
  89. return ((AssemblyDescriptionAttribute)attributes[0]).Description;
  90. }
  91. }
  92. public string AssemblyProduct
  93. {
  94. get
  95. {
  96. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
  97. if (attributes.Length == 0)
  98. {
  99. return "";
  100. }
  101. return ((AssemblyProductAttribute)attributes[0]).Product;
  102. }
  103. }
  104. public string AssemblyCopyright
  105. {
  106. get
  107. {
  108. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
  109. if (attributes.Length == 0)
  110. {
  111. return "";
  112. }
  113. return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
  114. }
  115. }
  116. public string AssemblyCompany
  117. {
  118. get
  119. {
  120. object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
  121. if (attributes.Length == 0)
  122. {
  123. return "";
  124. }
  125. return ((AssemblyCompanyAttribute)attributes[0]).Company;
  126. }
  127. }
  128. #endregion
  129. private void tableLayoutPanel_Paint(object sender, PaintEventArgs e)
  130. {
  131. }
  132. private void button2_Click(object sender, EventArgs e)
  133. {
  134. DialogResult dr = opfile.ShowDialog();
  135. if (dr == DialogResult.OK)
  136. {
  137. string filename = opfile.FileName;
  138. f_extract res = new f_extract(filename);
  139. res.ShowDialog();
  140. }
  141. }
  142. private void button1_Click(object sender, EventArgs e)
  143. {
  144. fold.Description = "Sélectionnez le répertoire où sera enregistrée l'archive";
  145. DialogResult dr = fold.ShowDialog();
  146. if (dr == DialogResult.OK)
  147. {
  148. DateTime dt = DateTime.Now;
  149. string filename = fold.SelectedPath + @"\Result_" +dt.ToString("yy_MM_dd_hh_mm_ss") + ".txt";
  150. StreamWriter writer = File.CreateText(filename);
  151. var zip = new ZipFile(fold.SelectedPath + @"\Backup_" +dt.ToString("yy_MM_dd_hh_mm_ss") + ".zip", writer);
  152. string tmpDir= Path.GetTempPath();
  153. if (! Directory.Exists(tmpDir))
  154. tmpDir= Environment.GetEnvironmentVariable("temp");
  155. if (!Directory.Exists(tmpDir))
  156. tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
  157. zip.TempFileFolder = tmpDir;
  158. zip.AddDirectory(Program.folder, "AsoFuel");
  159. zip.Save();
  160. writer.Close();
  161. f_result res = new f_result(filename, zip.Name);
  162. res.ShowDialog();
  163. }
  164. }
  165. private void bt_send_Click(object sender, EventArgs e)
  166. {
  167. label1.Visible = true;
  168. this.Cursor = Cursors.WaitCursor;
  169. System.Windows.Forms.Application.DoEvents();
  170. DateTime deb = DateTime.Now;
  171. Properties.Settings.Default.chemin_copie_locale = textCopieLocal.Text;
  172. if (Properties.Settings.Default.use_locale)
  173. {
  174. File.Copy(Program.subfolder + @"\station.json", Properties.Settings.Default.chemin_copie_locale + @"\station.json", true);
  175. File.Copy(Program.subfolder + @"\presta.json", Properties.Settings.Default.chemin_copie_locale + @"\presta.json", true);
  176. File.Copy(Program.subfolder + @"\vehicule.json", Properties.Settings.Default.chemin_copie_locale + @"\vehicule.json", true);
  177. File.Copy(Program.folder + @"\param\produit.json", Properties.Settings.Default.chemin_copie_locale + @"\produit.json", true);
  178. sendFile(Program.subfolder + @"\station.json", 2);
  179. sendFile(Program.subfolder + @"\presta.json", 2);
  180. sendFile(Program.subfolder + @"\vehicule.json", 2);
  181. sendFile(Program.folder + @"\param\produit.json", 2);
  182. }
  183. else
  184. {
  185. sendFile(Program.subfolder + @"\station.json",3);
  186. sendFile(Program.subfolder + @"\presta.json",3);
  187. sendFile(Program.subfolder + @"\vehicule.json",3);
  188. sendFile(Program.folder + @"\param\produit.json",3);
  189. }
  190. Thread.Sleep(5000);
  191. label1.Visible = false;
  192. this.Cursor = Cursors.Default;
  193. System.Windows.Forms.Application.DoEvents();
  194. }
  195. private void sendFile(string fileName,int mode)
  196. {
  197. isSending = true;
  198. if ( (mode & 1)==1)
  199. {
  200. string chaine = Properties.Settings.Default.adresse_copie_api;
  201. WebClient client = new WebClient();
  202. client.UploadProgressChanged += new UploadProgressChangedEventHandler(Client_UploadProgressChanged);
  203. client.UploadFileCompleted += new UploadFileCompletedEventHandler(Client_UploadFileCompleted);
  204. client.UploadFileAsync(new Uri(chaine), "POST", fileName);
  205. }
  206. if ((mode & 2) == 2)
  207. {
  208. string chaine2 = @"http://www.aformatix.com/ASOStationService/api/FileUpLoad/upLoadFiles";
  209. WebClient clientAfo = new WebClient();
  210. clientAfo.UploadFileAsync(new Uri(chaine2), "POST", fileName);
  211. }
  212. }
  213. private void Client_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
  214. {
  215. isSending = false;
  216. }
  217. private void Client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
  218. {
  219. double bytesIn = double.Parse(e.BytesSent.ToString());
  220. double totalBytes = double.Parse(e.TotalBytesToSend.ToString());
  221. double percentage = bytesIn / totalBytes * 100;
  222. progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
  223. }
  224. private void f_about_Load(object sender, EventArgs e)
  225. {
  226. }
  227. private void okButton_Click(object sender, EventArgs e)
  228. {
  229. }
  230. private void bt_clean_Click(object sender, EventArgs e)
  231. {
  232. f_clean fclean = new f_clean();
  233. fclean.ShowDialog();
  234. }
  235. private void button2_Click_1(object sender, EventArgs e)
  236. {
  237. string appName = Properties.Settings.Default.server_adress_bin.Substring(Properties.Settings.Default.server_adress_bin.LastIndexOf('/')+1);
  238. string chaine = Properties.Settings.Default.server_adress_bin;
  239. string tmpDir = Path.GetTempPath();
  240. if (!Directory.Exists(tmpDir))
  241. tmpDir = Environment.GetEnvironmentVariable("temp");
  242. if (!Directory.Exists(tmpDir))
  243. tmpDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
  244. WebClient client = new WebClient();
  245. client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
  246. client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
  247. try
  248. {
  249. runApp = tmpDir + appName;
  250. if (File.Exists(runApp))
  251. File.Delete(runApp);
  252. client.DownloadFileAsync(new Uri(chaine), tmpDir + appName);
  253. }
  254. catch
  255. {
  256. runApp = "";
  257. MessageBox.Show("Le téléchargement a échoué");
  258. }
  259. bt_maj.Text = "En cours..";
  260. bt_maj.Enabled = false; ;
  261. }
  262. void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  263. {
  264. double bytesIn = double.Parse(e.BytesReceived.ToString());
  265. double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
  266. double percentage = bytesIn / totalBytes * 100;
  267. progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
  268. }
  269. void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  270. {
  271. 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)
  272. {
  273. ProcessStartInfo myprocessStartInfo = new ProcessStartInfo(runApp);
  274. Process install = new Process();
  275. install.StartInfo = myprocessStartInfo;
  276. install.Start();
  277. System.Windows.Forms.Application.Exit();
  278. }
  279. bt_maj.Text = "MAJ";
  280. bt_maj.Enabled = true;
  281. bt_maj.BackColor = Color.Transparent;
  282. }
  283. private void bt_check_Click(object sender, EventArgs e)
  284. {
  285. TextBox from = null;
  286. CheckBox chk = null;
  287. if ((Button)sender == bt_checkBin)
  288. {
  289. from = textSrvBin;
  290. chk = checkBoxBin;
  291. }
  292. if ((Button)sender == bt_checkDatas)
  293. {
  294. from = textSrvDatas;
  295. chk = checkBoxDatas;
  296. }
  297. if ((Button)sender == bt_checkR)
  298. {
  299. from = textSignalR;
  300. chk = checkBoxSignalR;
  301. }
  302. if ((Button)sender == bt_chekAPI)
  303. {
  304. from = textCopieAPI;
  305. chk = checkBoxAPI;
  306. }
  307. lblRes.Text = "....";
  308. bool result = checkUrl(from.Text + ( (Button)sender == bt_chekAPI ? "test" : "" ));
  309. chk.CheckState = result ? CheckState.Checked :CheckState.Unchecked ;
  310. lblRes.Text= result.ToString();
  311. }
  312. private bool checkUrl(string url)
  313. {
  314. bool ret = false;
  315. try
  316. {
  317. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  318. request.Timeout = 5000;
  319. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  320. ret = true;
  321. response.Dispose();
  322. }
  323. catch (Exception ex)
  324. {
  325. MessageBox.Show(ex.Message);
  326. }
  327. return ret;
  328. }
  329. private void bt_sav_Click(object sender, EventArgs e)
  330. {
  331. if ( checkBoxDatas.CheckState == CheckState.Checked || checkAll.Checked )
  332. Properties.Settings.Default.server_adress_datas=textSrvDatas.Text ;
  333. if (checkBoxBin.CheckState == CheckState.Checked || checkAll.Checked)
  334. Properties.Settings.Default.server_adress_bin= textSrvBin.Text ;
  335. if (checkBoxSignalR.CheckState == CheckState.Checked || checkAll.Checked)
  336. Properties.Settings.Default.server_signalr= textSignalR.Text ;
  337. Properties.Settings.Default.chemin_copie_locale = textCopieLocal.Text;
  338. Properties.Settings.Default.use_locale = checkBoxLocale.Checked;
  339. if (checkBoxAPI.CheckState == CheckState.Checked || checkAll.Checked)
  340. Properties.Settings.Default.adresse_copie_api = textCopieAPI.Text;
  341. Properties.Settings.Default.Save();
  342. }
  343. private void bt_fold_Click(object sender, EventArgs e)
  344. {
  345. fold2.SelectedPath = textCopieLocal.Text;
  346. DialogResult res = fold2.ShowDialog();
  347. if (res == DialogResult.OK)
  348. textCopieLocal.Text = fold2.SelectedPath;
  349. }
  350. }
  351. }