// Комиссия public void UpdateComiss(bool critical) { Ipaybox.AddToLog(Ipaybox.Logs.Main, "Загрузка профилей комиссий..."); XmlDocument comission = new XmlDocument(); try { string xml = TryDownloadComiss(ref comission); if (xml != null) { if (xml.Length > 0) { Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); if (xml.IndexOf("result") == -1) { // нормальный Ipaybox.comiss.LoadXml(xml); Ipaybox.comiss.Save(Ipaybox.StartupPath + "\\config\\comiss.xml"); Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Профили успешно загружены."); Ipaybox.NeedUpdates.Comission = false; } else { // ошибка } } else { Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Не удалось загрузить профили."); if (critical) {// Останавливаем обновление } else {// не заменяем } } } else { //Останавливаем обновление Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Не удалось загрузить профили."); } } catch { //Останавливаем обновление Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Не удалось загрузить профили."); } }
private string TryPostData(string data, int RequestTimeOut) { XmlDocument d = new XmlDocument(); bool t = false; int count = 0; string xml = ""; while (!t && count < Ipaybox.ServiceUrl.Length * 2) { try { xml = SendRequestPost(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "sevice.exe", data, RequestTimeOut); if (xml != "") { Ipaybox.Incass.bytesSend += data.Length; Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); } d.LoadXml(xml); if (Ipaybox.RequestTimeout != 0.5) { Ipaybox.RequestTimeout = float.Parse("0,5"); } break; } catch (Exception ex) { Ipaybox.ServiceUrlIndex++; if (Ipaybox.ServiceUrlIndex == Ipaybox.ServiceUrl.Length) { Ipaybox.ServiceUrlIndex = 0; } count++; Ipaybox.RequestTimeout += 3; } } return(xml); }
private string TryDownloadOnLine(string param) { XmlDocument d = new XmlDocument(); bool t = false; int count = 0; string xml = ""; while (!t && count < Ipaybox.ServiceUrl.Length * 2) { try { WebClient Client = new WebClient(); //xml = SendRequestGET(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "xml_comiss.exe?trm_id="+Ipaybox.Terminal.terminal_id+"&trm_p="+Ipaybox.Terminal.terminal_pass); xml = Client.DownloadString(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "xml_online.exe?" + param); try { //string utf8 = Encoding.UTF8.GetString(Encoding.Convert(Encoding.ASCII, Encoding.UTF8, Encoding.ASCII.GetBytes(xml))); d.LoadXml(xml); Ipaybox.Incass.bytesSend += 10; Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); XML_Response = xml; break; } catch { count++; } } catch { Ipaybox.ServiceUrlIndex++; if (Ipaybox.ServiceUrlIndex == Ipaybox.ServiceUrl.Length) { Ipaybox.ServiceUrlIndex = 0; } count++; } } return(xml); }
// Терминал - Информация private string TryDownloadTerminalInfo() { Ipaybox.AddToLog(Ipaybox.Logs.Main, "Загрузка информации о терминале."); XmlDocument d = new XmlDocument(); bool t = false; int count = 0; string xml = ""; while (!t && count < Ipaybox.ServiceUrl.Length * 2) { try { //xml = SendRequestGET(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "xml_comiss.exe?trm_id="+Ipaybox.Terminal.terminal_id+"&trm_p="+Ipaybox.Terminal.terminal_pass); xml = Client.DownloadString(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "xml_terminal.exe?trm_id=" + Ipaybox.Terminal.terminal_id + "&trm_p=" + Ipaybox.Terminal.terminal_pass); try { //string utf8 = Encoding.UTF8.GetString(Encoding.Convert(Encoding.ASCII, Encoding.UTF8, Encoding.ASCII.GetBytes(xml))); d.LoadXml(xml); Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Успешно загружена."); Ipaybox.Incass.bytesSend += 10; Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); break; } catch { count++; } } catch { Ipaybox.ServiceUrlIndex++; if (Ipaybox.ServiceUrlIndex == Ipaybox.ServiceUrl.Length) { Ipaybox.ServiceUrlIndex = 0; } count++; } } return(xml); }
private string TryPostData(string data) { XmlDocument d = new XmlDocument(); bool t = false; int count = 0; string xml = ""; while (!t && count < Ipaybox.ServiceUrl.Length * 2) { try { xml = SendRequestPost(Ipaybox.ServiceUrl[Ipaybox.ServiceUrlIndex] + "sevice.exe", data); try { if (xml != "") { Ipaybox.Incass.bytesSend += data.Length; Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); } d.LoadXml(xml); break; } catch { count++; } } catch { Ipaybox.ServiceUrlIndex++; if (Ipaybox.ServiceUrlIndex == Ipaybox.ServiceUrl.Length) { Ipaybox.ServiceUrlIndex = 0; } count++; } } return(xml); }
public bool SendStatistic() { Ipaybox.AddToLog(Ipaybox.Logs.Main, "Формирование инкассации."); if (Ipaybox.Incass.incass_amount > 0) { string data = "<request>"; data += "<protocol>1.00</protocol>"; data += "<type>1.00</type>"; data += "<terminal>" + Ipaybox.Terminal.terminal_id + "</terminal>"; data += "<pass>" + Ipaybox.Terminal.terminal_pass + "</pass>"; XmlDocument inc = new XmlDocument(); inc.Load(Ipaybox.StartupPath + @"\incass.xml"); XmlElement el = inc.CreateElement("incass-stop-date"); el.InnerText = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"); inc.DocumentElement.InsertAfter(el, inc.DocumentElement.LastChild); data += "<statistic> " + inc.DocumentElement.InnerXml + "</statistic>"; data += "</request>"; Ipaybox.AddToLog(Ipaybox.Logs.Main, "Посылаем инкассацию на сервер..."); string response = TryPostData(data); if (response != "") { try { XmlDocument resp = new XmlDocument(); resp.LoadXml(response); XmlElement root = resp.DocumentElement; for (int i = 0; i < root.ChildNodes.Count; i++) { XmlElement row = (XmlElement)root.ChildNodes[i]; if (row.Name == "incass") { string res = row.GetAttribute("result"); string comment = row.GetAttribute("comment"); if (res != "0") { // все плохо Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Сервер не принял инкассацию."); return(false); } else { Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Успешно. Формируем инкассационный чек."); string check = "IPAYBOX ZEUS CORE V" + Ipaybox.CoreVersion + "\r\n" + Ipaybox.Terminal.jur_name + "\r\nТерминал: " + Ipaybox.Terminal.terminal_id + "\r\n"; check += "ИНКАССАЦИОННЫЙ ЧЕК\r\n_____________________\r\n"; check += "СУММА: " + Ipaybox.Incass.incass_amount.ToString() + "\r\n"; check += "Кол-во купюр: " + Ipaybox.Incass.count + "\r\n"; check += "Кол-во купюр 10 руб: " + Ipaybox.Incass.CountR10 + "\r\n"; check += "Кол-во купюр 50 руб: " + Ipaybox.Incass.CountR50 + "\r\n"; check += "Кол-во купюр 100 руб: " + Ipaybox.Incass.CountR100 + "\r\n"; check += "Кол-во купюр 500 руб: " + Ipaybox.Incass.CountR500 + "\r\n"; check += "Кол-во купюр 1000 руб: " + Ipaybox.Incass.CountR1000 + "\r\n"; check += "Кол-во купюр 5000 руб: " + Ipaybox.Incass.CountR5000 + "\r\n"; check += "Кол-во чеков: " + Ipaybox.Incass.countchecks + "\r\n"; check += "Дата начала: " + Ipaybox.Incass.incass_date_start.ToString() + "\r\n"; check += "Дата инкасс: " + DateTime.Now.ToString() + "\r\n"; check += "____________________\r\n"; check += "Сервер инкасации: " + res + "\\" + comment + "\r\n"; check += "Bytes send: " + Ipaybox.Incass.bytesSend + "\r\n"; check += "Bytes recieve: " + Ipaybox.Incass.bytesRead + "\r\n"; Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Печатаем чек."); PrintCheck = check; if (!Ipaybox.WindowsPrinter) { Ipaybox.Printer.Print(check); } else { doc.Print(); } Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Чек распечатан. Очистка статистики."); Ipaybox.Incass.bytesRead = 0; Ipaybox.Incass.bytesSend = 0; Ipaybox.Incass.count = 0; Ipaybox.Incass.CountR10 = 0; Ipaybox.Incass.CountR50 = 0; Ipaybox.Incass.CountR100 = 0; Ipaybox.Incass.CountR500 = 0; Ipaybox.Incass.CountR1000 = 0; Ipaybox.Incass.CountR5000 = 0; Ipaybox.Incass.countchecks = 0; Ipaybox.Incass.incass_amount = 0; Ipaybox.Incass.incass_date_start = DateTime.Now; Ipaybox.FlushStatistic(); Ipaybox.LoadIncass(); Ipaybox.AddToLog(Ipaybox.Logs.Main, "...Инкассация успешно проведена."); return(true); } } } } catch (Exception ex) { HelperClass.CrashLog.AddCrash(ex); Ipaybox.AddToLog(Ipaybox.Logs.Main, "Ошибка при инкассации нераспознанный ответ сервера.\r\n-----\r\n" + response + "\r\n-----"); return(false); } } else { return(false); } } else { return(true); } return(false); }
public void ValidateXmlAndLocal() { Ipaybox.UpdateState = 1; Ipaybox.AddToLog(Ipaybox.Logs.Update, "Запуск обновления. Download core file..."); Ipaybox.NeedUpdates.Core = false; list = new XmlDocument(); try { string xml = TryDownloadUpdateXml(); if (xml != null) { if (xml.Length > 0 && xml.IndexOf("result") == -1) { Ipaybox.Incass.bytesRead += xml.Length; Ipaybox.FlushStatistic(); Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Успешно."); } else { Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t НЕ Успешно."); // Останавливаем обновление Ipaybox.NeedUpdates.Core = true; Ipaybox.Working = false; return; } } else { //Останавливаем обновление Ipaybox.NeedUpdates.Core = true; Ipaybox.Working = false; return; } } catch { //Останавливаем обновление Ipaybox.NeedUpdates.Core = true; Ipaybox.Working = false; return; } if (!(list.DocumentElement != null && list.DocumentElement.Name == "fileinfo")) { Ipaybox.NeedUpdates.Core = true; Ipaybox.Working = false; return; } XmlElement root = list.DocumentElement; for (int i = 0; i < root.ChildNodes.Count; i++) { XmlElement row = (XmlElement)root.ChildNodes[i]; if (row.Name == "file") { // Сравнить данные по файлу CheckDirExist(row.GetAttribute("filepath")); FileCheckError err = ValidateLocalFile(row.GetAttribute("filepath"), row.GetAttribute("length"), row.GetAttribute("crc")); //Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Проверка файла " + row.GetAttribute("filepath") +" - "+ err.ToString()); switch (err) { case FileCheckError.UPDATE: bool result = DownloadFileGZ(row.GetAttribute("filepath"), row.GetAttribute("length"), row.GetAttribute("crc")); if (!result) { //Файл не скачался обновление остановить. Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Файл не скачался обновление остановить."); Ipaybox.NeedUpdates.Core = true; Ipaybox.Working = false; return; } break; } } } if (Needtorestart) { Ipaybox.NeedToRestart = true; } Ipaybox.UpdateState = 0; Ipaybox.AddToLog(Ipaybox.Logs.Update, "Выход из обновления."); }
private bool DownloadFileGZ(string file, string len, string crc) { bool ok = false; int counts = 0; string ftpfile = ""; string localfile = ""; // Скачивать и заменять файло. if (file[0] == '\\') { ftpfile = Ipaybox.UpdateUrl[Ipaybox.UpdateUrlIndex] + file.Replace(@"\", ""); localfile = Ipaybox.StartupPath + file; } else { ftpfile = Ipaybox.UpdateUrl[Ipaybox.UpdateUrlIndex] + file.Replace(@"\", "/"); localfile = Ipaybox.StartupPath + "\\" + file; } while (!ok && counts < 3) { try { if (file.Replace("\\", "").LastIndexOf(".") > 0 && file.IndexOf("rstrt.exe") == -1) { var _fileName = file.Substring(0, file.LastIndexOf(".")).Replace("\\", ""); var _fileExtension = file.Substring(file.LastIndexOf(".") + 1, file.Length - file.LastIndexOf(".") - 1); switch (_fileExtension.ToLower()) { case "dll": case "pdb": case "exe": localfile = Ipaybox.StartupPath + "\\" + _fileName + "." + _fileExtension + ".update"; Needtorestart = true; break; } } Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Скачиваем файл " + ftpfile); Ipaybox.AddToLog(Ipaybox.Logs.Update, "Сохраняем как:" + localfile); HttpWebRequest _req = (HttpWebRequest)HttpWebRequest.Create(ftpfile); _req.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); HttpWebResponse _resp = (HttpWebResponse)_req.GetResponse(); Stream str = _resp.GetResponseStream(); if (_resp.ContentEncoding.ToLower().Contains("gzip")) { str = new GZipStream(str, CompressionMode.Decompress); } else if (_resp.ContentEncoding.ToLower().Contains("deflate")) { str = new DeflateStream(str, CompressionMode.Decompress); } byte[] inBuf = new byte[100000]; int bytesReadTotal = 0; FileStream fstr = new FileStream(localfile, FileMode.Create, FileAccess.Write); while (true) { int n = str.Read(inBuf, 0, 100000); if ((n == 0) || (n == -1)) { break; } fstr.Write(inBuf, 0, n); bytesReadTotal += n; } str.Close(); fstr.Close(); FileInfo f = new FileInfo(localfile); if (f.Exists) { Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Скачали"); Ipaybox.AddToLog(Ipaybox.Logs.Main, "\t Загружен." + ftpfile); Ipaybox.Incass.bytesRead += (int)f.Length; Ipaybox.Incass.bytesSend += ftpfile.Length; Ipaybox.Incassation.Bytessend += (uint)ftpfile.Length; Ipaybox.Incassation.Bytesrecieved += (uint)f.Length; Ipaybox.FlushStatistic(); } } catch (Exception ex) { Ipaybox.AddToLog(Ipaybox.Logs.Main, "\t Не удалось " + ex.ToString()); Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Не удалось загрузить." + ftpfile); return(false); } if (ValidateLocalFile(localfile, len, crc) == FileCheckError.OK) { ok = true; } else { counts++; } } return(ok); }
private bool DownloadFile(string file, string len, string crc) { bool ok = false; int counts = 0; string ftpfile = ""; string localfile = ""; // Скачивать и заменять файло. if (file[0] == '\\') { ftpfile = Ipaybox.UpdateUrl[Ipaybox.UpdateUrlIndex] + file.Replace(@"\", ""); localfile = Ipaybox.StartupPath + file; } else { ftpfile = Ipaybox.UpdateUrl[Ipaybox.UpdateUrlIndex] + file.Replace(@"\", "/"); localfile = Ipaybox.StartupPath + "\\" + file; } while (!ok && counts < 3) { try { if (file.Replace("\\", "").LastIndexOf(".") > 0 && file.IndexOf("rstrt.exe") == -1) { var _fileName = file.Substring(0, file.LastIndexOf(".")).Replace("\\", ""); var _fileExtension = file.Substring(file.LastIndexOf(".") + 1, file.Length - file.LastIndexOf(".") - 1); switch (_fileExtension.ToLower()) { case "dll": case "pdb": case "exe": localfile = Ipaybox.StartupPath + "\\" + _fileName + "." + _fileExtension + ".update"; Needtorestart = true; break; } } Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Скачиваем файл " + ftpfile); Ipaybox.AddToLog(Ipaybox.Logs.Update, "Сохраняем как:" + localfile); Client.DownloadFile(ftpfile, localfile); FileInfo f = new FileInfo(localfile); if (f.Exists) { Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Скачали"); Ipaybox.AddToLog(Ipaybox.Logs.Main, "\t Загружен." + ftpfile); Ipaybox.Incass.bytesRead += (int)f.Length; Ipaybox.Incass.bytesSend += ftpfile.Length; Ipaybox.Incassation.Bytessend += (uint)ftpfile.Length; Ipaybox.Incassation.Bytesrecieved += (uint)f.Length; Ipaybox.FlushStatistic(); } } catch (Exception ex) { Ipaybox.AddToLog(Ipaybox.Logs.Main, "\t Не удалось " + ex.ToString()); Ipaybox.AddToLog(Ipaybox.Logs.Update, "\t Не удалось загрузить." + ftpfile); return(false); } if (ValidateLocalFile(localfile, len, crc) == FileCheckError.OK) { ok = true; } else { counts++; } } return(ok); }