Exemplo n.º 1
0
        private void ProcessNotification(object message)
        {
            WfsMsg msg;

              try
              {
            msg = JsonHelper.FromJson<WfsMsg>(message.ToString());
              }
              catch (Exception e)
              {
            _log.ErrorFormat("Failed to deserialize message {0}: {1}", message, e);
            return;
              }

              if (msg == null || String.IsNullOrEmpty(msg.Name))
            return;

              _log.DebugFormat("Message is {0}", msg);

              // TODO: refactor that switch out
              try
              {
            switch (msg.Name)
            {
              case "Config":
            TestStaticDataMng.Get(_login).ConfigData = new ClientConfig((msg.Body as Dictionary<string, object>)["Config"] as Dictionary<string, object>);
            break;

              case "LastInitMessage":
            if (InitializationFinished != null)
              InitializationFinished();
            break;

              case "IerIncoming":
            if (IncomingIer != null)
            {
              ClientUnacceptedIer ier = new ClientUnacceptedIer((msg.Body as Dictionary<string, object>)["Ier"] as Dictionary<string, object>);
              IncomingIer(ier);
            }
              break;

              case "IerDisconnected":
            if (CallDisconnected != null)
              CallDisconnected.Invoke();
              break;

              case "CCSState":
            if (CcsStateChanged != null)
              CcsStateChanged(msg.Body, false);
              break;

              case "IerChanged":
            if (CurrentIerChanged != null)
            {
              ClientIer ier = new ClientIer((msg.Body as Dictionary<string, object>)["Ier"] as Dictionary<string, object>);
              CurrentIerChanged(ier);
            }
              break;

              case "IerAcceptFailed":
            if (AcceptFailed != null)
              AcceptFailed();
              break;
            }
              }
              catch (Exception e)
              {
            _log.Error("Message processing failed", e);
              }
        }
Exemplo n.º 2
0
        private void OnIncomingIer(ClientUnacceptedIer ier)
        {
            _log.InfoFormat("New ier comes with cgpn = {0}", ier.CgPn);

              if (_ier != null)
            _log.WarnFormat("New IER {0} comes, but current IER {1} already exists", ier, _ier);

              _ier = new ClientIer();
              _ier.Id = ier.Id;
              _ier.CallingPartyNumber = ier.CgPn;

              if (_acceptCalls)
              {
            _log.InfoFormat("{0} IER {1}...", "Accepting", _ier);

            StatisticsGatherer.StartAcceptStopwatch();

            _ajaxHelper.AcceptIer(_ier, new AjaxCallback(
                                      str =>
                                        {
                                          if (CallOffered != null)
                                            CallOffered();
                                        },
                                      Failed));

            ++StatisticsGatherer.TotalCallCount;
              }
              else if (_rejectCalls)
              {
            _log.InfoFormat("{0} IER {1}...", "Rejecting", _ier);

            _ajaxHelper.RejectIer(ier.Id, _ier, new AjaxCallback(
                                              str =>
                                                {
                                                  if (CallOffered != null)
                                                    CallOffered();

                                                },
                                              Failed));

            ++StatisticsGatherer.RejectedCallCount;
              }
              else
              {
            ++StatisticsGatherer.IgnoredCallCount;
              }
        }