/// <summary>
 /// Set the values of the <see cref="Dto.ParameterValueSetBase"/> with the values of a original <see cref="ParameterValueSetBase"/>
 /// </summary>
 /// <param name="valueSet">The <see cref="Dto.ParameterValueSetBase"/></param>
 /// <param name="originalValueSet">The <see cref="ParameterValueSetBase"/></param>
 private void SetValueSetValues(Dto.ParameterValueSetBase valueSet, ParameterValueSetBase originalValueSet)
 {
     valueSet.Manual      = originalValueSet.Manual;
     valueSet.Reference   = originalValueSet.Reference;
     valueSet.ValueSwitch = originalValueSet.ValueSwitch;
     valueSet.Formula     = originalValueSet.Formula;
     valueSet.Computed    = originalValueSet.Computed;
 }
        /// <summary>
        /// Insert a new database record from the supplied data transfer object.
        /// </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="parameterValueSetBase">
        /// The parameterValueSetBase DTO that is to be persisted.
        /// </param>
        /// <param name="container">
        /// The container of the DTO to be persisted.
        /// </param>
        /// <returns>
        /// True if the concept was successfully persisted.
        /// </returns>
        public virtual bool Write(NpgsqlTransaction transaction, string partition, CDP4Common.DTO.ParameterValueSetBase parameterValueSetBase, CDP4Common.DTO.Thing container = null)
        {
            bool isHandled;
            var  valueTypeDictionaryAdditions = new Dictionary <string, string>();
            var  beforeWrite = this.BeforeWrite(transaction, partition, parameterValueSetBase, container, out isHandled, valueTypeDictionaryAdditions);

            if (!isHandled)
            {
                beforeWrite = beforeWrite && base.Write(transaction, partition, parameterValueSetBase, container);

                var valueTypeDictionaryContents = new Dictionary <string, string>
                {
                    { "Computed", !this.IsDerived(parameterValueSetBase, "Computed") ? parameterValueSetBase.Computed.ToHstoreString() : string.Empty },
                    { "Formula", !this.IsDerived(parameterValueSetBase, "Formula") ? parameterValueSetBase.Formula.ToHstoreString() : string.Empty },
                    { "Manual", !this.IsDerived(parameterValueSetBase, "Manual") ? parameterValueSetBase.Manual.ToHstoreString() : string.Empty },
                    { "Published", !this.IsDerived(parameterValueSetBase, "Published") ? parameterValueSetBase.Published.ToHstoreString() : string.Empty },
                    { "Reference", !this.IsDerived(parameterValueSetBase, "Reference") ? parameterValueSetBase.Reference.ToHstoreString() : string.Empty },
                    { "ValueSwitch", !this.IsDerived(parameterValueSetBase, "ValueSwitch") ? parameterValueSetBase.ValueSwitch.ToString() : string.Empty },
                }.Concat(valueTypeDictionaryAdditions).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

                using (var command = new NpgsqlCommand())
                {
                    var sqlBuilder = new System.Text.StringBuilder();

                    sqlBuilder.AppendFormat("INSERT INTO \"{0}\".\"ParameterValueSetBase\"", partition);
                    sqlBuilder.AppendFormat(" (\"Iid\", \"ValueTypeDictionary\", \"ActualOption\", \"ActualState\")");
                    sqlBuilder.AppendFormat(" VALUES (:iid, :valueTypeDictionary, :actualOption, :actualState);");

                    command.Parameters.Add("iid", NpgsqlDbType.Uuid).Value = parameterValueSetBase.Iid;
                    command.Parameters.Add("valueTypeDictionary", NpgsqlDbType.Hstore).Value = valueTypeDictionaryContents;
                    command.Parameters.Add("actualOption", NpgsqlDbType.Uuid).Value          = !this.IsDerived(parameterValueSetBase, "ActualOption") ? Utils.NullableValue(parameterValueSetBase.ActualOption) : Utils.NullableValue(null);
                    command.Parameters.Add("actualState", NpgsqlDbType.Uuid).Value           = !this.IsDerived(parameterValueSetBase, "ActualState") ? Utils.NullableValue(parameterValueSetBase.ActualState) : Utils.NullableValue(null);

                    command.CommandText = sqlBuilder.ToString();
                    command.Connection  = transaction.Connection;
                    command.Transaction = transaction;

                    this.ExecuteAndLogCommand(command);
                }
            }

            return(this.AfterWrite(beforeWrite, transaction, partition, parameterValueSetBase, container));
        }
Пример #3
0
        /// <summary>
        /// Obfuscates an <see cref="CDP4Common.DTO.ParameterValueSetBase" /> object
        /// </summary>
        /// <param name="thing">The <see cref="CDP4Common.DTO.ParameterValueSetBase" /> to obfuscate.</param>
        private void ObfuscateValueSet(ParameterValueSetBase thing)
        {
            var valueArrayCount = thing.Manual.Count;

            var newList = new List <string>();

            for (var i = 0; i < valueArrayCount; i++)
            {
                newList.Add("-");
            }

            var newArray = new ValueArray <string>(newList);

            thing.Manual      = newArray;
            thing.Reference   = newArray;
            thing.Computed    = newArray;
            thing.Published   = newArray;
            thing.Formula     = newArray;
            thing.ValueSwitch = ParameterSwitchKind.MANUAL;

            this.obfuscatedCache.Add(thing.Iid);
        }
        /// <summary>
        /// Create a new <see cref="ParameterSubscriptionValueSet"/> from the updated <see cref="ParameterValueSetBase"/>
        /// </summary>
        /// <param name="oldValue">The old <see cref="ParameterSubscriptionValueSet"/></param>
        /// <param name="valueSetBase">The subscribed <see cref="ParameterValueSetBase"/></param>
        /// <param name="container">The container</param>
        /// <param name="transaction">The current transaction</param>
        /// <param name="partition">The current partition</param>
        private void CreateParameterSubscriptionValueSet(ParameterSubscriptionValueSet oldValue, ParameterValueSetBase valueSetBase, ParameterSubscription container, NpgsqlTransaction transaction, string partition)
        {
            var isOldValueNull = oldValue == null;
            var newValueSet    = new ParameterSubscriptionValueSet(Guid.NewGuid(), 1)
            {
                Manual             = new ValueArray <string>((oldValue == null) ? valueSetBase.Manual : oldValue.Manual),
                ValueSwitch        = isOldValueNull ? CDP4Common.EngineeringModelData.ParameterSwitchKind.MANUAL : oldValue.ValueSwitch,
                SubscribedValueSet = valueSetBase.Iid
            };

            this.ParameterSubscriptionValueSetService.CreateConcept(transaction, partition, newValueSet, container);
        }