WebClient を使用してファイル (サイズ 100MB の Zip) をアップロードしていますが、正常に動作する場合と失敗する場合があります。
これが私のコードです。あなたの見解と、一貫性を保つために何をする必要があるか教えてください
public bool UploadFirmware(string srcPath, string destPath)
{
bool status = false;
List<Unisys.sPar.FirmwareInfo> orgFwList = new List<Unisys.sPar.FirmwareInfo>();
List<Unisys.sPar.FirmwareInfo> upFwList = new List<Unisys.sPar.FirmwareInfo>();
try
{
orgFwList = EnumerateFirmware();
Uri fwuri = new Uri(destPath);
string myStringWebResource = null;
WebClient myWebClient = new WebClient();
myStringWebResource = fwuri.ToString();
myWebClient.Encoding = Encoding.UTF8;
myWebClient.Credentials = new NetworkCredential(userName, password);
myWebClient.Headers[HttpRequestHeader.ContentType] = "application/zip";
bool gExecuteOnce = true;
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
myWebClient.UploadFileCompleted += new UploadFileCompletedEventHandler(myWebClientUploadloadFileCompleted);
myWebClient.UploadFileAsync(new System.Uri(myStringWebResource), "POST", srcPath);//upload method
while (myWebClient.IsBusy)
{
System.Threading.Thread.Sleep(10000);
if (gExecuteOnce == true)
{
SPARTestToolInit.logger.Log(NLog.LogLevel.Info, "Please Wait Uploading firmware.....");
gExecuteOnce = false;
}
}
upFwList = EnumerateFirmware();
if (upFwList.Count == orgFwList.Count + 1)
{
status = true;
SPARTestToolInit.logger.Log(NLog.LogLevel.Info, "Firmware Uploaded sucessfuly .....");
}
}
catch (Exception ex)
{
status = false;
SPARTestToolInit.logger.Log(NLog.LogLevel.Error, "Unable to upload firmware due to " + ex.ToString());
}
return status;
}