Exemplo n.º 1
0
        private void SetCallback(ChangeNotificationEventArgs.Notification n)
        {
            Interop.Telephony.NotificationCallback NotificationDelegate = (IntPtr handle, ChangeNotificationEventArgs.Notification notiId, IntPtr data, IntPtr userData) =>
            {
                SlotHandle simHandle = Manager.FindHandle(handle);
                object     notiData  = null;
                switch (notiId)
                {
                case ChangeNotificationEventArgs.Notification.SimStatus:
                {
                    notiData = (Sim.State)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.SimCallForwardingIndicatorState:
                {
                    notiData = ((Marshal.ReadInt32(data) == 0) ? false : true);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkServiceState:
                {
                    notiData = (Network.ServiceState)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkCellid:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkRoamingStatus:
                {
                    notiData = (Marshal.ReadInt32(data) == 0) ? false : true;
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkSignalstrengthLevel:
                {
                    notiData = (Network.Rssi)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkNetworkName:
                {
                    notiData = Marshal.PtrToStringAnsi(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkPsType:
                {
                    notiData = (Network.PsType)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkDefaultDataSubscription:
                {
                    notiData = (Network.DefaultDataSubscription)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkDefaultSubscription:
                {
                    notiData = (Network.DefaultSubscription)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkLac:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkTac:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkSystemId:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkId:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkBsId:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkBsLatitude:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.NetworkBsLongitude:
                {
                    notiData = Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusIdle:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusActive:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusHeld:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusDialing:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusAlerting:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VoiceCallStatusIncoming:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VideoCallStatusIdle:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VideoCallStatusActive:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VideoCallStatusDialing:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VideoCallStatusAlerting:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.VideoCallStatusIncoming:
                {
                    notiData = (uint)Marshal.ReadInt32(data);
                    break;
                }

                case ChangeNotificationEventArgs.Notification.CallPreferredVoiceSubscription:
                {
                    notiData = (CallPreferredVoiceSubscription)Marshal.ReadInt32(data);
                    break;
                }
                }

                ChangeNotificationEventArgs args = new ChangeNotificationEventArgs(notiId, notiData);
                ChangeNotification?.Invoke(simHandle, args);
            };
            _changeNotificationList.Add(NotificationDelegate);

            Interop.Telephony.TelephonyError error = Interop.Telephony.TelephonySetNotiCb(_handle, n, NotificationDelegate, IntPtr.Zero);
            if (error != Interop.Telephony.TelephonyError.None)
            {
                Exception e = ExceptionFactory.CreateException(error);
                // Check if error is Invalid Parameter then hide the error
                if (e is ArgumentException)
                {
                    e = new InvalidOperationException("Internal Error Occured");
                }

                throw e;
            }
        }