/// <summary> /// Loads a DDI file named sample.xml and outputs some item counts. /// </summary> public void LoadDdiAndCountSomeElements() { // Create the deserializer that will read the DDI 3.1 file and // return a populated DdiInstance object. DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); // Load the DdiInstance from the XML file. string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var instance = deserializer.LoadDdiFile(Path.Combine(directory, "sample.xml")); // Output some item counts. Console.WriteLine("ResourcePackages: " + instance.ResourcePackages.Count); if (instance.ResourcePackages.Count > 0) { Console.WriteLine("ConceptSchemes: " + instance.ResourcePackages[0].ConceptSchemes.Count); if (instance.ResourcePackages[0].ConceptSchemes.Count > 0) { Console.WriteLine("Concepts: " + instance.ResourcePackages[0].ConceptSchemes[0].Concepts.Count); } Console.WriteLine("QuestionSchemes: " + instance.ResourcePackages[0].QuestionSchemes.Count); Console.WriteLine("CategorySchemes: " + instance.ResourcePackages[0].CategorySchemes.Count); Console.WriteLine("CodeSchemes: " + instance.ResourcePackages[0].CodeSchemes.Count); } }
/// <summary> /// Load the sample DDI 3.1 file and register all its items with the Repository. /// </summary> public void RegisterFile() { // Load the sample data file. DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var instance = deserializer.LoadDdiFile(Path.Combine(directory, "sample.xml")); // Gather all items instance in the DdiInstance we just loaded. // We need to do this to get the items in a flat list. DirtyItemGatherer gatherer = new DirtyItemGatherer(gatherEvenIfNotDirty: true); instance.Accept(gatherer); // Grab a client to communicate with the Repository. var client = GetClient(); // Register each item with the Repository. foreach (var item in gatherer.DirtyItems) { client.RegisterItem(item, new CommitOptions()); } }
public void QueryObjectModel() { // Load the sample data file. DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var instance = deserializer.LoadDdiFile(Path.Combine(directory, "sample.xml")); // Use LINQ to find the first category with the label "Car". var carCat = (from rp in instance.ResourcePackages from cs in rp.CategorySchemes from cat in cs.Categories where cat.ItemName.ContainsKey("en-US") && cat.ItemName["en-US"] == "Car" select cat).FirstOrDefault(); // Output some information about the category. if (carCat != null) { Console.WriteLine("Found the category. Its identifier is " + carCat.Identifier); } else { Console.WriteLine("Could not find a category labeled 'Car'"); } }
/// <summary> /// Load the sample DDI 3.1 file and register all its items with the Repository. /// </summary> public void RegisterFile() { // Load the sample data file. DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var instance = deserializer.LoadDdiFile(Path.Combine(directory, "sample.xml")); // Gather all items instance in the DdiInstance we just loaded. // We need to do this to get the items in a flat list. DirtyItemGatherer gatherer = new DirtyItemGatherer(gatherEvenIfNotDirty:true); instance.Accept(gatherer); // Grab a client to communicate with the Repository. var client = GetClient(); // Register each item with the Repository. foreach (var item in gatherer.DirtyItems) { client.RegisterItem(item, new CommitOptions()); } }