📄 uploadsharecontent.cs
字号:
buffer = new byte[stream.Length];
}
else if ((from + base.EveryBlockSize) >= base.FileSize)
{
buffer = new byte[base.FileSize - from];
}
else
{
buffer = new byte[base.EveryBlockSize];
}
to = (from + buffer.Length) - 1;
if (((base.LastTimeCompleteSize != 0) && (from != 0)) && (from == base.LastTimeCompleteSize))
{
stream.Position = base.LastTimeCompleteSize;
stream.Read(buffer, 0, buffer.Length);
}
else
{
stream.Read(buffer, 0, buffer.Length);
}
base._tryInterval = 500;
Label_01D8:
request = ConnectionFactory.CreateHttpWebRequest(url, base.Owner, true, true);
using (MemoryStream output = new MemoryStream())
{
BinaryWriter writer = new BinaryWriter(output);
string text4 = "-----xz4BBcV-5C1C9B2B-95AC-4752-AF91-10B280A68D3B---";
writer.Write(Encoding.UTF8.GetBytes("--" + text4 + "\r\nContent-Disposition: form-data; name=UploadFile;filename=\"" + info.Name + "\"\r\n\r\n"));
writer.Write(buffer);
writer.Write(Encoding.UTF8.GetBytes("\r\n"));
writer.Write(Encoding.UTF8.GetBytes("--" + text4 + "\r\n"));
request.ContentLength = output.Length;
request.ContentType = "multipart/form-data; boundary=" + text4;
request.AddRange(from, to);
request.Headers.Add("Pragma", base.SessionId);
try
{
using (Stream stream3 = request.GetRequestStream())
{
output.WriteTo(stream3);
}
}
catch (WebException exception)
{
num++;
if (num2 > (base.Owner.Configuration.SystemSetting.FileShareSetting.RelayMaxTryTime * 0x3e8))
{
ClientLogger.WriteGeneral("Upload " + base.FilePath + " Failed,Try Count:" + num.ToString() + "\r\n", exception.ToString(), 10);
base.RaiseShareContentFailed("");
return;
}
int millisecondsTimeout = base._tryInterval * num;
base._tryInterval = millisecondsTimeout;
num2 += millisecondsTimeout;
Thread.Sleep(millisecondsTimeout);
goto Label_01D8;
}
output.Close();
}
HttpWebResponse response = null;
int num7 = 200;
try
{
response = (HttpWebResponse) request.GetResponse();
num3 = num7;
time2 = DateTime.Now;
}
catch (WebException exception2)
{
HttpWebResponse response2 = exception2.Response as HttpWebResponse;
num7 = (response2 == null) ? ((int) ((HttpStatusCode) 520)) : ((int) response2.StatusCode);
if (num7 > 0x12b)
{
if ((num7 == 520) || (((num7 != 400) && (num7 != 0x191)) && ((num7 != 0x194) && (num7 != 0x19f))))
{
num++;
if (num2 > (base.Owner.Configuration.SystemSetting.FileShareSetting.RelayMaxTryTime * 0x3e8))
{
ClientLogger.WriteGeneral("Upload " + base.FilePath + " Failed,Try Count:" + num.ToString() + "\r\n", exception2.ToString());
base.RaiseShareContentFailed("");
return;
}
int num8 = base._tryInterval * num;
base._tryInterval = num8;
num2 += num8;
Thread.Sleep(num8);
num3 = num7;
time2 = DateTime.Now;
goto Label_01D8;
}
switch (num7)
{
case 0x191:
text = string.Format("credential:{0},filesize:{1}", base.Owner.SsiCredential, base.FileSize);
break;
case 0x194:
text = string.Format("credential:{0},filesize:{1},start:{2},preHttpStatusCode{3},preBlockDateTime:{4}", new object[] { base.Owner.SsiCredential, base.FileSize, from, num3, time2.ToString("hh:mm ss") });
break;
}
ClientLogger.WriteGeneral("Upload " + base.FilePath + " Failed.." + text, exception2.ToString());
text = string.Empty;
base.RaiseShareContentFailed("");
return;
}
}
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
if (base.IsCancel)
{
return;
}
if (flag)
{
XmlDocument document = new XmlDocument();
document.LoadXml(reader.ReadToEnd());
XmlAttribute attribute = document.DocumentElement.ChildNodes[0].Attributes["upload"];
if (attribute != null)
{
this.UploadUri = attribute.Value;
}
base.DownLoadUrl = document.DocumentElement.ChildNodes[0].Attributes["download"].Value;
this.SaveShareContentHistory();
}
}
num = 0;
num2 = 0;
if (flag && (base.Transmittype == ShareContentTransmitType.Relay))
{
this.AsyncSendFileInfo();
this.relayAcceptEvent.WaitOne();
if (base.LastTimeCompleteSize != 0)
{
from = to = Convert.ToInt32(base.LastTimeCompleteSize);
}
}
if (base.IsCancel)
{
return;
}
if ((to >= (stream.Length - 1)) && (base.Transmittype == ShareContentTransmitType.Block))
{
this.AsyncSendFileInfo();
}
base.Start = true;
float num9 = ((float) DateTime.Now.Subtract(now).TotalMilliseconds) / 1000f;
if (num9 != 0f)
{
if (to >= base.LastTimeCompleteSize)
{
base.Rate = (to - base.LastTimeCompleteSize) / num9;
}
else
{
base.Rate = ((float) to) / num9;
}
}
base.FinishPercent = ((float) to) / ((float) base.FileSize);
base.RaiseShareContentProgress(new ShareContentProcessEventArgs(((float) to) / ((float) base.FileSize)));
if (response != null)
{
response.Close();
}
}
}
base.Complete = true;
base.RaiseShareContentComplete();
}
catch (Exception exception3)
{
if (!base.IsCancel)
{
ClientLogger.WriteGeneral("Upload " + base.FilePath + " Failed", exception3.ToString());
base.RaiseShareContentFailed((exception3 is IOException) ? "请检测此文件是否正在被使用!" : "");
}
}
finally
{
if (stream != null)
{
stream.Close();
}
}
}
private void SendFileRelayMode()
{
base.Owner.ConversationManager.RegisterKeepAlive();
base.Transmittype = ShareContentTransmitType.Relay;
this.GernerateFileInfo();
ThreadPool.QueueUserWorkItem(new WaitCallback(this.SendFileInThread), null);
ClientLogger.WriteGeneral(string.Format("--Relay传送开始,上传 {0} 给 {1}--", base.FileName, this.To));
}
private void SendP2PAfterGetOptions()
{
try
{
bool flag = ShareContentType.TCP == (Imps.Client.Core.Configuration.FixedClientSetting.ShareContentType & ShareContentType.TCP);
if (base.TcpP2PSocket == null)
{
base.PunchingResult = base.P2pFinder.SendPunchingRequests(base.OtherSideSharedContentOption);
}
else if (flag)
{
base.PunchingResult = new TcpConnectingResult(base.P2pFinder.LocalPeer, base.P2pFinder.RemotePeer, base.TcpP2PSocket);
}
if (!base.IsClosed && !base.IsCancel)
{
if (base.PunchingResult.Succeed)
{
base.Transmittype = ShareContentTransmitType.P2P;
this.GernerateFileInfo();
base.P2pTransport = AbstractFileTransportor.CreateSender(base.PunchingResult, base.TransportingFile);
if (base.P2pTransport != null)
{
this.AsyncSendFileInfo();
}
else
{
base.OtherSideSharedContentOption.SupportP2PV2 = false;
this.SendFileAfterGetOptions();
}
}
else
{
base.OtherSideSharedContentOption.SupportP2PV2 = false;
this.SendFileAfterGetOptions();
}
}
}
catch (Exception exception)
{
ClientLogger.WriteException(exception);
base.OtherSideSharedContentOption.SupportP2PV2 = false;
this.SendFileAfterGetOptions();
}
}
public bool DirectToMobile
{
get
{
return this._directToMobile;
}
set
{
this._directToMobile = value;
}
}
public bool SendToSelf
{
get
{
return this._sendToSelf;
}
set
{
this._sendToSelf = value;
}
}
public string To
{
get
{
return base.CurrentDialog.To;
}
}
public string UploadUri
{
get
{
return this._uploadUri;
}
internal set
{
this._uploadUri = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -