internal static ItemPropertyCollection[] GetItemPropertyCollections(ref IntPtr pInput, int count, bool deallocate) { ItemPropertyCollection[] propertysArray = null; if ((pInput != IntPtr.Zero) && (count > 0)) { propertysArray = new ItemPropertyCollection[count]; IntPtr ptr = pInput; for (int i = 0; i < count; i++) { OPCITEMPROPERTIES input = (OPCITEMPROPERTIES)Marshal.PtrToStructure(ptr, typeof(OPCITEMPROPERTIES)); propertysArray[i] = new ItemPropertyCollection(); propertysArray[i].ItemPath = null; propertysArray[i].ItemName = null; propertysArray[i].ResultID = OpcCom.Interop.GetResultID(input.hrErrorID); ItemProperty[] itemProperties = GetItemProperties(ref input, deallocate); if (itemProperties != null) { propertysArray[i].AddRange(itemProperties); } if (deallocate) { Marshal.DestroyStructure(ptr, typeof(OPCITEMPROPERTIES)); } ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCITEMPROPERTIES))); } if (deallocate) { Marshal.FreeCoTaskMem(pInput); pInput = IntPtr.Zero; } } return(propertysArray); }
internal static OPCITEMPROPERTIES GetItemProperties(ItemProperty[] input) { OPCITEMPROPERTIES opcitemproperties = new OPCITEMPROPERTIES(); if ((input != null) && (input.Length > 0)) { opcitemproperties.hrErrorID = 0; opcitemproperties.dwReserved = 0; opcitemproperties.dwNumProperties = input.Length; opcitemproperties.pItemProperties = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMPROPERTY)) * input.Length); bool flag = false; IntPtr pItemProperties = opcitemproperties.pItemProperties; for (int i = 0; i < input.Length; i++) { Marshal.StructureToPtr(GetItemProperty(input[i]), pItemProperties, false); pItemProperties = (IntPtr)(pItemProperties.ToInt32() + Marshal.SizeOf(typeof(OPCITEMPROPERTY))); if (input[i].ResultID.Failed()) { flag = true; } } if (flag) { opcitemproperties.hrErrorID = 1; } } return(opcitemproperties); }
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); }
internal static ItemProperty[] GetItemProperties(ref OPCITEMPROPERTIES input, bool deallocate) { ItemProperty[] array = null; if (input.dwNumProperties > 0) { array = new ItemProperty[input.dwNumProperties]; IntPtr pInput = input.pItemProperties; for (int i = 0; i < array.Length; i++) { try { array[i] = GetItemProperty(pInput, deallocate); } catch (Exception ex) { array[i] = new ItemProperty(); array[i].Description = ex.Message; array[i].ResultID = ResultID.E_FAIL; } pInput = (IntPtr)(pInput.ToInt64() + Marshal.SizeOf(typeof(OPCITEMPROPERTY))); } if (deallocate) { Marshal.FreeCoTaskMem(input.pItemProperties); input.pItemProperties = IntPtr.Zero; } } return(array); }
private static OpcDaItemProperties ReadItemProperties(ref OPCITEMPROPERTIES itemProperties) { var result = new OpcDaItemProperties { ErrorId = itemProperties.hrErrorID, Properties = ReadItemProperties(ref itemProperties.pItemProperties, itemProperties.dwNumProperties) }; return(result); }
internal static ItemProperty[] GetItemProperties(ref OPCITEMPROPERTIES input, bool deallocate) { ItemProperty[] propertyArray = null; if (input.dwNumProperties > 0) { propertyArray = new ItemProperty[input.dwNumProperties]; IntPtr pItemProperties = input.pItemProperties; for (int i = 0; i < propertyArray.Length; i++) { propertyArray[i] = GetItemProperty(pItemProperties, deallocate); pItemProperties = (IntPtr)(pItemProperties.ToInt32() + Marshal.SizeOf(typeof(OPCITEMPROPERTY))); } if (deallocate) { Marshal.FreeCoTaskMem(input.pItemProperties); input.pItemProperties = IntPtr.Zero; } } return(propertyArray); }
internal static IntPtr GetItemPropertyCollections(ItemPropertyCollection[] input) { IntPtr zero = IntPtr.Zero; if ((input != null) && (input.Length > 0)) { zero = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMPROPERTIES)) * input.Length); IntPtr ptr = zero; for (int i = 0; i < input.Length; i++) { OPCITEMPROPERTIES structure = new OPCITEMPROPERTIES(); if (input[i].Count > 0) { structure = GetItemProperties((ItemProperty[])input[i].ToArray(typeof(ItemProperty))); } structure.hrErrorID = OpcCom.Interop.GetResultID(input[i].ResultID); Marshal.StructureToPtr(structure, ptr, false); ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCITEMPROPERTIES))); } } return(zero); }
internal static IntPtr GetItemPropertyCollections(ItemPropertyCollection[] input) { IntPtr intPtr = IntPtr.Zero; if (input != null && input.Length > 0) { intPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(OPCITEMPROPERTIES)) * input.Length); IntPtr ptr = intPtr; for (int i = 0; i < input.Length; i++) { OPCITEMPROPERTIES oPCITEMPROPERTIES = default(OPCITEMPROPERTIES); if (input[i].Count > 0) { oPCITEMPROPERTIES = GetItemProperties((ItemProperty[])input[i].ToArray(typeof(ItemProperty))); } oPCITEMPROPERTIES.hrErrorID = OpcCom.Interop.GetResultID(input[i].ResultID); Marshal.StructureToPtr((object)oPCITEMPROPERTIES, ptr, fDeleteOld: false); ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(typeof(OPCITEMPROPERTIES))); } } return(intPtr); }