Ejemplo n.º 1
0
        internal override unsafe IntPtr ToNative(PinCollection pin, out NativeTypes.FABRIC_PROPERTY_BATCH_OPERATION_KIND nativeOperationType)
        {
            Requires.Argument <object>("PropertyValue", this.PropertyValue).NotNull();

            var nativePutCustomOperation = new NativeTypes.FABRIC_PUT_CUSTOM_PROPERTY_OPERATION[1];

            nativePutCustomOperation[0].PropertyName = pin.AddBlittable(this.PropertyName);

            switch (this.PropertyType)
            {
            case PropertyTypeId.Binary:
                nativePutCustomOperation[0].PropertyTypeId = NativeTypes.FABRIC_PROPERTY_TYPE_ID.FABRIC_PROPERTY_TYPE_BINARY;

                // Create FABRIC_OPERATION_DATA_BUFFER from the byte[]
                var valueAsArray          = this.PropertyValue as byte[];
                var nativeOperationBuffer = new NativeTypes.FABRIC_OPERATION_DATA_BUFFER[1];
                nativeOperationBuffer[0].BufferSize = (uint)valueAsArray.Length;
                nativeOperationBuffer[0].Buffer     = pin.AddBlittable(valueAsArray);

                nativePutCustomOperation[0].PropertyValue = pin.AddBlittable(nativeOperationBuffer);
                break;

            case PropertyTypeId.Double:
                nativePutCustomOperation[0].PropertyTypeId = NativeTypes.FABRIC_PROPERTY_TYPE_ID.FABRIC_PROPERTY_TYPE_DOUBLE;
                var valueAsDouble = new double[1];
                valueAsDouble[0] = (double)this.PropertyValue;
                nativePutCustomOperation[0].PropertyValue = pin.AddBlittable(valueAsDouble);
                break;

            case PropertyTypeId.Guid:
                nativePutCustomOperation[0].PropertyTypeId = NativeTypes.FABRIC_PROPERTY_TYPE_ID.FABRIC_PROPERTY_TYPE_GUID;
                nativePutCustomOperation[0].PropertyValue  = pin.AddBlittable((Guid)this.PropertyValue);
                break;

            case PropertyTypeId.Int64:
                nativePutCustomOperation[0].PropertyTypeId = NativeTypes.FABRIC_PROPERTY_TYPE_ID.FABRIC_PROPERTY_TYPE_INT64;
                var valueAsLong = new long[1];
                valueAsLong[0] = (long)this.PropertyValue;
                nativePutCustomOperation[0].PropertyValue = pin.AddBlittable(valueAsLong);
                break;

            case PropertyTypeId.String:
                nativePutCustomOperation[0].PropertyTypeId = NativeTypes.FABRIC_PROPERTY_TYPE_ID.FABRIC_PROPERTY_TYPE_WSTRING;
                nativePutCustomOperation[0].PropertyValue  = pin.AddBlittable((string)this.PropertyValue);
                break;

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.Error_TypeNotSupported_Formatted, this.PropertyType));
            }

            nativePutCustomOperation[0].PropertyCustomTypeId = pin.AddBlittable(this.CustomTypeId);

            nativeOperationType = NativeTypes.FABRIC_PROPERTY_BATCH_OPERATION_KIND.FABRIC_PROPERTY_BATCH_OPERATION_KIND_PUT_CUSTOM;
            return(pin.AddBlittable(nativePutCustomOperation));
        }
Ejemplo n.º 2
0
                public IntPtr GetData(out uint length)
                {
                    length = 1;
                    GCHandle handle = GCHandle.Alloc(this.DataOut, GCHandleType.Pinned);

                    var operationDataBuffer = new NativeTypes.FABRIC_OPERATION_DATA_BUFFER();

                    operationDataBuffer.BufferSize = (uint)this.DataOut.Length;
                    operationDataBuffer.Buffer     = handle.AddrOfPinnedObject();

                    GCHandle operationHandle = GCHandle.Alloc(operationDataBuffer, GCHandleType.Pinned);

                    return(operationHandle.AddrOfPinnedObject());
                }
Ejemplo n.º 3
0
        public IntPtr GetData(out UInt32 length)
        {
            length = 1;

            if (buffer == null)
            {
                this.buffer = new byte[this.size];
            }

            GCHandle handle = GCHandle.Alloc(this.buffer, GCHandleType.Pinned);

            var operationDataBuffer = new NativeTypes.FABRIC_OPERATION_DATA_BUFFER();

            operationDataBuffer.BufferSize = this.size;
            operationDataBuffer.Buffer     = handle.AddrOfPinnedObject();

            GCHandle operationHandle = GCHandle.Alloc(operationDataBuffer, GCHandleType.Pinned);

            return(operationHandle.AddrOfPinnedObject());
        }
Ejemplo n.º 4
0
            public IntPtr GetData(out uint count)
            {
                if (this.buffers == null || !Enumerable.Any(buffers))
                {
                    count = 0;
                    return(IntPtr.Zero);
                }

                this.pinnedObjects = new PinCollection();
                count = (uint)Enumerable.Count(buffers);
                NativeTypes.FABRIC_OPERATION_DATA_BUFFER[] operationDataBuffers = new NativeTypes.FABRIC_OPERATION_DATA_BUFFER[count];
                IntPtr returnValue = this.pinnedObjects.AddBlittable(operationDataBuffers);
                int    index       = 0;

                foreach (ArraySegment <byte> buffer in buffers)
                {
                    operationDataBuffers[index].Buffer     = this.pinnedObjects.AddBlittable(buffer.Array) + buffer.Offset;
                    operationDataBuffers[index].BufferSize = (uint)buffer.Count;
                    index++;
                }

                return(returnValue);
            }