Esempio n. 1
0
        public override void Add(CimProperty newProperty)
        {
            if (newProperty == null)
            {
                throw new ArgumentNullException("newProperty");
            }

            MI_Result result = this._instance.InstanceHandle.AddElement(
                newProperty.Name,
                ValueHelpers.ConvertToNativeLayer(newProperty.Value, newProperty.CimType),
                newProperty.CimType.FromCimType(),
                newProperty.Flags.FromCimFlags());

            CimException.ThrowIfMiResultFailure(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Sets a custom server or CIM provider option
        /// </summary>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="optionName"/> is <c>null</c></exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="optionName"/> or <paramref name="optionValue"/> is <c>null</c></exception>
        public void SetCustomOption(string optionName, object optionValue, CimType cimType, bool mustComply)
        {
            if (string.IsNullOrWhiteSpace(optionName))
            {
                throw new ArgumentNullException("optionName");
            }
            if (optionValue == null)
            {
                throw new ArgumentNullException("optionValue");
            }
            this.AssertNotDisposed();

            MI_Value nativeLayerValue;

            try
            {
                nativeLayerValue = ValueHelpers.ConvertToNativeLayer(optionValue, cimType);
                ValueHelpers.ThrowIfMismatchedType(cimType.FromCimType(), nativeLayerValue);
            }
            catch (InvalidCastException e)
            {
                throw new ArgumentException(e.Message, "optionValue", e);
            }
            catch (FormatException e)
            {
                throw new ArgumentException(e.Message, "optionValue", e);
            }
            catch (ArgumentException e)
            {
                throw new ArgumentException(e.Message, "optionValue", e);
            }

            MI_OperationOptionsFlags flags = MI_OperationOptionsFlags.Unused;
            MI_Result result = this.OperationOptionsHandleOnDemand.SetCustomOption(
                optionName,
                cimType.FromCimType(),
                nativeLayerValue,
                mustComply,
                flags);

            CimException.ThrowIfMiResultFailure(result);
        }