/// <summary>
        /// Processing Test ID 001, 002, and 003
        /// Register Items with Repository
        /// </summary>
        /// <returns></returns>
        public static async Task RegisterItems(IVersionable item)
        {
            // First find all the items that should be registered.
            // The dirty item finder can collect new and changed items in a model
            var dirtyItemGatherer = new DirtyItemGatherer();

            item.Accept(dirtyItemGatherer);

            // Get an API client, windows or username
            var api = GetRepositoryApiWindows();

            // start a transaction
            var transaction = await api.CreateTransactionAsync();

            // Add all of the items to register to a transaction
            var addItemsRequest = new RepositoryTransactionAddItemsRequest();

            foreach (var itemToRegister in dirtyItemGatherer.DirtyItems)
            {
                addItemsRequest.Items.Add(VersionableToRepositoryItem(itemToRegister));
            }

            // commit the transaction, the Repository will handle the versioning
            var options = new RepositoryTransactionCommitOptions()
            {
                TransactionId   = transaction.TransactionId,
                TransactionType = RepositoryTransactionType.CommitAsLatestWithLatestChildrenAndPropagateVersions
            };
            var results = await api.CommitTransactionAsync(options);
        }
Esempio n. 2
0
        public void IncrementDityItemAndParents(IVersionable item)
        {
            Dig(item);
            var dirtyGthr = new DirtyItemGatherer();

            item.Accept(dirtyGthr);
            foreach (var dirtyItem in dirtyGthr.DirtyItems)
            {
                Increment(dirtyItem);
                var allParents = GetAllParents(dirtyItem);
                foreach (var parent in allParents)
                {
                    Increment(parent);
                }
            }
        }
        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);
        }