private List <PDTFileInfo> getPdtFilesInfo() { PerformQuery("GetPDTFiles"); var result = new List <PDTFileInfo>(); if (!IsExistParameters || !(ResultParameters[0] is DataTable)) { return(result); } var table = ResultParameters[0] as DataTable; foreach (DataRow row in table.Rows) { var _PDTFilesInfo = new PDTFileInfo(); _PDTFilesInfo.Name = row["Name"].ToString(); _PDTFilesInfo.Size = Convert.ToInt32(row["Size"]); _PDTFilesInfo.Date = row["Date"].ToString().ToDateTime(); _PDTFilesInfo.Id = new Guid(row["Id"].ToString()); _PDTFilesInfo.Version = Convert.ToInt32(row["Version"]); result.Add(_PDTFilesInfo); } return(result); }
private bool downloadFile(PDTFileInfo fileInfo, string path) { var destinationFilePath = string.Format("{0}\\{1}", path, fileInfo.Name); try { using (var newFile = File.OpenWrite(destinationFilePath)) { var bytesToLeft = fileInfo.Size; var currentIndex = 0; while (bytesToLeft > 0) { PerformQuery("GetPDTFileBlock", fileInfo.Id.ToString(), currentIndex, FILE_BLOCK_SIZE); if (!IsExistParameters || !(ResultParameters[0] is string)) { return(false); } var downloadedFileBlock = ResultParameters[0] as string; int blockSize = downloadedFileBlock.Length / 2; var downloadedBytes = new byte[blockSize]; for (int byteIndex = 0; byteIndex < blockSize; byteIndex++) { var byteHex = downloadedFileBlock.Substring(byteIndex << 1, 2); byte currentByte = byte.Parse(byteHex, NumberStyles.HexNumber); downloadedBytes[byteIndex] = currentByte; } newFile.Write(downloadedBytes, 0, downloadedBytes.Length); bytesToLeft -= blockSize; currentIndex += blockSize; currentDownloadedBytes += blockSize; updateProgress(); } newFile.Close(); } } catch (Exception exp) { Trace.WriteLine(string.Format("Ошибка записи файла:\r\n{0}", exp.Message)); return(false); } return(true); }
private List<PDTFileInfo> getPdtFilesInfo() { PerformQuery("GetPDTFiles"); var result = new List<PDTFileInfo>(); if (!IsExistParameters || !(ResultParameters[0] is DataTable)) return result; var table = ResultParameters[0] as DataTable; foreach (DataRow row in table.Rows) { var _PDTFilesInfo = new PDTFileInfo(); _PDTFilesInfo.Name = row["Name"].ToString(); _PDTFilesInfo.Size = Convert.ToInt32(row["Size"]); _PDTFilesInfo.Date = row["Date"].ToString().ToDateTime(); _PDTFilesInfo.Id = new Guid(row["Id"].ToString()); _PDTFilesInfo.Version = Convert.ToInt32(row["Version"]); result.Add(_PDTFilesInfo); } return result; }
private bool downloadFile(PDTFileInfo fileInfo, string path) { var destinationFilePath = string.Format("{0}\\{1}", path, fileInfo.Name); try { using (var newFile = File.OpenWrite(destinationFilePath)) { var bytesToLeft = fileInfo.Size; var currentIndex = 0; while (bytesToLeft > 0) { PerformQuery("GetPDTFileBlock", fileInfo.Id.ToString(), currentIndex, FILE_BLOCK_SIZE); if (!IsExistParameters || !(ResultParameters[0] is string)) return false; var downloadedFileBlock = ResultParameters[0] as string; int blockSize = downloadedFileBlock.Length / 2; var downloadedBytes = new byte[blockSize]; for (int byteIndex = 0; byteIndex < blockSize; byteIndex++) { var byteHex = downloadedFileBlock.Substring(byteIndex << 1, 2); byte currentByte = byte.Parse(byteHex, NumberStyles.HexNumber); downloadedBytes[byteIndex] = currentByte; } newFile.Write(downloadedBytes, 0, downloadedBytes.Length); bytesToLeft -= blockSize; currentIndex += blockSize; currentDownloadedBytes += blockSize; updateProgress(); } newFile.Close(); } } catch (Exception exp) { Trace.WriteLine(string.Format("Ошибка записи файла:\r\n{0}", exp.Message)); return false; } return true; }