public bool InsertSummaryInfo(string errorId, SummaryField[] summaries) { SummaryItem[] summaryItems = new SummaryItem[summaries.Length]; int i = 0; foreach (SummaryField field in summaries) { summaryItems[i] = new SummaryItem(); summaryItems[i].Key = field.Name; summaryItems[i].Value = field.Value; summaryItems[i].DataType = field.Type; i++; } ErrorShortInfo errorShortInfo = new ErrorShortInfo(); errorShortInfo.ErrorId = errorId; errorShortInfo.Summary = summaryItems; return (promovaService.InsertSummaryInfo(errorShortInfo) == summaryItems.Length ? true : false); }
public void TryDoUploads() { int k = 100; string errorType = string.Empty; string metaFileName = string.Empty; SummaryField[] summaryItems = new SummaryField[0]; string[] filesUploading = new string[0]; PackageForUpload packageForUpload = packageUploadManager.GetPackageForUpload(maxContentLength, fileExt, out metaFileName, out errorType, out summaryItems, out filesUploading); //ReLoad uploading queue string uploadingQueueFileName = string.Empty; if(filesUploading.Length>0) { uploadingQueueFileName = System.IO.Path.GetDirectoryName(filesUploading[0]); uploadingQueueFileName = uploadingQueueFileName.Substring(0, uploadingQueueFileName.LastIndexOf(@"\")); uploadingQueueFileName = System.IO.Path.Combine(uploadingQueueFileName, "UploadingQueue.xml"); if (System.IO.File.Exists(uploadingQueueFileName)) uploadingFiles = UploadingFileManager.LoadUploadingInfo(uploadingQueueFileName); } while (k-- > 0 && packageForUpload != null) { string errorID = null; try { if (serviceInvoker == null) { serviceInvoker = new WebServiceInvoker(); serviceInvoker.SetServiceUrl(myServiceUrl); } if (filesUploading.Length > 0) { errorID = null; if (uploadingFiles != null) errorID = uploadingFiles.GetErrorIDByFileName(filesUploading[0]); if(errorID == null) { errorID = serviceInvoker.CreateError(metaFileName, errorType, packageForUpload.ShortVersion); } else { serviceInvoker.InitLastErrorInfo(errorID); } if (errorID != null) { if (uploadingFiles == null) { uploadingFiles = new UploadingFiles(errorID, filesUploading); } else { uploadingFiles.AddUploadingFiles(errorID, filesUploading); } //Save the Queue before upload data UploadingFileManager.SaveUploadingInfo(uploadingFiles, uploadingQueueFileName); if(summaryItems.Length > 0) serviceInvoker.InsertSummaryInfo(errorID, summaryItems); #region Upload File int uploadedFilesCount = 0; for (int i = 0; i < filesUploading.Length; i++) { string uploading = filesUploading[i]; //Thread thread = new Thread(new ParameterizedThreadStart(ThreadUploadFile)); //thread.Start(errorID, uploading, FileUtils.GetFileContent(uploading)); int numberOfUploadingTimes = 10; bool resultUploading = false; int times = 0; while (times < numberOfUploadingTimes && !resultUploading) { times++; resultUploading = serviceInvoker.UploadErrorFile(System.IO.Path.GetFileName(uploading), FileUtils.GetFileContent(uploading)); } if (!resultUploading) { //packageUploadManager.PutPackageBack(packageForUpload.PackageName); } else { uploadedFilesCount++; uploadingFiles.MarkUploaded(errorID, uploading); System.IO.File.Delete(uploading); } } #endregion if (uploadedFilesCount > 0) packageUploadManager.MarkFinishedUpload(packageForUpload.PackageName); //Save the Queue again UploadingFileManager.SaveUploadingInfo(uploadingFiles, uploadingQueueFileName); } } } catch (Exception exception) { try { //If the error processed but did not upload any file, we have to push back to upload later. if (errorID == null) { packageUploadManager.PutPackageBack(packageForUpload.PackageName); errorID = "null"; } else { packageUploadManager.MarkFinishedUpload(packageForUpload.PackageName); } ProcessException.Handle(exception,"ApplicationUtils.ErrorReporting.Upload.Uploader.TryDoUpLoad()", string.Format("Uploder.TryDoUploads({0}) Error", errorID)); } catch { } } packageForUpload = packageUploadManager.GetPackageForUpload(maxContentLength, fileExt, out metaFileName, out errorType, out summaryItems, out filesUploading); } return; }
public PackageForUpload GetPackageForUpload(int maxContentLength, string fileExt, out string metaFileName, out string errorType, out SummaryField[] summaryItems, out string[] splittedFiles) { lock (synchRoot) { #region Validate info RecycleTimeoutUploads(); metaFileName = null; summaryItems = new SummaryField[0]; errorType = string.Empty; splittedFiles = new string[0]; byte[] shortVersionContent = null; PackageForUpload packageForUpload = null; string fullFilePath = tools.PickPackageForUpload(); if (fullFilePath == null) { return null; } if (System.IO.Path.GetExtension(fullFilePath).ToLower().Equals(fileExt.ToLower())) { uploadingPackages.Add(fullFilePath, DateTime.Now); shortVersionContent = FileUtils.GetFileContent(fullFilePath); packageForUpload = new PackageForUpload(Path.GetFileName(fullFilePath), null, shortVersionContent); splittedFiles = new string[1]; splittedFiles[0] = fullFilePath; return packageForUpload; } string storeFolder = Path.GetDirectoryName(fullFilePath); #endregion byte[] packageContent = FileUtils.GetFileContent(fullFilePath); try { FastZip zipFile = new FastZip(); //get a temporary directory name string tmpDirName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); //unzip the archive zipFile.ExtractZip(fullFilePath, tmpDirName, ""); string xmlFilename = System.IO.Path.Combine(tmpDirName, "ReportDetails.xml"); //add -short to the name of the package metaFileName = Path.GetFileNameWithoutExtension(fullFilePath) + "-meta.zip"; string shortFilePath = Path.Combine(Path.GetTempPath(), metaFileName); #region Get Summary information from ReportDetails.xml string xmlDefineFields = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SummaryFields.xml"); XmlMetaProcessing metaProcessing = new XmlMetaProcessing(xmlDefineFields, xmlFilename); summaryItems = metaProcessing.SummaryFields; string snapShotFolderName = System.IO.Path.Combine(tmpDirName, "Data"); string hasSnapShot = "False"; if (System.IO.Directory.Exists(snapShotFolderName)) hasSnapShot = "True"; if (summaryItems.Length > 0) { foreach (SummaryField item in summaryItems) { if (item.Name.ToLower().Equals("errorlocation")) { errorType = (item.Value != null ? item.Value.ToString() : ""); } else if (item.Name.ToLower().Equals("hassnapshot")) { item.Value = hasSnapShot; } } } #endregion #if SHORT_INFO_INCLUDE_LOG try { DirectoryInfo tmpLogsDir = new DirectoryInfo(Path.Combine(tmpDirName, "Logs")); if (tmpLogsDir.Exists) { FileInfo[] files = tmpLogsDir.GetFiles(); foreach (FileInfo logFile in files) { logFile.CopyTo(Path.Combine(tmpDirName, logFile.Name)); } } } catch (Exception e) { ProcessException.Handle(e); Debug.Fail(e.Message); } #endif //create a new package, but without Data folder - this is Meta package zipFile.CreateZip(shortFilePath, tmpDirName, false, string.Empty); shortVersionContent = FileUtils.GetFileContent(shortFilePath); if (packageContent.Length > maxContentLength) { splittedFiles = SplitFile(maxContentLength, fullFilePath, fileExt); } else { splittedFiles = new string[1]; splittedFiles[0] = fullFilePath; } try { //clean up Directory.Delete(tmpDirName, true); File.Delete(shortFilePath); //Delete the main file after splited File.Delete(fullFilePath); } catch (Exception ex) { ProcessException.Handle(ex); Debug.Fail(ex.Message); } } catch (Exception ex) { ProcessException.Handle(ex); Debug.Fail(ex.Message); } uploadingPackages.Add(fullFilePath, DateTime.Now); packageForUpload = new PackageForUpload(Path.GetFileName(fullFilePath), null, shortVersionContent); return packageForUpload; } }