Пример #1
0
        /// <summary>
        /// Serialize the <see cref="SpecializedQuantityKind"/>
        /// </summary>
        /// <param name="specializedQuantityKind">The <see cref="SpecializedQuantityKind"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(SpecializedQuantityKind specializedQuantityKind)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](specializedQuantityKind.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("category", this.PropertySerializerMap["category"](specializedQuantityKind.Category.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), specializedQuantityKind.ClassKind)));
            jsonObject.Add("defaultScale", this.PropertySerializerMap["defaultScale"](specializedQuantityKind.DefaultScale));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](specializedQuantityKind.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](specializedQuantityKind.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](specializedQuantityKind.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("general", this.PropertySerializerMap["general"](specializedQuantityKind.General));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](specializedQuantityKind.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](specializedQuantityKind.Iid));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](specializedQuantityKind.IsDeprecated));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](specializedQuantityKind.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](specializedQuantityKind.Name));
            jsonObject.Add("possibleScale", this.PropertySerializerMap["possibleScale"](specializedQuantityKind.PossibleScale.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("quantityDimensionSymbol", this.PropertySerializerMap["quantityDimensionSymbol"](specializedQuantityKind.QuantityDimensionSymbol));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](specializedQuantityKind.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](specializedQuantityKind.ShortName));
            jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](specializedQuantityKind.Symbol));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](specializedQuantityKind.ThingPreference));
            return(jsonObject);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SpecializedQuantityKindDialogViewModel"/> class.
 /// </summary>
 /// <param name="specializedQuantityKind">
 /// The Specialized quantity Kind.
 /// </param>
 /// <param name="transaction">
 /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
 /// </param>
 /// <param name="session">
 /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
 /// </param>
 /// <param name="isRoot">
 /// Assert if this <see cref="SpecializedQuantityKindDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="SpecializedQuantityKindDialogViewModel"/> performs
 /// </param>
 /// <param name="thingDialogNavigationService">
 /// The <see cref="IThingDialogNavigationService"/> that is used to navigate to a dialog of a specific <see cref="Thing"/>.
 /// </param>
 /// <param name="container">
 /// The <see cref="Thing"/> that contains the created <see cref="Thing"/> in this Dialog
 /// </param>
 /// <param name="chainOfContainers">
 /// The optional chain of containers that contains the <paramref name="container"/> argument
 /// </param>
 /// <exception cref="ArgumentException">
 /// The container must be of type <see cref="ReferenceDataLibrary"/>.
 /// </exception>
 public SpecializedQuantityKindDialogViewModel(SpecializedQuantityKind specializedQuantityKind, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(specializedQuantityKind, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
     this.WhenAnyValue(vm => vm.Container).Subscribe(_ => { this.PopulatePossiblePossibleScales(); this.PopulatePossibleGeneral(); });
     this.WhenAnyValue(vm => vm.SelectedDefaultScale).Subscribe(_ => this.UpdateOkCanExecute());
     this.WhenAnyValue(vm => vm.SelectedGeneral).Subscribe(_ => { this.PopulatePossiblePossibleScales(); this.UpdateOkCanExecute(); });
 }
        public void VerifyThatParameterTypeEventsAreCaught()
        {
            var textParamType = new TextParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);

            CDPMessageBus.Current.SendObjectChangeEvent(textParamType, EventKind.Added);
            Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count);
            CDPMessageBus.Current.SendObjectChangeEvent(textParamType, EventKind.Removed);
            Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any());

            var booleanParamType = new BooleanParameterType(Guid.NewGuid(), this.assembler.Cache, this.uri);

            CDPMessageBus.Current.SendObjectChangeEvent(booleanParamType, EventKind.Added);
            Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count);
            CDPMessageBus.Current.SendObjectChangeEvent(booleanParamType, EventKind.Removed);
            Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any());

            var defaultScale = new CyclicRatioScale(Guid.NewGuid(), this.assembler.Cache, this.uri);

            var simpleQuantityKind =
                new SimpleQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                DefaultScale = defaultScale
            };

            CDPMessageBus.Current.SendObjectChangeEvent(simpleQuantityKind, EventKind.Added);
            Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count);
            CDPMessageBus.Current.SendObjectChangeEvent(simpleQuantityKind, EventKind.Removed);
            Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any());

            var specializedQuantityKind =
                new SpecializedQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                DefaultScale = defaultScale
            };

            CDPMessageBus.Current.SendObjectChangeEvent(specializedQuantityKind, EventKind.Added);
            Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count);
            CDPMessageBus.Current.SendObjectChangeEvent(specializedQuantityKind, EventKind.Removed);
            Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any());

            var derivedQuantityKind =
                new DerivedQuantityKind(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                DefaultScale = defaultScale
            };

            CDPMessageBus.Current.SendObjectChangeEvent(derivedQuantityKind, EventKind.Added);
            Assert.AreEqual(1, this.ParameterTypesBrowserViewModel.ParameterTypes.Count);
            CDPMessageBus.Current.SendObjectChangeEvent(derivedQuantityKind, EventKind.Removed);
            Assert.IsFalse(this.ParameterTypesBrowserViewModel.ParameterTypes.Any());
        }
Пример #4
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.permissionService = new Mock <IPermissionService>();
            this.permissionService.Setup(x => x.CanRead(It.IsAny <Thing>())).Returns(true);
            this.permissionService.Setup(x => x.CanWrite(It.IsAny <Thing>())).Returns(true);
            this.session = new Mock <ISession>();
            this.session.Setup(x => x.PermissionService).Returns(this.permissionService.Object);
            var person = new Person(Guid.NewGuid(), null, null)
            {
                Container = this.siteDir
            };

            this.session.Setup(x => x.ActivePerson).Returns(person);

            this.siteDir = new SiteDirectory(Guid.NewGuid(), null, null);
            this.siteDir.Person.Add(person);
            this.rdl = new SiteReferenceDataLibrary(Guid.NewGuid(), null, null)
            {
                Name = "testRDL", ShortName = "test"
            };
            this.specializedQuantityKind = new SpecializedQuantityKind(Guid.NewGuid(), null, null)
            {
                Name = "specializedQuantityKind", ShortName = "sqk"
            };
            this.rdl.ParameterType.Add(new SimpleQuantityKind {
                Name = "testSQK", ShortName = "tSQK"
            });
            this.siteDir.SiteReferenceDataLibrary.Add(this.rdl);

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

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

            this.session.Setup(x => x.RetrieveSiteDirectory()).Returns(this.siteDir);
            this.session.Setup(x => x.OpenReferenceDataLibraries).Returns(new HashSet <ReferenceDataLibrary>(this.siteDir.SiteReferenceDataLibrary));

            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 SpecializedQuantityKindDialogViewModel(this.specializedQuantityKind, this.transaction, this.session.Object, true, ThingDialogKind.Create, null, null, null);
        }
Пример #5
0
        public void TestGetAllPossibleScaleSpecialized()
        {
            var quantityKind = new SpecializedQuantityKind();

            var scale = new LogarithmicScale();

            quantityKind.PossibleScale.Add(scale);

            quantityKind.General = new SimpleQuantityKind();
            quantityKind.General.PossibleScale.Add(new RatioScale());
            quantityKind.General.PossibleScale.Add(new CyclicRatioScale());
            quantityKind.General.PossibleScale.Add(scale);

            Assert.AreEqual(3, quantityKind.AllPossibleScale.Count);
        }
Пример #6
0
        public void Setup()
        {
            // QuantityKind tree: rootQk -> specializedQk -> derivedQk -> simpleQk
            this.simpleQk = new SimpleQuantityKind(Guid.NewGuid(), 0);

            this.derivedQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.simpleQk.Iid
            };

            this.derivedQk = new DerivedQuantityKind(Guid.NewGuid(), 0)
            {
                QuantityKindFactor =
                {
                    new OrderedItem {
                        K = 1, V = this.derivedQkFactor.Iid.ToString()
                    }
                }
            };

            this.specializedQk = new SpecializedQuantityKind(Guid.NewGuid(), 0)
            {
                General = this.derivedQk.Iid
            };

            this.rootQkFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.specializedQk.Iid
            };

            this.rootQk = new DerivedQuantityKind(Guid.NewGuid(), 0)
            {
                QuantityKindFactor =
                {
                    new OrderedItem {
                        K = 1, V = this.rootQkFactor.Iid.ToString()
                    }
                }
            };

            // cyclic factor
            this.derivedQkCyclicFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.rootQk.Iid
            };

            // outside RDL factor
            this.outsideRdlQk = new SimpleQuantityKind(Guid.NewGuid(), 0);

            this.derivedQkOutsideRdlFactor = new QuantityKindFactor(Guid.NewGuid(), 0)
            {
                QuantityKind = this.outsideRdlQk.Iid
            };

            // RDL chain: mrdl -> srdl
            this.srdl = new SiteReferenceDataLibrary(Guid.NewGuid(), 0)
            {
                ParameterType =
                {
                    this.simpleQk.Iid
                }
            };

            this.mrdl = new ModelReferenceDataLibrary(Guid.NewGuid(), 0)
            {
                ParameterType =
                {
                    this.derivedQk.Iid,
                    this.specializedQk.Iid,
                    this.rootQk.Iid
                },
                RequiredRdl = this.srdl.Iid
            };

            // setup services
            this.npgsqlTransaction = null;
            this.securityContext   = new Mock <ISecurityContext>();

            this.siteReferenceDataLibraryService = new Mock <ISiteReferenceDataLibraryService>();
            this.siteReferenceDataLibraryService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       null,
                       It.IsAny <ISecurityContext>()))
            .Returns(new List <ReferenceDataLibrary>
            {
                this.srdl
            });

            this.quantityKindFactorService = new Mock <IQuantityKindFactorService>();
            this.quantityKindFactorService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       It.IsAny <IEnumerable <Guid> >(),
                       It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>(
                (transaction, partition, iids, context) =>
            {
                iids = iids.ToList();

                return(new List <Thing>
                {
                    this.derivedQkFactor,
                    this.rootQkFactor,
                    this.derivedQkCyclicFactor,
                    this.derivedQkOutsideRdlFactor
                }.Where(qkf => iids.Contains(qkf.Iid)));
            });

            this.quantityKindService = new Mock <IQuantityKindService>();
            this.quantityKindService
            .Setup(x => x.Get(
                       this.npgsqlTransaction,
                       It.IsAny <string>(),
                       It.IsAny <IEnumerable <Guid> >(),
                       It.IsAny <ISecurityContext>()))
            .Returns <NpgsqlTransaction, string, IEnumerable <Guid>, ISecurityContext>(
                (transaction, partition, iids, context) =>
            {
                iids = iids.ToList();

                return(new List <Thing>
                {
                    this.simpleQk,
                    this.derivedQk,
                    this.specializedQk,
                    this.rootQk,
                    this.outsideRdlQk
                }.Where(qk => iids.Contains(qk.Iid)));
            });

            this.sideEffect = new DerivedQuantityKindSideEffect
            {
                SiteReferenceDataLibraryService = this.siteReferenceDataLibraryService.Object,
                QuantityKindFactorService       = this.quantityKindFactorService.Object,
                QuantityKindService             = this.quantityKindService.Object
            };
        }
Пример #7
0
        /// <summary>
        /// Persist the <see cref="SpecializedQuantityKind"/> containment tree to the ORM layer. Update if it already exists.
        /// This is typically used during the import of existing data to the Database.
        /// </summary>
        /// <param name="transaction">
        /// The current <see cref="NpgsqlTransaction"/> to the database.
        /// </param>
        /// <param name="partition">
        /// The database partition (schema) where the requested resource will be stored.
        /// </param>
        /// <param name="specializedQuantityKind">
        /// The <see cref="SpecializedQuantityKind"/> instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool UpsertContainment(NpgsqlTransaction transaction, string partition, SpecializedQuantityKind specializedQuantityKind)
        {
            var results = new List <bool>();

            foreach (var alias in this.ResolveFromRequestCache(specializedQuantityKind.Alias))
            {
                results.Add(this.AliasService.UpsertConcept(transaction, partition, alias, specializedQuantityKind));
            }

            foreach (var definition in this.ResolveFromRequestCache(specializedQuantityKind.Definition))
            {
                results.Add(this.DefinitionService.UpsertConcept(transaction, partition, definition, specializedQuantityKind));
            }

            foreach (var hyperLink in this.ResolveFromRequestCache(specializedQuantityKind.HyperLink))
            {
                results.Add(this.HyperLinkService.UpsertConcept(transaction, partition, hyperLink, specializedQuantityKind));
            }

            return(results.All(x => x));
        }
Пример #8
0
        public void TestGetDerivedQuantityDimensionExpression()
        {
            var quantityKind = new SpecializedQuantityKind();

            Assert.Throws <NotSupportedException>(() => { var test = quantityKind.QuantityDimensionExpression; });
        }
Пример #9
0
        public void Setup()
        {
            this.npgsqlTransaction = null;
            this.securityContext   = new Mock <ISecurityContext>();

            // There is a chain a -> b -> c
            this.specializedQuantityKindC = new SpecializedQuantityKind {
                Iid = Guid.NewGuid()
            };
            this.specializedQuantityKindB =
                new SpecializedQuantityKind {
                Iid = Guid.NewGuid(), General = this.specializedQuantityKindC.Iid
            };
            this.specializedQuantityKindA =
                new SpecializedQuantityKind {
                Iid = Guid.NewGuid(), General = this.specializedQuantityKindB.Iid
            };
            this.specializedQuantityKindD = new SpecializedQuantityKind {
                Iid = Guid.NewGuid()
            };

            // Outside the rdl chain
            this.specializedQuantityKindE = new SpecializedQuantityKind {
                Iid = Guid.NewGuid()
            };

            // There is a chain librayA -> LibraryB
            this.referenceDataLibraryB =
                new SiteReferenceDataLibrary {
                Iid = Guid.NewGuid(), ParameterType = { this.specializedQuantityKindD.Iid }
            };
            this.referenceDataLibraryA = new ModelReferenceDataLibrary
            {
                Iid           = Guid.NewGuid(),
                ParameterType =
                {
                    this.specializedQuantityKindA.Iid,
                    this.specializedQuantityKindB.Iid,
                    this.specializedQuantityKindC.Iid
                },
                RequiredRdl = this.referenceDataLibraryB.Iid
            };

            this.siteReferenceDataLibraryService = new Mock <ISiteReferenceDataLibraryService>();
            this.siteReferenceDataLibraryService
            .Setup(
                x => x.Get(
                    this.npgsqlTransaction,
                    It.IsAny <string>(),
                    null,
                    It.IsAny <ISecurityContext>()))
            .Returns(new List <ReferenceDataLibrary> {
                this.referenceDataLibraryB
            });

            this.specializedQuantityKindService = new Mock <ISpecializedQuantityKindService>();
            this.specializedQuantityKindService
            .Setup(
                x => x.Get(
                    this.npgsqlTransaction,
                    It.IsAny <string>(),
                    new List <Guid>
            {
                this.specializedQuantityKindD.Iid,
                this.specializedQuantityKindA.Iid,
                this.specializedQuantityKindB.Iid,
                this.specializedQuantityKindC.Iid
            },
                    It.IsAny <ISecurityContext>())).Returns(
                new List <SpecializedQuantityKind>
            {
                this.specializedQuantityKindD,
                this.specializedQuantityKindA,
                this.specializedQuantityKindB,
                this.specializedQuantityKindC
            });
        }