// Token: 0x06000528 RID: 1320 RVA: 0x00013480 File Offset: 0x00011680
        public bool SetValue(string propertyName, object propertyValue, RegistryValueKind valueKind, bool isBestEffort, ReadWriteConstraints constraints)
        {
            bool result = false;

            using (ClusdbMarshalledProperty clusdbMarshalledProperty = ClusdbMarshalledProperty.Create(propertyName, propertyValue, valueKind))
            {
                if (clusdbMarshalledProperty != null)
                {
                    int num = ClusapiMethods.ClusterRegSetValue(this.KeyHandle, clusdbMarshalledProperty.PropertyName, clusdbMarshalledProperty.ValueKind, clusdbMarshalledProperty.PropertyValueIntPtr, clusdbMarshalledProperty.PropertyValueSize);
                    if (num != 0)
                    {
                        if (!isBestEffort)
                        {
                            throw AmExceptionHelper.ConstructClusterApiException(num, "ClusterRegSetValue()", new object[0]);
                        }
                    }
                    else
                    {
                        result = true;
                    }
                }
                else if (!isBestEffort)
                {
                    string typeName = (propertyValue != null) ? propertyValue.GetType().Name : "<null>";
                    throw new ClusterApiException("ClusterRegSetValue(unsupported registry type)", new ClusterUnsupportedRegistryTypeException(typeName));
                }
            }
            return(result);
        }
        // Token: 0x06000539 RID: 1337 RVA: 0x00013B08 File Offset: 0x00011D08
        private object ParseRegistryValue(RegistryValueKind valueType, IntPtr value, int valueSize)
        {
            switch (valueType)
            {
            case RegistryValueKind.String:
                return(Marshal.PtrToStringUni(value));

            case RegistryValueKind.ExpandString:
            case (RegistryValueKind)5:
            case (RegistryValueKind)6:
                break;

            case RegistryValueKind.Binary:
            {
                byte[] array = new byte[valueSize];
                Marshal.Copy(value, array, 0, valueSize);
                return(array);
            }

            case RegistryValueKind.DWord:
                return(Marshal.ReadInt32(value));

            case RegistryValueKind.MultiString:
                return(ClusdbMarshalledProperty.FromIntPtrToStringArray(value, valueSize));

            default:
                if (valueType == RegistryValueKind.QWord)
                {
                    return(Marshal.ReadInt64(value));
                }
                break;
            }
            throw new ClusterApiException("ParseRegistryValue", new ClusterUnsupportedRegistryTypeException(valueType.ToString()));
        }
        // Token: 0x060004FB RID: 1275 RVA: 0x00012F34 File Offset: 0x00011134
        public void SetValue(string propertyName, object propertyValue, RegistryValueKind valueKind)
        {
            ClusdbMarshalledProperty clusdbMarshalledProperty = ClusdbMarshalledProperty.Create(propertyName, propertyValue, valueKind);

            if (clusdbMarshalledProperty == null)
            {
                throw new ClusterApiException("WfcDataStoreBatch.SetValue - property value is null", new ClusterUnsupportedRegistryTypeException("null"));
            }
            this.properties.Add(clusdbMarshalledProperty);
            int num = ClusapiMethods.ClusterRegBatchAddCommand(this.batchHandle, CLUSTER_REG_COMMAND.CLUSREG_SET_VALUE, clusdbMarshalledProperty.PropertyName, clusdbMarshalledProperty.ValueKind, clusdbMarshalledProperty.PropertyValueIntPtr, clusdbMarshalledProperty.PropertyValueSize);

            if (num != 0)
            {
                throw AmExceptionHelper.ConstructClusterApiException(num, "ClusterRegBatchAddCommand(CLUSREG_SET_VALUE)", new object[0]);
            }
            Interlocked.Increment(ref this.totalCommands);
        }
示例#4
0
        public static ClusdbMarshalledProperty Create(string propertyName, object propertyValue, RegistryValueKind valueKind = RegistryValueKind.Unknown)
        {
            int propertyValueSize = 0;

            if (valueKind == RegistryValueKind.Unknown)
            {
                valueKind = Utils.GetValueKind(propertyValue);
            }
            IntPtr intPtr;

            if (propertyValue is string)
            {
                string text = propertyValue as string;
                intPtr            = Marshal.StringToHGlobalUni(text);
                propertyValueSize = (text.Length + 1) * 2;
            }
            else if (propertyValue is string[])
            {
                string[] strings = propertyValue as string[];
                intPtr = ClusdbMarshalledProperty.FromStringArrayToIntPtr(strings, out propertyValueSize);
            }
            else if (propertyValue is IEnumerable <string> )
            {
                string[] strings2 = (propertyValue as IEnumerable <string>).ToArray <string>();
                intPtr = ClusdbMarshalledProperty.FromStringArrayToIntPtr(strings2, out propertyValueSize);
            }
            else if (propertyValue is byte[])
            {
                intPtr = ClusdbMarshalledProperty.FromByteArrayToIntPtr(propertyValue as byte[], out propertyValueSize);
            }
            else if (propertyValue is int)
            {
                intPtr = Marshal.AllocHGlobal(4);
                Marshal.WriteInt32(intPtr, Convert.ToInt32(propertyValue));
                propertyValueSize = 4;
            }
            else if (propertyValue is uint)
            {
                intPtr = Marshal.AllocHGlobal(4);
                Marshal.WriteInt32(intPtr, (int)Convert.ToUInt32(propertyValue));
                propertyValueSize = 4;
            }
            else if (propertyValue is long)
            {
                intPtr = Marshal.AllocHGlobal(8);
                Marshal.WriteInt64(intPtr, Convert.ToInt64(propertyValue));
                propertyValueSize = 8;
            }
            else
            {
                if (!(propertyValue is ulong))
                {
                    return(null);
                }
                intPtr = Marshal.AllocHGlobal(8);
                Marshal.WriteInt64(intPtr, (long)Convert.ToUInt64(propertyValue));
                propertyValueSize = 8;
            }
            return(new ClusdbMarshalledProperty
            {
                PropertyName = propertyName,
                PropertyValue = propertyValue,
                ValueKind = valueKind,
                PropertyValueIntPtr = intPtr,
                PropertyValueSize = propertyValueSize
            });
        }