示例#1
0
 protected virtual int OnOIASNotify(NOTIFY_INFO notifyInfo)
 {
     if (notifyInfo.objectType == "client" && wishLogin)
     {
         if (notifyInfo.eventName == "loginFault.restore" || notifyInfo.eventName == "connectBreak.restore")
         {
             hasSessiontionFault = false;
             hasLogin            = true;
         }
         else if (notifyInfo.eventName == "loginFault" || notifyInfo.eventName == "connectBreak")
         {
             hasSessiontionFault = true;
             hasLogin            = false;
         }
     }
     if (Notify != null)
     {
         return(Notify(this, notifyInfo));
     }
     else
     {
         PrintNotify(notifyInfo);
         return(0);
     }
 }
示例#2
0
        protected static int OIASNotifyCB(HCLIENT hClient, NOTIFY_INFO notifyInfo)
        {
            OIASClient clientObj = FindClient(hClient);

            if (clientObj == null)
            {
                PrintNotify(notifyInfo);
                return(0);
            }
            return(clientObj.OnOIASNotify(notifyInfo));
        }
示例#3
0
        int cbOIASNotifyRecvProc(OIASClient sender, NOTIFY_INFO info)
        {
            if (info.eventName == "groupNotify" && info.eventData != 0)
            {
                IntPtr      listPtr    = new IntPtr(info.eventData);
                OBJECT_LIST notifyList = new OBJECT_LIST();
                Marshal.PtrToStructure(listPtr, notifyList);
                int[] itemAddresses = new int[notifyList.count];
                Marshal.Copy(notifyList.items, itemAddresses, 0, notifyList.count);
                for (int i = 0; i < notifyList.count; i++)
                {
                    NOTIFY_INFO subNotifyInfo = new NOTIFY_INFO();
                    IntPtr      itemPtr       = new IntPtr(itemAddresses[i]);
                    Marshal.PtrToStructure(itemPtr, subNotifyInfo);
                    cbOIASNotifyRecvProc(sender, subNotifyInfo);
                }
            }
            else
            {
                if (info.objectType == "client")
                {
                    if (info.eventName == "loginFault" || info.eventName == "connectBreak")
                    {
                        this.Notify(1, "", "");
                    }
                    else if (info.eventName == "connectBreak.restore" || info.eventName == "loginFault.restore")
                    {
                        this.Notify(1, "", "");
                    }
                }
                else if (info.objectType == "sensor")
                {
                    ParseSensorEvent(info.objectName, info.eventName);
                }
            }
            if (DataReceived != null)
            {
                string msg = string.Format("IP {0}, name: {1} event: {2}, description: {3}", device.ip, info.objectName, info.eventName, info.description);
                DataReceived(msg);
            }

            return(0);
        }
示例#4
0
        public override void RegisterDevice(Device device)
        {
            if (mapDriver.ContainsKey(device.id))
            {
                return;
            }
            OIASClient oiasClient = new OIASClient();

            oiasClient.Notify += new OIASClient.OIASNotifyEventHandler(cbOIASNotifyRecvProc);
            mapDriver.Add(device.id, oiasClient);

            LOGIN_INFO loginInfo = new LOGIN_INFO();

            loginInfo.hostIP   = device.ip;
            loginInfo.hostPort = device.port;
            loginInfo.userName = device.user;
            loginInfo.password = device.pwd;
            oiasClient.SetLoginInfo(loginInfo);
            if (!oiasClient.HasSessionFault && oiasClient.Login() == 0)
            {
                OBJECT_LIST list    = new OBJECT_LIST();
                IntPtr      listPtr = new IntPtr(Marshal.SizeOf(list));

                if (oiasClient.ListFault(list) == 0)
                {
                    if (list.count > 0)
                    {
                        int[] itemAddresses = new int[list.count];
                        Marshal.Copy(list.items, itemAddresses, 0, list.count);
                        for (int i = 0; i < list.count; i++)
                        {
                            NOTIFY_INFO subNotifyInfo = new NOTIFY_INFO();
                            IntPtr      itemPtr       = new IntPtr(itemAddresses[i]);
                            Marshal.PtrToStructure(itemPtr, subNotifyInfo);
                            if (subNotifyInfo.objectType == "sensor")
                            {
                                ParseSensorEvent(subNotifyInfo.objectName, subNotifyInfo.eventName);
                            }

                            if (DataReceived != null)
                            {
                                string msg = string.Format("历史事件:IP:{0},name:{1}, event:{2},description:{3}", device.ip, subNotifyInfo.objectName, subNotifyInfo.eventName, subNotifyInfo.description);
                                DataReceived(msg);
                            }
                        }
                    }
                }

                if (DataReceived != null)
                {
                    DataReceived("start success");
                }
                OnConnectEH(device, 0);
            }
            else
            {
                if (DataReceived != null)
                {
                    DataReceived("start failure");
                }
                OnConnectEH(device, 1);
            }
        }
示例#5
0
 static void PrintNotify(NOTIFY_INFO notifyInfo)
 {
 }