public void OnMonitorStart(string ServerIPAndPort, string Prefix, string Extension, string xRef)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            ss.XrefId = Int32Parse(xRef, 0);
            ss.MonitorPacketStatus = ServerPacketStatus.PacketReceived;
        }
        public void OnCallIdReceived(string ServerIPAndPort, string Prefix, string CallerDevice, string CallId, string CalledDevice)
        {
            if (CallerDevice[0] == 'N')
            {
                CallerDevice = CallerDevice.Substring(1);
            }
            if (CalledDevice[0] == 'N')
            {
                CalledDevice = CalledDevice.Substring(1);
            }
            if (CallerDevice[0] == '<' && CallerDevice.IndexOf('>') > 0)
            {
                CallerDevice = CallerDevice.Substring(1, CallerDevice.IndexOf('>') - 1);
            }
            if (CalledDevice[0] == '<' && CalledDevice.IndexOf('>') > 0)
            {
                CalledDevice = CalledDevice.Substring(1, CalledDevice.IndexOf('>') - 1);
            }

            //           int CallerDeviceInt = Int32Parse(CallerDevice, 0);
            int CallIdInt = Int32Parse(CallId, 0);
//            int CalledDeviceInt = Int32Parse(CalledDevice, 0);

            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, CallerDevice);

            ss.CallId      = CallIdInt;
            ss.CallPartner = Int32Parse(CalledDevice, 0);

            ss             = GetStatusStore(ServerIPAndPort, Prefix, CalledDevice);
            ss.CallId      = CallIdInt;
            ss.CallPartner = Int32Parse(CallerDevice, 0);
        }
        public PhoneNumber PhoneNumberGetByXRef(string ServerIPAndPort, long XRef)
        {
            MonitorStatusStore ss = GetStatusStoreXRef(ServerIPAndPort, XRef);

            if (ss != null)
            {
                return(PhoneNumberGetFirst(ss.ServerIPAndPort, ss.Prefix, ss.Extension, true));
            }
            return(null);
        }
        public void OnMonitorStop(string ServerIPAndPort, string Prefix, string pxRef)
        {
            int xRef = Int32Parse(pxRef, -1);
            MonitorStatusStore ss = GetStatusStoreXRef(ServerIPAndPort, xRef);

            if (ss != null)
            {
                ss.XrefId = 0;
                ss.MonitorPacketStatus = ServerPacketStatus.PacketReceived; // it's bad, but the best we can do
                return;
            }
        }
        public void OnStatusChange(string ServerIPAndPort, string Prefix, string Extension, PhoneStatusCodes NewStatus)
        {
            //mark that we are alive
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            ss.LastStatusUpdateStamp = Environment.TickCount;
            ss.PacketStatus          = ServerPacketStatus.PacketReceived;
            ss.LastStatus            = NewStatus;

            //try to attach a monitor to it
            if (ss.LastStatus != PhoneStatusCodes.PHONE_DOESNOT && ss.ShouldTryAttachMonitor() == true)
            {
                ss.MonitorPacketStatus   = ServerPacketStatus.PacketSent;
                ss.LastMonitorQueryStamp = Environment.TickCount;
                if (Globals.ConnectionManager != null)
                {
                    NetworkClient nc = Globals.ConnectionManager.GetCLient(ss.ServerIPAndPort);
                    nc.PacketBuilder.MonitorStart(Extension);
                }
            }

            string ExtensionRange = Extension.Substring(0, Extension.Length - 1);

            foreach (PhoneNumber pn in PhoneNumbers)
            {
                if (pn.GetExtension() == Extension || (pn.IsSubscriberRange() == true && pn.GetExtension() == ExtensionRange))
                {
                    if (App.Current != null)
                    {
                        App.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() =>
                        {
                            if (App.Current == null)
                            {
                                return;
                            }

                            MainWindow MainObject = (MainWindow)App.Current.MainWindow;

                            if (MainObject == null)
                            {
                                return;
                            }

                            pn.SetStatus(NewStatus, Extension); // extension is provided for ranges
                        }));
                    }
                }
            }
        }
        public void OnClientReceivedPacketWithExtension_(string ServerIPAndPort, string Prefix, string Extension)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            ss.ServerIPAndPort = ServerIPAndPort;
            if (ss.Extension == null)
            {
                ss.Extension = Extension;
            }
            if (ss.Prefix == null)
            {
                ss.Prefix = Prefix;
            }
            ss.ServerIPAndPort = ServerIPAndPort;
        }
        public HashSet <string> GetExtensionsQueryForward()
        {
            HashSet <string> ret = new HashSet <string>();

            foreach (PhoneNumber pn in PhoneNumbers)
            {
                if (pn.GetExtension().Length > 0 && pn.GetGUID() != 0)
                {
                    MonitorStatusStore ss = GetStatusStore(pn.GetServerIPAndPort(), pn.GetPrefix(), pn.GetExtension());
                    if (ss.LastStatus != PhoneStatusCodes.PHONE_DOESNOT && ss.ShouldQueryStatus() == false && ss.PacketStatus == ServerPacketStatus.PacketReceived)
                    {
                        ret.Add(pn.GetExtension());
                    }
                }
            }
            return(ret);
        }
        private MonitorStatusStore GetStatusStore(string ServerIPAndPort, string Prefix, string Extension)
        {
//            string ExtensionFull = GetMultiServerExtension(ServerIPAndPort, Prefix, Extension);
            foreach (MonitorStatusStore it in ExtensionMonitors)
            {
                if (it.CheckSearchMatch(ServerIPAndPort, Prefix, Extension) == true)
                {
                    return(it);
                }
            }

            //if we got here, than we need to create a new store
            MonitorStatusStore fw = new MonitorStatusStore(ServerIPAndPort, Prefix, Extension);

            ExtensionMonitors.Add(fw);

            return(fw);
        }
        public void OnConsultaionCallIdReceived(string ServerIPAndPort, string Prefix, string CallerDevice, string CallId, string CalledDevice)
        {
            if (CallerDevice[0] == 'N')
            {
                CallerDevice = CallerDevice.Substring(1);
            }
            if (CalledDevice[0] == 'N')
            {
                CalledDevice = CalledDevice.Substring(1);
            }

//            int CallerDeviceInt = Int32Parse(CallerDevice, 0);
            int CallIdInt = Int32Parse(CallId, 0);
//            int CalledDeviceInt = Int32Parse(CalledDevice, 0);

            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, CallerDevice);

            ss.CallIdConsultation      = CallIdInt;
            ss.CallPartnerConsultation = Int32Parse(CalledDevice, 0);

            ss = GetStatusStore(ServerIPAndPort, Prefix, CalledDevice);
            ss.CallIdConsultation      = CallIdInt;
            ss.CallPartnerConsultation = Int32Parse(CallerDevice, 0);
        }
Example #10
0
        private void PhoneNumberQueryDeviceStatus(string ServerIPAndPort, string Prefix, string Extension)
        {
            //ignore dummy extensions
            if (Extension.Length == 0)
            {
                return;
            }

            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            if (ss.ShouldQueryStatus() == true)
            {
                ss.LastQueryStamp = Environment.TickCount; // if there is no reply comming for this extension, we should retry a bit later
                ss.PacketStatus   = ServerPacketStatus.PacketSent;
                if (ss.ServerIPAndPort != null && Globals.ConnectionManager != null)
                {
                    NetworkClient nc = Globals.ConnectionManager.GetCLient(ss.ServerIPAndPort);
                    if (nc != null)
                    {
                        nc.PacketBuilder.SnapshotDevice(Extension.ToString());
                    }
                }
            }
        }
Example #11
0
        public long GetConsultaionCallId(string ServerIPAndPort, string Prefix, string Extension)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            return(ss.CallIdConsultation);
        }
Example #12
0
        public PhoneStatusCodes GetCachedStatus(string ServerIPAndPort, string Prefix, string Extension)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            return(ss.LastStatus);
        }
Example #13
0
        /// <summary>
        /// An extension can exist and be offline. We can set a monitor on an offline extension. We can NOT set a monitor for an unexisting extension
        /// </summary>
        /// <param name="Extension"></param>
        /// <returns></returns>
        public bool ExtensionExists(string ServerIPAndPort, string Prefix, string Extension)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            return(ss.ExtensionExists());
        }
Example #14
0
        public bool HasMonitor(string ServerIPAndPort, string Prefix, string Extension)
        {
            MonitorStatusStore ss = GetStatusStore(ServerIPAndPort, Prefix, Extension);

            return(ss.HasMonitorSet());
        }