/// <summary>
        /// Extracting event from the json.
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public CallingServerEventBase ExtractEvent(string content)
        {
            CloudEvent cloudEvent = CloudEvent.Parse(BinaryData.FromString(content));

            if (cloudEvent != null && cloudEvent.Data != null)
            {
                if (cloudEvent.Type.Equals(CallingServerEventType.CallConnectionStateChangedEvent.ToString()))
                {
                    return(CallConnectionStateChangedEvent.Deserialize(cloudEvent.Data.ToString()));
                }
                else if (cloudEvent.Type.Equals(CallingServerEventType.ToneReceivedEvent.ToString()))
                {
                    return(ToneReceivedEvent.Deserialize(cloudEvent.Data.ToString()));
                }
                else if (cloudEvent.Type.Equals(CallingServerEventType.PlayAudioResultEvent.ToString()))
                {
                    return(PlayAudioResultEvent.Deserialize(cloudEvent.Data.ToString()));
                }
                else if (cloudEvent.Type.Equals(CallingServerEventType.AddParticipantResultEvent.ToString()))
                {
                    return(AddParticipantResultEvent.Deserialize(cloudEvent.Data.ToString()));
                }
            }

            return(null);
        }
示例#2
0
        public void AddParticipantResultEventTest()
        {
            var json = "{\"resultInfo\":{\"code\":400,\"subcode\":415,\"message\":\"failure message\"},\"operationContext\":\"operatingContext\",\"status\":\"failed\"}";

            var c = AddParticipantResultEvent.Deserialize(json);

            Assert.AreEqual("operatingContext", c.OperationContext);
            Assert.AreEqual(OperationStatus.Failed, c.Status);
            Assert.IsNotNull(c.ResultInfo);
            Assert.AreEqual(400, c.ResultInfo.Code);
            Assert.AreEqual(415, c.ResultInfo.Subcode);
            Assert.AreEqual("failure message", c.ResultInfo.Message);

            json = "{\"operationContext\":\"operatingContext\",\"status\":\"running\"}";
            c    = AddParticipantResultEvent.Deserialize(json);

            Assert.AreEqual("operatingContext", c.OperationContext);
            Assert.AreEqual(OperationStatus.Running, c.Status);
            Assert.IsNull(c.ResultInfo);
        }