Example #1
0
 internal static Condition[] GetConditions(ref IntPtr pInput, int count, bool deallocate)
 {
     Condition[] conditionArray = null;
     if ((pInput != IntPtr.Zero) && (count > 0))
     {
         conditionArray = new Condition[count];
         IntPtr ptr = pInput;
         for (int i = 0; i < count; i++)
         {
             OPCCONDITIONSTATE opcconditionstate = (OPCCONDITIONSTATE)Marshal.PtrToStructure(ptr, typeof(OPCCONDITIONSTATE));
             conditionArray[i]                                = new Condition();
             conditionArray[i].State                          = opcconditionstate.wState;
             conditionArray[i].Quality                        = new Quality(opcconditionstate.wQuality);
             conditionArray[i].Comment                        = opcconditionstate.szComment;
             conditionArray[i].AcknowledgerID                 = opcconditionstate.szAcknowledgerID;
             conditionArray[i].CondLastActive                 = OpcCom.Interop.GetFILETIME(Convert(opcconditionstate.ftCondLastActive));
             conditionArray[i].CondLastInactive               = OpcCom.Interop.GetFILETIME(Convert(opcconditionstate.ftCondLastInactive));
             conditionArray[i].SubCondLastActive              = OpcCom.Interop.GetFILETIME(Convert(opcconditionstate.ftSubCondLastActive));
             conditionArray[i].LastAckTime                    = OpcCom.Interop.GetFILETIME(Convert(opcconditionstate.ftLastAckTime));
             conditionArray[i].ActiveSubCondition.Name        = opcconditionstate.szActiveSubCondition;
             conditionArray[i].ActiveSubCondition.Definition  = opcconditionstate.szASCDefinition;
             conditionArray[i].ActiveSubCondition.Severity    = opcconditionstate.dwASCSeverity;
             conditionArray[i].ActiveSubCondition.Description = opcconditionstate.szASCDescription;
             string[] strArray  = OpcCom.Interop.GetUnicodeStrings(ref opcconditionstate.pszSCNames, opcconditionstate.dwNumSCs, deallocate);
             int[]    numArray  = OpcCom.Interop.GetInt32s(ref opcconditionstate.pdwSCSeverities, opcconditionstate.dwNumSCs, deallocate);
             string[] strArray2 = OpcCom.Interop.GetUnicodeStrings(ref opcconditionstate.pszSCDefinitions, opcconditionstate.dwNumSCs, deallocate);
             string[] strArray3 = OpcCom.Interop.GetUnicodeStrings(ref opcconditionstate.pszSCDescriptions, opcconditionstate.dwNumSCs, deallocate);
             conditionArray[i].SubConditions.Clear();
             if (opcconditionstate.dwNumSCs > 0)
             {
                 for (int j = 0; j < strArray.Length; j++)
                 {
                     SubCondition condition = new SubCondition {
                         Name        = strArray[j],
                         Severity    = numArray[j],
                         Definition  = strArray2[j],
                         Description = strArray3[j]
                     };
                     conditionArray[i].SubConditions.Add(condition);
                 }
             }
             object[] objArray  = OpcCom.Interop.GetVARIANTs(ref opcconditionstate.pEventAttributes, opcconditionstate.dwNumEventAttrs, deallocate);
             int[]    numArray2 = OpcCom.Interop.GetInt32s(ref opcconditionstate.pErrors, opcconditionstate.dwNumEventAttrs, deallocate);
             conditionArray[i].Attributes.Clear();
             if (opcconditionstate.dwNumEventAttrs > 0)
             {
                 for (int k = 0; k < objArray.Length; k++)
                 {
                     AttributeValue value2 = new AttributeValue {
                         ID       = 0,
                         Value    = objArray[k],
                         ResultID = GetResultID(numArray2[k])
                     };
                     conditionArray[i].Attributes.Add(value2);
                 }
             }
             if (deallocate)
             {
                 Marshal.DestroyStructure(ptr, typeof(OPCCONDITIONSTATE));
             }
             ptr = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCCONDITIONSTATE)));
         }
         if (deallocate)
         {
             Marshal.FreeCoTaskMem(pInput);
             pInput = IntPtr.Zero;
         }
     }
     return(conditionArray);
 }
Example #2
0
        internal static Condition[] GetConditions(ref IntPtr pInput, int count, bool deallocate)
        {
            Condition[] array = null;
            if (pInput != IntPtr.Zero && count > 0)
            {
                array = new Condition[count];
                IntPtr ptr = pInput;
                for (int i = 0; i < count; i++)
                {
                    OPCCONDITIONSTATE oPCCONDITIONSTATE = (OPCCONDITIONSTATE)Marshal.PtrToStructure(ptr, typeof(OPCCONDITIONSTATE));
                    array[i]                                = new Condition();
                    array[i].State                          = oPCCONDITIONSTATE.wState;
                    array[i].Quality                        = new Quality(oPCCONDITIONSTATE.wQuality);
                    array[i].Comment                        = oPCCONDITIONSTATE.szComment;
                    array[i].AcknowledgerID                 = oPCCONDITIONSTATE.szAcknowledgerID;
                    array[i].CondLastActive                 = OpcCom.Interop.GetFILETIME(Convert(oPCCONDITIONSTATE.ftCondLastActive));
                    array[i].CondLastInactive               = OpcCom.Interop.GetFILETIME(Convert(oPCCONDITIONSTATE.ftCondLastInactive));
                    array[i].SubCondLastActive              = OpcCom.Interop.GetFILETIME(Convert(oPCCONDITIONSTATE.ftSubCondLastActive));
                    array[i].LastAckTime                    = OpcCom.Interop.GetFILETIME(Convert(oPCCONDITIONSTATE.ftLastAckTime));
                    array[i].ActiveSubCondition.Name        = oPCCONDITIONSTATE.szActiveSubCondition;
                    array[i].ActiveSubCondition.Definition  = oPCCONDITIONSTATE.szASCDefinition;
                    array[i].ActiveSubCondition.Severity    = oPCCONDITIONSTATE.dwASCSeverity;
                    array[i].ActiveSubCondition.Description = oPCCONDITIONSTATE.szASCDescription;
                    string[] unicodeStrings  = OpcCom.Interop.GetUnicodeStrings(ref oPCCONDITIONSTATE.pszSCNames, oPCCONDITIONSTATE.dwNumSCs, deallocate);
                    int[]    int32s          = OpcCom.Interop.GetInt32s(ref oPCCONDITIONSTATE.pdwSCSeverities, oPCCONDITIONSTATE.dwNumSCs, deallocate);
                    string[] unicodeStrings2 = OpcCom.Interop.GetUnicodeStrings(ref oPCCONDITIONSTATE.pszSCDefinitions, oPCCONDITIONSTATE.dwNumSCs, deallocate);
                    string[] unicodeStrings3 = OpcCom.Interop.GetUnicodeStrings(ref oPCCONDITIONSTATE.pszSCDescriptions, oPCCONDITIONSTATE.dwNumSCs, deallocate);
                    array[i].SubConditions.Clear();
                    if (oPCCONDITIONSTATE.dwNumSCs > 0)
                    {
                        for (int j = 0; j < unicodeStrings.Length; j++)
                        {
                            SubCondition subCondition = new SubCondition();
                            subCondition.Name        = unicodeStrings[j];
                            subCondition.Severity    = int32s[j];
                            subCondition.Definition  = unicodeStrings2[j];
                            subCondition.Description = unicodeStrings3[j];
                            array[i].SubConditions.Add(subCondition);
                        }
                    }

                    object[] vARIANTs = OpcCom.Interop.GetVARIANTs(ref oPCCONDITIONSTATE.pEventAttributes, oPCCONDITIONSTATE.dwNumEventAttrs, deallocate);
                    int[]    int32s2  = OpcCom.Interop.GetInt32s(ref oPCCONDITIONSTATE.pErrors, oPCCONDITIONSTATE.dwNumEventAttrs, deallocate);
                    array[i].Attributes.Clear();
                    if (oPCCONDITIONSTATE.dwNumEventAttrs > 0)
                    {
                        for (int k = 0; k < vARIANTs.Length; k++)
                        {
                            AttributeValue attributeValue = new AttributeValue();
                            attributeValue.ID       = 0;
                            attributeValue.Value    = vARIANTs[k];
                            attributeValue.ResultID = GetResultID(int32s2[k]);
                            array[i].Attributes.Add(attributeValue);
                        }
                    }

                    if (deallocate)
                    {
                        Marshal.DestroyStructure(ptr, typeof(OPCCONDITIONSTATE));
                    }

                    ptr = (IntPtr)(ptr.ToInt64() + Marshal.SizeOf(typeof(OPCCONDITIONSTATE)));
                }

                if (deallocate)
                {
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return(array);
        }