예제 #1
0
        protected virtual void OnCall(CallEventHandler handler, CallEventArgs e, IPortId destPortId)
        {
            //Debug.WriteLine("[PhoneExchange.OnCall]");
            //Debug.WriteLine(e);

            if (handler != null)
            {
                // Только один нужный порт может быть
                var destPortHandler = handler.GetInvocationList()
                                      .Where(d => (d.Target as IPort) != null && ((IPort)d.Target).PortId.Equals(destPortId))
                                      .OfType <CallEventHandler>()
                                      .FirstOrDefault();

                var invListOthers = handler.GetInvocationList().Where(d => !(d.Target is IPort))
                                    .OfType <CallEventHandler>();

                // Вызвать событие только на порту назначения и для всех подписчиков - не портов
                if (destPortHandler != null)
                {
                    OnCallLog(e);
                    destPortHandler(this, e);
                }
                else
                {
                    e.State = CallEventStates.Invalid;
                    OnCallLog(e);
                }

                foreach (var callEventHandler in invListOthers)
                {
                    callEventHandler(this, e);
                }
            }
        }
예제 #2
0
        protected void PortCallEnded(object sender, CallEventArgs e)
        {
            // разделить входящий и исходящий звонок
            IPortId destPortId = e.State == CallEventStates.IncommingCallFinished
                ? e.SourcePortId
                : e.DestinationPortId;

            var destPort = _ports.FirstOrDefault(p => p.PortId.Equals(destPortId));

            if (destPort != null)
            {
                OnCall(CallEnded, e, destPortId);
            }
        }
예제 #3
0
        public virtual IPort CreatePort()
        {
            // На события станции порт подпишится сам при событии PortAdded
            // А на него - в конструкторе
            IPort port = _portFactory.CreatePort(this, _portId);

            _portId               = _portId.NextValue();
            port.ApeCallStarted  += PortCallStarted;
            port.ApeCallEnded    += PortCallEnded;
            port.ApeCallAccepted += PortCallAccepted;
            _ports.Add(port);
            OnPortAdded(port);
            return(port);
        }
예제 #4
0
        public Port(IPhoneExchange phoneExchange, IPortId portId)
        {
            if (phoneExchange == null)
            {
                throw new ArgumentNullException("phoneExchange", "phoneExchange cannot be null.");
            }
            if (portId == null)
            {
                throw new ArgumentNullException("portId", "portId cannot be null.");
            }

            PortId    = portId;
            PortState = PortStates.NotConnected;

            phoneExchange.PortAdded += PortAddedToApe;
        }
예제 #5
0
        public virtual bool StartCall(IPortId portId)
        {
            if (PortState != PortStates.Connected)
            {
                return(false);
            }

            _call = new CallEventArgs()
            {
                CallId            = Guid.NewGuid(),
                Date              = _dtHelper.Now,
                DestinationPortId = portId,
                SourcePortId      = _port != null ? _port.PortId : null,
                State             = CallEventStates.Started
            };

            return(OnCallStarted(_call));
        }
예제 #6
0
 public PhoneExchange(IPortFactory portFactory, IPortId startPortId)
 {
     _portFactory = portFactory;
     _portId      = startPortId;
 }
예제 #7
0
 public virtual double CallCost(IPortId portId, Call call)
 {
     return(call.SourcePortId.Equals(portId) ? call.Duration.TotalMinutes * Cost : 0);
 }
예제 #8
0
 public IPort CreatePort(IPhoneExchange phoneExchange, IPortId portId)
 {
     return(new Port(phoneExchange, portId));
 }
예제 #9
0
 public override double CallCost(IPortId portId, Call call)
 {
     return(call.SourcePortId.Equals(portId) ? Cost : (call.DestinationPortId.Equals(portId) ? IncomingCost : 0));
 }
예제 #10
0
 public bool Equals(IPortId other)
 {
     return(other != null && Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase));
 }