/// <summary> /// Crea el archivo temporal para la recepción de las partes /// </summary> private void createFile() { lock (thisLock) { try { PartsNumber = getPartsNumber(FileInformation.Size, PartSize); parts = new FilePartIndicator[PartsNumber]; for (long i = 0; i < parts.Length; i++) { parts[i] = new FilePartIndicator(); } //crea e inicializa el archivo temporal bool exists = true; int j = 0; while (exists) { FileName = downloadDir + "/" + RemoteNetUser.Name + "." + j + "." + FileInformation.Name; FileInfo fileInfo = new FileInfo(FileName); exists = fileInfo.Exists; j++; } FileHandlerStream = new FileStream(FileName, FileMode.Create, FileAccess.Write); partsLoaded = 0; if (FileInformation.Size <= 0) { State = FileMessageHandlerState.COMPLETED; } else { State = FileMessageHandlerState.OPEN; } } catch (ThreadAbortException e) { throw e; } catch (Exception e) { State = FileMessageHandlerState.ERROR; Error = e.Message; close(); } } }
/// <summary> /// Crea el archivo temporal para la recepción de las partes /// </summary> private void createFile() { lock (thisLock) { try { PartsNumber = getPartsNumber(FileInformation.Size, PartSize); parts = new FilePartIndicator[PartsNumber]; for (long i = 0; i < parts.LongLength; i++) { parts[i] = new FilePartIndicator(); } //crea e inicializa el archivo temporal bool exists = true; int j = 0; while (exists) { FileName = downloadDir + "/" + RemoteNetUser.Name + "." + j + "." + FileInformation.Name; FileInfo fileInfo = new FileInfo(FileName); exists = fileInfo.Exists; j++; } Int64 currentPart = 0; long pointer = currentPart * PartSize; FileHandlerStream = new FileStream(FileName, FileMode.Create, FileAccess.Write); while (pointer < FileInformation.Size) { int dataSize; if (currentPart == PartsNumber - 1) { dataSize = (int)(FileInformation.Size - PartSize * (PartsNumber - 1)); } else { dataSize = PartSize; } byte[] fileData = new byte[dataSize]; FileHandlerStream.Seek(pointer, SeekOrigin.Begin); FileHandlerStream.Write(fileData, 0, fileData.Length); currentPart++; pointer = currentPart * PartSize; } partsLoaded = 0; if (FileInformation.Size <= 0) { State = FileMessageHandlerState.COMPLETED; } else { State = FileMessageHandlerState.OPEN; } } catch (ThreadAbortException e) { throw e; } catch (Exception e) { State = FileMessageHandlerState.ERROR; Error = e.Message; close(); } } }