/// <summary>
        /// Serialize the <see cref="SampledFunctionParameterType"/>
        /// </summary>
        /// <param name="sampledFunctionParameterType">The <see cref="SampledFunctionParameterType"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(SampledFunctionParameterType sampledFunctionParameterType)
        {
            var jsonObject = new JObject();

            jsonObject.Add("alias", this.PropertySerializerMap["alias"](sampledFunctionParameterType.Alias.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("category", this.PropertySerializerMap["category"](sampledFunctionParameterType.Category.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), sampledFunctionParameterType.ClassKind)));
            jsonObject.Add("definition", this.PropertySerializerMap["definition"](sampledFunctionParameterType.Definition.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("degreeOfInterpolation", this.PropertySerializerMap["degreeOfInterpolation"](sampledFunctionParameterType.DegreeOfInterpolation));
            jsonObject.Add("dependentParameterType", this.PropertySerializerMap["dependentParameterType"](sampledFunctionParameterType.DependentParameterType.OrderBy(x => x, this.orderedItemComparer)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](sampledFunctionParameterType.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](sampledFunctionParameterType.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("hyperLink", this.PropertySerializerMap["hyperLink"](sampledFunctionParameterType.HyperLink.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](sampledFunctionParameterType.Iid));
            jsonObject.Add("independentParameterType", this.PropertySerializerMap["independentParameterType"](sampledFunctionParameterType.IndependentParameterType.OrderBy(x => x, this.orderedItemComparer)));
            jsonObject.Add("interpolationPeriod", this.PropertySerializerMap["interpolationPeriod"](sampledFunctionParameterType.InterpolationPeriod));
            jsonObject.Add("isDeprecated", this.PropertySerializerMap["isDeprecated"](sampledFunctionParameterType.IsDeprecated));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](sampledFunctionParameterType.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](sampledFunctionParameterType.Name));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](sampledFunctionParameterType.RevisionNumber));
            jsonObject.Add("shortName", this.PropertySerializerMap["shortName"](sampledFunctionParameterType.ShortName));
            jsonObject.Add("symbol", this.PropertySerializerMap["symbol"](sampledFunctionParameterType.Symbol));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](sampledFunctionParameterType.ThingPreference));
            return(jsonObject);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SampledFunctionParameterTypeValueSetGridViewModel" /> class.
        /// </summary>
        /// <param name="thing">The <see cref="IValueSet" /></param>
        public SampledFunctionParameterTypeValueSetGridViewModel(IValueSet thing, SampledFunctionParameterType parameterType, bool isValueSetEditable)
        {
            this.ValueSet           = thing;
            this.ParameterType      = parameterType;
            this.IsValueSetEditable = isValueSetEditable;

            this.IsParameterOrOverride = false;

            this.ValueColumns = new ReactiveList <ParameterTypeAllocationColumn>
            {
                ChangeTrackingEnabled = true
            };
        }
        /// <summary>
        /// Verify that the <paramref name="parameterType"/> is compatible with this dst adapter
        /// </summary>
        /// <param name="parameterType">The <see cref="SampledFunctionParameterType"/></param>
        /// <param name="value">The <see cref="object"/> value</param>
        /// <param name="scale">The <see cref="MeasurementScale"/></param>
        /// <returns>A value indicating if the <paramref name="parameterType"/> is compliant</returns>
        public static bool Validate(this SampledFunctionParameterType parameterType, object value, MeasurementScale scale = null)
        {
            if (!parameterType.HasTheRightNumberOfParameterType(out var independantParameterType, out var dependantParameterType))
            {
                return(false);
            }

            var independentValidation = independantParameterType.IsQuantityKindOrText();
            var measurementScale      = scale ?? (dependantParameterType as QuantityKind)?.DefaultScale;
            var validate            = dependantParameterType.Validate(value, measurementScale);
            var dependentValidation = validate.ResultKind == ValidationResultKind.Valid;

            return(independentValidation && dependentValidation);
        }
        /// <summary>
        /// Verify that the <paramref name="parameterType"/> has the right number of IndependentParameterType and DependentParameterType
        /// </summary>
        /// <param name="parameterType">The <see cref="SampledFunctionParameterType"/></param>
        /// <param name="independantParameterType">The single IndependantParameterType if the output is true</param>
        /// <param name="dependantParameterType">The single dependantParameterType if the output is true</param>
        /// <returns>A value indicating if <see cref="SampledFunctionParameterType"/> has the right number of IndependentParameterType and DependentParameterType</returns>
        public static bool HasTheRightNumberOfParameterType(this SampledFunctionParameterType parameterType, out ParameterType independantParameterType, out ParameterType dependantParameterType)
        {
            independantParameterType = null;
            dependantParameterType   = null;

            if (parameterType.IndependentParameterType.Count == 1 && parameterType.DependentParameterType.Count == 1 &&
                parameterType.IndependentParameterType.FirstOrDefault()?.ParameterType is { } iParameterType &&
                parameterType.DependentParameterType.FirstOrDefault()?.ParameterType is { } dParameterType)
            {
                independantParameterType = iParameterType;
                dependantParameterType   = dParameterType;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Recursive function that computes the number of values for a <see cref="SampledFunctionParameterType" />
        /// </summary>
        /// <param name="sampledFunctionParameterType">
        /// The <see cref="SampledFunctionParameterType" /> for which the number of values needs to be computed
        /// </param>
        /// <returns>
        /// an integer representing the number of values
        /// </returns>
        private int ComputeNumberOfValuesForSampledFunctionParameterType(SampledFunctionParameterType sampledFunctionParameterType)
        {
            var result = 0;

            if (sampledFunctionParameterType.IndependentParameterType.Count == 0)
            {
                Logger.Warn("The SampledFunctionParameterType with Iid {0} does not contain any IndependetnParameterTypeAssignments", sampledFunctionParameterType.Iid);
                return(0);
            }

            if (sampledFunctionParameterType.DependentParameterType.Count == 0)
            {
                Logger.Warn("The SampledFunctionParameterType with Iid {0} does not contain any DependetnParameterTypeAssignments", sampledFunctionParameterType.Iid);
                return(0);
            }

            // handle all independent
            foreach (var parameterTypeComponentKeyVaulePair in sampledFunctionParameterType.IndependentParameterType)
            {
                var parameterTypeAssignmentIid = Guid.Parse(parameterTypeComponentKeyVaulePair.V.ToString());

                if (!this.parameterTypeAssignmentCache.TryGetValue(parameterTypeAssignmentIid, out var parameterTypeAssignment))
                {
                    var exceptionMessage = $"The ParameterTypeAssignment with Iid {parameterTypeAssignmentIid} could not be found in the DefaultValueArrayFactory cache. A Default ValueArray could not be created";
                    Logger.Error(exceptionMessage);
                    throw new KeyNotFoundException(exceptionMessage);
                }

                if (!this.parameterTypeCache.TryGetValue(parameterTypeAssignment.ParameterType, out var parameterType))
                {
                    var exceptionMessage = $"The ParameterType {parameterTypeAssignment.ParameterType} of the ParameterTypeAssignment {((Thing)parameterTypeAssignment).Iid} could not be found in the DefaultValueArrayFactory cache. A Default ValueArray could not be created";
                    Logger.Error(exceptionMessage);
                    throw new KeyNotFoundException(exceptionMessage);
                }

                if (parameterType is ScalarParameterType)
                {
                    result++;
                }
                else
                {
                    result += this.ComputeNumberOfValuesForCompoundParamterType(parameterType as CompoundParameterType);
                }
            }

            // handle all dependent
            foreach (var parameterTypeComponentKeyVaulePair in sampledFunctionParameterType.DependentParameterType)
            {
                var parameterTypeAssignmentIid = Guid.Parse(parameterTypeComponentKeyVaulePair.V.ToString());

                if (!this.parameterTypeAssignmentCache.TryGetValue(parameterTypeAssignmentIid, out var parameterTypeAssignment))
                {
                    var exceptionMessage = $"The ParameterTypeAssignment with Iid {parameterTypeAssignmentIid} could not be found in the DefaultValueArrayFactory cache. A Default ValueArray could not be created";
                    Logger.Error(exceptionMessage);
                    throw new KeyNotFoundException(exceptionMessage);
                }

                if (!this.parameterTypeCache.TryGetValue(parameterTypeAssignment.ParameterType, out var parameterType))
                {
                    var exceptionMessage = $"The ParameterType {parameterTypeAssignment.ParameterType} of the ParameterTypeAssignment {((Thing)parameterTypeAssignment).Iid} could not be found in the DefaultValueArrayFactory cache. A Default ValueArray could not be created";
                    Logger.Error(exceptionMessage);
                    throw new KeyNotFoundException(exceptionMessage);
                }

                if (parameterType is ScalarParameterType)
                {
                    result++;
                }
                else
                {
                    result += this.ComputeNumberOfValuesForCompoundParamterType(parameterType as CompoundParameterType);
                }
            }

            return(result);
        }
예제 #6
0
        public void VerifyIsValid()
        {
            var viewModel = new VariableRowViewModel((new ReferenceDescription()
            {
                NodeId = new ExpandedNodeId(Guid.NewGuid()),
                DisplayName = new LocalizedText("", "DummyVariable0")
            }, new DataValue()
            {
                Value = .2
            }));

            Assert.IsFalse(viewModel.IsValid());
            Assert.IsNull(viewModel.IsVariableMappingValid);
            viewModel.SelectedValues.Add(new TimeTaggedValueRowViewModel(131234, .01));
            Assert.IsFalse(viewModel.IsValid());
            Assert.IsNull(viewModel.IsVariableMappingValid);
            viewModel.SelectedParameterType = new DateTimeParameterType();
            Assert.IsTrue(viewModel.IsValid());
            Assert.IsFalse(viewModel.IsVariableMappingValid);

            var sampledFunctionParameterType = new SampledFunctionParameterType(Guid.NewGuid(), null, null)
            {
                Name = "TextXQuantity",
                IndependentParameterType =
                {
                    new IndependentParameterTypeAssignment(Guid.NewGuid(), null, null)
                    {
                        ParameterType = new SimpleQuantityKind(Guid.NewGuid(),null, null)
                        {
                            Name = "Time",                                 PossibleScale =
                            {
                                new RatioScale()
                                {
                                    Name = "millisecond"
                                },
                                new RatioScale()
                                {
                                    Name = "second"
                                },
                                new RatioScale()
                                {
                                    Name = "minute"
                                },
                                new RatioScale()
                                {
                                    Name = "hour"
                                },
                                new RatioScale()
                                {
                                    Name = "Day"
                                }
                            }
                        }
                    }
                },

                DependentParameterType =
                {
                    new DependentParameterTypeAssignment(Guid.NewGuid(), null, null)
                    {
                        ParameterType = new DateTimeParameterType(Guid.NewGuid(),null, null)
                        {
                            Name = "DependentDateTime"
                        }
                    }
                }
            };

            viewModel.SelectedParameterType = sampledFunctionParameterType;
            Assert.IsTrue(viewModel.IsValid());
            Assert.IsFalse(viewModel.IsVariableMappingValid);

            sampledFunctionParameterType.DependentParameterType.Clear();
            var scale = new RatioScale()
            {
                NumberSet = NumberSetKind.REAL_NUMBER_SET
            };

            sampledFunctionParameterType.DependentParameterType.Add(
                new DependentParameterTypeAssignment(Guid.NewGuid(), null, null)
            {
                ParameterType = new SimpleQuantityKind(Guid.NewGuid(), null, null)
                {
                    Name = "DependentQuantityKing", DefaultScale = scale, PossibleScale = { scale }
                }
            });

            viewModel.SelectedScale = scale;
            Assert.IsTrue(viewModel.IsValid());
            Assert.IsTrue(viewModel.IsVariableMappingValid);
            viewModel.SelectedParameterType = new SimpleQuantityKind()
            {
                PossibleScale = { scale }, DefaultScale = scale
            };
            Assert.IsTrue(viewModel.IsValid());
            Assert.IsTrue(viewModel.IsVariableMappingValid);
        }
예제 #7
0
        /// <summary>
        /// Persist the <see cref="SampledFunctionParameterType"/> 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="sampledFunctionParameterType">
        /// The <see cref="SampledFunctionParameterType"/> instance to persist.
        /// </param>
        /// <returns>
        /// True if the persistence was successful.
        /// </returns>
        private bool UpsertContainment(NpgsqlTransaction transaction, string partition, SampledFunctionParameterType sampledFunctionParameterType)
        {
            var results = new List <bool>();

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

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

            foreach (var dependentParameterType in this.ResolveFromRequestCache(sampledFunctionParameterType.DependentParameterType))
            {
                results.Add(this.DependentParameterTypeService.UpsertConcept(transaction, partition, (DependentParameterTypeAssignment)dependentParameterType.V, sampledFunctionParameterType, dependentParameterType.K));
            }

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

            foreach (var independentParameterType in this.ResolveFromRequestCache(sampledFunctionParameterType.IndependentParameterType))
            {
                results.Add(this.IndependentParameterTypeService.UpsertConcept(transaction, partition, (IndependentParameterTypeAssignment)independentParameterType.V, sampledFunctionParameterType, independentParameterType.K));
            }

            return(results.All(x => x));
        }
예제 #8
0
        public void Setup()
        {
            this.domain = new DomainOfExpertise();

            this.modelReferenceDataLibrary = new ModelReferenceDataLibrary();

            this.iteration = new Iteration()
            {
                Element = { new ElementDefinition()
                            {
                                Owner = this.domain
                            } },
                Option    = { new Option() },
                Container = new EngineeringModel()
                {
                    EngineeringModelSetup = new EngineeringModelSetup()
                    {
                        RequiredRdl = { this.modelReferenceDataLibrary },
                        Container   = new SiteReferenceDataLibrary()
                        {
                            Container = new SiteDirectory()
                        }
                    }
                }
            };

            this.hubController = new Mock <IHubController>();
            this.hubController.Setup(x => x.OpenIteration).Returns(this.iteration);
            this.hubController.Setup(x => x.CurrentDomainOfExpertise).Returns(this.domain);
            this.hubController.Setup(x => x.GetSiteDirectory()).Returns(new SiteDirectory());

            this.dstController = new Mock <IDstController>();
            this.dstController.Setup(x => x.Map(It.IsAny <List <VariableRowViewModel> >()));

            this.variableRowViewModels = new List <VariableRowViewModel>
            {
                new VariableRowViewModel(
                    (new ReferenceDescription()
                {
                    NodeId = new ExpandedNodeId(Guid.NewGuid()),
                    DisplayName = new LocalizedText("", "el.DummyVariable0")
                }, new DataValue()
                {
                    Value = .2
                })),

                new VariableRowViewModel(
                    (new ReferenceDescription()
                {
                    NodeId = new ExpandedNodeId(Guid.NewGuid()),
                    DisplayName = new LocalizedText("", "res0.DummyVariable1")
                }, new DataValue())),

                new VariableRowViewModel(
                    (new ReferenceDescription()
                {
                    NodeId = new ExpandedNodeId(Guid.NewGuid()),
                    DisplayName = new LocalizedText("", "trans0.Gain.DummyVariable2")
                }, new DataValue()))
            };

            this.scale = new RatioScale()
            {
                Name = "scale", NumberSet = NumberSetKind.REAL_NUMBER_SET
            };

            this.parameterType = new SampledFunctionParameterType()
            {
                Name = "TextXQuantity",
                IndependentParameterType =
                {
                    new IndependentParameterTypeAssignment()
                    {
                        ParameterType = new TextParameterType()
                        {
                            Name = "IndependentText"
                        }
                    }
                },

                DependentParameterType =
                {
                    new DependentParameterTypeAssignment()
                    {
                        ParameterType = new SimpleQuantityKind()
                        {
                            Name          = "DependentQuantityKing",
                            DefaultScale  = this.scale,
                            PossibleScale ={ this.scale                     }
                        }
                    }
                }
            };

            var invalidParameterType = new SampledFunctionParameterType()
            {
                Name = "TextXQuantity",
                IndependentParameterType =
                {
                    new IndependentParameterTypeAssignment()
                    {
                        ParameterType = new CompoundParameterType()
                        {
                            Name = "IndependentText"
                        }
                    }
                },

                DependentParameterType =
                {
                    new DependentParameterTypeAssignment()
                    {
                        ParameterType = new SimpleQuantityKind()
                        {
                            Name = "DependentQuantityKing"
                        }
                    }
                }
            };

            this.quantityKindParameterType = new SimpleQuantityKind()
            {
                DefaultScale  = this.scale,
                PossibleScale = { this.scale },
                Name          = "SimpleQuantityKind"
            };

            this.modelReferenceDataLibrary.ParameterType.Add(this.parameterType);
            this.modelReferenceDataLibrary.ParameterType.Add(invalidParameterType);
            this.statusBar = new Mock <IStatusBarControlViewModel>();

            this.navigationService = new Mock <INavigationService>();

            this.viewModel = new DstMappingConfigurationDialogViewModel(
                this.hubController.Object, this.dstController.Object, this.statusBar.Object, this.navigationService.Object);

            this.viewModel.Initialize();

            this.viewModel.Variables.AddRange(this.variableRowViewModels);

            this.closeBehavior = new Mock <ICloseWindowBehavior>();
            this.closeBehavior.Setup(x => x.Close());
        }