Ejemplo n.º 1
0
        /// <summary>
        /// Returns the sub-condition names for the event condition.
        /// </summary>
        public void GetSubConditionNames(string conditionName, out string[] subConditionNames)
        {
            subConditionNames = null;
            string methodName = "IOPCEventServer.QuerySubConditionNames";

            int    count = 0;
            IntPtr pSubConditionNames = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QuerySubConditionNames(
                    conditionName,
                    out count,
                    out pSubConditionNames);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            subConditionNames = ComUtils.GetUnicodeStrings(ref pSubConditionNames, count, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the status from the server.
        /// </summary>
        public OPCEVENTSERVERSTATUS?GetStatus()
        {
            string methodName = "IOPCEventServer.GetStatus";

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                IntPtr ppServerStatus;
                server.GetStatus(out ppServerStatus);

                OPCEVENTSERVERSTATUS pStatus = (OPCEVENTSERVERSTATUS)Marshal.PtrToStructure(ppServerStatus, typeof(OPCEVENTSERVERSTATUS));

                Marshal.DestroyStructure(ppServerStatus, typeof(OPCEVENTSERVERSTATUS));
                Marshal.FreeCoTaskMem(ppServerStatus);

                return(pStatus);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the event categories.
        /// </summary>
        /// <param name="eventType">Type of the event.</param>
        /// <param name="categories">The categories.</param>
        /// <param name="descriptions">The descriptions.</param>
        public void GetEventCategories(int eventType, out int[] categories, out string[] descriptions)
        {
            string methodName = "IOPCEventServer.QueryEventCategories";

            int    count         = 0;
            IntPtr pCategories   = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QueryEventCategories(
                    eventType,
                    out count,
                    out pCategories,
                    out pDescriptions);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            categories   = ComUtils.GetInt32s(ref pCategories, count, true);
            descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the area browser.
        /// </summary>
        /// <returns>An object which browses areas and sources.</returns>
        public IOPCEventAreaBrowser CreateAreaBrowser()
        {
            object unknown = null;

            string methodName = "IOPCEventServer.CreateAreaBrowser";

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);
                Guid            riid   = typeof(IOPCEventAreaBrowser).GUID;
                server.CreateAreaBrowser(ref riid, out unknown);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_NOTIMPL))
                {
                    ComCallError(methodName, e);
                }

                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }

            return((IOPCEventAreaBrowser)unknown);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an event subscription.
        /// </summary>
        /// <returns>An object which manages a subscription.</returns>
        public IOPCEventSubscriptionMgt CreateEventSubscription()
        {
            object unknown = null;

            string methodName = "IOPCEventServer.CreateEventSubscription";

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);
                Guid            riid   = typeof(IOPCEventSubscriptionMgt).GUID;

                int revisedBufferTime = 0;
                int revisedMaxSize    = 0;

                server.CreateEventSubscription(
                    1,
                    0,
                    0,
                    0,
                    ref riid,
                    out unknown,
                    out revisedBufferTime,
                    out revisedMaxSize);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }

            return((IOPCEventSubscriptionMgt)unknown);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the event attributes.
        /// </summary>
        /// <param name="categoryId">The category id.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <param name="descriptions">The descriptions.</param>
        /// <param name="datatypes">The datatypes.</param>
        public bool GetEventAttributes(
            int categoryId,
            out int[] attributeIds,
            out string[] descriptions,
            out short[] datatypes)
        {
            string methodName = "IOPCEventServer.QueryEventAttributes";

            int    count         = 0;
            IntPtr pAttributeIds = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;
            IntPtr pDataTypes    = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.QueryEventAttributes(
                    categoryId,
                    out count,
                    out pAttributeIds,
                    out pDescriptions,
                    out pDataTypes);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            attributeIds = ComUtils.GetInt32s(ref pAttributeIds, count, true);
            descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
            datatypes    = ComUtils.GetInt16s(ref pDataTypes, count, true);

            // remove the AREAS attribute which is never exposed.
            for (int ii = 0; ii < count; ii++)
            {
                if (String.Compare(descriptions[ii], "AREAS", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    int[]    attributeIds2 = new int[count - 1];
                    string[] descriptions2 = new string[count - 1];
                    short[]  datatypes2    = new short[count - 1];

                    if (ii > 0)
                    {
                        Array.Copy(attributeIds, attributeIds2, ii);
                        Array.Copy(descriptions, descriptions2, ii);
                        Array.Copy(datatypes, datatypes2, ii);
                    }

                    if (ii < count - 1)
                    {
                        Array.Copy(attributeIds, ii + 1, attributeIds2, ii, count - ii - 1);
                        Array.Copy(descriptions, ii + 1, descriptions2, ii, count - ii - 1);
                        Array.Copy(datatypes, ii + 1, datatypes2, ii, count - ii - 1);
                    }

                    attributeIds = attributeIds2;
                    descriptions = descriptions2;
                    datatypes    = datatypes2;
                    break;
                }
            }

            return(count > 0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Acknowledges the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="eventId">The event id.</param>
        /// <param name="comment">The comment.</param>
        /// <returns></returns>
        public uint Acknowledge(
            ServerSystemContext context,
            byte[] eventId,
            LocalizedText comment)
        {
            // get the user name from the context.
            string userName = String.Empty;

            if (context.UserIdentity != null)
            {
                userName = context.UserIdentity.DisplayName;
            }

            // get the comment.
            string commentText = String.Empty;

            if (comment != null)
            {
                commentText = comment.Text;
            }

            System.Runtime.InteropServices.ComTypes.FILETIME ftActiveTime;

            // unpack the event id.
            ServiceMessageContext messageContext = new ServiceMessageContext();

            messageContext.NamespaceUris = context.NamespaceUris;
            messageContext.ServerUris    = context.ServerUris;
            messageContext.Factory       = context.EncodeableFactory;

            BinaryDecoder decoder = new BinaryDecoder(eventId, messageContext);

            string source        = decoder.ReadString(null);
            string conditionName = decoder.ReadString(null);

            ftActiveTime.dwHighDateTime = decoder.ReadInt32(null);
            ftActiveTime.dwLowDateTime  = decoder.ReadInt32(null);
            int cookie = decoder.ReadInt32(null);

            decoder.Close();

            string methodName = "IOPCEventServer.AckCondition";

            IntPtr pErrors = IntPtr.Zero;

            try
            {
                IOPCEventServer server = BeginComCall <IOPCEventServer>(methodName, true);

                server.AckCondition(
                    1,
                    userName,
                    commentText,
                    new string[] { source },
                    new string[] { conditionName },
                    new System.Runtime.InteropServices.ComTypes.FILETIME[] { ftActiveTime },
                    new int[] { cookie },
                    out pErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                return(StatusCodes.BadUnexpectedError);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            int[] errors = ComUtils.GetInt32s(ref pErrors, 1, true);

            if (errors[0] == ResultIds.S_ALREADYACKED)
            {
                return(StatusCodes.BadConditionBranchAlreadyAcked);
            }
            else if (errors[0] < 0)
            {
                return(StatusCodes.BadEventIdUnknown);
            }

            return(StatusCodes.Good);
        }