Пример #1
0
        /// <summary>
        /// Posts a predefined <see cref="Parameter"/>
        /// </summary>
        private void PostParameter()
        {
            if (this.session.OpenIterations.Count == 0)
            {
                Console.WriteLine("At first an iteration should be opened");
                return;
            }

            var iteration = this.session.OpenIterations.Keys.First();

            if (iteration != null)
            {
                var elementDefinition      = iteration.Element[0];
                var elementDefinitionClone = elementDefinition.Clone(false);
                this.session.OpenIterations.TryGetValue(iteration, out var tuple);
                var domainOfExpertise = tuple.Item1;

                var parameter = new Parameter(Guid.NewGuid(), this.session.Assembler.Cache, this.uri);
                parameter.ParameterType = this.session.Assembler.Cache.Values.Select(x => x.Value)
                                          .OfType <ParameterType>().First();
                parameter.Owner = domainOfExpertise;

                var transaction = new ThingTransaction(
                    TransactionContextResolver.ResolveContext(elementDefinitionClone),
                    elementDefinitionClone);
                transaction.Create(parameter, elementDefinitionClone);

                this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult();

                this.PrintCacheCount();

                this.PrintCommands();
            }
        }
Пример #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);
        }
        /// <summary>
        /// Performs the drop operation
        /// </summary>
        /// <param name="dropInfo">
        /// Information about the drop operation.
        /// </param>
        public async Task Drop(IDropInfo dropInfo)
        {
            var termPayload = dropInfo.Payload as Term;

            if (termPayload == null)
            {
                return;
            }

            if (dropInfo.Effects == DragDropEffects.Move)
            {
                var termClone       = termPayload.Clone(false);
                var currentGlossary = (Glossary)this.Thing.Container.Clone(false);
                currentGlossary.Term.Add(termClone);

                var context     = TransactionContextResolver.ResolveContext(this.Thing);
                var transaction = new ThingTransaction(context);

                transaction.CreateOrUpdate(currentGlossary);
                await this.DalWrite(transaction);
            }
            else if (dropInfo.Effects == DragDropEffects.Copy)
            {
                throw new NotImplementedException("drag and drop on a different data-source is not implemented yet.");
            }
        }
Пример #4
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.navigation        = new Mock <IThingDialogNavigationService>();
            this.permissionService = new Mock <IPermissionService>();
            this.session           = new Mock <ISession>();

            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.siteDir     = new SiteDirectory(Guid.NewGuid(), null, this.uri);
            this.siteRdl     = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri);
            this.derivedUnit = new DerivedUnit(Guid.NewGuid(), null, this.uri);
            this.factor      = new UnitFactor(Guid.NewGuid(), null, this.uri);
            this.derivedUnit.UnitFactor.Add(this.factor);
            this.unit = new SimpleUnit(Guid.NewGuid(), null, this.uri);
            this.siteRdl.Unit.Add(this.unit);
            this.factor.Unit = this.unit;

            this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl);
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
Пример #5
0
        /// <summary>
        /// Method for creating a <see cref="BinaryRelationship"/> for requirement verification between a <see cref="ParameterOrOverrideBase"/> and a <see cref="RelationalExpression"/>.
        /// </summary>
        /// <param name="session">The <see cref="Session"/> for which the <see cref="BinaryRelationship"/> will be created</param>
        /// <param name="iteration">The <see cref="Iteration"/> for which the  <see cref="BinaryRelationship"/> will be created</param>
        /// <param name="parameter">The <see cref="ParameterOrOverrideBase"/> that acts as the source of the <see cref="BinaryRelationship"/></param>
        /// <param name="relationalExpression">The <see cref="RelationalExpression"/> that acts as the target of the <see cref="BinaryRelationship"/></param>
        /// <returns>An awaitable <see cref="Task"/></returns>
        public async Task CreateBinaryRelationshipForRequirementVerification(ISession session, Iteration iteration, ParameterOrOverrideBase parameter, RelationalExpression relationalExpression)
        {
            session.OpenIterations.TryGetValue(iteration, out var tuple);

            var binaryRelationship = new BinaryRelationship(Guid.NewGuid(), null, null)
            {
                Owner = tuple?.Item1
            };

            var transaction = new ThingTransaction(TransactionContextResolver.ResolveContext(relationalExpression));

            binaryRelationship.Container = iteration;
            binaryRelationship.Source    = parameter;
            binaryRelationship.Target    = relationalExpression;

            var iterationClone = iteration.Clone(false);

            iterationClone.Relationship.Add(binaryRelationship);
            transaction.CreateOrUpdate(iterationClone);
            transaction.Create(binaryRelationship);

            try
            {
                var operationContainer = transaction.FinalizeTransaction();
                await session.Write(operationContainer);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(typeof(Iteration).FullName).Error("The inline update operation failed: {0}", ex.Message);
            }
        }
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.cache             = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();
            this.navigation        = new Mock <IThingDialogNavigationService>();
            this.permissionService = new Mock <IPermissionService>();
            this.session           = new Mock <ISession>();

            this.siteDir     = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.siteRdl     = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.derivedUnit = new DerivedUnit(Guid.NewGuid(), this.cache, this.uri);
            this.unit        = new SimpleUnit(Guid.NewGuid(), this.cache, this.uri);

            this.siteRdl.Unit.Add(this.unit);

            this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.cache.TryAdd(new CacheKey(this.derivedUnit.Iid, null), new Lazy <Thing>(() => this.derivedUnit));
            this.clone = this.derivedUnit.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
Пример #7
0
        /// <summary>
        /// Execute the creation of a <see cref="ModellingAnnotationItem"/>
        /// </summary>
        protected void ExecuteCreateModellingAnnotation(ModellingAnnotationItem annotation, Participant participant, DomainOfExpertise owner)
        {
            if (this.SelectedThing == null)
            {
                return;
            }

            annotation.Owner  = owner;
            annotation.Author = participant;
            annotation.Status = AnnotationStatusKind.OPEN;

            var annotatedThing = new ModellingThingReference(this.SelectedThing.Thing);

            annotation.RelatedThing.Add(annotatedThing);
            annotation.PrimaryAnnotatedThing = annotatedThing;

            var transactionContext = TransactionContextResolver.ResolveContext(this.Thing);
            var model = this.Thing.TopContainer as EngineeringModel;

            if (model == null)
            {
                throw new InvalidOperationException("A modelling annotation item can only be created in the context of a Engineering Model.");
            }

            var containerClone = model.Clone(false);
            var transaction    = new ThingTransaction(transactionContext, containerClone);

            this.ThingDialogNavigationService.Navigate(annotation, transaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService, containerClone);
        }
Пример #8
0
        /// <summary>
        /// Deletes a <see cref="BinaryRelationship" /> for the selected pair of thing
        /// </summary>
        /// <param name="direction">The direction of the relationship to delete</param>
        /// <returns>The task</returns>
        private Task DeleteRelationship(RelationshipDirectionKind direction)
        {
            if (!(this.SelectedCell is MatrixCellViewModel vm))
            {
                return(Task.FromResult(0));
            }

            var iterationClone = this.iteration.Clone(false);
            var context        = TransactionContextResolver.ResolveContext(iterationClone);
            var transaction    = new ThingTransaction(context, iterationClone);

            foreach (var binaryRelationship in vm.Relationships)
            {
                var clone = binaryRelationship.Clone(false);

                if (vm.RelationshipDirection != RelationshipDirectionKind.BiDirectional ||
                    direction == RelationshipDirectionKind.BiDirectional)
                {
                    // delete every relationship
                    transaction.Delete(clone);
                }
                else if (direction == RelationshipDirectionKind.RowThingToColumnThing &&
                         vm.SourceY.Iid == binaryRelationship.Source.Iid)
                {
                    transaction.Delete(clone);
                }
                else if (direction == RelationshipDirectionKind.ColumnThingToRowThing &&
                         vm.SourceX.Iid == binaryRelationship.Source.Iid)
                {
                    transaction.Delete(clone);
                }
            }

            return(this.session.Write(transaction.FinalizeTransaction()));
        }
Пример #9
0
        public void VerifyThatSetDefaultWorks()
        {
            var statelist = new PossibleFiniteStateList
            {
                Name      = "name",
                ShortName = "shortname"
            };

            var state = new PossibleFiniteState(Guid.NewGuid(), this.cache, this.uri);

            statelist.PossibleState.Add(state);

            var containerClone = this.iteration.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);
            var transaction        = new ThingTransaction(transactionContext, containerClone);

            var vm = new PossibleFiniteStateListDialogViewModel(statelist, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object, containerClone);

            vm.SelectedPossibleState = vm.PossibleState.Single();
            vm.SetDefaultStateCommand.Execute(null);

            Assert.IsTrue(((PossibleFiniteStateRowViewModel)vm.SelectedPossibleState).IsDefault);
            Assert.AreSame(vm.SelectedDefaultState, state);
        }
        public void SetUp()
        {
            this.session = new Mock <ISession>();
            var uri     = new Uri("http://rheagroup.com");
            var siteDir = new SiteDirectory(Guid.NewGuid(), null, uri);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(siteDir);
            this.simpleUnit = new SimpleUnit(Guid.NewGuid(), null, uri);

            var transactionContext = TransactionContextResolver.ResolveContext(siteDir);

            this.transaction = new ThingTransaction(transactionContext);

            this.simpleUnitDialogView = new TestView();
            var viewExportAttribute = new ThingDialogViewExportAttribute(ClassKind.SimpleUnit);
            var lazyview            = new Lazy <IThingDialogView, IClassKindMetaData>(() => this.simpleUnitDialogView, viewExportAttribute);

            this.simpleUnitDialogViewModel = new TestViewModel(this.simpleUnit, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, null);
            var viewModelExportAttribute = new ThingDialogViewModelExportAttribute(ClassKind.SimpleUnit);
            var lazyviewmodel            = new Lazy <IThingDialogViewModel, IClassKindMetaData>(() => this.simpleUnitDialogViewModel, viewModelExportAttribute);

            this.lazyviews = new List <Lazy <IThingDialogView, IClassKindMetaData> >();
            this.lazyviews.Add(lazyview);

            this.lazyviewmodels = new List <Lazy <IThingDialogViewModel, IClassKindMetaData> >();
            this.lazyviewmodels.Add(lazyviewmodel);

            this.specialTermService = new SpecialTermsService();
        }
Пример #11
0
        /// <summary>
        /// Creates a <see cref="BinaryRelationship" /> for the selected cell
        /// </summary>
        /// <param name="direction">The direction fo the relationship to create</param>
        /// <returns>The task</returns>
        private Task CreateRelationship(RelationshipDirectionKind direction)
        {
            var vm = this.SelectedCell as MatrixCellViewModel;

            if (vm == null)
            {
                return(Task.FromResult(0));
            }

            var relationship = new BinaryRelationship(Guid.NewGuid(), null, null)
            {
                Owner = this.session.OpenIterations[this.iteration].Item1
            };

            relationship.Category.Add(vm.Rule.RelationshipCategory);

            relationship.Source =
                direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceY : vm.SourceX;

            relationship.Target =
                direction == RelationshipDirectionKind.RowThingToColumnThing ? vm.SourceX : vm.SourceY;

            var iterationClone = this.iteration.Clone(false);

            iterationClone.Relationship.Add(relationship);

            var context     = TransactionContextResolver.ResolveContext(relationship);
            var transaction = new ThingTransaction(context, iterationClone);

            transaction.Create(relationship, iterationClone);

            return(this.session.Write(transaction.FinalizeTransaction()));
        }
 public TestViewModel(Thing thing, ThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService nav, Thing container = null, List <Thing> chainOfContainers = null)
 {
     this.thing        = thing;
     this.transaction  = transaction;
     this.session      = session;
     this.spellChecker = new SpellChecker();
 }
Пример #13
0
        public void Setup()
        {
            this.navigation       = new Mock <IThingDialogNavigationService>();
            this.permissionServce = new Mock <IPermissionService>();
            this.cache            = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.session      = new Mock <ISession>();
            this.siteDir      = new SiteDirectory(Guid.NewGuid(), this.cache, null);
            this.organization = new Organization()
            {
                Name = "organization", ShortName = "orga"
            };

            this.clone = this.siteDir.Clone(false);
            this.cache.TryAdd(new CacheKey(this.siteDir.Iid, null), new Lazy <Thing>(() => this.siteDir));

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());

            this.viewmodel = new OrganizationDialogViewModel(this.organization, this.transaction, this.session.Object, true, ThingDialogKind.Create, this.navigation.Object, this.clone);
        }
Пример #14
0
        /// <summary>
        /// Removes the first found <see cref="Parameter"/> from the first found <see cref="ElementDefinition"/>
        /// </summary>
        private void RemoveParameter()
        {
            if (this.session.OpenIterations.Count == 0)
            {
                Console.WriteLine("At first an iteration should be opened");
                return;
            }

            var iteration = this.session.OpenIterations.Keys.First();

            if (iteration != null)
            {
                var elementDefinition      = iteration.Element[0];
                var elementDefinitionClone = elementDefinition.Clone(false);
                var parameterClone         = elementDefinition.Parameter[0].Clone(false);

                var transaction = new ThingTransaction(
                    TransactionContextResolver.ResolveContext(elementDefinitionClone),
                    elementDefinitionClone);
                transaction.Delete(parameterClone, elementDefinitionClone);

                this.session.Write(transaction.FinalizeTransaction()).GetAwaiter().GetResult();

                this.PrintCacheCount();

                this.PrintCommands();
            }
        }
Пример #15
0
        /// <summary>
        /// Executes the <see cref="CreateSubscriptionCommand"/>
        /// </summary>
        private async Task ExecuteCreateSubscriptionCommand()
        {
            if (this.SelectedThing == null)
            {
                return;
            }

            var parameterOrOverrideRow = this.SelectedThing as ParameterOrOverrideBaseRowViewModel;

            if (parameterOrOverrideRow == null)
            {
                return;
            }

            Tuple <DomainOfExpertise, Participant> tuple;

            this.Session.OpenIterations.TryGetValue(this.Thing.GetContainerOfType <Iteration>(), out tuple);

            var subscription = new ParameterSubscription
            {
                Owner = tuple.Item1
            };

            var transactionContext = TransactionContextResolver.ResolveContext(this.Thing);
            var transaction        = new ThingTransaction(transactionContext);

            var clone = parameterOrOverrideRow.Thing.Clone(false);

            transaction.Create(subscription);
            transaction.CreateOrUpdate(clone);
            clone.ParameterSubscription.Add(subscription);

            await this.DalWrite(transaction);
        }
Пример #16
0
        public void VerifyThatPropertiesAreSet()
        {
            var statelist = new PossibleFiniteStateList
            {
                Name      = "name",
                ShortName = "shortname"
            };
            var containerClone = this.iteration.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);
            var transaction        = new ThingTransaction(transactionContext, containerClone);

            var vm = new PossibleFiniteStateListDialogViewModel(statelist, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object, containerClone);

            Assert.AreEqual(statelist.Name, vm.Name);
            Assert.AreEqual(statelist.ShortName, vm.ShortName);

            Assert.AreEqual(1, vm.PossibleOwner.Count);
            Assert.AreEqual(1, vm.PossibleCategory.Count);

            Assert.IsFalse(vm.OkCanExecute);

            statelist.PossibleState.Add(new PossibleFiniteState(Guid.NewGuid(), null, null));
            statelist.DefaultState = statelist.PossibleState.First();
            vm = new PossibleFiniteStateListDialogViewModel(statelist, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object, containerClone);
            Assert.AreEqual(1, vm.PossibleState.Count);
            Assert.AreEqual(statelist.DefaultState, vm.SelectedDefaultState);
        }
Пример #17
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;

            this.navigation        = new Mock <IThingDialogNavigationService>();
            this.permissionService = new Mock <IPermissionService>();
            this.session           = new Mock <ISession>();

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, this.uri);
            this.siteRdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, this.uri);
            this.siteDir.SiteReferenceDataLibrary.Add(this.siteRdl);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, null);

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.testEnumerationValueDefinition = new EnumerationValueDefinition(Guid.NewGuid(), null, null);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());

            this.viewModel = new EnumerationValueDefinitionDialogViewModel(this.testEnumerationValueDefinition, this.transaction, this.session.Object, true,
                                                                           ThingDialogKind.Create, this.navigation.Object, this.derivedUnit);
        }
Пример #18
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.serviceLocator       = new Mock <IServiceLocator>();
            this.navigation           = new Mock <IThingDialogNavigationService>();
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);
            this.serviceLocator.Setup(x => x.GetInstance <IThingDialogNavigationService>()).Returns(this.navigation.Object);
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.session       = new Mock <ISession>();
            this.testEM        = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.testIteration = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            testEM.Iteration.Add(testIteration);
            this.testED         = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            this.parameterGroup = new ParameterGroup()
            {
                Name = "1"
            };
            testIteration.Element.Add(this.testED);

            this.cache.TryAdd(new CacheKey(this.testED.Iid, testIteration.Iid), new Lazy <Thing>(() => this.testED));
            var clone = this.testED.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.testIteration);

            this.transaction = new ThingTransaction(transactionContext, clone);

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());

            this.viewmodel = new ParameterGroupDialogViewModel(this.parameterGroup, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, clone);
        }
Пример #19
0
        /// <summary>
        /// Execute the creation of a <see cref="ModellingAnnotationItem"/>
        /// </summary>
        protected void ExecuteCreateEngineeringModelDataNote(EngineeringModelDataNote engineeringModelDataNote, Participant participant)
        {
            if (this.SelectedThing == null)
            {
                return;
            }

            engineeringModelDataNote.Author = participant;

            var annotatedThing = new ModellingThingReference(this.SelectedThing.Thing);

            engineeringModelDataNote.PrimaryAnnotatedThing = annotatedThing;
            engineeringModelDataNote.RelatedThing.Add(annotatedThing);

            var transactionContext = TransactionContextResolver.ResolveContext(this.Thing);
            var model = this.Thing.TopContainer as EngineeringModel;

            if (model == null)
            {
                throw new InvalidOperationException("A EngineeringModelDataNote item can only be created in the context of a Engineering Model.");
            }

            var containerClone = model.Clone(false);
            var transaction    = new ThingTransaction(transactionContext, containerClone);

            this.ThingDialogNavigationService.Navigate(engineeringModelDataNote, transaction, this.Session, true, ThingDialogKind.Create, this.ThingDialogNavigationService, containerClone);
        }
Пример #20
0
        public void VerifyThatCreateComponentWork()
        {
            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
            var transaction        = new ThingTransaction(transactionContext);

            var viewmodel = new CompoundParameterTypeDialogViewModel(this.compoundPt, transaction, this.session.Object, true, ThingDialogKind.Create, null, null);

            Assert.IsEmpty(viewmodel.Component);
            viewmodel.CreateComponentCommand.Execute(null);
            Assert.AreEqual(1, viewmodel.Component.Count);

            Assert.IsFalse(viewmodel.OkCommand.CanExecute(null));

            var componentRow = (ParameterTypeComponentRowViewModel)viewmodel.Component.Single();

            componentRow.ParameterType = componentRow.PossibleParameterType.First();

            Assert.IsFalse(viewmodel.OkCommand.CanExecute(null));
            viewmodel.Component.First().ShortName = "FirstComponent";
            Assert.IsTrue(viewmodel.OkCommand.CanExecute(null));
            viewmodel.CreateComponentCommand.Execute(null);
            viewmodel.Component.Last().ShortName = "SecondComponent";
            Assert.AreEqual(2, viewmodel.Component.Count);

            Assert.IsFalse(viewmodel.OkCommand.CanExecute(null));
            var c2Row = (ParameterTypeComponentRowViewModel)viewmodel.Component.Last();

            c2Row.ParameterType = c2Row.PossibleParameterType.Single(x => x is SimpleQuantityKind);

            Assert.IsNotNull(c2Row.Scale);
            Assert.IsTrue(viewmodel.OkCommand.CanExecute(null));
        }
Пример #21
0
        public void VerifyThatPropertiesAreSet()
        {
            var category = new Category();

            category.PermissibleClass.Add(ClassKind.Glossary);
            var glossary = new Glossary
            {
                Name      = "aaaa",
                ShortName = "bbb"
            };

            var term = new Term();

            glossary.Term.Add(term);

            this.srdl.DefinedCategory.Add(category);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
            var transaction        = new ThingTransaction(transactionContext);

            var viewmodel = new GlossaryDialogViewModel(glossary, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object);

            Assert.IsNotEmpty(viewmodel.Term);
            Assert.IsNotEmpty(viewmodel.PossibleContainer);
            Assert.IsNotEmpty(viewmodel.PossibleCategory);
            Assert.AreEqual(viewmodel.Name, glossary.Name);
            Assert.AreEqual(viewmodel.ShortName, glossary.ShortName);
            Assert.AreEqual(viewmodel.IsDeprecated, glossary.IsDeprecated);
        }
        private async Task WriteParametersValueSets(Parameter parameter, int elementIndex)
        {
            var valueConfigPair =
                StressGeneratorConfiguration.ParamValueConfig.FirstOrDefault(pvc =>
                                                                             pvc.Key == parameter.ParameterType.ShortName);
            var parameterSwitchKind =
                elementIndex % 2 == 0 ? ParameterSwitchKind.MANUAL : ParameterSwitchKind.REFERENCE;
            var parameterValue = (valueConfigPair.Value + elementIndex).ToString(CultureInfo.InvariantCulture);
            var valueSetClone  = ParameterGenerator.UpdateValueSets(parameter.ValueSets,
                                                                    parameterSwitchKind, parameterValue);

            try
            {
                var transactionContext = TransactionContextResolver.ResolveContext(valueSetClone);
                var transaction        = new ThingTransaction(transactionContext);
                transaction.CreateOrUpdate(valueSetClone);
                var operationContainer = transaction.FinalizeTransaction();
                await this.configuration.Session.Write(operationContainer);

                this.NotifyMessage($"Successfully generated ValueSet (Published value: {parameterValue}) for parameter {parameter.ParameterType.Name} ({parameter.ParameterType.ShortName}).");
            }
            catch (Exception ex)
            {
                this.NotifyMessage($"Cannot update ValueSet (Published value: {parameterValue}) for parameter {parameter.ParameterType.Name} ({parameter.ParameterType.ShortName}). Exception: {ex.Message}");
            }
        }
Пример #23
0
        public void Setup()
        {
            RxApp.MainThreadScheduler = Scheduler.CurrentThread;
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.session = new Mock <ISession>();
            this.siteDir = new SiteDirectory(Guid.NewGuid(), this.cache, null);
            this.model   = new EngineeringModelSetup(Guid.NewGuid(), this.cache, null);
            this.siteDir.Model.Add(this.model);

            this.iteration = new IterationSetup(Guid.NewGuid(), this.cache, null);
            this.model.IterationSetup.Add(this.iteration);

            this.clone = this.model.Clone(false);
            this.cache.TryAdd(new CacheKey(this.siteDir.Iid, null), new Lazy <Thing>(() => this.siteDir));
            this.cache.TryAdd(new CacheKey(this.model.Iid, null), new Lazy <Thing>(() => this.model));

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);

            this.transaction = new ThingTransaction(transactionContext, this.clone);

            this.navigation        = new Mock <IThingDialogNavigationService>();
            this.permissionService = new Mock <IPermissionService>();

            var dal = new Mock <IDal>();

            this.session.Setup(x => x.DalVersion).Returns(new Version(1, 1, 0));
            this.session.Setup(x => x.Dal).Returns(dal.Object);
            dal.Setup(x => x.MetaDataProvider).Returns(new MetaDataProvider());
        }
        public void VerifyThatPropertiesAreSet()
        {
            var category = new Category();

            category.PermissibleClass.Add(ClassKind.FileType);
            var filetype = new FileType
            {
                Name      = "aaaa",
                ShortName = "bbb",
                Extension = "txt"
            };

            this.srdl.DefinedCategory.Add(category);

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
            var transaction        = new ThingTransaction(transactionContext);

            var viewmodel = new FileTypeDialogViewModel(filetype, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object);

            Assert.IsNotEmpty(viewmodel.PossibleContainer);
            Assert.IsNotEmpty(viewmodel.PossibleCategory);
            Assert.AreEqual(viewmodel.Name, filetype.Name);
            Assert.AreEqual(viewmodel.Extension, filetype.Extension);
            Assert.AreEqual(viewmodel.ShortName, filetype.ShortName);
            Assert.AreEqual(viewmodel.IsDeprecated, filetype.IsDeprecated);
        }
        /// <summary>
        /// Moves a <see cref="File"/> to another <see cref="Folder"/> or <see cref="FileStore"/>
        /// A <see cref="File"/>'s parent folder is its latest <see cref="FileRevision"/>'s <see cref="FileRevision.ContainingFolder"/>.
        /// When <see cref="FileRevision.ContainingFolder"/> is null, that means that the <see cref="File"/> is located
        /// Moving a file means that a new <see cref="FileRevision"/> has to be created that has the destination parent folder set as its <see cref="FileRevision.ContainingFolder"/>.
        /// </summary>
        /// <param name="file"><The <see cref="File"/></param>
        /// <param name="destinationFolder">The destination <see cref="Folder"/></param>
        /// <param name="creator">The <see cref="Participant"/> that executes the move action</param>
        /// <param name="session">The <see cref="ISession"/></param>
        public static async Task MoveFile(this File file, Folder destinationFolder, Participant creator, ISession session)
        {
            var transactionContext   = TransactionContextResolver.ResolveContext(file);
            var containerClone       = file.TopContainer.Clone(false);
            var containerTransaction = new ThingTransaction(transactionContext, containerClone);

            var fileClone = file.Clone(false);

            var newFileRevision = file.CurrentFileRevision.CopyToNew(creator);

            fileClone.FileRevision.Add(newFileRevision);

            newFileRevision.ContainingFolder = destinationFolder;
            containerTransaction.CreateOrUpdate(fileClone);
            containerTransaction.CreateOrUpdate(newFileRevision);

            try
            {
                var operationContainer = containerTransaction.FinalizeTransaction();
                await session.Write(operationContainer);
            }
            catch (Exception ex)
            {
                throw new Exception($"Moving file failed: {ex.Message}");
            }
        }
        public void VerifyThatExtensionValidationWorks()
        {
            var filetype = new FileType
            {
                Name      = "aaaa",
                ShortName = "bbb"
            };

            var transactionContext = TransactionContextResolver.ResolveContext(this.siteDir);
            var transaction        = new ThingTransaction(transactionContext);

            var viewmodel = new FileTypeDialogViewModel(filetype, transaction, this.session.Object, true, ThingDialogKind.Create, this.thingDialogNavigationService.Object);

            var rule = viewmodel["Extension"];

            Assert.That(rule, Is.Not.Null.Or.Not.Empty);

            viewmodel.Extension = "Abc";
            rule = viewmodel["Extension"];
            Assert.That(rule, Is.Not.Null.Or.Not.Empty);

            viewmodel.Extension = "abc9 ";
            rule = viewmodel["Extension"];
            Assert.That(rule, Is.Not.Null.Or.Not.Empty);

            viewmodel.Extension = "abc9";
            rule = viewmodel["Extension"];
            Assert.IsNull(rule);
        }
Пример #27
0
        /// <summary>
        /// Create a <see cref="ThingTransaction"/> object from the <see cref="RequirementsSpecification"/>
        /// </summary>
        /// <returns>The <see cref="ThingTransaction"/></returns>
        private ThingTransaction CreateTransaction()
        {
            var transactionContext = TransactionContextResolver.ResolveContext(this.IterationClone);
            var transaction        = new ThingTransaction(transactionContext, this.IterationClone);

            foreach (var externalIdentifierMap in this.IterationClone.ExternalIdentifierMap)
            {
                transaction.CreateOrUpdate(externalIdentifierMap);
            }

            foreach (var specMap in this.thingFactory.SpecificationMap)
            {
                transaction.CreateDeep(specMap.Value);
            }

            foreach (var relationshipMap in this.thingFactory.SpecRelationMap)
            {
                transaction.CreateDeep(relationshipMap.Value);
            }

            foreach (var relationshipMap in this.thingFactory.RelationGroupMap)
            {
                transaction.CreateDeep(relationshipMap.Value);
            }

            return(transaction);
        }
Пример #28
0
        public void VerifyThatDialogWorks()
        {
            var clone = this.iteration.Clone(false);

            var transactionContext = TransactionContextResolver.ResolveContext(this.iteration);
            var transaction        = new ThingTransaction(transactionContext, clone);
            var vm = new BinaryRelationshipDialogViewModel(new BinaryRelationship(), transaction, this.session.Object,
                                                           true, ThingDialogKind.Create, this.dialogNavigationService.Object, clone);

            Assert.AreEqual(1, vm.PossibleCategory.Count);
            Assert.AreEqual(0, vm.PossibleSource.Count);
            Assert.AreEqual(0, vm.PossibleTarget.Count);

            vm.PossibleSource.Add(this.req1);
            vm.PossibleTarget.Add(this.req2);

            vm.Category = new ReactiveList <Category> {
                this.relationshipCat
            };
            Assert.AreEqual(1, vm.PossibleSource.Count);
            Assert.AreEqual(1, vm.PossibleTarget.Count);

            Assert.IsTrue(vm.PossibleSource.Contains(this.req1));
            vm.SelectedSource = this.req1;
            Assert.IsTrue(vm.PossibleTarget.Contains(this.req2));
            vm.SelectedTarget = this.req2;

            Assert.IsTrue(vm.PossibleOwner.Contains(this.domain));
            vm.SelectedOwner = this.domain;

            Assert.IsTrue(vm.OkCommand.CanExecute(null));
        }
Пример #29
0
        /// <summary>
        /// Write the inline operations to the Data-access-layer
        /// </summary>
        /// <param name="clone">The <see cref="Thing"/> to update</param>
        /// <param name="showConfirmation">A value indicating whether a confirmation should be displayed</param>
        protected async Task DalWrite(Thing clone, bool showConfirmation = false)
        {
            var transactionContext = TransactionContextResolver.ResolveContext(clone);
            var transaction        = new ThingTransaction(transactionContext, clone);

            await this.DalWrite(transaction, showConfirmation);
        }
        /// <summary>
        /// Move the value of reference value to manual value on value sets of parameters of specified element definition.
        /// The move is only done if the manual value = default value = "-"
        /// </summary>
        public void MoveReferenceValuesToManualValues()
        {
            foreach (var parameter in this.sessionService.Iteration.Element.Where(e => this.filterService.IsFilteredIn(e))
                     .SelectMany(e => e.Parameter).OrderBy(x => x.ParameterType.ShortName))
            {
                if (parameter.ParameterType is ScalarParameterType && this.filterService.IsParameterSpecifiedOrAny(parameter))
                {
                    var valueSet    = parameter.ValueSet.FirstOrDefault();
                    var refValue    = valueSet?.Reference;
                    var manualValue = valueSet?.Manual;

                    if (valueSet?.ValueSwitch == ParameterSwitchKind.REFERENCE && manualValue[0] == "-")
                    {
                        var valueSetClone = valueSet.Clone(true);
                        var transaction   = new ThingTransaction(TransactionContextResolver.ResolveContext(valueSetClone), valueSetClone);
                        valueSetClone.Manual[0]    = refValue[0];
                        valueSetClone.ValueSwitch  = ParameterSwitchKind.MANUAL;
                        valueSetClone.Reference[0] = "-";
                        transaction.CreateOrUpdate(valueSetClone);
                        this.sessionService.Transactions.Add(transaction);

                        Console.WriteLine($"Moved {parameter.UserFriendlyShortName} = {refValue[0]} ref value to manual value and changed switch to MANUAL");
                    }
                }
            }
        }