Пример #1
0
        internal static ItemProperty GetItemProperty(IntPtr pInput, bool deallocate)
        {
            ItemProperty property = null;

            if (pInput != IntPtr.Zero)
            {
                OPCITEMPROPERTY opcitemproperty = (OPCITEMPROPERTY)Marshal.PtrToStructure(pInput, typeof(OPCITEMPROPERTY));
                property = new ItemProperty {
                    ID          = GetPropertyID(opcitemproperty.dwPropertyID),
                    Description = opcitemproperty.szDescription,
                    DataType    = OpcCom.Interop.GetType((VarEnum)opcitemproperty.vtDataType),
                    ItemPath    = null,
                    ItemName    = opcitemproperty.szItemID,
                    Value       = UnmarshalPropertyValue(property.ID, opcitemproperty.vValue),
                    ResultID    = OpcCom.Interop.GetResultID(opcitemproperty.hrErrorID)
                };
                if (opcitemproperty.hrErrorID == -1073479674)
                {
                    property.ResultID = new ResultID(ResultID.Da.E_WRITEONLY, -1073479674L);
                }
                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OPCITEMPROPERTY));
                }
            }
            return(property);
        }
Пример #2
0
        internal static OPCITEMPROPERTY GetItemProperty(ItemProperty input)
        {
            OPCITEMPROPERTY result = default(OPCITEMPROPERTY);

            if (input != null)
            {
                result.dwPropertyID  = input.ID.Code;
                result.szDescription = input.Description;
                result.vtDataType    = (short)OpcCom.Interop.GetType(input.DataType);
                result.vValue        = MarshalPropertyValue(input.ID, input.Value);
                result.wReserved     = 0;
                result.hrErrorID     = OpcCom.Interop.GetResultID(input.ResultID);
                PropertyDescription propertyDescription = PropertyDescription.Find(input.ID);
                if (propertyDescription != null)
                {
                    result.vtDataType = (short)OpcCom.Interop.GetType(propertyDescription.Type);
                }

                if (input.ResultID == ResultID.Da.E_WRITEONLY)
                {
                    result.hrErrorID = -1073479674;
                }
            }

            return(result);
        }
Пример #3
0
        internal static OPCITEMPROPERTIES GetItemProperties(ItemProperty[] input)
        {
            OPCITEMPROPERTIES result = default(OPCITEMPROPERTIES);

            if (input != null && input.Length > 0)
            {
                result.hrErrorID       = 0;
                result.dwReserved      = 0;
                result.dwNumProperties = input.Length;
                result.pItemProperties = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMPROPERTY)) * input.Length);
                bool   flag = false;
                IntPtr ptr  = result.pItemProperties;
                for (int i = 0; i < input.Length; i++)
                {
                    OPCITEMPROPERTY itemProperty = GetItemProperty(input[i]);
                    Marshal.StructureToPtr((object)itemProperty, ptr, fDeleteOld: false);
                    ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(typeof(OPCITEMPROPERTY)));
                    if (input[i].ResultID.Failed())
                    {
                        flag = true;
                    }
                }

                if (flag)
                {
                    result.hrErrorID = 1;
                }
            }

            return(result);
        }
Пример #4
0
        internal static OPCITEMPROPERTY GetItemProperty(ItemProperty input)
        {
            OPCITEMPROPERTY opcitemproperty = new OPCITEMPROPERTY();

            if (input != null)
            {
                opcitemproperty.dwPropertyID  = input.ID.Code;
                opcitemproperty.szDescription = input.Description;
                opcitemproperty.vtDataType    = (short)OpcCom.Interop.GetType(input.DataType);
                opcitemproperty.vValue        = MarshalPropertyValue(input.ID, input.Value);
                opcitemproperty.wReserved     = 0;
                opcitemproperty.hrErrorID     = OpcCom.Interop.GetResultID(input.ResultID);
                PropertyDescription description = PropertyDescription.Find(input.ID);
                if (description != null)
                {
                    opcitemproperty.vtDataType = (short)OpcCom.Interop.GetType(description.Type);
                }
                if (input.ResultID == ResultID.Da.E_WRITEONLY)
                {
                    opcitemproperty.hrErrorID = -1073479674;
                }
            }
            return(opcitemproperty);
        }