public void RewriteCCS() { MultilingualString.CurrentCulture = "en-GB"; VersionableBase.DefaultAgencyId = "example.org"; var client = RepositoryIntro.GetClient(); var instance = client.GetItem(new Guid("b9ee3aa5-5bc5-43ed-a24e-f560abb30801"), "example.org", 2) as DdiInstance; //DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); //var instance = deserializer.LoadDdiFile(@"D:\Downloads\filesforMinneapolis\filesforMinneapolis\bcs08v08.xml"); GraphPopulator populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.Populate; instance.Accept(populator); var resourcePackage = instance.ResourcePackages[0]; var instrument = instance.ResourcePackages[0].DataCollections[0].Instruments[0]; //var topLevelSequence = client.GetLatestItem(new Guid("ceaa9acf-2b2f-4c41-b298-b9f419412586"), "cls") // as CustomSequenceActivity; var topLevelSequence = instrument.Sequence; var moduleSequences = topLevelSequence.Activities; foreach (CustomSequenceActivity module in moduleSequences.OfType <CustomSequenceActivity>()) { DirtyItemGatherer gatherer = new DirtyItemGatherer(true); module.Accept(gatherer); var allChildren = gatherer.DirtyItems; ControlConstructScheme ccs = new ControlConstructScheme(); ccs.ItemName.Copy(module.ItemName); foreach (var child in allChildren.OfType <ActivityBase>()) { ccs.ControlConstructs.Add(child); } //client.RegisterItem(ccs, new CommitOptions()); resourcePackage.ControlConstructSchemes.Add(ccs); } DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; var doc = serializer.Serialize(instance); doc.Save(@"d:\ColecticaOutput\bcsv8.xml"); }
public void RewriteCCS() { MultilingualString.CurrentCulture = "en-GB"; VersionableBase.DefaultAgencyId = "example.org"; var client = RepositoryIntro.GetClient(); var instance = client.GetItem(new Guid("b9ee3aa5-5bc5-43ed-a24e-f560abb30801"), "example.org", 2) as DdiInstance; //DDIWorkflowDeserializer deserializer = new DDIWorkflowDeserializer(); //var instance = deserializer.LoadDdiFile(@"D:\Downloads\filesforMinneapolis\filesforMinneapolis\bcs08v08.xml"); GraphPopulator populator = new GraphPopulator(client); populator.ChildProcessing = ChildReferenceProcessing.Populate; instance.Accept(populator); var resourcePackage = instance.ResourcePackages[0]; var instrument = instance.ResourcePackages[0].DataCollections[0].Instruments[0]; //var topLevelSequence = client.GetLatestItem(new Guid("ceaa9acf-2b2f-4c41-b298-b9f419412586"), "cls") // as CustomSequenceActivity; var topLevelSequence = instrument.Sequence; var moduleSequences = topLevelSequence.Activities; foreach (CustomSequenceActivity module in moduleSequences.OfType<CustomSequenceActivity>()) { DirtyItemGatherer gatherer = new DirtyItemGatherer(true); module.Accept(gatherer); var allChildren = gatherer.DirtyItems; ControlConstructScheme ccs = new ControlConstructScheme(); ccs.ItemName.Copy(module.ItemName); foreach (var child in allChildren.OfType<ActivityBase>()) { ccs.ControlConstructs.Add(child); } //client.RegisterItem(ccs, new CommitOptions()); resourcePackage.ControlConstructSchemes.Add(ccs); } DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; var doc = serializer.Serialize(instance); doc.Save(@"d:\ColecticaOutput\bcsv8.xml"); }
public void Convert(string inputFileName, string outputFileName) { VersionableBase.DefaultAgencyId = "example.org"; if (string.IsNullOrWhiteSpace(inputFileName)) { throw new ArgumentNullException("inputFileName"); } if (string.IsNullOrWhiteSpace(outputFileName)) { throw new ArgumentNullException("outputFileName"); } InitializeDdiElements(); // Go through each row of the spreadsheet. DataTable iscoTable = GetSpreadsheetContents(inputFileName); foreach (DataRow row in iscoTable.Rows) { // Create a category and map information from each column. Category category = new Category(); category.Label["en"] = row["description EN"].ToString(); category.Label["fr"] = row["description FR"].ToString(); category.Label["de"] = row["description DE"].ToString(); category.Description["en"] = row["texte auto EN"].ToString(); category.Description["fr"] = row["texte auto FR"].ToString(); category.Description["de"] = row["texte auto DE"].ToString(); categoryScheme.Categories.Add(category); // Create a code. Code code = new Code(); code.Category = category; code.Value = row["code"].ToString(); // First level codes are added directly the CodeScheme. int level = code.Value.Length; if (level == 1) { codeScheme.Codes.Add(code); } else { // For child codes, look up the parent code. // The parent's value will be the same as this new code's value, // minus the last character. var flatCodes = codeScheme.GetFlattenedCodes(); Code parent = flatCodes.SingleOrDefault(c => c.Value == code.Value.Substring(0, code.Value.Length - 1)); parent.ChildCodes.Add(code); } Console.WriteLine(string.Format("{0} {1}", code.Value, category.Label["en"])); } // Save the DDI XML. DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; XmlDocument doc = serializer.Serialize(this.instance); DDIWorkflowSerializer.SaveXml(outputFileName, doc); }
/// <summary> /// This method builds up a DdiInstance and writes it to a /// valid DDI 3.1. XML file. /// </summary> public void BuildSomeDdiAndWriteToXml() { // It is helpful to set some default properties before // working with the SDK's model. These two properties // determine the default language and agency identifier // for every item. MultilingualString.CurrentCulture = "en-US"; VersionableBase.DefaultAgencyId = "example.org"; // Start out by creating a new DDIInstance. // The DdiInstance can hold StudyUnits, Groups, and ResourcePackages. DdiInstance instance = new DdiInstance(); Instance = instance; instance.DublinCoreMetadata.Title.Current = "My First Instance"; // Since we set the CurrentCulture to "en-US", that last line is // equivalent to this next one. instance.DublinCoreMetadata.Title["en-US"] = "My First Instance"; // We can set multiple languages, if we want to. instance.DublinCoreMetadata.Title["fr"] = "TODO"; // Add a ResourcePackage to the DdiInstance. There are three things to do. // 1. First, create it. // 2. Then, set whatever properties you like. Here, we just set the Title. // 3. Add the item to it's parent. In this case, that's the DdiInstance. ResourcePackage resourcePackage = new ResourcePackage(); resourcePackage.DublinCoreMetadata.Title.Current = "RP1"; instance.AddChild(resourcePackage); // Now let's add a ConceptScheme to the ResourcePackage. We'll do this // using the same three steps we used to create the ResourcePackage. ConceptScheme conceptScheme = new ConceptScheme(); conceptScheme.ItemName.Current = "My Concepts"; conceptScheme.Description.Current = "Just some concepts for testing."; resourcePackage.AddChild(conceptScheme); // Let's add some Concepts to the ConceptScheme. string[] conceptLabels = { "Pet", "Dog", "Cat", "Bird", "Fish", "Monkey" }; foreach (string label in conceptLabels) { // Again, for each Concept we create, we want to perform the // same three steps as above: // 1. instantiate, 2. assign properties, 3. add to parent. Concept concept = new Concept(); concept.Label.Current = label; conceptScheme.AddChild(concept); } // Let's create a collection of questions. QuestionScheme questionScheme = new QuestionScheme(); questionScheme.ItemName.Current = "Sample Questions"; resourcePackage.QuestionSchemes.Add(questionScheme); // First, we can ask for a name. This will just collect textual data. Question q1 = new Question(); q1.QuestionText.Current = "What is your name?"; q1.ResponseDomains.Add(new TextDomain()); questionScheme.Questions.Add(q1); // Next, we can ask what method of transportation somebody used to get to Minneapolis. Question transportationQuestion = new Question(); transportationQuestion.QuestionText.Current = "How did you get to Minneapolis?"; // For this question, the respondent will choose from a list of answers. // Let's make that list. CategoryScheme catScheme = new CategoryScheme(); resourcePackage.CategorySchemes.Add(catScheme); var codeScheme = new CodeList(); resourcePackage.CodeSchemes.Add(codeScheme); // Add the first category and code: Airplane Category airplaneCategory = new Category(); airplaneCategory.Label.Current = "Airplane"; Code airplaneCode = new Code { Value = "0", Category = airplaneCategory }; catScheme.Categories.Add(airplaneCategory); codeScheme.Codes.Add(airplaneCode); // Car Category carCategory = new Category(); carCategory.ItemName.Current = "Car"; Code carCode = new Code { Value = "1", Category = carCategory }; catScheme.Categories.Add(carCategory); codeScheme.Codes.Add(carCode); // Train Category trainCategory = new Category(); trainCategory.ItemName.Current = "Train"; Code trainCode = new Code { Value = "2", Category = trainCategory }; catScheme.Categories.Add(trainCategory); codeScheme.Codes.Add(trainCode); // Now that we have a Category and CodeScheme, we can create // a CodeDomain and assign this as the type of data the transportation // question will collect. CodeDomain codeDomain = new CodeDomain(); codeDomain.Codes = codeScheme; transportationQuestion.ResponseDomains.Add(codeDomain); questionScheme.Questions.Add(transportationQuestion); // We have created a DdiInstance, a ResourcePackage, some concepts, // and some questions. // // Now what? // // Let's save all this to a DDI 3.1 XML file. // // First, we can call EnsureCompliance to make sure // our objects have all fields that are required // by the DDI 3.1 schemas. If we missed anything, // this method will fill in some defaults for us. DDIWorkflowSerializer.EnsureCompliance(instance); // Now, create the serializer object that will save our items to XML. // Setting UseConciseBoundedDescription to false makes sure we // write every item, and not just references to items. DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; // Getting a valid XML representation of our model is just one method call. XmlDocument xmlDoc = serializer.Serialize(instance); // Finally, save the XML document to a file. xmlDoc.Save("sample.xml"); }
/// <summary> /// This method builds up a DdiInstance and writes it to a /// valid DDI 3.1. XML file. /// </summary> public void BuildSomeDdiAndWriteToXml() { // It is helpful to set some default properties before // working with the SDK's model. These two properties // determine the default language and agency identifier // for every item. MultilingualString.CurrentCulture = "en-US"; VersionableBase.DefaultAgencyId = "example.org"; // Start out by creating a new DDIInstance. // The DdiInstance can hold StudyUnits, Groups, and ResourcePackages. DdiInstance instance = new DdiInstance(); Instance = instance; instance.DublinCoreMetadata.Title.Current = "My First Instance"; // Since we set the CurrentCulture to "en-US", that last line is // equivalent to this next one. instance.DublinCoreMetadata.Title["en-US"] = "My First Instance"; // We can set multiple languages, if we want to. instance.DublinCoreMetadata.Title["fr"] = "TODO"; // Add a ResourcePackage to the DdiInstance. There are three things to do. // 1. First, create it. // 2. Then, set whatever properties you like. Here, we just set the Title. // 3. Add the item to it's parent. In this case, that's the DdiInstance. ResourcePackage resourcePackage = new ResourcePackage(); resourcePackage.DublinCoreMetadata.Title.Current = "RP1"; instance.AddChild(resourcePackage); // Now let's add a ConceptScheme to the ResourcePackage. We'll do this // using the same three steps we used to create the ResourcePackage. ConceptScheme conceptScheme = new ConceptScheme(); conceptScheme.ItemName.Current = "My Concepts"; conceptScheme.Description.Current = "Just some concepts for testing."; resourcePackage.AddChild(conceptScheme); // Let's add some Concepts to the ConceptScheme. string[] conceptLabels = { "Pet", "Dog", "Cat", "Bird", "Fish", "Monkey" }; foreach (string label in conceptLabels) { // Again, for each Concept we create, we want to perform the // same three steps as above: // 1. instantiate, 2. assign properties, 3. add to parent. Concept concept = new Concept(); concept.Label.Current = label; conceptScheme.AddChild(concept); } // Let's create a collection of questions. QuestionScheme questionScheme = new QuestionScheme(); questionScheme.ItemName.Current = "Sample Questions"; resourcePackage.QuestionSchemes.Add(questionScheme); // First, we can ask for a name. This will just collect textual data. Question q1 = new Question(); q1.QuestionText.Current = "What is your name?"; q1.ResponseDomains.Add(new TextDomain()); questionScheme.Questions.Add(q1); // Next, we can ask what method of transportation somebody used to get to Minneapolis. Question transportationQuestion = new Question(); transportationQuestion.QuestionText.Current = "How did you get to Minneapolis?"; // For this question, the respondent will choose from a list of answers. // Let's make that list. CategoryScheme catScheme = new CategoryScheme(); resourcePackage.CategorySchemes.Add(catScheme); var codeScheme = new CodeList(); resourcePackage.CodeSchemes.Add(codeScheme); // Add the first category and code: Airplane Category airplaneCategory = new Category(); airplaneCategory.Label.Current = "Airplane"; Code airplaneCode = new Code { Value = "0", Category = airplaneCategory }; catScheme.Categories.Add(airplaneCategory); codeScheme.Codes.Add(airplaneCode); // Car Category carCategory = new Category(); carCategory.ItemName.Current = "Car"; Code carCode = new Code { Value = "1", Category = carCategory }; catScheme.Categories.Add(carCategory); codeScheme.Codes.Add(carCode); // Train Category trainCategory = new Category(); trainCategory.ItemName.Current = "Train"; Code trainCode = new Code { Value = "2", Category = trainCategory }; catScheme.Categories.Add(trainCategory); codeScheme.Codes.Add(trainCode); // Now that we have a Category and CodeScheme, we can create // a CodeDomain and assign this as the type of data the transportation // question will collect. CodeDomain codeDomain = new CodeDomain(); codeDomain.Codes = codeScheme; transportationQuestion.ResponseDomains.Add(codeDomain); questionScheme.Questions.Add(transportationQuestion); // We have created a DdiInstance, a ResourcePackage, some concepts, // and some questions. // // Now what? // // Let's save all this to a DDI 3.1 XML file. // // First, we can call EnsureCompliance to make sure // our objects have all fields that are required // by the DDI 3.1 schemas. If we missed anything, // this method will fill in some defaults for us. DDIWorkflowSerializer.EnsureCompliance(instance); // Now, create the serializer object that will save our items to XML. // Setting UseConciseBoundedDescription to false makes sure we // write every item, and not just references to items. DDIWorkflowSerializer serializer = new DDIWorkflowSerializer(); serializer.UseConciseBoundedDescription = false; // Getting a valid XML representation of our model is just one method call. XmlDocument xmlDoc = serializer.Serialize(instance); // Finally, save the XML document to a file. xmlDoc.Save("sample.xml"); }