public void TryGet_String_TagMissing_Fail() { DicomDataset ds = new DicomDataset(); string testValue; bool success = ds.TryGetString(DicomTag.Modality, out testValue); Assert.False(success); }
public void TryGetStringMayNeverThrow() { DicomDataset dataSet = new DicomDataset(); // add some empty value dataSet.Add(DicomTag.PregnancyStatus, ""); foreach (var item in dataSet) { Assert.Null(Record.Exception(() => dataSet.TryGetString(item.Tag, out string _))); } }
public void Transform(DicomDataset dataset, DicomDataset modifiedAttributesSequenceItem = null) { IDbConnection connection = null; try { if (ConnectionType == DatabaseType.MsSql) { connection = new SqlConnection(ConnectionString); } #if !__IOS__ && !__ANDROID__ && !NETSTANDARD else if (ConnectionType == DatabaseType.Odbc) { connection = new OdbcConnection(ConnectionString); } #endif using (IDbCommand command = connection.CreateCommand()) { command.Connection = connection; command.CommandText = Query; for (int i = 0; i < Parameters.Count; i++) { var str = dataset.TryGetString(Parameters[i], out var dummy) ? dummy : String.Empty; SqlParameter prm = new SqlParameter($"@{i}", str); command.Parameters.Add(prm); } connection.Open(); if (Output.Count == 0) { command.ExecuteNonQuery(); } else { using (IDataReader reader = command.ExecuteReader()) { if (reader.Read()) { for (int i = 0; i < Output.Count; i++) { dataset.CopyTo(modifiedAttributesSequenceItem, Output[i]); string str = reader.GetString(i); dataset.AddOrUpdate(Output[i], str); } } } } connection.Close(); connection = null; } } finally { if (connection != null) { if (connection.State == ConnectionState.Closed || connection.State == ConnectionState.Broken) { connection.Close(); } connection.Dispose(); } } }