/// <summary>
        /// Query the <see cref="RequirementsContainerParameterValue"/> if it exists or create a new one
        /// </summary>
        /// <param name="reqContainer">The <see cref="RequirementsContainer"/> container</param>
        /// <param name="simpleParameterValue">The queried <see cref="RequirementsContainerParameterValue"/></param>
        /// <returns>A value indicating if the <see cref="RequirementsContainerParameterValue"/> existed</returns>
        protected bool TryQueryOrderParameterOrCreate(RequirementsContainer reqContainer, out RequirementsContainerParameterValue simpleParameterValue)
        {
            var parameterValue = this.QueryOrderParameter(reqContainer);

            if (parameterValue != null)
            {
                simpleParameterValue = parameterValue;
                return(true);
            }

            var iteration = reqContainer.GetContainerOfType <Iteration>();
            Tuple <DomainOfExpertise, Participant> domainTuple;

            if (!this.session.OpenIterations.TryGetValue(iteration, out domainTuple) || domainTuple.Item1 == null)
            {
                throw new InvalidOperationException("The domain is null.");
            }

            simpleParameterValue = new RequirementsContainerParameterValue(Guid.NewGuid(), null, null)
            {
                ParameterType = this.reqOrderParameterType,
                Value         = new ValueArray <string>(new[] { int.MaxValue.ToString() }),
            };

            return(false);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RequirementsContainerParameterValueRowViewModel"/> class
 /// </summary>
 /// <param name="simpleParameterValue">The <see cref="RequirementsContainerParameterValue"/> associated with this row </param>
 /// <param name="session">The session</param>
 /// <param name="containerViewModel">The container <see cref="IViewModelBase{T}"/></param>
 /// <param name="valueIndex">The value index</param>
 /// <param name="isReadOnly">Indicates whether the row is read-only</param>
 public RequirementsContainerParameterValueRowViewModel(RequirementsContainerParameterValue simpleParameterValue, ISession session, IViewModelBase <Thing> containerViewModel, int valueIndex, bool isReadOnly)
     : base(simpleParameterValue, session, containerViewModel)
 {
     this.valueIndex    = valueIndex;
     this.IsReadOnly    = isReadOnly;
     this.PossibleScale = new ReactiveList <MeasurementScale>();
     this.SetValues();
     this.PopulatePossibleScale();
 }
Example #3
0
        /// <summary>
        /// Removes a value row
        /// </summary>
        /// <param name="value">The associated <see cref="RequirementsContainerParameterValue"/> to remove</param>
        private void RemoveValue(RequirementsContainerParameterValue value)
        {
            var row = this.simpleParameters.ContainedRows.SingleOrDefault(x => x.Thing == value);

            if (row != null)
            {
                this.simpleParameters.ContainedRows.Remove(row);
                row.Dispose();
            }
        }
        /// <summary>
        /// Query the sorting key from the <paramref name="simpleParameterValue"/>
        /// </summary>
        /// <param name="simpleParameterValue">The <see cref="SimpleParameterValue"/></param>
        /// <returns>The key or max int value if the key could not be parsed</returns>
        protected int getOrderKey(RequirementsContainerParameterValue simpleParameterValue)
        {
            int key;

            if (int.TryParse(simpleParameterValue.Value.FirstOrDefault(), out key))
            {
                return(key);
            }

            return(int.MaxValue);
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RequirementsContainerParameterValueRowViewModel"/> class
 /// </summary>
 /// <param name="parameterValue">The <see cref="RequirementsContainerParameterValue"/> associated with this row </param>
 /// <param name="session">The session</param>
 /// <param name="containerViewModel">The container <see cref="IViewModelBase{T}"/></param>
 public RequirementsContainerParameterValueRowViewModel(RequirementsContainerParameterValue parameterValue, ISession session, IViewModelBase <Thing> containerViewModel)
     : base(parameterValue, session, containerViewModel)
 {
     this.PossibleScales = new ReactiveList <MeasurementScale>();
     this.WhenAnyValue(x => x.Scale).Where(x => x != null).Subscribe(
         x =>
     {
         if (!this.Thing.IsCached())
         {
             this.Thing.Scale = x;
         }
     });
     this.UpdateProperties();
 }
        /// <summary>
        /// Serialize the <see cref="RequirementsContainerParameterValue"/>
        /// </summary>
        /// <param name="requirementsContainerParameterValue">The <see cref="RequirementsContainerParameterValue"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(RequirementsContainerParameterValue requirementsContainerParameterValue)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), requirementsContainerParameterValue.ClassKind)));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](requirementsContainerParameterValue.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](requirementsContainerParameterValue.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](requirementsContainerParameterValue.Iid));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](requirementsContainerParameterValue.ModifiedOn));
            jsonObject.Add("parameterType", this.PropertySerializerMap["parameterType"](requirementsContainerParameterValue.ParameterType));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](requirementsContainerParameterValue.RevisionNumber));
            jsonObject.Add("scale", this.PropertySerializerMap["scale"](requirementsContainerParameterValue.Scale));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](requirementsContainerParameterValue.ThingPreference));
            jsonObject.Add("value", this.PropertySerializerMap["value"](requirementsContainerParameterValue.Value));
            return(jsonObject);
        }
Example #7
0
        /// <summary>
        /// Add a <see cref="RequirementsContainerParameterValue"/> to a <see cref="RequirementsContainer"/>
        /// </summary>
        /// <param name="requirementContainer">The <see cref="RequirementsContainer"/></param>
        /// <param name="value">The <see cref="AttributeValue"/></param>
        private void SetParameterValue(RequirementsContainer requirementContainer, AttributeValue value)
        {
            if (this.datatypeDefMap[value.AttributeDefinition.DatatypeDefinition].ParameterType == null)
            {
                throw new InvalidOperationException("The datatype-definition of an AttributeValue that is mapped to a Parameter-Value shall be mapped to a ParameterType.");
            }

            var theValue   = this.GetAttributeValue(value);
            var valueArray = new string[] { theValue };

            // TODO get mapped scale
            var simpleParameter = new RequirementsContainerParameterValue
            {
                ParameterType = this.datatypeDefMap[value.AttributeDefinition.DatatypeDefinition].ParameterType
            };

            simpleParameter.Value = new ValueArray <string>(valueArray);
            requirementContainer.ParameterValue.Add(simpleParameter);
        }
Example #8
0
        /// <summary>
        /// Handles the drop action of a <see cref="Tuple{ParameterType, MeasurementScale}"/>
        /// </summary>
        /// <param name="tuple">The <see cref="Tuple{ParameterType, MeasurementScale}"/></param>
        protected async Task Drop(Tuple <ParameterType, MeasurementScale> tuple)
        {
            var clone = this.Thing.Clone(false);

            var parameterValue = new RequirementsContainerParameterValue();

            parameterValue.ParameterType = tuple.Item1;
            parameterValue.Scale         = tuple.Item2;
            parameterValue.Value         = new ValueArray <string>(new[] { "-" });

            clone.ParameterValue.Add(parameterValue);

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

            transaction.Create(parameterValue);
            transaction.CreateOrUpdate(clone);

            await this.DalWrite(transaction);
        }
Example #9
0
 /// <summary>
 /// Add an Parameter Value row view model to the list of <see cref="ParameterValue"/>
 /// </summary>
 /// <param name="parameterValue">
 /// The <see cref="ParameterValue"/> that is to be added
 /// </param>
 private RequirementsContainerParameterValueRowViewModel AddParameterValueRowViewModel(RequirementsContainerParameterValue parameterValue)
 {
     return(new RequirementsContainerParameterValueRowViewModel(parameterValue, this.Session, this));
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RequirementsContainerParameterValueDialogViewModel"/> class
 /// </summary>
 /// <param name="simpleParameterValue">
 /// The <see cref="RequirementsContainerParameterValue"/> that is the subject of the current view-model. This is the object
 /// that will be either created, or edited.
 /// </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="IThingDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
 /// </param>
 /// <param name="dialogKind">
 /// The kind of operation this <see cref="IThingDialogViewModel"/> 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>
 public RequirementsContainerParameterValueDialogViewModel(RequirementsContainerParameterValue simpleParameterValue, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind, IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
     : base(simpleParameterValue, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
 {
     this.WhenAnyValue(vm => vm.SelectedScale).Subscribe(_ => this.UpdateOkCanExecute());
     this.Values.CountChanged.Subscribe(_ => this.UpdateOkCanExecute());
 }
Example #11
0
        /// <summary>
        /// Add a row representing a new <see cref="RequirementsContainerParameterValue"/>
        /// </summary>
        /// <param name="value">The associated <see cref="RequirementsContainerParameterValue"/></param>
        private void AddValue(RequirementsContainerParameterValue value)
        {
            var row = new RequirementsContainerParameterValueRowViewModel(value, this.Session, this);

            this.simpleParameters.ContainedRows.Add(row);
        }
Example #12
0
        public void Setup()
        {
            this.session                      = new Mock <ISession>();
            this.permissionService            = new Mock <IPermissionService>();
            this.thingDialogNavigationService = new Mock <IThingDialogNavigationService>();
            this.cache = new ConcurrentDictionary <CacheKey, Lazy <Thing> >();

            this.siteDir        = new SiteDirectory(Guid.NewGuid(), this.cache, this.uri);
            this.modelsetup     = new EngineeringModelSetup(Guid.NewGuid(), this.cache, this.uri);
            this.iterationsetup = new IterationSetup(Guid.NewGuid(), this.cache, this.uri);
            this.srdl           = new SiteReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri);
            this.mrdl           = new ModelReferenceDataLibrary(Guid.NewGuid(), this.cache, this.uri)
            {
                RequiredRdl = this.srdl
            };
            this.siteDir.Model.Add(this.modelsetup);
            this.modelsetup.IterationSetup.Add(this.iterationsetup);
            this.siteDir.SiteReferenceDataLibrary.Add(this.srdl);
            this.modelsetup.RequiredRdl.Add(this.mrdl);
            this.pt = new BooleanParameterType(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.ParameterType.Add(this.pt);

            this.model = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri)
            {
                EngineeringModelSetup = this.modelsetup
            };
            this.iteration = new Iteration(Guid.NewGuid(), this.cache, this.uri)
            {
                IterationSetup = this.iterationsetup
            };
            this.requirement    = new Requirement(Guid.NewGuid(), this.cache, this.uri);
            this.parameterValue = new RequirementsContainerParameterValue(Guid.NewGuid(), this.cache, this.uri)
            {
                ParameterType = this.pt
            };
            this.reqSpec = new RequirementsSpecification(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Requirement.Add(this.requirement);
            this.reqSpec.ParameterValue.Add(this.parameterValue);
            this.grp = new RequirementsGroup(Guid.NewGuid(), this.cache, this.uri);
            this.reqSpec.Group.Add(this.grp);
            this.cache.TryAdd(new CacheKey(this.reqSpec.Iid, null), new Lazy <Thing>(() => this.reqSpec));

            this.model.Iteration.Add(this.iteration);
            this.iteration.RequirementsSpecification.Add(this.reqSpec);

            this.cat1 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.cat1.PermissibleClass.Add(ClassKind.Requirement);
            this.srdl.DefinedCategory.Add(this.cat1);

            this.cat2 = new Category(Guid.NewGuid(), this.cache, this.uri);
            this.srdl.DefinedCategory.Add(this.cat2);

            this.clone = this.reqSpec.Clone(false);

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

            this.thingTransaction = 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.cache.TryAdd(new CacheKey(this.parameterValue.Iid, this.iteration.Iid), new Lazy <Thing>(() => this.parameterValue));
        }