public List<aim_dotnet.Annotation> getAnnotationOfAnnotationInfoList(AIMQueryParameters queryParameters) { var annoStr = getAnnotationOfAnnotationInfo(queryParameters); if (annoStr == null) return null; var annotations = new List<aim_dotnet.Annotation>(); var xmlModel = new aim_dotnet.XmlModel(); foreach (var str in annoStr) { var annoAnnotation = xmlModel.ReadAnnotationFromXmlString(str) as aim_dotnet.AnnotationOfAnnotation; if (annoAnnotation != null) annotations.Add(annoAnnotation); } return annotations; }
public List <aim_dotnet.Annotation> getAnnotationOfAnnotationInfoList(AIMQueryParameters queryParameters) { var annoStr = getAnnotationOfAnnotationInfo(queryParameters); if (annoStr == null) { return(null); } var annotations = new List <aim_dotnet.Annotation>(); var xmlModel = new aim_dotnet.XmlModel(); foreach (var str in annoStr) { var annoAnnotation = xmlModel.ReadAnnotationFromXmlString(str) as aim_dotnet.AnnotationOfAnnotation; if (annoAnnotation != null) { annotations.Add(annoAnnotation); } } return(annotations); }
private int SendAnnotationsInFolderToDataService(string folderName, string dataServiceUrl) { if (string.IsNullOrEmpty(folderName) || string.IsNullOrEmpty(dataServiceUrl)) { Platform.Log(LogLevel.Error, "Trying to send queued annotations from an invalid folder ({0}) or to an invalid data service ({1})", folderName, dataServiceUrl); return 0; } var folderPath = System.IO.Path.Combine(AimSettings.Default.AnnotationQueuesFolder, folderName); if (!System.IO.Directory.Exists(folderPath)) return 0; var sentCounter = 0; try { var annotationFiles = System.IO.Directory.GetFiles(folderPath, "*.xml", System.IO.SearchOption.TopDirectoryOnly); const int fileCountToSendAtOnce = 10; for (var i = 0; i < (annotationFiles.Length + fileCountToSendAtOnce) / fileCountToSendAtOnce; i++) { var xmlAnnotations = new Dictionary<string, string>(); var readAnnotationFiles = new List<string>(); using (var xmlModel = new aim_dotnet.XmlModel()) { var nextBatchMax = Math.Min((i + 1)*fileCountToSendAtOnce, annotationFiles.Length); for (var j = i*fileCountToSendAtOnce; j < nextBatchMax; j++) { var annotationPathName = System.IO.Path.Combine(folderPath, annotationFiles[j]); try { var annotations = xmlModel.ReadAnnotationsFromFile(annotationPathName); try { foreach (var annotation in annotations) { xmlAnnotations.Add(annotation.UniqueIdentifier, xmlModel.WriteAnnotationToXmlString(annotation)); } readAnnotationFiles.Add(annotationPathName); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to convert annotation to XML string. File: {0}", annotationPathName); xmlAnnotations.Clear(); } finally { annotations.Clear(); } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to read annotation file from queue: {0}", annotationPathName); } } } if (xmlAnnotations.Count > 0) { try { AIMTCGAService.AIMTCGASubmit.sendAIMTCGAAnnotation(new List<string>(xmlAnnotations.Values).ToArray()); sentCounter += xmlAnnotations.Count; Debug.Assert(readAnnotationFiles.Count <= xmlAnnotations.Count, "There are more files to delete than read annoations"); xmlAnnotations.Clear(); foreach (var readAnnotationFile in readAnnotationFiles) { try { System.IO.File.Delete(readAnnotationFile); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to delete sent annoation file ({0}). The file will be send again.", readAnnotationFile); } } readAnnotationFiles.Clear(); } catch (Exception ex) { Platform.Log(LogLevel.Debug, ex, "Failed to send annotations to the AIM Data Serice ({0}).", dataServiceUrl); break; } } } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to send files from {0} to server {1}", folderPath, dataServiceUrl); } return sentCounter; }
public static bool WriteXmlAnnotationToFile(aim_dotnet.Annotation annotation, string filePathName) { var xmlModel = new aim_dotnet.XmlModel(); try { xmlModel.WriteAnnotationToFile(annotation, filePathName); return true; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to save annotation to file \"{0}\"", filePathName); } finally { xmlModel = null; } return false; }
public static string[] WriteXmlAnnotationsToFolder(List<aim_dotnet.Annotation> annotations, string folderPath) { var savedFileNames = new List<string>(); var xmlModel = new aim_dotnet.XmlModel(); foreach (var annotation in annotations) { string xmlFileName = null; var fileName = string.IsNullOrEmpty(annotation.UniqueIdentifier) ? System.IO.Path.GetRandomFileName() : annotation.UniqueIdentifier; try { xmlFileName = System.IO.Path.ChangeExtension(System.IO.Path.Combine(folderPath, fileName), "xml"); xmlModel.WriteAnnotationToFile(annotation, xmlFileName); savedFileNames.Add(xmlFileName); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to save annotation to file \"{0}\"", xmlFileName); try { if (!string.IsNullOrEmpty(xmlFileName)) System.IO.File.Delete(xmlFileName); } catch (Exception) { } } } xmlModel = null; return savedFileNames.ToArray(); }
private int SendAnnotationsInFolderToDataService(string folderName, string dataServiceUrl) { if (string.IsNullOrEmpty(folderName) || string.IsNullOrEmpty(dataServiceUrl)) { Platform.Log(LogLevel.Error, "Trying to send queued annotations from an invalid folder ({0}) or to an invalid data service ({1})", folderName, dataServiceUrl); return(0); } var folderPath = System.IO.Path.Combine(AimSettings.Default.AnnotationQueuesFolder, folderName); if (!System.IO.Directory.Exists(folderPath)) { return(0); } var sentCounter = 0; try { var annotationFiles = System.IO.Directory.GetFiles(folderPath, "*.xml", System.IO.SearchOption.TopDirectoryOnly); const int fileCountToSendAtOnce = 10; for (var i = 0; i < (annotationFiles.Length + fileCountToSendAtOnce) / fileCountToSendAtOnce; i++) { var xmlAnnotations = new Dictionary <string, string>(); var readAnnotationFiles = new List <string>(); using (var xmlModel = new aim_dotnet.XmlModel()) { var nextBatchMax = Math.Min((i + 1) * fileCountToSendAtOnce, annotationFiles.Length); for (var j = i * fileCountToSendAtOnce; j < nextBatchMax; j++) { var annotationPathName = System.IO.Path.Combine(folderPath, annotationFiles[j]); try { var annotations = xmlModel.ReadAnnotationsFromFile(annotationPathName); try { foreach (var annotation in annotations) { xmlAnnotations.Add(annotation.UniqueIdentifier, xmlModel.WriteAnnotationToXmlString(annotation)); } readAnnotationFiles.Add(annotationPathName); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to convert annotation to XML string. File: {0}", annotationPathName); xmlAnnotations.Clear(); } finally { annotations.Clear(); } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to read annotation file from queue: {0}", annotationPathName); } } } if (xmlAnnotations.Count > 0) { try { AIMTCGAService.AIMTCGASubmit.sendAIMTCGAAnnotation(new List <string>(xmlAnnotations.Values).ToArray()); sentCounter += xmlAnnotations.Count; Debug.Assert(readAnnotationFiles.Count <= xmlAnnotations.Count, "There are more files to delete than read annoations"); xmlAnnotations.Clear(); foreach (var readAnnotationFile in readAnnotationFiles) { try { System.IO.File.Delete(readAnnotationFile); } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to delete sent annoation file ({0}). The file will be send again.", readAnnotationFile); } } readAnnotationFiles.Clear(); } catch (Exception ex) { Platform.Log(LogLevel.Debug, ex, "Failed to send annotations to the AIM Data Serice ({0}).", dataServiceUrl); break; } } } } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to send files from {0} to server {1}", folderPath, dataServiceUrl); } return(sentCounter); }
// Writes all annotations to a given folder. Returns number of annotations written. public static int WriteXmlAnnotationsToFolder(List<aim_dotnet.Annotation> annotations, string folderPath) { int cnt = 0; aim_dotnet.XmlModel xmlModel = new aim_dotnet.XmlModel(); foreach (aim_dotnet.Annotation annotation in annotations) { string tempFileNameXml = null; string fileName = string.IsNullOrEmpty(annotation.UniqueIdentifier) ? System.IO.Path.GetRandomFileName() : annotation.UniqueIdentifier; try { tempFileNameXml = System.IO.Path.ChangeExtension(System.IO.Path.Combine(folderPath, fileName), "xml"); xmlModel.WriteAnnotationToFile(annotation, tempFileNameXml); cnt++; } catch (Exception ex) { Platform.Log(LogLevel.Error, ex, "Failed to save annotation to file \"{0}\"", tempFileNameXml); try { if (!string.IsNullOrEmpty(tempFileNameXml)) System.IO.File.Delete(tempFileNameXml); } catch (Exception) { } } } xmlModel = null; return cnt; }