// This example builds a IDbCommand // for querying the MyPatient table // The generated WHERE clause contains PatientName and PatientSex public void MyExample() { MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection(); MatchingParameterList matchingParamList = new MatchingParameterList(); MyPatient myPatient = new MyPatient(); myPatient.PatientName = "Smith"; myPatient.PatientSex = "M"; matchingParamList.Add(myPatient); matchingParamCollection.Add(matchingParamList); IDbCommand command = new SqlCommand(); // This reads the storage catalog // Before you run this, make sure and add the following to your application configuration file //<configSections> // <section name="xmlStorageCatalogSettings" type="Leadtools.Medical.Storage.DataAccessLayer.XmlStorageCatalogSettings, Leadtools.Medical.Storage.DataAccessLayer" /> //</configSections> StorageCatalog myCatalog = new StorageCatalog(); Collection <CatalogElement[]> catalogElements = CatalogDescriptor.GetElementsCollection(matchingParamCollection, myCatalog, true); PreparePatientsQueryCommand(command, catalogElements, ExtraQueryOptions.Typical); // The 'WHERE' clause of command.CommandText is the following: // WHERE ( ( MyPatientTable.PatientName LIKE 'Smith' ) AND ( MyPatientTable.PatientSex LIKE 'M' ) ) Console.WriteLine(command.CommandText); }
private IEnumerable<CatalogDescriptor> FlattenDescriptors(CatalogDescriptor descriptor, int level = 0) { var cats = new List<CatalogDescriptor>(); descriptor.Level = level; cats.Add(descriptor); foreach (var catalog in descriptor.ChildCatalogs) cats.AddRange(FlattenDescriptors(catalog, level + 1)); return cats; }
private int MyDeleteEntity(MatchingParameterCollection matchingEntitiesCollection, PrepareEntityQueryCommandDelegate deleteHandler) { DbCommand command = DataProvider.CreateConnection().CreateCommand(); Collection <CatalogElement[]> matchingParametersCollection = CatalogDescriptor.GetElementsCollection(matchingEntitiesCollection, StorageCatalog, true); deleteHandler(command, matchingParametersCollection, ExtraQueryOptions.Typical); command.Connection.Open(); try { return((int)command.ExecuteNonQuery()); } finally { command.Connection.Close(); } }
// This example is a test to build all queries public void MySampleQueries() { MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection(); MatchingParameterList matchingParamList = new MatchingParameterList(); matchingParamCollection.Add(matchingParamList); StorageCatalog myCatalog = new StorageCatalog(); Collection <CatalogElement[]> catalogElements = CatalogDescriptor.GetElementsCollection(matchingParamCollection, myCatalog, true); IDbCommand command = new SqlCommand(); PreparePatientsQueryCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareStudiesQueryCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareSeriesQueryCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareInstanceQueryCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareDeletePatientsCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareDeleteStudiesCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareDeleteSeriesCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareDeleteInstanceCommand(command, catalogElements, ExtraQueryOptions.Typical); PrepareDeletePatientsNoChildStudiesCommand(command); PrepareDeleteStudiesNoChildSeriesCommand(command); PrepareDeleteSeriesNoChildInstancesCommand(command); DeletePatient(matchingParamCollection); DeleteStudy(matchingParamCollection); DeleteSeries(matchingParamCollection); DeleteInstance(matchingParamCollection); PrepareIsPatientExistsCommand(command, "1111"); PrepareIsStudyExistsCommand(command, "2222"); PrepareIsSeriesExistsCommand(command, "3333"); PrepareIsInstanceExistsCommand(command, "4444"); }
/// <summary> /// Gets the catalog descriptors for the specified catalog. /// </summary> /// <param name="catalog">The part catalog.</param> /// <returns>A set of catalog descriptors.</returns> private static IEnumerable<CatalogDescriptor> GetCatalogDescriptors(ComposablePartCatalog catalog) { var result = new List<CatalogDescriptor>(); CatalogDescriptor descriptor = null; var glimpseCatalog = catalog as GlimpseCatalog; if (glimpseCatalog != null) { result.AddRange(GetCatalogDescriptors(glimpseCatalog.Catalog)); return result; } var aggregateCatalog = catalog as AggregateCatalog; if (aggregateCatalog != null) { descriptor = new CatalogDescriptor() { Type = aggregateCatalog.GetType().Name, IsAggregate = true}; foreach (var child in aggregateCatalog.Catalogs) descriptor.ChildCatalogs.AddRange(GetCatalogDescriptors(child)); result.Add(descriptor); return result; } descriptor = new CatalogDescriptor() { Type = catalog.GetType().Name }; descriptor.Properties = catalog.GetProperties(); foreach (var part in catalog.Parts) { foreach (var def in part.ExportDefinitions) { var meta = def.Metadata.Keys .Where(k => k != CreationPolicyTypeName) .ToDictionary(key => key, key => def.Metadata[key].ToString()); string policy = null; if (def.Metadata.ContainsKey(CreationPolicyTypeName)) policy = def.Metadata[CreationPolicyTypeName].ToString(); var export = new ExportDescriptor { CreationPolicy = policy, DisplayName = part.ToString(), Metadata = meta }; descriptor.Parts.Add(export); } } result.Add(descriptor); return result; }