private void showQueryResults(QueryObject response) { Dispatcher.BeginInvoke(new Action(() => { // Add columns var gridView = new GridView(); listView.View = gridView; PropertyInfo[] properties = response.GetType().GetProperties(); foreach (PropertyInfo property in properties) { bool a = (property.Name == "StudyInstanceUID"); int testInt = a ? 1 : 0; gridView.Columns.Add(new GridViewColumn { Header = property.Name, DisplayMemberBinding = new Binding(property.Name), Width = 100 * (1 - testInt) }); } listView.Items.Add(response); }), DispatcherPriority.ContextIdle); }
public static void addMenuEntry(QueryObject response, BitmapImage image, DownloadPage downloadPageIstance) { GridView gridView = new GridView(); downloadPageIstance.listView.View = gridView; List <dynamic> myItems = new List <dynamic>(); dynamic myItem; IDictionary <string, object> myItemValues; // Populate the objects with dynamic columns // for (var i = 0; i < allResponses.Count;i++) // { myItem = new System.Dynamic.ExpandoObject(); if (response != null) { PropertyInfo[] p = response.GetType().GetProperties(); for (int j = 0; j < p.Length; j++) { myItemValues = (IDictionary <string, object>)myItem; myItemValues[p[j].Name] = p[j].GetValue(response); //MessageBox.Show(p[j].GetValue(response).ToString()); } } myItem.Icon = image; myItems.Add(myItem); // } if (myItems.Count > 0) { // Assuming that all objects have same columns - using first item to determine the columns List <Column> columns = new List <Column>(); myItemValues = (IDictionary <string, object>)myItems[0]; // Key is the column, value is the value foreach (var pair in myItemValues) { Column column = new Column(); column.Title = pair.Key; column.SourceField = pair.Key; columns.Add(column); } // Add the column definitions to the list view gridView.Columns.Clear(); foreach (var column in columns) { if (column.SourceField == "Icon") { gridView.Columns.Add(new GridViewColumn { Header = column.Title, CellTemplate = downloadPageIstance.FindResource("iconTemplate") as DataTemplate }); } else { bool a = (column.Title == "StudyInstanceUID" || column.Title == "SeriesInstanceUID"); int testInt = a ? 0 : 1; var binding = new Binding(column.SourceField); gridView.Columns.Add(new GridViewColumn { Header = column.Title, DisplayMemberBinding = binding, Width = 100 * testInt }); } } // Add all items to the list foreach (dynamic item in myItems) { downloadPageIstance.listView.Items.Add(item); } } }
public void move(string callingAE, QueryObject query, string level, GUILogic guiLogic) { var cmove = new DicomCMoveRequest("", ""); if (query.GetType().ToString() == "QueryRetrieveService.StudyResponseQuery") { string studyId = ((StudyResponseQuery)query).StudyInstanceUID; cmove = new DicomCMoveRequest(callingAE, studyId); } if (query.GetType().ToString() == "QueryRetrieveService.SeriesResponseQuery") { string studyId = ((SeriesResponseQuery)query).StudyInstanceUID; string seriesId = ((SeriesResponseQuery)query).SeriesInstanceUID; cmove = new DicomCMoveRequest(callingAE, studyId, seriesId); } if (query.GetType().ToString() == "QueryRetrieveService.ImageResponseQuery") { string studyId = ((ImageResponseQuery)query).StudyInstanceUID; string seriesId = ((ImageResponseQuery)query).SeriesInstanceUID; string imageId = ((ImageResponseQuery)query).SOPInstanceUID; cmove = new DicomCMoveRequest(callingAE, studyId, seriesId, imageId); Console.WriteLine(studyId + " " + seriesId + " " + imageId); } var client = new DicomClient(); bool?moveSuccessfully = null; cmove.OnResponseReceived += (DicomCMoveRequest requ, DicomCMoveResponse response) => { if (response.Status.State == DicomState.Pending) { Console.WriteLine("Sending is in progress. please wait: " + response.Remaining.ToString()); } else if (response.Status.State == DicomState.Success) { Console.WriteLine("Sending successfully finished"); moveSuccessfully = true; } else if (response.Status.State == DicomState.Failure) { Console.WriteLine("Error sending datasets: " + response.Status.Description); moveSuccessfully = false; } Console.WriteLine(response.Status); }; var pcs = DicomPresentationContext.GetScpRolePresentationContextsFromStorageUids( DicomStorageCategory.Image, DicomTransferSyntax.ExplicitVRLittleEndian, DicomTransferSyntax.ImplicitVRLittleEndian, DicomTransferSyntax.ImplicitVRBigEndian); client.AdditionalPresentationContexts.AddRange(pcs); client.AddRequest(cmove); // cicle to kill listener and restart it (thus ending associatio) if move takes too much time bool sendSuccess = false; new Thread(() => { Thread.CurrentThread.IsBackground = true; Thread.Sleep(5000); if (!sendSuccess) { guiLogic.listenerProcess.Kill(); guiLogic.newProcess(); } }).Start(); client.Send(GUILogic.readFromFile("server"), Int32.Parse(GUILogic.readFromFile("serverPort")), false, GUILogic.readFromFile("thisMachineAE"), GUILogic.readFromFile("serverAE"), 1000); sendSuccess = true; }
public void find(QueryObject query, string level) { if (level != "Study" && level != "Series" && level != "Image") { MessageBox.Show("incorrect level"); return; } DicomQueryRetrieveLevel queryLevel = (DicomQueryRetrieveLevel)Enum.Parse(typeof(DicomQueryRetrieveLevel), level); DicomCFindRequest cfind = new DicomCFindRequest(queryLevel); Type tipo = query.GetType(); PropertyInfo[] properties1 = tipo.GetProperties(); foreach (PropertyInfo property in properties1) { var tag = typeof(DicomTag).GetField(property.Name).GetValue(null); DicomTag theTag = (DicomTag.Parse(tag.ToString())); var variabile = property.GetValue(query); if (variabile.GetType().ToString() == "System.String") { String a = (String)variabile; cfind.Dataset.Add(theTag, a); } if (variabile.GetType().ToString() == "Dicom.DicomDateRange") { DicomDateRange a = (DicomDateRange)variabile; cfind.Dataset.Add(theTag, a); } } cfind.OnResponseReceived = (DicomCFindRequest rq, DicomCFindResponse rp) => { if (rp.HasDataset) { var type = Type.GetType("QueryRetrieveService." + level + "ResponseQuery"); var response = (QueryObject)Activator.CreateInstance(type); queryResponses.Add(response); PropertyInfo[] properties = response.GetType().GetProperties(); foreach (PropertyInfo property in properties) { var tag = typeof(DicomTag).GetField(property.Name).GetValue(null); DicomTag myTag = DicomTag.Parse(tag.ToString()); try { property.SetValue(response, rp.Dataset.GetValues <string>(myTag)[0]); } catch (Exception e) { // MessageBox.Show("tag " + myTag.ToString() + " not found in this dataset"); } } RaiseEvent(response); } }; var client = new DicomClient(); client.AddRequest(cfind); client.AssociationReleased += (sender, e) => { // non può inviare la lista 'queryResponses' prima // che 'cfind.OnResponseReceived' abbia finito di riempirla!! Thread.Sleep(5); RaiseConnectionClosed(queryResponses); }; try { client.Send(GUILogic.readFromFile("server"), Int32.Parse(GUILogic.readFromFile("serverPort")), false, GUILogic.readFromFile("thisMachineAE"), GUILogic.readFromFile("serverAE"), 1000); } catch (Exception e) { MessageBox.Show("impossible connect to server"); } }