private string ExportAddressBookPkg() { // 旧版作法,生成 xml 后转成 pkg string xmlFilePath = Path.GetAddressBookTempXmlFilePath(); string TempFolderPath = Path.GetAddressBookTempFolderPath(); //if (!File.Exists(xmlFilePath)) { AddLog("XML File 不存在, 生成 XML File 中..."); ExportXmlAddressBook(); } string pkgFilePath = Path.GetAddressBookPkgFilePath(); PkgTool.ToPkgFile(TempFolderPath, pkgFilePath); return(pkgFilePath); }
private void ExportAddressBookUclPkg(string pkgFilePath, AddrList.DevDataTable Devices) { List <string> xmlFilesPath = ExportMultiple4BytesAlignXmls( Path.GetAddressBookTempFolderPath(), Devices); List <string> uclFilesPath = new List <string>(); string uclTempFolderPath = Path.GetAddressBookUclTempFolderPath(); int count = xmlFilesPath.Count; for (int i = 0; i < count; ++i) { string xmlFilePath = xmlFilesPath[i]; string uclFilePath = (i == 0) ? (uclTempFolderPath + @"\addressbook.ucl") : (uclTempFolderPath + @"\addressbook" + i + ".ucl"); try { if (false == FileConverter.Xml2Ucl(xmlFilePath, uclFilePath)) { throw new Exception("UCL无法導出"); } uclFilesPath.Add(uclFilePath); } catch (Exception ex) { MessageBox.Show(ex.Message, "操作错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (uclFilesPath.Count > 0) { PkgTool.ToPkgFile(uclTempFolderPath, pkgFilePath); } foreach (string filePath in xmlFilesPath) { File.Delete(filePath); } foreach (string filePath in uclFilesPath) { File.Delete(filePath); } }
private void ExportAddressBookXmlPkg(string pkgFilePath, AddrList.DevDataTable Devices) { string xmlFilePath = Path.GetAddressBookTempXmlFilePath(); if (ExportXml(xmlFilePath, Devices)) { try { PkgTool.ToPkgFile(System.IO.Path.GetDirectoryName(xmlFilePath), pkgFilePath); } catch (Exception ex) { throw ex; } finally { File.Delete(xmlFilePath); } } }
private async void DoUpdate() { AddLog("Enter Update Thread"); m_UpdateThread = Thread.CurrentThread; FtpServer.Instance.NewDataConnection += FtpServer_NewDataConnection; FtpServer.Instance.ClosedDataConnection += FtpServer_ClosedDataConnection; FtpServer.Instance.SentData += FtpServer_SentData; for (int i = 0; i < m_Devices.Count();) { lock (m_FtpTransferStatus) { if (m_FtpTransferStatus.Count() >= 5) { List <FtpTransferStatus> toBeRemoved = new List <FtpTransferStatus>(); foreach (var status in m_FtpTransferStatus) { if (status.Status != FtpTransferStatus.STATUS.LOAD_ING) { toBeRemoved.Add(status); } } foreach (var status in toBeRemoved) { m_FtpTransferStatus.Remove(status); } } if (m_FtpTransferStatus.Count() >= 5) { continue; } } Device Device = m_Devices[i]; AddLog(string.Format("Generate XML File for ({0}:{1})", Device.roomid, Device.ip)); string TempFolderPath = Path.GetCardListTempFolderPath(Device.roomid); GenerateXmlFile(Device, TempFolderPath + @"\cardlist.xml"); string pkgFilePath = Path.GetCardListFolderRelativePath(Device.roomid) + @"\CARD.PKG"; //传入参数 目录为\\导致CMD命令执行失败。 PkgTool.ToPkgFile(TempFolderPath, (Path.GetCardListFolderPath(Device.roomid) + @"\CARD.PKG")); AddLog(string.Format("HTTP ({0}): Sending Upgrade Command", Device.ip)); FtpTransferStatus transferStatus = new FtpTransferStatus(Device, i, pkgFilePath); var result = await ICMServer.Net.HttpClient.SendCardListUpgradeNotification(Device.ip, Config.Instance.LocalIP, pkgFilePath); //string uri = string.Format("http://{0}/dev/info.cgi?action=upgrade_cardlist&url=ftp://{1}/{2}", // Device.ip, Config.Instance.LocalIP, pkgFilePath.Replace(@"\", "/")); //System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); //client.Timeout = new TimeSpan(0, 0, 1); try { if (result) { //var response = await client.GetStringAsync(uri); AddLog(string.Format("HTTP ({0}): Send Upgrade success!", Device.ip)); SetStatusColumnText(i, "0%", Color.Black); // TODO: Progress bar } else { transferStatus.Status = FtpTransferStatus.STATUS.LOAD_ERROR; AddLog(string.Format("HTTP ({0}): Send Upgrade fail!", Device.ip)); SetStatusColumnText(i, "send upgrade command fail!", Color.Red); } } catch (Exception) { } lock (m_FtpTransferStatus) { m_FtpTransferStatus.Add(transferStatus); } ++i; } AddLog("Leave Update Thread"); }