コード例 #1
0
        public override void Runner(string[] parts, IEnumerable <IVersionable> ws)
        {
            string qref = parts[parts.Length - 2].Trim();
            string tref = parts[parts.Length - 1].Trim();

            if (tref == "0")
            {
                return;
            }

            var scopedWS = ws;

            if (parts.Length > 2)
            {
                var gthr = new ItemGathererVisitor();
                var ccs  = scopedWS.OfType <ControlConstructScheme>().FirstOrDefault(x => x.ItemName.Best == parts[0].Trim());
                if (ccs != default(ControlConstructScheme))
                {
                    ccs.Accept(gthr);
                    scopedWS = gthr.FoundItems;
                }
            }

            var question = scopedWS.OfType <QuestionActivity>().FirstOrDefault(x => x.ItemName.Best == qref);

            if (question != default(QuestionActivity))
            {
                var ccg = ccs.ControlConstructGroups.FirstOrDefault(x => x.ItemName.Best == tref);
                if (ccg != default(ControlConstructGroup))
                {
                    var in_group = ccg.GetChildren().OfType <QuestionActivity>().Any(x => x.ItemName.Best == question.ItemName.Best);
                    if (!in_group)
                    {
                        var old_ccgs = new List <ControlConstructGroup>();
                        for (var j = 0; j < ccs.ControlConstructGroups.Count; j++)
                        {
                            var children = ccs.ControlConstructGroups[j].ItemsList;
                            for (var i = 0; i < children.Count; i++)
                            {
                                if (children[i] is QuestionActivity)
                                {
                                    if (((DescribableBase)children[i]).ItemName.Best == question.ItemName.Best)
                                    {
                                        old_ccgs.Add(ccs.ControlConstructGroups[j]);
                                    }
                                }
                            }
                        }
                        for (var i = 0; i < old_ccgs.Count; i++)
                        {
                            var to_be_removed = old_ccgs[i].GetChildren().OfType <QuestionActivity>().FirstOrDefault(x => x.ItemName.Best == question.ItemName.Best);
                            old_ccgs[i].RemoveChild(to_be_removed);
                        }
                        ccg.AddChild(question);
                    }
                }
            }
        }
コード例 #2
0
        protected Collection <IVersionable> getAllItems()
        {
            Ddi32Deserializer   deserializer = new Ddi32Deserializer();
            HarmonizationResult harmonized   = deserializer.HarmonizeIdentifiers(this.doc, DdiFileFormat.Ddi32);

            DdiInstance instance = deserializer.GetDdiInstance(this.doc.Root);

            var gatherer = new ItemGathererVisitor();

            instance.Accept(gatherer);
            return(gatherer.FoundItems);
        }
コード例 #3
0
        public void Execute()
        {
            // Use the SpssImporter to get a ResourcePackage with all metadata
            // contained in the SPSS file.
            var spssImporter = new SpssImporter();
            var resourcePackage = spssImporter.Import(fileName, "uk.cls");

            // Get a list of all items contained in the ResourcePackage.
            var gatherer = new ItemGathererVisitor();
            resourcePackage.Accept(gatherer);
            var allItems = gatherer.FoundItems;

            // Add the items to the repository.
            WorkingSet.AddRange(allItems);
        }
コード例 #4
0
ファイル: VariableMapper.cs プロジェクト: Colectica/curation
        static void CreateCodeList(Variable variable, PhysicalInstance physicalInstance, DataRelationship dataRelationship, VariableStatistic variableStatistic)
        {
            // Create and save a code list with all the unique values.
            var codeList = CreateCodeList(physicalInstance, dataRelationship, variable, variableStatistic);

            variable.CodeRepresentation.Codes = codeList;

            if (codeList != null)
            {
                var gatherer = new ItemGathererVisitor();
                codeList.Accept(gatherer);

                var client      = RepositoryHelper.GetClient();
                var repoOptions = new CommitOptions();
                repoOptions.NamedOptions.Add("RegisterOrReplace");
                client.RegisterItems(gatherer.FoundItems, repoOptions);
            }
        }
コード例 #5
0
        public void Execute()
        {
            // Use the SpssImporter to get a ResourcePackage with all metadata
            // contained in the SPSS file.
            var spssImporter    = new SpssImporter();
            var resourcePackage = spssImporter.Import(fileName, "uk.cls");


            // Get a list of all items contained in the ResourcePackage.
            var gatherer = new ItemGathererVisitor();

            resourcePackage.Accept(gatherer);
            var allItems = gatherer.FoundItems;


            // Add the items to the repository.
            WorkingSet.AddRange(allItems);
        }
コード例 #6
0
        public static IEnumerable <IVersionable> FinishedAllBuilds(bool clear_vs_reference = true)
        {
            if (vs == default(VariableScheme))
            {
                return(new List <IVersionable>());
            }
            else
            {
                var gthr = new ItemGathererVisitor();
                gthr.TypesToFind.Add(DdiItemType.VariableScheme);
                gthr.TypesToFind.Add(DdiItemType.VariableGroup);
                vs.Accept(gthr);

                var foundItems = gthr.FoundItems;

                if (clear_vs_reference)
                {
                    vs = default(VariableScheme);
                }

                return(foundItems);
            }
        }
コード例 #7
0
        public void BuildAndRegisterConcepts()
        {
            // Setting the default agency like this means
            // we don't need to manually set it for every
            // item we create.
            VersionableBase.DefaultAgencyId = "int.example";

            // Create a scheme to hold the concepts.
            ConceptScheme scheme = new ConceptScheme();

            scheme.Label.Current = "Transportation Modes";

            // Create 6 concepts, setting up a small hierarchy.
            Concept transportMode = new Concept();

            transportMode.Label.Current = "Transport Mode";

            Concept auto = new Concept();

            auto.SubclassOf.Add(transportMode);
            auto.Label.Current = "Auto";

            Concept car = new Concept();

            car.SubclassOf.Add(auto);
            car.Label.Current = "Car";

            Concept truck = new Concept();

            truck.SubclassOf.Add(auto);
            truck.Label.Current = "Truck";

            Concept bike = new Concept();

            bike.SubclassOf.Add(transportMode);
            bike.Label.Current = "Bike";

            Concept walk = new Concept();

            walk.SubclassOf.Add(transportMode);
            walk.Label.Current = "Walk";

            // Add the concpts to the scheme.
            scheme.Concepts.Add(transportMode);
            scheme.Concepts.Add(auto);
            scheme.Concepts.Add(car);
            scheme.Concepts.Add(truck);
            scheme.Concepts.Add(bike);
            scheme.Concepts.Add(walk);

            var           client  = GetClient();
            CommitOptions options = new CommitOptions();

            // Gather all the scheme and all the items in the scheme,
            // so we can register them with a single call to the repository.
            ItemGathererVisitor gatherer = new ItemGathererVisitor();

            scheme.Accept(gatherer);

            // Register the items with the repository.
            client.RegisterItems(gatherer.FoundItems, options);

            // Alternatively, we could register the items one at a time, like this.

            //client.RegisterItem(scheme, options);
            //client.RegisterItem(transportMode, options);
            //client.RegisterItem(auto, options);
            //client.RegisterItem(car, options);
            //client.RegisterItem(truck, options);
            //client.RegisterItem(bike, options);
            //client.RegisterItem(walk, options);
        }
コード例 #8
0
        public int Compare(IVersionable A, IVersionable B)
        {
            var gathererA = new ItemGathererVisitor();
            var gathererB = new ItemGathererVisitor();

            A.Accept(gathererA);
            B.Accept(gathererB);

            var childrenA = gathererA.FoundItems.Where(x => x.UserIds.Count > 0).ToCollection();
            var childrenB = gathererB.FoundItems.Where(x => x.UserIds.Count > 0).ToCollection();

            int compared = 0;

            foreach (var childA in childrenA)
            {
                compared++;

                var childB = childrenB.FirstOrDefault(x => x.UserIds[0].Identifier == childA.UserIds[0].Identifier);
                if (childB != default(IVersionable))
                {
                    var amendmended = false;
                    if (childB.ItemType == DdiItemType.Loop)
                    {
                        bool stop = true;
                    }
                    amendmended |= Compare <DescribableBase>(
                        new[] { "Label", "ItemName", "Description" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <QuestionActivity>(
                        new[] { "ResponseUnit", "Question", "QuestionGrid" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <CustomLoopActivity>(
                        new[] { "Condition", "InitialValue" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <CustomIfElseActivity>(
                        new[] { "Branches" },
                        childA,
                        childB
                        );
                    var question_properties = new[] { "EstimatedTime", "QuestionIntent", "QuestionText", "ResponseDomains" };
                    amendmended |= Compare <Question>(
                        question_properties,
                        childA,
                        childB
                        );
                    var qgrid_properties = new[] { "Dimensions" };
                    amendmended |= Compare <QuestionGrid>(
                        question_properties.Concat(qgrid_properties).ToArray(),
                        childA,
                        childB
                        );
                    amendmended |= Compare <InterviewerInstruction>(
                        new[] { "Instructions" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <StatementActivity>(
                        new[] { "EstimatedTime", "StatementText" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <CodeList>(
                        new[] { "Codes" },
                        childA,
                        childB
                        );
                    amendmended |= Compare <Variable>(
                        new[] { "SourceQuestions", "SourceQuestionGrids", "SourceVariables" },
                        childA,
                        childB
                        );

                    if (childA is CustomSequenceActivity)
                    {
                        var seqA = (CustomSequenceActivity)childA;
                        var seqB = (CustomSequenceActivity)childB;

                        var ccsA = seqA.GetChildren();
                        var ccsB = seqB.GetChildren();

                        var reorderControlConstructs = false;

                        if (ccsA.Count != ccsB.Count)
                        {
                            reorderControlConstructs = true;
                        }
                        else
                        {
                            for (var i = 0; i < ccsA.Count; i++)
                            {
                                if (ccsA[i].UserIds[0].Identifier != ccsB[i].UserIds[0].Identifier)
                                {
                                    reorderControlConstructs = true;
                                    break;
                                }
                            }
                        }
                        if (reorderControlConstructs)
                        {
                            foreach (var cc in ccsA)
                            {
                                seqA.RemoveChild(cc.CompositeId);
                            }
                            for (var i = 0; i < ccsB.Count; i++)
                            {
                                var          tmp   = repoSet.Where(x => x.UserIds.Count > 0).ToList();
                                IVersionable found = tmp.FirstOrDefault(x => x.UserIds[0].Identifier == ccsB[i].UserIds[0].Identifier);
                                seqA.AddChild(found);
                            }
                            childA.IsDirty = true;
                            amendmended    = true;
                        }
                    }

                    if (amendmended)
                    {
                        amendments.Add(childA);
                    }
                }
            }
            return(compared);
        }
コード例 #9
0
        public void BuildAndRegisterConcepts()
        {
            // Setting the default agency like this means
            // we don't need to manually set it for every
            // item we create.
            VersionableBase.DefaultAgencyId = "int.example";

            // Create a scheme to hold the concepts.
            ConceptScheme scheme = new ConceptScheme();
            scheme.Label.Current = "Transportation Modes";

            // Create 6 concepts, setting up a small hierarchy.
            Concept transportMode = new Concept();
            transportMode.Label.Current = "Transport Mode";

            Concept auto = new Concept();
            auto.SubclassOf.Add(transportMode);
            auto.Label.Current = "Auto";

            Concept car = new Concept();
            car.SubclassOf.Add(auto);
            car.Label.Current = "Car";

            Concept truck = new Concept();
            truck.SubclassOf.Add(auto);
            truck.Label.Current = "Truck";

            Concept bike = new Concept();
            bike.SubclassOf.Add(transportMode);
            bike.Label.Current = "Bike";

            Concept walk = new Concept();
            walk.SubclassOf.Add(transportMode);
            walk.Label.Current = "Walk";

            // Add the concpts to the scheme.
            scheme.Concepts.Add(transportMode);
            scheme.Concepts.Add(auto);
            scheme.Concepts.Add(car);
            scheme.Concepts.Add(truck);
            scheme.Concepts.Add(bike);
            scheme.Concepts.Add(walk);

            var client = GetClient();
            CommitOptions options = new CommitOptions();

            // Gather all the scheme and all the items in the scheme,
            // so we can register them with a single call to the repository.
            ItemGathererVisitor gatherer = new ItemGathererVisitor();
            scheme.Accept(gatherer);

            // Register the items with the repository.
            client.RegisterItems(gatherer.FoundItems, options);

            // Alternatively, we could register the items one at a time, like this.

            //client.RegisterItem(scheme, options);
            //client.RegisterItem(transportMode, options);
            //client.RegisterItem(auto, options);
            //client.RegisterItem(car, options);
            //client.RegisterItem(truck, options);
            //client.RegisterItem(bike, options);
            //client.RegisterItem(walk, options);
        }
コード例 #10
0
        public void Execute()
        {
            // Load the DDI 3.2 toplevel file.
            if (!System.IO.File.Exists(fileName))
            {
                Trace.WriteLine("   missing file: " + fileName);
               return;
            }
            var validator = new DdiValidator(fileName, DdiFileFormat.Ddi32);
            bool isValid = validator.Validate();

            var doc = validator.ValidatedXDocument;

            var deserializer = new Ddi32Deserializer();
            var harmonized = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32);

            var instance = deserializer.GetDdiInstance(doc.Root);

            // Get a list of all items contained in the DdiInstance.
            var gatherer = new ItemGathererVisitor();
            instance.Accept(gatherer);
            var allItems = gatherer.FoundItems;

            //mesh in the instrument references
            //nb: ItemName seems to be the empty string rather than null if it does not exist in the ddi file
            var dataCollections = allItems.OfType<DataCollection>().Where(x => string.Compare(x.ItemName.Best, "") != 0);
            foreach (var dc in dataCollections)
            {
                var instrumentName = dc.ItemName.Best + "-in-000001";
                var instruments = WorkingSet.OfType<Instrument>().Where(x => string.Compare(x.UserIds[0].Identifier, instrumentName, ignoreCase: true) == 0);
                var ic = instruments.Count();
                if (ic == 1)
                    dc.AddChild(instruments.First());
                else if (ic > 1)
                   Trace.WriteLine("   more than one instrument found for " + instrumentName);
                else
                {
                    Trace.WriteLine("   no instrument found for " + instrumentName);
                    //to do: try repo
                    //var client = Utility.GetClient();
                    //var facet = new SearchFacet();
                    //facet.ItemTypes.Add(DdiItemType.Instrument);
                    //SearchResponse response = client.Search(facet);
                    //if (response.ReturnedResults > 1)
                    //{
                    //    var repoInstruments = client.GetItems(response.Results);
                    //}
                }
            }

            //mesh in variable set references
            //I assume that there may be more than one corresponding dataset (i.e. its log prod, phys prod...) with same base name but with a hyphenated suffix
            //get all the study units (from toplevel, assumed) and go through all its data collections
            //find the logical products with a base name matching the data collection name and attach them to the study unit
            //find physical data product and do the same, -I assume sdk physical product is ddi physical data product?-
            //find physicalInstance with base alternate title matching data collection name and attach them to the study unit
            var studyUnits = allItems.OfType<StudyUnit>();
            foreach (var su in studyUnits)
            {
                foreach (var dc in su.DataCollections.Where(x => string.Compare(x.ItemName.Best, "") != 0))
                {
                    var dcName =  dc.ItemName.Best;

                    var matchingLogicalProducts = WorkingSet.OfType<LogicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var lpc = matchingLogicalProducts.Count();
                    //if (lpc == 1)
                    //    su.AddChild(matchingLogicalProducts.First());
                    //else if (lpc > 1)
                    //    Trace.WriteLine("   more than one logical product found for " + dcName);
                    if (lpc > 0)
                        foreach (var lp in matchingLogicalProducts)
                            su.AddChild(lp);
                    else
                        Trace.WriteLine("   no logical product found for " + dcName);

                    var matchingPhysicalProducts = WorkingSet.OfType<PhysicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var pdpc = matchingPhysicalProducts.Count();
                    //if (pdpc == 1)
                    //    su.AddChild(matchingPhysicalProducts.First());
                    //else if (pdpc > 1)
                    //    Trace.WriteLine("   more than one physical data product found for " + dcName);
                    if (pdpc > 0)
                        foreach (var pp in matchingPhysicalProducts)
                            su.AddChild(pp);
                    else
                        Trace.WriteLine("   no physical data product found for " + dcName);

                    var matchingPhysicalInstances = WorkingSet.OfType<PhysicalInstance>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var pic = matchingPhysicalInstances.Count();
                    //if (pic == 1)
                    //    su.AddChild(matchingPhysicalInstances.First());
                    //else if (pic > 1)
                    //    Trace.WriteLine("   more than one physical instance found for " + dcName);
                    if (pic > 0)
                        foreach (var pi in matchingPhysicalInstances)
                            su.AddChild(pi);
                    else
                        Trace.WriteLine("   no physical instance found for " + dcName);

                    var matchingResourcePackages = WorkingSet.OfType<ResourcePackage>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var rpc = matchingResourcePackages.Count();
                    //if (rpc == 1)
                    //    su.AddChild(matchingResourcePackages.First());
                    //else if (rpc > 1)
                    //    Trace.WriteLine("   more than one resource package found for " + dcName);
                    if (rpc > 0)
                        foreach (var rp in matchingResourcePackages)
                            su.AddChild(rp);
                    else
                        Trace.WriteLine("   no resource package found for " + dcName);
                }
            }

            // Add the items to the working set.
            WorkingSet.AddRange(allItems);
        }
コード例 #11
0
        public void RunGlobalActions(bool prepare = false)
        {
            bool prepared = false;
            if (prepare)
            {
                prepared = Prepare();
            }
            if (prepare == prepared)
            {
                foreach (var action in actions)
                {
                    try 
                    {
                        action.Validate();
                        workingSet.AddRange(action.Build(workingSet));
                    }
                    catch (Exception e)
                    {
                        console.WriteLine("{0}", e.Message);
                        continue;
                    }
                }
                var client = Utility.GetClient();
                var facet = new SearchFacet();
                facet.ItemTypes.Add(DdiItemType.DdiInstance);
                facet.SearchTargets.Add(DdiStringType.Name);

                //Compare
                var repoItems = new List<IVersionable>();
                var wsIs = workingSet.OfType<DdiInstance>();
                var countint = wsIs.Count();

                foreach (var wsI in wsIs)
                {
                    facet.SearchTerms.Clear();
                    facet.SearchTerms.Add(wsI.ItemName.Best);
                    var response = client.Search(facet);
                    foreach (var res in response.Results)
                    {
                        var rp = client.GetItem(
                        res.CompositeId,
                        ChildReferenceProcessing.PopulateLatest) as DdiInstance;
                        var graphPopulator = new GraphPopulator(client)
                        {
                            ChildProcessing = ChildReferenceProcessing.PopulateLatest
                        };
                        rp.Accept(graphPopulator);
                        var gatherer = new ItemGathererVisitor();
                        rp.Accept(gatherer);
                        repoItems.AddRange(gatherer.FoundItems);
                    }
                }
                toBeAdded = workingSet;
                var toBeRemoved = new List<IVersionable>();
                foreach (var repoItem in repoItems)
                {
                    if (repoItem.UserIds.Count == 0) continue;
                    var wsItem = workingSet.Find(x => (x.UserIds.Count > 0 ? x.UserIds[0].ToString() : "") == repoItem.UserIds[0].ToString());
                    if (wsItem != default(IVersionable))
                    {
                        if (toBeAdded.IndexOf(wsItem) != -1)
                        {
                            toBeAdded.Remove(wsItem);
                        }
                        else
                        {
                            var node = toBeAdded.Where(
                                item => item.UserIds.Count > 0
                            ).FirstOrDefault(
                                item => item.UserIds[0] == wsItem.UserIds[0]
                            );
                            if (node != default(IVersionable))
                            {
                                toBeAdded.Remove(node);
                            }
                        }
                    }
                    else
                    {
                        toBeRemoved.Add(repoItem);
                    }
                }

                console.WriteLine("Global: Commiting {0} items...", workingSet.Count);
                client.RegisterItems(workingSet, new CommitOptions());
            }
            else
            {
                console.WriteLine("Failed to prepare build.");
            }
            console.Publish();
        }
コード例 #12
0
ファイル: LoadDdiFile.cs プロジェクト: claude-uk/loader
        public void Execute()
        {
            // Load the DDI 3.2 file.
            if (!System.IO.File.Exists(fileName))
            {
                //throw new System.Exception("...Missing file: " + fileName);
                Trace.WriteLine("   missing file: " + fileName);
               return;
            }
            var validator = new DdiValidator(fileName, DdiFileFormat.Ddi32);
            bool isValid = validator.Validate();

            var doc = validator.ValidatedXDocument;

            var deserializer = new Ddi32Deserializer();
            var harmonized = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32);

            var instance = deserializer.GetDdiInstance(doc.Root);

            // Get a list of all items contained in the DdiInstance.
            var gatherer = new ItemGathererVisitor();
            instance.Accept(gatherer);
            var allItems = gatherer.FoundItems;

            //test if there is a caddies-style question scheme (non-grid)
            //in which case add parameters
            var questionSchemes = allItems.OfType<QuestionScheme>().Where(x => string.Compare(x.ItemName.Best.Substring(x.ItemName.Best.Length - 5, 5), "_qs01") == 0);
            if (questionSchemes.Count() != 0)
            {
                var questionItems = questionSchemes.First().Questions;
                foreach (var qi in questionItems)
                {
                    var p = new Parameter();
                    p.ParameterType = InstrumentParameterType.Out;
                    p.Name.Add("en-GB", "p_" + qi.ItemName.Best);
                    qi.OutParameters.Add(p);
                }

                //I assume that there are the corresponding caddies question constructs
                //add an InParameter based on the first (the only) OutParameter of its QuestionItem,
                //an OutputParameter based on the construct name
                //and a binding between the two
                var questionConstructs = allItems.OfType<QuestionActivity>();
                foreach (var qc in questionConstructs)
                {
                    if (qc.Question != null)
                    {
                        var p = new Parameter();
                        p.ParameterType = InstrumentParameterType.In;
                        p.Name.Add("en-GB", qc.Question.OutParameters.First().Name.Best);
                        qc.InParameters.Add(p);
                        var p2 = new Parameter();
                        p2.ParameterType = InstrumentParameterType.Out;
                        p2.Name.Add("en-GB", "p_" + qc.ItemName.Best);
                        qc.OutParameters.Add(p2);
                        var b = new Binding();
                        //b.SourceParameter = p;
                        //b.TargetParameter = p2;
                        //qc.Bindings.Add(b);
                    }
                    else if (qc.QuestionGrid != null)
                    {
                        continue;
                    }
                    else
                    {
                        Trace.WriteLine("   question construct with no source");
                    }
                }
            }
            // Add the items to the working set.
            WorkingSet.AddRange(allItems);
        }
コード例 #13
0
        public override void Runner(string[] parts, IEnumerable <IVersionable> ws)
        {
            IEnumerable <IVersionable> subFocusedWS = ws;
            string questionName, variableName;

            int    qindex = (parts.Length / 2) - 1;
            int    vindex = parts.Length - 1;
            string questionColumn = parts[qindex].Trim();

            string[] questionNameParts = questionColumn.Split(new char[] { '$' });     //remove grid cell info
            questionName = questionNameParts[0];
            variableName = parts[vindex].Trim();

            if (questionName == "0" || variableName == "0")
            {
                return;
            }

            if (parts.Length == 4)
            {
                var foundCcs = ws.OfType <ControlConstructScheme>().Where(x => x.ItemName.Best == parts[0].Trim());
                if (foundCcs.Count() == 0)
                {
                    Console.WriteLine("Invalid question scheme: {0}", parts[0]);
                    counter[Counters.Skipped] += 1;
                    return;
                }

                var foundVs = ws.OfType <VariableScheme>().Where(x => x.ItemName.Best == parts[2].Trim());
                if (foundVs.Count() == 0)
                {
                    Console.WriteLine("Invalid variable scheme: {0}", parts[2]);
                    counter[Counters.Skipped] += 1;
                    return;
                }

                var gatherer = new ItemGathererVisitor();
                foreach (var foundCc in foundCcs)
                {
                    foundCc.Accept(gatherer);
                }
                foreach (var foundV in foundVs)
                {
                    foundV.Accept(gatherer);
                }

                subFocusedWS = gatherer.FoundItems;
            }

            var qs = subFocusedWS.OfType <QuestionActivity>().Where(x => x.ItemName.Best == questionName);
            var vs = subFocusedWS.OfType <Variable>().Where(x => x.ItemName.Best == variableName);

            if (qs.Count() > 0 && vs.Count() > 0)
            {
                if (qs.First().Question != null)
                {
                    vs.First().SourceQuestions.Add(qs.First().Question);
                }
                if (qs.First().QuestionGrid != null)
                {
                    vs.First().SourceQuestionGrids.Add(qs.First().QuestionGrid);
                }
            }
        }
コード例 #14
0
ファイル: LoadDdiFile.cs プロジェクト: claude-uk/loader
        public void Execute()
        {
            // Load the DDI 3.2 file.
            if (!System.IO.File.Exists(fileName))
            {
                //throw new System.Exception("...Missing file: " + fileName);
                Trace.WriteLine("   missing file: " + fileName);
                return;
            }
            var  validator = new DdiValidator(fileName, DdiFileFormat.Ddi32);
            bool isValid   = validator.Validate();

            var doc = validator.ValidatedXDocument;

            var deserializer = new Ddi32Deserializer();
            var harmonized   = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32);

            var instance = deserializer.GetDdiInstance(doc.Root);


            // Get a list of all items contained in the DdiInstance.
            var gatherer = new ItemGathererVisitor();

            instance.Accept(gatherer);
            var allItems = gatherer.FoundItems;


            //test if there is a caddies-style question scheme (non-grid)
            //in which case add parameters
            var questionSchemes = allItems.OfType <QuestionScheme>().Where(x => string.Compare(x.ItemName.Best.Substring(x.ItemName.Best.Length - 5, 5), "_qs01") == 0);

            if (questionSchemes.Count() != 0)
            {
                var questionItems = questionSchemes.First().Questions;
                foreach (var qi in questionItems)
                {
                    var p = new Parameter();
                    p.ParameterType = InstrumentParameterType.Out;
                    p.Name.Add("en-GB", "p_" + qi.ItemName.Best);
                    qi.OutParameters.Add(p);
                }

                //I assume that there are the corresponding caddies question constructs
                //add an InParameter based on the first (the only) OutParameter of its QuestionItem,
                //an OutputParameter based on the construct name
                //and a binding between the two
                var questionConstructs = allItems.OfType <QuestionActivity>();
                foreach (var qc in questionConstructs)
                {
                    if (qc.Question != null)
                    {
                        var p = new Parameter();
                        p.ParameterType = InstrumentParameterType.In;
                        p.Name.Add("en-GB", qc.Question.OutParameters.First().Name.Best);
                        qc.InParameters.Add(p);
                        var p2 = new Parameter();
                        p2.ParameterType = InstrumentParameterType.Out;
                        p2.Name.Add("en-GB", "p_" + qc.ItemName.Best);
                        qc.OutParameters.Add(p2);
                        var b = new Binding();
                        //b.SourceParameter = p;
                        //b.TargetParameter = p2;
                        //qc.Bindings.Add(b);
                    }
                    else if (qc.QuestionGrid != null)
                    {
                        continue;
                    }
                    else
                    {
                        Trace.WriteLine("   question construct with no source");
                    }
                }
            }
            // Add the items to the working set.
            WorkingSet.AddRange(allItems);
        }
コード例 #15
0
        public void CompareWithRepository()
        {
            var client = Utility.GetClient();

            var facet = new SearchFacet()
            {
                SearchLatestVersion = true
            };

            facet.ItemTypes.Add(DdiItemType.StudyUnit);
            var response = client.Search(facet);

            foreach (var result in response.Results)
            {
                var su = client.GetItem(
                    result.CompositeId,
                    ChildReferenceProcessing.PopulateLatest) as StudyUnit;
                foreach (var dc in su.DataCollections)
                {
                    try
                    {
                        var scope = scopes[dc.ItemName.Best];
                        scope.su = su;
                        scope.rp = su.ResourcePackages.Where(x => x.ItemName.Best == dc.ItemName.Best).FirstOrDefault();
                    } catch (KeyNotFoundException)
                    {
                    }
                }
            }

            foreach (var scope in scopes)
            {
                if (scope.Value.rp != default(ResourcePackage))
                {
                    continue;
                }

                var wsRps = workingSet.OfType <ResourcePackage>().Where(x => string.Compare(
                                                                            x.DublinCoreMetadata.Title.Best, scope.Value.name
                                                                            ) == 0
                                                                        );
                if (wsRps.Any())
                {
                    scope.Value.rp = wsRps.First();
                    var bubbleOut = false;
                    foreach (var g in workingSet.OfType <Algenta.Colectica.Model.Ddi.Group>())
                    {
                        foreach (var su in g.StudyUnits)
                        {
                            if (su.DataCollections.Count(x => x.ItemName.Best == scope.Key) > 0)
                            {
                                scope.Value.su = su;
                                var gatherer = new ItemGathererVisitor();
                                g.Accept(gatherer);
                                toBeAdded.AddRange(gatherer.FoundItems);
                                bubbleOut = true;
                            }
                            if (bubbleOut)
                            {
                                break;
                            }
                        }
                        if (bubbleOut)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    var rp = new ResourcePackage();
                    rp.DublinCoreMetadata.Title["en-GB"] = scope.Key;
                    scope.Value.su.AddChild(rp);
                    toBeAdded.Add(scope.Value.su);
                    rp.AddChild(scope.Value.su.DataCollections.First(x => x.ItemName.Best == scope.Key));
                    scope.Value.rp = rp;
                }
            }

            var ccgs = workingSet.OfType <ControlConstructGroup>();

            if (ccgs.Count() > 1)
            {
                facet.ItemTypes.Clear();
                facet.SearchTargets.Clear();
                facet.ItemTypes.Add(DdiItemType.QuestionConstruct);
                facet.SearchTargets.Add(DdiStringType.UserId);
                foreach (var ccg in ccgs)
                {
                    var qcs = ccg.GetChildren().OfType <QuestionActivity>().ToList();
                    foreach (var qc in ccg.GetChildren().OfType <QuestionActivity>())
                    {
                        facet.SearchTerms.Clear();
                        facet.SearchTerms.Add(qc.UserIds.First().Identifier);

                        response = client.Search(facet);
                        if (response.Results.Count > 1)
                        {
                            Console.WriteLine("{0} question constrcuts found during CCG syncing for the question '{1}'", response.Results.Count, qc.UserIds.First().Identifier);
                        }
                        else if (response.Results.Count < 1)
                        {
                            Console.WriteLine("No question constructs were found for the CCG syncing matching '{0}'", qc.UserIds.First().Identifier);
                        }
                        else
                        {
                            var remote_qc = client.GetItem(response.Results.First().CompositeId) as IVersionable;
                            if (remote_qc != default(IVersionable))
                            {
                                ccg.ReplaceChild(qc.CompositeId, remote_qc);
                            }
                        }
                    }
                }
            }

            var vgs = workingSet.OfType <VariableGroup>();

            if (vgs.Count() > 0)
            {
                facet.ItemTypes.Clear();
                facet.ItemTypes.Add(DdiItemType.Variable);
                foreach (var vg in vgs)
                {
                    foreach (var variable in vg.GetChildren().OfType <Variable>())
                    {
                        facet.SearchTerms.Clear();
                        facet.SearchTargets.Clear();
                        bool closer_id_found = false;
                        foreach (var user_id in variable.UserIds)
                        {
                            if (user_id.Type == "closer:id")
                            {
                                closer_id_found = true;
                                facet.SearchTerms.Add(user_id.Identifier);
                                facet.SearchTargets.Add(DdiStringType.UserId);
                                break;
                            }
                        }
                        if (!closer_id_found)
                        {
                            facet.SearchTerms.Add(variable.ItemName.Best);
                            facet.SearchTargets.Add(DdiStringType.Name);
                        }
                        response = client.Search(facet);
                        if (response.Results.Count > 1)
                        {
                            Console.WriteLine("{0} variables found during variable group syncing for the variable '{1}:{2}'", response.Results.Count, name, variable.ItemName.Best);
                        }
                        else if (response.Results.Count < 1)
                        {
                            Console.WriteLine("No variables were found for the variable grouping syncing matching '{0}:{1}'", name, variable.ItemName.Best);
                        }
                        else
                        {
                            var remote_variable = client.GetItem(response.Results.First().CompositeId) as IVersionable;
                            if (remote_variable != default(IVersionable))
                            {
                                vg.ReplaceChild(variable.CompositeId, remote_variable);
                            }
                        }
                    }
                }
            }

            var progress = new ParallelProgressMonitor(scopes.Count);

            Parallel.ForEach <KeyValuePair <string, Scope> >(scopes, scope =>
            {
                string text = String.Format("{0}: Comparing {1}", name, scope.Value.name);
                progress.StartThread(
                    Thread.CurrentThread.ManagedThreadId,
                    text
                    );
                scope.Value.Compare();
                progress.FinishThread(
                    Thread.CurrentThread.ManagedThreadId,
                    text.PadRight(40, '-') +
                    "> done." +
                    String.Format("{0} compared.", scope.Value.counter[Counters.Compared]).PadLeft(16) +
                    String.Format("{0} updated.", scope.Value.counter[Counters.Updated]).PadLeft(16) +
                    String.Format("{0} added.", scope.Value.counter[Counters.Added]).PadLeft(16) +
                    String.Format("{0} removed.", scope.Value.counter[Counters.Removed]).PadLeft(16)
                    );
            });
        }
コード例 #16
0
        public void Execute()
        {
            // Load the DDI 3.2 toplevel file.
            if (!System.IO.File.Exists(fileName))
            {
                Trace.WriteLine("   missing file: " + fileName);
                return;
            }
            var  validator = new DdiValidator(fileName, DdiFileFormat.Ddi32);
            bool isValid   = validator.Validate();

            var doc = validator.ValidatedXDocument;

            var deserializer = new Ddi32Deserializer();
            var harmonized   = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32);

            var instance = deserializer.GetDdiInstance(doc.Root);

            // Get a list of all items contained in the DdiInstance.
            var gatherer = new ItemGathererVisitor();

            instance.Accept(gatherer);
            var allItems = gatherer.FoundItems;

            //mesh in the instrument references
            //nb: ItemName seems to be the empty string rather than null if it does not exist in the ddi file
            var dataCollections = allItems.OfType <DataCollection>().Where(x => string.Compare(x.ItemName.Best, "") != 0);

            foreach (var dc in dataCollections)
            {
                var instrumentName = dc.ItemName.Best + "-in-000001";
                var instruments    = WorkingSet.OfType <Instrument>().Where(x => string.Compare(x.UserIds[0].Identifier, instrumentName, ignoreCase: true) == 0);
                var ic             = instruments.Count();
                if (ic == 1)
                {
                    dc.AddChild(instruments.First());
                }
                else if (ic > 1)
                {
                    Trace.WriteLine("   more than one instrument found for " + instrumentName);
                }
                else
                {
                    Trace.WriteLine("   no instrument found for " + instrumentName);
                    //to do: try repo
                    //var client = Utility.GetClient();
                    //var facet = new SearchFacet();
                    //facet.ItemTypes.Add(DdiItemType.Instrument);
                    //SearchResponse response = client.Search(facet);
                    //if (response.ReturnedResults > 1)
                    //{
                    //    var repoInstruments = client.GetItems(response.Results);
                    //}
                }
            }

            //mesh in variable set references
            //I assume that there may be more than one corresponding dataset (i.e. its log prod, phys prod...) with same base name but with a hyphenated suffix
            //get all the study units (from toplevel, assumed) and go through all its data collections
            //find the logical products with a base name matching the data collection name and attach them to the study unit
            //find physical data product and do the same, -I assume sdk physical product is ddi physical data product?-
            //find physicalInstance with base alternate title matching data collection name and attach them to the study unit
            var studyUnits = allItems.OfType <StudyUnit>();

            foreach (var su in studyUnits)
            {
                foreach (var dc in su.DataCollections.Where(x => string.Compare(x.ItemName.Best, "") != 0))
                {
                    var dcName = dc.ItemName.Best;

                    var matchingLogicalProducts = WorkingSet.OfType <LogicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var lpc = matchingLogicalProducts.Count();
                    //if (lpc == 1)
                    //    su.AddChild(matchingLogicalProducts.First());
                    //else if (lpc > 1)
                    //    Trace.WriteLine("   more than one logical product found for " + dcName);
                    if (lpc > 0)
                    {
                        foreach (var lp in matchingLogicalProducts)
                        {
                            su.AddChild(lp);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("   no logical product found for " + dcName);
                    }

                    var matchingPhysicalProducts = WorkingSet.OfType <PhysicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var pdpc = matchingPhysicalProducts.Count();
                    //if (pdpc == 1)
                    //    su.AddChild(matchingPhysicalProducts.First());
                    //else if (pdpc > 1)
                    //    Trace.WriteLine("   more than one physical data product found for " + dcName);
                    if (pdpc > 0)
                    {
                        foreach (var pp in matchingPhysicalProducts)
                        {
                            su.AddChild(pp);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("   no physical data product found for " + dcName);
                    }

                    var matchingPhysicalInstances = WorkingSet.OfType <PhysicalInstance>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var pic = matchingPhysicalInstances.Count();
                    //if (pic == 1)
                    //    su.AddChild(matchingPhysicalInstances.First());
                    //else if (pic > 1)
                    //    Trace.WriteLine("   more than one physical instance found for " + dcName);
                    if (pic > 0)
                    {
                        foreach (var pi in matchingPhysicalInstances)
                        {
                            su.AddChild(pi);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("   no physical instance found for " + dcName);
                    }

                    var matchingResourcePackages = WorkingSet.OfType <ResourcePackage>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0);
                    var rpc = matchingResourcePackages.Count();
                    //if (rpc == 1)
                    //    su.AddChild(matchingResourcePackages.First());
                    //else if (rpc > 1)
                    //    Trace.WriteLine("   more than one resource package found for " + dcName);
                    if (rpc > 0)
                    {
                        foreach (var rp in matchingResourcePackages)
                        {
                            su.AddChild(rp);
                        }
                    }
                    else
                    {
                        Trace.WriteLine("   no resource package found for " + dcName);
                    }
                }
            }

            // Add the items to the working set.
            WorkingSet.AddRange(allItems);
        }
コード例 #17
0
        public void Compare()
        {
            if (workingSet.Count == 0)
            {
                return;
            }

            if (rp == default(ResourcePackage))
            {
                //New resource package
                rp = new ResourcePackage
                {
                    DublinCoreMetadata =
                    {
                        Title = new MultilingualString(name, "en-GB")
                    }
                };
            }

            var client         = Utility.GetClient();
            var graphPopulator = new GraphPopulator(client)
            {
                ChildProcessing = ChildReferenceProcessing.PopulateLatest
            };

            rp.Accept(graphPopulator);
            var gatherer = new ItemGathererVisitor();

            rp.Accept(gatherer);
            var rpItems = gatherer.FoundItems.ToList();

            comparator.repoSet = rpItems;

            foreach (var item in rpItems)
            {
                item.IsDirty = false;
            }


            DataCollection dc = null;

            if (rp.DataCollections.Count == 1)
            {
                dc = rp.DataCollections.First();
            }

            var wsRPs = workingSet.OfType <ResourcePackage>();

            Guid[] dcBindings =
            {
                DdiItemType.Instrument
            };
            Guid[] suBindings =
            {
                DdiItemType.LogicalProduct,
                DdiItemType.PhysicalDataProduct,
                DdiItemType.PhysicalInstance,
            };

            var updated = false;

            foreach (var wsRP in wsRPs)
            {
                foreach (var item in wsRP.GetChildren())
                {
                    item.IsDirty = false;
                    var rpFind = rpItems.FirstOrDefault(x => x.UserIds.Count > 0 ? item.UserIds[0].Identifier == x.UserIds[0].Identifier : false);
                    if (rpFind == default(IVersionable))
                    {
                        counter[Counters.Added] += item.GetChildren().Count + 1;
                        rp.AddItem(item);
                        if (dc != null && dcBindings.Contains(item.ItemType))
                        {
                            dc.AddChild(item);
                            continue;
                        }

                        if (dc != null && item.ItemType == DdiItemType.InstrumentScheme)
                        {
                            foreach (var instrument in item.GetChildren())
                            {
                                dc.AddChild(instrument);
                            }
                        }

                        if (su != default(StudyUnit) && suBindings.Contains(item.ItemType))
                        {
                            su.AddChild(item);
                            continue;
                        }

                        item.IsDirty = true;
                        var gthr = new ItemGathererVisitor();
                        item.Accept(gthr);
                        foreach (var i in gthr.FoundItems)
                        {
                            i.IsDirty = true;
                        }
                    }
                    else
                    {
                        rpFind.IsDirty              = false;
                        updated                     = true;
                        counter[Counters.Compared] += comparator.Compare(rpFind, item);
                    }
                }
            }

            var allGthr = new ItemGathererVisitor();

            rp.Accept(allGthr);
            toBeAdded.AddRange(allGthr.FoundItems);
        }