Example #1
0
        /// <summary>
        /// Handle the drop of a <see cref="ElementDefinition"/>
        /// </summary>
        /// <param name="dropInfo">The <see cref="IDropInfo"/> containing the payload</param>
        /// <param name="elementDefinition">The <see cref="ElementDefinition"/></param>
        private async Task Drop(IDropInfo dropInfo, ElementDefinition elementDefinition)
        {
            try
            {
                if (elementDefinition.Iid == Guid.Empty)
                {
                    logger.Debug("Copying an Element Definition that has been created as template - iid is the empty guid");
                    dropInfo.Effects = DragDropEffects.Copy;

                    var iteration = (Iteration)this.Thing.Container;
                    await ElementDefinitionService.CreateElementDefinitionFromTemplate(this.Session, iteration, elementDefinition);

                    return;
                }

                if (elementDefinition.TopContainer == this.Thing.TopContainer)
                {
                    await this.ThingCreator.CreateElementUsage(this.Thing, elementDefinition, this.currentDomain, this.Session);
                }
                else
                {
                    // copy the payload to this iteration
                    var copyCreator = new CopyCreator(this.Session, this.dialogNavigationService);
                    await copyCreator.Copy(elementDefinition, (Iteration)this.Thing.Container, dropInfo.KeyStates);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                this.ErrorMsg = ex.Message;
            }
        }
Example #2
0
        /// <summary>
        /// Performs the drop operation
        /// </summary>
        /// <param name="dropInfo">
        /// Information about the drop operation.
        /// </param>
        public async Task Drop(IDropInfo dropInfo)
        {
            var droptarget = dropInfo.TargetItem as IDropTarget;

            if (droptarget != null)
            {
                try
                {
                    this.IsBusy = true;

                    await droptarget.Drop(dropInfo);
                }
                catch (Exception ex)
                {
                    this.Feedback = ex.Message;
                }
                finally
                {
                    this.IsBusy = false;
                }

                return;
            }

            var elementDefinition = dropInfo.Payload as ElementDefinition;

            if (elementDefinition != null)
            {
                if (elementDefinition.Iid == Guid.Empty)
                {
                    logger.Debug("Copying an Element Definition that has been created as template - iid is the empty guid");

                    dropInfo.Effects = DragDropEffects.Copy;

                    try
                    {
                        this.IsBusy = true;
                        await ElementDefinitionService.CreateElementDefinitionFromTemplate(this.Session, this.Thing, elementDefinition);
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                        this.Feedback = e.Message;
                    }
                    finally
                    {
                        this.IsBusy = false;
                    }
                }
                else
                {
                    // copy the payload to this iteration
                    try
                    {
                        this.IsBusy = true;

                        var copyCreator = new CopyCreator(this.Session, this.DialogNavigationService);
                        await copyCreator.Copy(elementDefinition, this.Thing, dropInfo.KeyStates);
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                        this.Feedback = e.Message;
                    }
                    finally
                    {
                        this.IsBusy = false;
                    }
                }
            }
        }
        public void VerifyCopyElementDefWorks()
        {
            var modelSetupService = new Mock <IEngineeringModelSetupService>();
            var modelSetup        = new EngineeringModelSetup(Guid.NewGuid(), 0);

            modelSetupService.Setup(x => x.GetEngineeringModelSetup(It.IsAny <NpgsqlTransaction>(), It.IsAny <Guid>())).Returns(modelSetup);

            this.copySourceDtos = new List <Thing>();

            var boolParamTypeId = Guid.NewGuid();
            var mrdl            = new ModelReferenceDataLibrary(Guid.NewGuid(), 1);

            mrdl.ParameterType.Add(boolParamTypeId);

            var sourceIteration   = new Iteration(Guid.NewGuid(), 1);
            var sourceElementDef1 = new ElementDefinition(Guid.NewGuid(), 1);
            var sourceElementDef2 = new ElementDefinition(Guid.NewGuid(), 1);
            var sourceUsage1      = new ElementUsage(Guid.NewGuid(), 1)
            {
                ElementDefinition = sourceElementDef2.Iid
            };

            sourceElementDef1.ContainedElement.Add(sourceUsage1.Iid);
            sourceIteration.Element.Add(sourceElementDef1.Iid);
            sourceIteration.Element.Add(sourceElementDef2.Iid);

            var parameter1 = new Parameter(Guid.NewGuid(), 1)
            {
                ParameterType = boolParamTypeId
            };
            var pvs1 = new ParameterValueSet(Guid.NewGuid(), 1)
            {
                Manual      = new ValueArray <string>(new[] { "true" }),
                Computed    = new ValueArray <string>(new[] { "-" }),
                Reference   = new ValueArray <string>(new[] { "-" }),
                Published   = new ValueArray <string>(new[] { "-" }),
                ValueSwitch = ParameterSwitchKind.MANUAL
            };

            var parameter2 = new Parameter(Guid.NewGuid(), 1)
            {
                ParameterType = boolParamTypeId
            };
            var pvs2 = new ParameterValueSet(Guid.NewGuid(), 1)
            {
                Manual      = new ValueArray <string>(new[] { "true" }),
                Computed    = new ValueArray <string>(new[] { "-" }),
                Reference   = new ValueArray <string>(new[] { "-" }),
                Published   = new ValueArray <string>(new[] { "-" }),
                ValueSwitch = ParameterSwitchKind.MANUAL
            };

            parameter1.ValueSet.Add(pvs1.Iid);
            sourceElementDef1.Parameter.Add(parameter1.Iid);
            parameter2.ValueSet.Add(pvs2.Iid);
            sourceElementDef2.Parameter.Add(parameter2.Iid);

            var override2 = new ParameterOverride(Guid.NewGuid(), 1);

            override2.Parameter = parameter2.Iid;
            var ovs = new ParameterOverrideValueSet(Guid.NewGuid(), 1)
            {
                ParameterValueSet = pvs2.Iid
            };

            override2.ValueSet.Add(ovs.Iid);
            sourceUsage1.ParameterOverride.Add(override2.Iid);

            this.copySourceDtos.Add(sourceIteration);
            this.copySourceDtos.Add(sourceElementDef1);
            this.copySourceDtos.Add(sourceElementDef2);
            this.copySourceDtos.Add(sourceUsage1);
            this.copySourceDtos.Add(parameter1);
            this.copySourceDtos.Add(pvs1);
            this.copySourceDtos.Add(parameter2);
            this.copySourceDtos.Add(pvs2);
            this.copySourceDtos.Add(override2);
            this.copySourceDtos.Add(ovs);

            var targetIteration = new Iteration(Guid.NewGuid(), 1);

            this.serviceProvider.Setup(x => x.MapToReadService(It.IsAny <string>())).Returns <string>(x => new TestSourceService(this.copySourceDtos, x));
            this.serviceProvider.Setup(x => x.MapToReadService(It.Is <string>(t => t == ClassKind.ModelReferenceDataLibrary.ToString())))
            .Returns <string>(x => new TestSourceService(new List <Thing> {
                mrdl
            }, x));

            this.serviceProvider.Setup(x => x.MapToReadService(It.Is <string>(t => t == ClassKind.Iteration.ToString())))
            .Returns <string>(x => new TestSourceService(new List <Thing> {
                sourceIteration, targetIteration
            }, x));

            var customOperationSideEffectProcessor = new Mock <IOperationSideEffectProcessor>();

            customOperationSideEffectProcessor.Setup(x => x.BeforeCreate(It.IsAny <Thing>(), It.IsAny <Thing>(), It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <ISecurityContext>())).
            Returns(true);

            var paramSubscriptionService = new ParameterSubscriptionService
            {
                ParameterSubscriptionDao = new Mock <IParameterSubscriptionDao>().Object,
                PermissionService        = this.permissionService.Object,
            };

            var parameterContextProvider = new OldParameterContextProvider
            {
                ParameterValueSetService = new TestSourceService(this.copySourceDtos, ClassKind.ParameterValueSet.ToString())
            };

            var paramGroupService = new ParameterGroupService
            {
                PermissionService = this.permissionService.Object,

                TransactionManager = this.transactionManager.Object,
                ParameterGroupDao  = new Mock <IParameterGroupDao>().Object
            };

            var valueSetService = new Mock <IParameterValueSetService>();

            valueSetService.Setup(x => x.GetShallow(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <IEnumerable <Guid> >(), It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>((a, b, c, d) =>
            {
                var list = new List <ParameterValueSet>();
                foreach (var guid in c)
                {
                    var vs = new ParameterValueSet(guid, 1)
                    {
                        Manual    = new ValueArray <string>(new [] { "-" }),
                        Computed  = new ValueArray <string>(new [] { "-" }),
                        Reference = new ValueArray <string>(new [] { "-" }),
                        Published = new ValueArray <string>(new [] { "-" })
                    };

                    list.Add(vs);
                }

                return(list);
            });

            var overrideValueSetService = new Mock <IParameterOverrideValueSetService>();

            overrideValueSetService.Setup(x => x.GetShallow(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <IEnumerable <Guid> >(), It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>((a, b, c, d) =>
            {
                var list = new List <ParameterOverrideValueSet>();
                foreach (var guid in c)
                {
                    var vs = new ParameterOverrideValueSet(guid, 1)
                    {
                        Manual    = new ValueArray <string>(new[] { "-" }),
                        Computed  = new ValueArray <string>(new[] { "-" }),
                        Reference = new ValueArray <string>(new[] { "-" }),
                        Published = new ValueArray <string>(new[] { "-" })
                    };

                    list.Add(vs);
                }

                return(list);
            });

            var paramDao     = new TestParameterDao();
            var paramService = new ParameterService
            {
                PermissionService            = this.permissionService.Object,
                ParameterDao                 = paramDao,
                OperationSideEffectProcessor = customOperationSideEffectProcessor.Object,
                TransactionManager           = this.transactionManager.Object,
                OldParameterContextProvider  = parameterContextProvider,
                ParameterSubscriptionService = paramSubscriptionService,
                ParameterValueSetService     = valueSetService.Object
            };

            var paramOverrideDao = new TestParameterOverrideDao();

            var paramOverrideService = new ParameterOverrideService
            {
                PermissionService = this.permissionService.Object,

                ParameterOverrideDao             = paramOverrideDao,
                TransactionManager               = this.transactionManager.Object,
                OperationSideEffectProcessor     = customOperationSideEffectProcessor.Object,
                ParameterSubscriptionService     = paramSubscriptionService,
                ParameterOverrideValueSetService = overrideValueSetService.Object
            };

            var usageDao     = new Mock <IElementUsageDao>();
            var usageService = new ElementUsageService
            {
                PermissionService = this.permissionService.Object,

                ParameterOverrideService     = paramOverrideService,
                ElementUsageDao              = usageDao.Object,
                TransactionManager           = this.transactionManager.Object,
                OperationSideEffectProcessor = customOperationSideEffectProcessor.Object
            };

            var edDao     = new TestElementDefinitionDao();
            var edService = new ElementDefinitionService
            {
                PermissionService = this.permissionService.Object,

                ElementDefinitionDao         = edDao,
                ElementUsageService          = usageService,
                ParameterService             = paramService,
                TransactionManager           = this.transactionManager.Object,
                OperationSideEffectProcessor = customOperationSideEffectProcessor.Object,
                ParameterGroupService        = paramGroupService
            };

            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.ElementDefinition.ToString())).Returns(edService);
            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.ElementUsage.ToString())).Returns(usageService);
            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.Parameter.ToString())).Returns(paramService);
            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.ParameterOverride.ToString())).Returns(paramOverrideService);
            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.ParameterSubscription.ToString())).Returns(paramSubscriptionService);
            this.serviceProvider.Setup(x => x.MapToPersitableService(ClassKind.ParameterGroup.ToString())).Returns(paramGroupService);

            var postOperation = new CdpPostOperation();
            var copyinfo      = new CopyInfo
            {
                ActiveOwner = Guid.NewGuid(),
                Options     = new CopyInfoOptions
                {
                    CopyKind   = CopyKind.Deep,
                    KeepOwner  = true,
                    KeepValues = true
                },
                Source = new CopySource
                {
                    IterationId = sourceIteration.Iid,
                    Thing       = new CopyReference
                    {
                        Iid       = sourceElementDef1.Iid,
                        ClassKind = ClassKind.ElementDefinition
                    },
                    TopContainer = new CopyReference
                    {
                        Iid       = Guid.NewGuid(),
                        ClassKind = ClassKind.EngineeringModel
                    }
                },
                Target = new CopyTarget
                {
                    IterationId = targetIteration.Iid,
                    Container   = new CopyReference
                    {
                        Iid       = targetIteration.Iid,
                        ClassKind = ClassKind.Iteration
                    },
                    TopContainer = new CopyReference
                    {
                        Iid       = Guid.NewGuid(),
                        ClassKind = ClassKind.EngineeringModel
                    }
                }
            };

            postOperation.Copy.Add(copyinfo);

            this.serviceProvider.Setup(x => x.MapToReadService(ClassKind.EngineeringModelSetup.ToString())).Returns(modelSetupService.Object);
            this.operationProcessor.Process(postOperation, null, $"Iteration_{targetIteration.Iid.ToString().Replace("-", "_")}", null);

            Assert.AreEqual(2, edDao.WrittenThingCount);
            Assert.AreEqual(2, paramDao.WrittenThingCount);
            Assert.AreEqual(1, paramOverrideDao.WrittenThingCount);
            usageDao.Verify(x => x.Write(It.IsAny <NpgsqlTransaction>(), It.IsAny <string>(), It.IsAny <ElementUsage>(), It.IsAny <Thing>()), Times.Once);
        }