Exemple #1
0
        public static List <string> CollectIds(StudyUnit studyUnit)
        {
            List <string> ids = new List <string>();

            //0. StudyUnit itself
            CollectIds(studyUnit, ids);
            //1. Event
            CollectIds(studyUnit.Events, ids);
            //2. Member
            CollectIds(studyUnit.Members, ids);
            //3. Organization
            CollectIds(studyUnit.Organizations, ids);
            //4. Abstract
            CollectIds(studyUnit.Abstract, ids);
            //5. Coverage
            CollectIds(studyUnit.Coverage, ids);
            //6. Funding Agency
            CollectIds(studyUnit.FundingInfos, ids);
            //6-1. Organization including
            CollectIds(FundingInfo.GetOrganizations(studyUnit.FundingInfos), ids);
            //7.Universe
            CollectIds(Sampling.GetUniverses(studyUnit.Samplings), ids);
            //8.Sampling
            CollectIds(studyUnit.Samplings, ids);
            //9. Concept Scheme
            CollectIds(studyUnit.ConceptSchemes, ids);
            //9-1. Concept
            CollectIds(ConceptScheme.GetConcepts(studyUnit.ConceptSchemes), ids);
            //10. Question
            CollectIds(studyUnit.Questions, ids);
            //10-1. Answer
            CollectIds(Question.GetResponses(studyUnit.Questions), ids);
            //11. Category Scheme
            CollectIds(studyUnit.CategorySchemes, ids);
            //11-1. Category
            CollectIds(CategoryScheme.GetCategories(studyUnit.CategorySchemes), ids);
            //12. Code Scheme
            CollectIds(studyUnit.CodeSchemes, ids);
            //12-1. Code
            CollectIds(CodeScheme.GetCodes(studyUnit.CodeSchemes), ids);
            //13. Variable Scheme
            CollectIds(studyUnit.VariableScheme, ids);
            //14. Variable
            CollectIds(studyUnit.Variables, ids);
            //14-1. Answer
            CollectIds(Variable.GetResponses(studyUnit.Variables), ids);
            //15. Dataset
            CollectIds(studyUnit.DataSets, ids);
            //16. Data File
            CollectIds(studyUnit.DataFiles, ids);
            //17. Order of Question
            CollectIds(studyUnit.ControlConstructSchemes, ids);
            //17-1.Sequence
            CollectIds(ControlConstructScheme.GetSequences(studyUnit.ControlConstructSchemes), ids);
            //17-2.Constructs
            CollectIds(ControlConstructScheme.GetConstructs(studyUnit.ControlConstructSchemes), ids);

            return(ids);
        }
Exemple #2
0
 public CategorySchemeVM(CategoryScheme categoryScheme)
 {
     this.categoryScheme = categoryScheme;
     categories          = new ObservableCollection <CategoryVM>();
     foreach (Category categoryModel in categoryScheme.Categories)
     {
         CategoryVM category = new CategoryVM(categoryModel);
         category.Parent = this;
         categories.Add(category);
     }
     modelSyncher = new ModelSyncher <CategoryVM, Category>(this, categories, categoryScheme.Categories);
     modelSyncher.AddActionHandler = (param) => {
         param.CategorySchemeId = Id;
     };
 }
Exemple #3
0
        public void AddCategoryScheme()
        {
            InputDialog dlg = new InputDialog();

            dlg.Title = Resources.InputCategorySchemeName; //Enter the name of Category Scheme
            dlg.Owner = Application.Current.MainWindow;
            dlg.ShowDialog();
            if (dlg.DialogResult == true)
            {
                CategoryScheme categorySchemeModel = new CategoryScheme()
                {
                    Title = dlg.textBox.Text
                };
                CategorySchemeVM categoryScheme = new CategorySchemeVM(categorySchemeModel);
                categorySchemes.Add(categoryScheme);
                if (SelectedCategoryScheme == null)
                {
                    SelectedCategoryScheme = categoryScheme;
                }
                Memorize();
            }
        }
        void InitializeDdiElements()
        {
            resourcePackage = new ResourcePackage();
            resourcePackage.DublinCoreMetadata.Title["en"] = "ISCO Classification";
            resourcePackage.Abstract.Strings["en"] = "Not specified";
            resourcePackage.Purpose.Strings["en"] = "Not specified";

            categoryScheme = new CategoryScheme();
            categoryScheme.Label["en"] = "ISCO Categories";

            codeScheme = new CodeScheme();
            codeScheme.Label["en"] = "ISCO Codes";

            resourcePackage.CategorySchemes.Add(categoryScheme);
            resourcePackage.CodeSchemes.Add(codeScheme);

            instance = new DdiInstance();
            instance.ResourcePackages.Add(resourcePackage);
        }
Exemple #5
0
        static void ExtractAndCollapseMissingCategories()
        {
            MultilingualString.CurrentCulture = "en-GB";
            VersionableBase.DefaultAgencyId   = "cls";

            string[] missingCategories =
            {
                "Refusal",
                "Don't Know",
                "Item not applicable",
                "Schedule not applicable",
                "Not applicable",
            };

            var client = RepositoryIntro.GetClient();

            //CategoryScheme newMissingScheme = new CategoryScheme();
            //newMissingScheme.ItemName.Current = "Missing";

            Dictionary <string, Category> categoryMap = new Dictionary <string, Category>();
            //foreach (string catLabel in missingCategories)
            //{
            //    Category cat = new Category();
            //    cat.IsMissing = true;
            //    cat.Label.Current = catLabel;
            //    newMissingScheme.Categories.Add(cat);

            //    categoryMap.Add(catLabel, cat);

            //    client.RegisterItem(cat, new CommitOptions());
            //}

            //client.RegisterItem(newMissingScheme, new CommitOptions());

            CategoryScheme newMissingScheme = client.GetItem(new Guid("12aaf470-953d-4ebe-9d51-15de00a97921"), "cls", 1, ChildReferenceProcessing.Populate)
                                              as CategoryScheme;

            foreach (var cat in newMissingScheme.Categories)
            {
                categoryMap.Add(cat.Label.Current, cat);
            }

            // Get all codeSchemes in the repository, so we can update the category references
            // to the new, harmonized categories that we created above.
            //SetSearchFacet facet = new SetSearchFacet();
            //facet.ItemTypes.Add(DdiItemType.CodeScheme);
            //var codeSchemeIDs = client.SearchTypedSet(new IdentifierTriple(new Guid("e92ac0d9-9f2f-4891-9c42-75bfeafc6d23"), 3, "ucl.ac.uk"), facet);
            //var codeSchemes = client.GetItems(codeSchemeIDs.ToIdentifierCollection());

            ResourcePackage resourcePackage = client.GetItem(new IdentifierTriple(new Guid("e92ac0d9-9f2f-4891-9c42-75bfeafc6d23"), 3, "ucl.ac.uk"))
                                              as ResourcePackage;

            resourcePackage.CategorySchemes.Add(newMissingScheme);

            //foreach (CodeScheme cs in resourcePackage.CodeSchemes)
            //{
            //    client.PopulateItem(cs, false, ChildReferenceProcessing.Populate);

            //    foreach (Code code in cs.Codes)
            //    {
            //        if (categoryMap.ContainsKey(code.Category.Label.Current))
            //        {
            //            var category = categoryMap[code.Category.Label.Current];
            //            code.Category = category;
            //        }
            //    }

            //    cs.Version++;
            //    client.RegisterItem(cs, new CommitOptions());
            //}

            // TODO go through all CategorySchemes and remove the missing categories.
            // Codes will point to the new categories instead.
            // Also, rename the category schemes based on the new contents.
            foreach (CategoryScheme cs in resourcePackage.CategorySchemes)
            {
                if (cs == newMissingScheme)
                {
                    continue;
                }

                client.PopulateItem(cs, false, ChildReferenceProcessing.Populate);

                var toRemove = cs.Categories.Where(cat => categoryMap.ContainsKey(cat.Label.Current)).ToList();
                foreach (var remove in toRemove)
                {
                    cs.Categories.Remove(remove);
                }

                cs.ItemName.Current = string.Join(", ", cs.Categories
                                                  .Select(cat => cat.Label.Current)
                                                  .Take(Math.Min(cs.Categories.Count, 3))
                                                  .ToArray());

                cs.Version++;
                client.RegisterItem(cs, new CommitOptions());
            }

            // Don't forget to publish the new ResourcePackage.
            resourcePackage.Version++;
            client.RegisterItem(resourcePackage, new CommitOptions());
        }
Exemple #6
0
        public bool ImportVariables(string path, StudyUnitVM studyUnit)
        {
            Debug.Assert(!string.IsNullOrEmpty(path));
            StudyUnit       studyUnitModel = studyUnit.StudyUnitModel;
            FileStream      stream         = File.OpenRead(path);
            SavFileParser   parser         = new SavFileParser(stream);
            List <Variable> variables      = new List <Variable>();

            foreach (SpssLib.SpssDataset.Variable v in parser.Variables)
            {
                Variable variable = new Variable();
                variable.Title = v.Name;
                variable.Label = v.Label;
                variables.Add(variable);
                if (v.Type == SpssLib.SpssDataset.DataType.Text)
                {
                    variable.Response.TypeCode = Options.RESPONSE_TYPE_FREE_CODE;
                }
                else
                {
                    if (v.ValueLabels.Count > 0)
                    {
                        CategoryScheme categoryScheme = new CategoryScheme();
                        categoryScheme.Title = v.Label;
                        studyUnitModel.CategorySchemes.Add(categoryScheme);
                        CodeScheme codeScheme = new CodeScheme();
                        codeScheme.Title = v.Label;;
                        studyUnitModel.CodeSchemes.Add(codeScheme);

                        variable.Response.TypeCode     = Options.RESPONSE_TYPE_CHOICES_CODE;
                        variable.Response.CodeSchemeId = codeScheme.Id;
                        // Create Category
                        foreach (KeyValuePair <double, string> pair in v.ValueLabels)
                        {
                            Category category = new Category();
                            categoryScheme.Categories.Add(category);
                            category.Title            = pair.Value;
                            category.CategorySchemeId = categoryScheme.Id;

                            Code code = new Code();
                            codeScheme.Codes.Add(code);
                            code.CategoryId   = category.Id;
                            code.CodeSchemeId = codeScheme.Id;
                            code.Value        = pair.Key.ToString();
                        }
                        // Add Missing value
                        if (v.MissingValues.Count > 0)
                        {
                            foreach (double missingValue in v.MissingValues)
                            {
                                string missingValueStr = missingValue.ToString();
                                if (ExistValue(codeScheme, missingValueStr))
                                {
                                    continue;
                                }
                                Category category = new Category();
                                categoryScheme.Categories.Add(category);
                                category.Title            = Resources.MissingValue; //Missing value
                                category.IsMissingValue   = true;
                                category.CategorySchemeId = categoryScheme.Id;

                                Code code = new Code();
                                codeScheme.Codes.Add(code);
                                code.CategoryId   = category.Id;
                                code.CodeSchemeId = codeScheme.Id;
                                code.Value        = missingValueStr;
                            }
                        }
                    }
                    else
                    {
                        variable.Response.TypeCode = Options.RESPONSE_TYPE_NUMBER_CODE;
                    }
                }
            }

            if (variables.Count > 0)
            {
                ConceptScheme conceptScheme = new ConceptScheme();
                conceptScheme.Title = EDOUtils.UniqueLabel(ConceptScheme.GetTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable);                        //Imported Variable
                string name = Path.GetFileName(path);
                conceptScheme.Memo = EDOUtils.UniqueLabel(ConceptScheme.GetMemos(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name)); //Imported variable from {0}

                Concept concept = new Concept();
                concept.Title   = EDOUtils.UniqueLabel(ConceptScheme.GetConceptTitles(studyUnitModel.ConceptSchemes), Resources.ImportVariable);                            //Imported Variable
                concept.Content = EDOUtils.UniqueLabel(ConceptScheme.GetConceptContents(studyUnitModel.ConceptSchemes), string.Format(Resources.ImportVariableFrom, name)); //Imported variable from {0}
                conceptScheme.Concepts.Add(concept);
                studyUnitModel.ConceptSchemes.Add(conceptScheme);

                foreach (Variable variable in variables)
                {
                    Question question = new Question();
                    question.Title                  = variable.Label;
                    question.ConceptId              = concept.Id;
                    question.Response.TypeCode      = variable.Response.TypeCode;
                    question.Response.CodeSchemeId  = variable.Response.CodeSchemeId;
                    question.VariableGenerationInfo = question.CreateVariableGenerationInfo();
                    studyUnitModel.Questions.Add(question);
                    variable.ConceptId  = concept.Id;
                    variable.QuestionId = question.Id;
                    studyUnitModel.Variables.Add(variable);
                }
            }
            return(true);
        }
Exemple #7
0
        public static void RenameIds(StudyUnit orgStudyUnit, StudyUnit newStudyUnit)
        {
            // renumber the ID of newStudyUnit to avoid duplication between ID of newStudyUnit ID and orgStudyUnit

            List <string> ids = CollectIds(orgStudyUnit);

            //0. StudyUnit itself
            RenameIds(newStudyUnit, ids);
            //1. Event
            RenameIds(newStudyUnit.Events, ids);
            //2. Member
            RenameIds(newStudyUnit.Members, ids, (result) =>
            {
                Sampling.ChangeMemberId(newStudyUnit.Samplings, result.OldId, result.NewId);
            });

            //3. Organization
            RenameIds(newStudyUnit.Organizations, ids, (result) =>
            {
                Member.ChangeOrganizationId(newStudyUnit.Members, result.OldId, result.NewId);
                Sampling.ChangeMemberId(newStudyUnit.Samplings, result.OldId, result.NewId);
            });
            //4. Abstract
            RenameIds(newStudyUnit.Abstract, ids);
            //5. Coverage
            RenameIds(newStudyUnit.Coverage, ids);
            //6. Funding Agency
            RenameIds(newStudyUnit.FundingInfos, ids);
            RenameIds(newStudyUnit.FundingInfoOrganizations, ids); //Organization of Funding Agency
            ////7.Universe
            RenameIds(newStudyUnit.AllUniverses, ids, (result) =>
            {
                Variable.ChangeUniverseId(newStudyUnit.Variables, result.OldId, result.NewId);
            });
            //8.Sampling
            RenameIds(newStudyUnit.Samplings, ids);
            //9. Concept Scheme
            RenameIds(newStudyUnit.ConceptSchemes, ids);
            //9-1. Concept
            RenameIds(ConceptScheme.GetConcepts(newStudyUnit.ConceptSchemes), ids, (result) =>
            {
                Question.ChangeConceptId(newStudyUnit.Questions, result.OldId, result.NewId);
                Variable.ChangeConceptId(newStudyUnit.Variables, result.OldId, result.NewId);
                Book.ChangeMetaDataId(newStudyUnit.Books, result.OldId, result.NewId);
            });
            //10. Question
            RenameIds(newStudyUnit.Questions, ids, (result) =>
            {
                ControlConstructScheme.ChangeQuestionId(newStudyUnit.ControlConstructSchemes, result.OldId, result.NewId);
                Variable.ChangeQuestionId(newStudyUnit.Variables, result.OldId, result.NewId);
                Book.ChangeMetaDataId(newStudyUnit.Books, result.OldId, result.NewId);
            });
            //11. Category Scheme
            RenameIds(newStudyUnit.CategorySchemes, ids, (result) =>
            {
                CategoryScheme.ChangeCategorySchemeId(newStudyUnit.CategorySchemes, result.OldId, result.NewId);
            });
            //11-1. Category
            RenameIds(CategoryScheme.GetCategories(newStudyUnit.CategorySchemes), ids, (result) =>
            {
                CodeScheme.ChangeCategoryId(newStudyUnit.CodeSchemes, result.OldId, result.NewId);
            });
            //12. Code Scheme
            RenameIds(newStudyUnit.CodeSchemes, ids, (result) =>
            {
                CodeScheme.ChangeCodeSchemeId(newStudyUnit.CodeSchemes, result.OldId, result.NewId);
            });
            //12-1. Code
            RenameIds(CodeScheme.GetCodes(newStudyUnit.CodeSchemes), ids);
            //13. Variable Scheme
            RenameIds(newStudyUnit.VariableScheme, ids);
            //14. Variable
            RenameIds(newStudyUnit.Variables, ids, (result) =>
            {
                DataSet.ChangeVariableId(newStudyUnit.DataSets, result.OldId, result.NewId);
                Book.ChangeMetaDataId(newStudyUnit.Books, result.OldId, result.NewId);
                StatisticsInfo.ChangeVariableId(newStudyUnit.StatisticsInfos, result.OldId, result.NewId);
            });
            //15. Dataset
            RenameIds(newStudyUnit.DataSets, ids, (result) =>
            {
                DataFile.ChangeDataSetId(newStudyUnit.DataFiles, result.OldId, result.NewId);
            });
            //16. Data File
            RenameIds(newStudyUnit.DataFiles, ids);
            //17. Order of Question
            RenameIds(newStudyUnit.ControlConstructSchemes, ids);
            //17-1.Sequence
            RenameIds(ControlConstructScheme.GetSequences(newStudyUnit.ControlConstructSchemes), ids);
            //17-2.Constructs
            RenameIds(ControlConstructScheme.GetConstructs(newStudyUnit.ControlConstructSchemes), ids, (result) =>
            {
                ControlConstructScheme.ChangeControlConstructId(newStudyUnit.ControlConstructSchemes, result.OldId, result.NewId);
            });

            //Related materials
            RenameIds(newStudyUnit.Books, ids);
        }
        /// <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");
        }