private void OnDownloadFailure(int downloadTaskId, DownloadTaskInfo downloadTaskInfo, DownloadErrorCode errorCode, string errorMessage) { if (m_DownloadRetryTimes >= m_Owner.DownloadRetryCount) { m_DownloadRetryTimes = -1; m_RootUrlIndex++; if (m_RootUrlIndex >= RootUrls.Count) { ResetStatus(); errorMessage = Utility.Text.Format( "Cannot update remote index file. Error code is '{0}'. Error message is '{1}'.", errorCode, errorMessage); if (m_CallbackSet.OnFailure != null) { m_CallbackSet.OnFailure(errorMessage, m_Context); } else { throw new InvalidOperationException(errorMessage); } return; } } m_DownloadRetryTimes++; if (m_DownloadRetryTimes == 0) { m_DownloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/index_{1}.dat", RootUrls[m_RootUrlIndex].ToString(), m_RemoteIndexFileInfo.Crc32.ToString()), m_Owner.CachedRemoteIndexPath, m_RemoteIndexFileInfo.FileSize, m_RemoteIndexFileInfo.Crc32, new DownloadCallbackSet { OnSuccess = m_OnDownloadSuccess, OnFailure = m_OnDownloadFailure, OnProgress = null, }, null); } m_Owner.DownloadService.StartDownloading(m_DownloadTaskInfo); }
private void OnDownloadFailure(int taskId, DownloadTaskInfo info, DownloadErrorCode errorCode, string errorMessage) { Debug.LogWarningFormat("Download '{0}' to '{1}' failed with error code '{2}' and message '{3}'.", info.UrlStr, info.SavePath, errorCode, errorMessage); }
private void OnDownloadFailure(int downloadTaskId, DownloadTaskInfo downloadTaskInfo, DownloadErrorCode errorCode, string errorMessage) { var downloadContext = (DownloadContext)downloadTaskInfo.Context; var resourceGroup = m_ResourceGroupsBeingUpdated[downloadContext.ResourceGroupId]; resourceGroup.DownloadTaskIds.Remove(downloadTaskId); errorMessage = Utility.Text.Format( "Download failed for '{0}' from '{1}'. Inner error code is '{2}'. Inner error message is '{3}'.", downloadContext.ResourcePath, downloadTaskInfo.UrlStr, errorCode, errorMessage); if (downloadContext.RetryTimes >= m_Owner.DownloadRetryCount) { downloadContext.RetryTimes = -1; downloadContext.RootUrlIndex++; if (downloadContext.RootUrlIndex >= RootUrls.Count) { SingleFail(resourceGroup, downloadContext.ResourcePath, errorMessage); ClearBeingUpdated(resourceGroup.GroupId); Fail(resourceGroup, null, errorMessage); return; } } downloadContext.RetryTimes++; var newDownloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/{1}_{2}{3}", RootUrls[downloadContext.RootUrlIndex], downloadContext.ResourcePath, downloadTaskInfo.Crc32.Value, Constant.ResourceFileExtension), downloadTaskInfo.SavePath, downloadTaskInfo.Size, downloadTaskInfo.Crc32, new DownloadCallbackSet { OnFailure = m_OnDownloadFailure, OnSuccess = m_OnDownloadSuccess, OnProgress = m_OnDownloadProgress, }, downloadContext); resourceGroup.DownloadTaskIds.Add(m_Owner.DownloadService.StartDownloading(newDownloadTaskInfo)); }
public void Start() { //email settings List <string> attachmentPathList = new List <string>(); string subject; string content = null; string errMsg = null; byte status = 0; DateTime startTime = DateTime.Now; try { XmlNodeList tasksNode = _projectSettings.SelectNodes("./tasks/task"); foreach (XmlNode node in tasksNode) { DownloadTask task = new DownloadTask(node, _outputBaseFolder); if (task.Run()) { if (task.LastErrorMsg == "No validation is required.") { errMsg += string.Format("\t\tError Task:\t{0}\r\n\t\t\tError Code is:\t{1}\t\r\n\t\t\tError Message is:\t{2} \r\n\r\n", task.taskName, task.LastErrorCode, task.LastErrorMsg); } //get attachments attachmentPathList.Add(task.OutputPath); } else { //err = task.LastErrorCode; //errMsg = task.LastErrorMsg; err = DownloadErrorCode.PartialError; errMsg += string.Format("\t\tError Task:\t{0}\r\n\t\t\tError Code is:\t{1}\t\r\n\t\t\tError Message is:\t{2} \r\n\r\n", task.taskName, task.LastErrorCode, task.LastErrorMsg); continue; } } DateTime endTime = DateTime.Now; /* this snippet was overrided by WriteWebCrawlRunLog * * //Step: Write run log * //Guid id = Guid.NewGuid(); * //string type = _projectSettings.SelectSingleNode("//runLog/type").InnerText; * //string url = "http://www.acelife.com.hk/en/ace_fund-prices/index.aspx/"; * //WriteACERunLog(id, type, url, startTime, endTime); */ //Step: send emails here if (attachmentPathList.Count != 0) { //if (err == DownloadErrorCode.NoError || err == DownloadErrorCode.PartialError) //{ //Send email result string mailto = _projectSettings.SelectSingleNode("./email/mailto").InnerText; string mailcc = _projectSettings.SelectSingleNode("./email/mailcc").InnerText; subject = _projectSettings.SelectSingleNode("./email/subject").InnerText; content = "It is sent from GeneralDailyDownload.CAS.\r\n\r\n"; content += string.Format("\tProject Name:\t{0}\r\n\tAttachments:\t{1}\r\n", _projectName, attachmentPathList.Count); content += string.Format("\tError Status:\t{0}\r\n", err.ToString()); content += string.Format("\tError Message Content:\r\n{0}", errMsg); EmailSender.SendEmail(mailto, mailcc, attachmentPathList, subject, content, false); //} // ELSE? No need } else { //status = 1; indicates failure status = 1; //Send error report email here Console.WriteLine("Sending error report.."); string mailto = _projectSettings.SelectSingleNode("./errorreport/mailto").InnerText; string mailcc = _projectSettings.SelectSingleNode("./errorreport/mailcc").InnerText; subject = _projectSettings.SelectSingleNode("./errorreport/subject").InnerText; content += string.Format("\tError Status:\t{0}\r\n", err.ToString()); content += string.Format("\tError Message Content:\r\n\t\t{0}", "Failure"); EmailSender.SendEmail(mailto, mailcc, attachmentPathList, subject, content, false); Console.WriteLine("Error report sent!"); } } catch (Exception e) { //status=1 indicates failure. status = 1; //send error email here string mailto = _projectSettings.SelectSingleNode("./errorreport/mailto").InnerText; string mailcc = _projectSettings.SelectSingleNode("./errorreport/mailcc").InnerText; subject = _projectSettings.SelectSingleNode("./errorreport/subject").InnerText; content = e.ToString(); errMsg = content; EmailSender.SendEmail(mailto, mailcc, attachmentPathList, subject, content, false); //e.Message; } finally { this.WriteWebCrawlRunLog(_projectName, startTime, DateTime.Now, Environment.UserName, status, errMsg); } }