Пример #1
0
        public void VerifyThatGetContainerOfTypeWorks()
        {
            var sitedir = new SiteDirectory(Guid.NewGuid(), null, null);
            var siterdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null);
            var unit    = new DerivedUnit(Guid.NewGuid(), null, null);

            sitedir.SiteReferenceDataLibrary.Add(siterdl);
            siterdl.Unit.Add(unit);

            Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(ReferenceDataLibrary)));
            Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(SiteReferenceDataLibrary)));
            Assert.AreSame(siterdl, unit.GetContainerOfType(typeof(ModelReferenceDataLibrary)));
            Assert.AreSame(sitedir, unit.GetContainerOfType(typeof(SiteDirectory)));
            Assert.IsNull(unit.GetContainerOfType(typeof(Iteration)));

            Assert.AreSame(siterdl, unit.GetContainerOfType <SiteReferenceDataLibrary>());
            Assert.AreSame(sitedir, unit.GetContainerOfType <SiteDirectory>());
            Assert.IsNull(unit.GetContainerOfType <ModelReferenceDataLibrary>());
            Assert.AreSame(siterdl, unit.GetContainerOfType <ReferenceDataLibrary>());

            var requirementsgroup1 = new RequirementsGroup(Guid.NewGuid(), null, null);
            var requirementsgroup2 = new RequirementsGroup(Guid.NewGuid(), null, null);

            requirementsgroup1.Group.Add(requirementsgroup2);

            Assert.AreSame(requirementsgroup1, requirementsgroup2.GetContainerOfType <RequirementsGroup>());
            Assert.AreSame(requirementsgroup1, requirementsgroup2.GetContainerOfType(typeof(RequirementsGroup)));
        }
Пример #2
0
        /// <summary>
        /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload
        /// </summary>
        /// <param name="requirementGroupPayload">
        /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsSpecification"/>
        /// </param>
        private async Task OnRequirementGroupDrop(RequirementsGroup requirementGroupPayload)
        {
            var context                 = TransactionContextResolver.ResolveContext(this.Thing);
            var transaction             = new ThingTransaction(context);
            var previousRequirementSpec = requirementGroupPayload.GetContainerOfType <RequirementsSpecification>();

            // Add the RequirementGroup to the RequirementsSpecification represented by this RowViewModel
            var requirementsSpecificationClone = this.Thing.Clone(false);

            requirementsSpecificationClone.Group.Add(requirementGroupPayload);
            transaction.CreateOrUpdate(requirementsSpecificationClone);

            if (previousRequirementSpec != this.Thing)
            {
                // Update the requirements that were inside any of the groups that have been dropped
                var previousRequirementSpecRow = ((RequirementsBrowserViewModel)this.ContainerViewModel).ReqSpecificationRows.Single(x => x.Thing == previousRequirementSpec);
                var droppedRequirementGroups   = requirementGroupPayload.ContainedGroup().ToList();
                droppedRequirementGroups.Add(requirementGroupPayload);
                foreach (var keyValuePair in previousRequirementSpecRow.requirementContainerGroupCache)
                {
                    if (!droppedRequirementGroups.Contains(keyValuePair.Value))
                    {
                        continue;
                    }

                    var requirementClone = keyValuePair.Key.Clone(false);
                    requirementClone.Group = null;
                    transaction.CreateOrUpdate(requirementClone);
                }
            }

            await this.DalWrite(transaction);
        }
Пример #3
0
        /// <summary>
        /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload
        /// </summary>
        /// <param name="requirementGroupPayload">
        /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsSpecification"/>
        /// </param>
        private async Task OnRequirementGroupDrop(RequirementsGroup requirementGroupPayload)
        {
            var firstRow = this.ContainedRows.OfType <RequirementsGroupRowViewModel>().FirstOrDefault();

            if (firstRow == null)
            {
                var context                 = TransactionContextResolver.ResolveContext(this.Thing);
                var transaction             = new ThingTransaction(context);
                var previousRequirementSpec = requirementGroupPayload.GetContainerOfType <RequirementsSpecification>();

                // Add the RequirementGroup to the RequirementsSpecification represented by this RowViewModel
                var requirementsSpecificationClone = this.Thing.Clone(false);
                requirementsSpecificationClone.Group.Add(requirementGroupPayload);
                transaction.CreateOrUpdate(requirementsSpecificationClone);

                if (previousRequirementSpec != this.Thing)
                {
                    // Update the requirements that were inside any of the groups that have been dropped
                    var previousRequirementSpecRow =
                        (RequirementsSpecificationRowViewModel)((RequirementsBrowserViewModel)this.ContainerViewModel)
                        .ReqSpecificationRows.Single(x => x.Thing == previousRequirementSpec);
                    var droppedRequirementGroups = requirementGroupPayload.ContainedGroup().ToList();
                    droppedRequirementGroups.Add(requirementGroupPayload);
                    foreach (var keyValuePair in previousRequirementSpecRow.requirementContainerGroupCache)
                    {
                        if (!droppedRequirementGroups.Contains(keyValuePair.Value))
                        {
                            continue;
                        }

                        var requirementClone = keyValuePair.Key.Clone(false);
                        requirementClone.Group = null;
                        transaction.CreateOrUpdate(requirementClone);
                    }
                }

                await this.DalWrite(transaction);
            }
            else
            {
                // insert before first
                var model   = (EngineeringModel)this.Thing.TopContainer;
                var orderPt = OrderHandlerService.GetOrderParameterType(model);

                if (orderPt == null)
                {
                    return;
                }

                var orderService = new RequirementsGroupOrderHandlerService(this.Session, orderPt);
                var transaction  = orderService.Insert(requirementGroupPayload, firstRow.Thing, InsertKind.InsertBefore);
                await this.Session.Write(transaction.FinalizeTransaction());
            }
        }