Exemplo n.º 1
0
        /// <summary>
        /// Performs the drop operation for a <see cref="Requirement"/> payload
        /// </summary>
        /// <param name="requirement">
        /// The <see cref="Requirement"/> that was dropped into this <see cref="RequirementsGroup"/>
        /// </param>
        private async Task OnRequirementDrop(Requirement requirement)
        {
            var firstRow = this.ContainedRows.OfType <RequirementRowViewModel>().FirstOrDefault();

            if (firstRow == null)
            {
                await this.ChangeRequirementGroup(requirement);
            }
            else
            {
                // insert before first
                var model   = (EngineeringModel)this.Thing.TopContainer;
                var orderPt = OrderHandlerService.GetOrderParameterType(model);

                if (orderPt == null)
                {
                    await this.ChangeRequirementGroup(requirement);

                    return;
                }

                var orderService = new RequirementOrderHandlerService(this.Session, orderPt);
                var transaction  = orderService.Insert(requirement, firstRow.Thing, InsertKind.InsertBefore);
                await this.Session.Write(transaction.FinalizeTransaction());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload
        /// </summary>
        /// <param name="requirementGroup">
        /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsGroup"/>
        /// </param>
        /// <param name="dropInfo">The <see cref="IDropInfo"/></param>
        private async Task OnRequirementGroupDrop(RequirementsGroup requirementGroup, IDropInfo dropInfo)
        {
            if (dropInfo.KeyStates == (DragDropKeyStates.LeftMouseButton | DragDropKeyStates.ControlKey))
            {
                // ordered-move
                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(requirementGroup, this.Thing,
                                                       dropInfo.IsDroppedAfter ? InsertKind.InsertAfter : InsertKind.InsertBefore);
                await this.Session.Write(transaction.FinalizeTransaction());
            }
            else
            {
                var context                 = TransactionContextResolver.ResolveContext(this.Thing);
                var transaction             = new ThingTransaction(context);
                var previousRequirementSpec = requirementGroup.GetContainerOfType <RequirementsSpecification>();
                var currentRequirementSpec  = this.Thing.GetContainerOfType <RequirementsSpecification>();

                // Add this RequirementGroup to the RequirementGroup represented by this RowViewModel
                var requirementGroupClone          = requirementGroup.Clone(false);
                var containerRequirementGroupClone = this.Thing.Clone(false);
                containerRequirementGroupClone.Group.Add(requirementGroupClone);
                transaction.CreateOrUpdate(containerRequirementGroupClone);

                if (previousRequirementSpec != currentRequirementSpec)
                {
                    // Update the requirements that were inside any of the groups that have been dropped
                    var previousRequirementSpecRow =
                        (RequirementsSpecificationRowViewModel)
                        ((RequirementsBrowserViewModel)this.TopParentRow.ContainerViewModel).ReqSpecificationRows
                        .Single(x => x.Thing == previousRequirementSpec);
                    var droppedRequirementGroups = requirementGroup.ContainedGroup().ToList();
                    droppedRequirementGroups.Add(requirementGroup);
                    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);
            }
        }
Exemplo n.º 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());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a requirement rows
        /// </summary>
        /// <param name="req">The <see cref="Requirement"/> to add</param>
        private void AddRequirementRow(Requirement req)
        {
            var row = new RequirementRowViewModel(req, this.Session, this);

            this.requirementCache[req] = row;
            this.requirementContainerGroupCache[req] = req.Group;

            if (req.Group == null)
            {
                this.ContainedRows.SortedInsert(row, ChildRowComparer);
            }
            else
            {
                IRowViewModelBase <Thing> groupRow;
                if (this.GroupCache.TryGetValue(req.Group, out groupRow))
                {
                    groupRow.ContainedRows.SortedInsert(row, ChildRowComparer);
                }
                else
                {
                    logger.Error("The requirement group with iid {0} could not be found", req.Group.Iid);
                    this.ContainedRows.SortedInsert(row, ChildRowComparer);
                }
            }

            var updateListener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(req)
                                 .Where(objectChange => objectChange.EventKind == EventKind.Updated &&
                                        objectChange.ChangedThing.RevisionNumber > this.RevisionNumber)
                                 .ObserveOn(RxApp.MainThreadScheduler)
                                 .Subscribe(x => this.UpdateRequirementRow((Requirement)x.ChangedThing, false));

            var orderPt = OrderHandlerService.GetOrderParameterType((EngineeringModel)this.Thing.TopContainer);

            if (orderPt != null)
            {
                var orderListener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(typeof(SimpleParameterValue))
                                    .Where(objectChange =>
                                           ((SimpleParameterValue)objectChange.ChangedThing).ParameterType == orderPt &&
                                           this.Thing.Requirement.Any(r => r.ParameterValue.Contains(objectChange.ChangedThing)))
                                    .ObserveOn(RxApp.MainThreadScheduler)
                                    .Subscribe(x => this.UpdateRequirementRow((Requirement)x.ChangedThing.Container, true));

                this.Disposables.Add(orderListener);
            }

            this.Disposables.Add(updateListener);
            this.listenerCache[req] = updateListener;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Performs the drop operation for a <see cref="RequirementsGroup"/> payload
        /// </summary>
        /// <param name="reqSpecPayload">
        /// The <see cref="RequirementsGroup"/> that was dropped into this <see cref="RequirementsSpecification"/>
        /// </param>
        /// <param name="dropinfo">The <see cref="IDropInfo"/></param>
        private async Task OnRequirementSpecificationDrop(RequirementsSpecification reqSpecPayload, IDropInfo dropinfo)
        {
            var model   = (EngineeringModel)this.Thing.TopContainer;
            var orderPt = OrderHandlerService.GetOrderParameterType(model);

            if (orderPt == null)
            {
                return;
            }

            var orderService = new RequirementsSpecificationOrderHandlerService(this.Session, orderPt);
            var transaction  = orderService.Insert(reqSpecPayload, this.Thing,
                                                   dropinfo.IsDroppedAfter ? InsertKind.InsertAfter : InsertKind.InsertBefore);

            await this.Session.Write(transaction.FinalizeTransaction());
        }