private ResoucesInfo(TransferDataType resoucesType, TransferPolicy policy, long postion, long length) : base(policy.MillisecondsTimeout) { this.Rid = GUIDEx.GetGUIDHashCode(); this.ResoucesType = resoucesType; this.Policy = policy; this.Postion = postion; this.Length = length; }
/// <summary> /// 发送数据 /// </summary> /// <param name="filePath">要发送的文件路径</param> /// <param name="policy">发送数据在流中的起始位置</param> public void SendFile(string filePath, TransferPolicy policy) { if (string.IsNullOrWhiteSpace(filePath)) { throw new ArgumentNullException(nameof(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException("要发送的文件不存在", filePath); } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } using (var resoucesInfo = new ResoucesInfo(filePath, policy, 0, new FileInfo(filePath).Length)) { this.PrimitiveSend(resoucesInfo); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="data">要发送的数据</param> /// <param name="policy">发送策略</param> public void SendData(byte[] data, TransferPolicy policy) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (data.Length == 0) { return; } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } using (var resoucesInfo = new ResoucesInfo(data, policy, 0, data.Length)) { this.PrimitiveSend(resoucesInfo); } }
/// <summary> /// 发送数据 /// </summary> /// <param name="data">要发送的数据</param> /// <param name="postion">发送数据在流中的起始位置</param> /// <param name="length">要发送数据长度</param> /// <param name="policy">发送策略</param> public void SendData(byte[] data, int postion, int length, TransferPolicy policy) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (data.Length == 0) { return; } if (postion < 0) { throw new ArgumentOutOfRangeException($"发送数据在总数据中的起始位置值:{postion}无效", nameof(postion)); } if (length < 1) { throw new ArgumentOutOfRangeException($"要发送的数据长度值:{length}无效", nameof(length)); } if (postion + length > data.Length) { throw new ArgumentOutOfRangeException($"要发送的数据长度值:{length}过大,超出数据[{postion}-{data.Length}]范围"); } if (policy == null) { throw new ArgumentNullException(nameof(policy)); } using (var resoucesInfo = new ResoucesInfo(data, policy, postion, length)) { this.PrimitiveSend(resoucesInfo); } }
public ResoucesInfo(string filePath, TransferPolicy policy, long postion, long length) : this(TransferDataType.File, policy, postion, length) { this.FilePath = filePath; }
public ResoucesInfo(Stream stream, TransferPolicy policy, long postion, long length) : this(TransferDataType.Stream, policy, postion, length) { this._stream = stream; }
public ResoucesInfo(byte[] data, TransferPolicy policy, int postion, int length) : this(TransferDataType.Data, policy, postion, length) { this.Data = data; }