public void SendInitialConnectionAck()
    {
        FlatBufferBuilder fbb = new FlatBufferBuilder(1024);

        var playerInfoOffset = FlatCreator.CreatePlayerInfo(fbb, Id, _playerGo.transform.position.x, _playerGo.transform.position.y,
                                                            _playerGo.transform.position.z,
                                                            _playerGo.transform.rotation.x, _playerGo.transform.rotation.y, _playerGo.transform.rotation.z,
                                                            _playerGo.transform.rotation.w);

        InitialConnectCommand.StartInitialConnectCommand(fbb);
        InitialConnectCommand.AddPlayer(fbb, playerInfoOffset);
        var initialCommandOffset = InitialConnectCommand.EndInitialConnectCommand(fbb);

        MessageRoot.StartMessageRoot(fbb);
        MessageRoot.AddDataType(fbb, Data.InitialConnectCommand);
        MessageRoot.AddData(fbb, initialCommandOffset.Value);
        var msgRootOffset = MessageRoot.EndMessageRoot(fbb);

        MessageRoot.FinishMessageRootBuffer(fbb, msgRootOffset);


        byte[] buf = fbb.SizedByteArray();

        _writer.BaseStream.Write(buf, 0, buf.Length);
        _writer.Flush();
    }
    public void SendMeetPlayer(string id)
    {
        FlatBufferBuilder fbb = new FlatBufferBuilder(1024);

        var _id = fbb.CreateString(id);

        PlayerInfo.StartPlayerInfo(fbb);
        PlayerInfo.AddId(fbb, _id);
        var playerInfoOffset = PlayerInfo.EndPlayerInfo(fbb);

        MeetCommand.StartMeetCommand(fbb);
        MeetCommand.AddOtherPlayer(fbb, playerInfoOffset);
        var meetCommandOffset = MeetCommand.EndMeetCommand(fbb);

        MessageRoot.StartMessageRoot(fbb);
        MessageRoot.AddDataType(fbb, Data.MeetCommand);
        MessageRoot.AddData(fbb, meetCommandOffset.Value);
        var msgRootOffset = MessageRoot.EndMessageRoot(fbb);

        MessageRoot.FinishMessageRootBuffer(fbb, msgRootOffset);

        byte[] buf = fbb.SizedByteArray();

        _writer.BaseStream.Write(buf, 0, buf.Length);
        _writer.Flush();
    }
Beispiel #3
0
        private static Attachment CreateAttachmentFromMessage(
            MessageRoot message,
            MessageDetails messageDetails)
        {
            Attachment attachment = null;

            if (message != null)
            {
                string type = message.Type;
                if (message.MediaId != Guid.Empty)
                {
                    switch (type)
                    {
                    case "album":
                        attachment = new AlbumAttachment(message.MediaId, null, null, null, Guid.Empty);
                        break;

                    case "playlist":
                        attachment = new PlaylistAttachment(message.MediaId, null, null);
                        break;

                    case "podcast":
                        attachment = new PodcastAttachment(message.MediaId, null, null, null, null);
                        break;

                    case "song":
                        attachment = new TrackAttachment(message.MediaId, null, null, null);
                        break;

                    case "video":
                        attachment = new EpisodeAttachment(message.MediaId, null, null, null);
                        break;

                    case "movie":
                        attachment = new MovieAttachment(message.MediaId, null, null);
                        break;

                    case "movietrailer":
                        attachment = new TrailerAttachment(message.MediaId, null, null);
                        break;
                    }
                }
                else if (messageDetails != null)
                {
                    if (messageDetails.PodcastMediaId != Guid.Empty)
                    {
                        if (type == "podcast")
                        {
                            attachment = new PodcastAttachment(messageDetails.PodcastMediaId, null, null, null, null);
                        }
                    }
                    else if (!string.IsNullOrEmpty(messageDetails.ZuneTag) && type == "card")
                    {
                        attachment = new ProfileAttachment(messageDetails.ZuneTag, null, null);
                    }
                }
            }
            return(attachment);
        }
Beispiel #4
0
        public void UpdateMessages(string type)
        {
            string      script = ReqBuilder.GetRequestScript(RequestType.getOverviewForCategory, type);
            string      ret    = (string)StaticData.jsExecutor.ExecuteAsyncScript(script);
            MessageRoot ress   = JsonConvert.DeserializeObject <MessageRoot>(ret);

            ListClass.MessageCenter = ress;
        }
    public void SendMovement(float pX, float pY, float pZ,
                             float rX, float rY, float rZ, float rW)
    {
        FlatBufferBuilder fbb = new FlatBufferBuilder(1024);

        var playerInfoOffset = FlatCreator.CreatePlayerInfo(fbb, Id, pX, pY, pZ, rX, rY, rZ, rW);

        MovementCommand.StartMovementCommand(fbb);
        MovementCommand.AddPlayer(fbb, playerInfoOffset);
        var movementCommandOffset = MovementCommand.EndMovementCommand(fbb);

        MessageRoot.StartMessageRoot(fbb);
        MessageRoot.AddDataType(fbb, Data.MovementCommand);
        MessageRoot.AddData(fbb, movementCommandOffset.Value);
        var msgRootOffset = MessageRoot.EndMessageRoot(fbb);

        MessageRoot.FinishMessageRootBuffer(fbb, msgRootOffset);

        byte[] buf = fbb.SizedByteArray();

        _writer.BaseStream.Write(buf, 0, buf.Length);
        _writer.Flush();
    }
        async public static void SendIM_Step04(HttpClient httpClient)
        {
            try
            {
                httpClient.DefaultRequestHeaders.Remove("Accept");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigData.ucwaAuthenticationResult.AccessToken);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                string url_00 = ConfigData.ucwaApplicationsHost + ConfigData.ucwaConversation;

                ConfigData.Log("1", String.Format("Step 04 : GET : {0}", url_00));

                ConfigData.Log("3", String.Format(">> Request: {0}", "GET"));
                ConfigData.Log("3", String.Format(">> URL: {0}", url_00));
                //ConfigData.Log("3", String.Format("\r\n{0}", httpClient.DefaultRequestHeaders.ToString()));

                var res_00 = await httpClient.GetAsync(url_00);

                string res_00_request = res_00.RequestMessage.ToString();
                string res_00_headers = res_00.Headers.ToString();
                string res_00_status  = res_00.StatusCode.ToString();
                var    res_00_content = await res_00.Content.ReadAsStringAsync();

                ConfigData.Log("3", String.Format(">> Response: {0}", res_00_status));
                ConfigData.Log("3", String.Format("{0}", res_00_headers));
                ConfigData.Log("3", String.Format("\r\n{0}", res_00_content));
                if (res_00_status == "NotFound")
                {
                    SendIM_Step02(httpClient);
                }
                else if (res_00_status == "OK")
                {
                    ConfigData.ucwaMessaging = ConfigData.ucwaConversation + "/messaging";
                    MessageRoot obj = new MessageRoot();
                    JsonConvert.PopulateObject(res_00_content, obj);
                    //ConfigData.ucwaEvents = obj._links.next.href;
                    if (obj != null)
                    {
                        if (obj.sender != null && obj.sender.Count > 0)
                        {
                            Sender sender = obj.sender.Find(x => x.rel == "messaging");
                            if (sender != null)
                            {
                                ConfigData.ucwaMessaging = sender.href;
                            }
                        }
                    }

                    //    switch (xml04.GetAttribute("rel"))  case "messaging": ConfigData.ucwaMessaging));
                    await SendIM_Step05(httpClient);
                }
                else
                {
                    ConfigData.Log("2", String.Format(">> Error in step 04. {0}", "No OK received"));
                }
            }
            catch (Exception ex)
            {
                ConfigData.Log("2", String.Format(">> Error in step 04. {0}", ex.InnerException.Message));
            }
        }
        async public static void SendIM_Step03(HttpClient httpClient, bool retry = false)
        {
            try
            {
                httpClient.DefaultRequestHeaders.Remove("Accept");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigData.ucwaAuthenticationResult.AccessToken);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                string url_00 = ConfigData.ucwaApplicationsHost + ConfigData.ucwaEvents;//.Replace('#', '3');
                if (retry)
                {
                    url_00 = ConfigData.ucwaApplicationsHost + ConfigData.ucwaEvents.Replace('#', '1');
                }

                ConfigData.Log("1", String.Format("Step 03 : GET : {0}", url_00));

                ConfigData.Log("3", String.Format(">> Request: {0}", "GET"));
                ConfigData.Log("3", String.Format(">> URL: {0}", url_00));
                //ConfigData.Log("3", String.Format("\r\n{0}", httpClient.DefaultRequestHeaders.ToString()));

                var res_00 = await httpClient.GetAsync(url_00);

                string res_00_request = res_00.RequestMessage.ToString();
                string res_00_headers = res_00.Headers.ToString();
                string res_00_status  = res_00.StatusCode.ToString();
                var    res_00_content = await res_00.Content.ReadAsStringAsync();

                ConfigData.Log("3", String.Format(">> Response: {0}", res_00_status));
                ConfigData.Log("3", String.Format("{0}", res_00_headers));
                ConfigData.Log("3", String.Format("\r\n{0}", res_00_content));

                if (res_00_status == "OK")
                {
                    MessageRoot obj = new MessageRoot();
                    JsonConvert.PopulateObject(res_00_content, obj);

                    if (obj.sender != null && obj.sender.Count > 0)
                    {
                        Sender sender = obj.sender.FindLast(x => x.rel == "conversation");
                        if (sender != null)
                        {
                            ConfigData.ucwaConversation = sender.href;
                        }

                        Sender sender1 = obj.sender.Find(x => x.rel == "stopMessaging");
                        if (sender1 != null)
                        {
                            ConfigData.ucwaStopMessaging = sender1.href;
                        }

                        Sender sender2 = obj.sender.Find(x => x.rel == "next");
                        if (sender2 != null)
                        {
                            ConfigData.ucwaEvents = sender2.href;
                        }
                    }
                    SendIM_Step04(httpClient);
                }
                else
                {
                    ConfigData.Log("2", String.Format(">> Error in step 03. {0}", "No OK received"));
                }
            }
            catch (Exception ex)
            {
                ConfigData.Log("2", String.Format(">> Error in step 03. {0}", ex.InnerException.Message));
            }
        }
Beispiel #8
0
        async public static void GetIM_Step03_Events(HttpClient httpClient)
        {
            try
            {
                httpClient.DefaultRequestHeaders.Remove("Accept");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ConfigData.ucwaAuthenticationResult.AccessToken);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                string url_00 = ConfigData.ucwaApplicationsHost + ConfigData.ucwaEvents;

                ConfigData.Log("1", String.Format("Step 03 : GET : {0}", url_00));

                ConfigData.Log("3", String.Format(">> Request: {0}", "GET"));
                ConfigData.Log("3", String.Format(">> URL: {0}", url_00));

                var res_00 = await httpClient.GetAsync(url_00);

                string res_00_request = res_00.RequestMessage.ToString();
                string res_00_headers = res_00.Headers.ToString();
                string res_00_status  = res_00.StatusCode.ToString();
                var    res_00_content = await res_00.Content.ReadAsStringAsync();

                ConfigData.Log("3", String.Format(">> Response: {0}", res_00_status));
                ConfigData.Log("3", String.Format("{0}", res_00_headers));
                ConfigData.Log("3", String.Format("\r\n{0}", res_00_content));

                if (res_00_status == "OK")
                {
                    bool hendle = false;

                    EventRoot eventRoot = JsonConvert.DeserializeObject <EventRoot>(res_00_content);
                    //JsonConvert.PopulateObject(res_00_content, eventRoot);
                    if (eventRoot.sender?.Exists(s => s.events?.Exists(e => (e.status?.Equals("Success", StringComparison.OrdinalIgnoreCase) ?? false) && (e.type?.Equals("completed", StringComparison.OrdinalIgnoreCase) ?? false) && (e._embedded?.message?.direction?.Equals("Incoming", StringComparison.OrdinalIgnoreCase) ?? false)) ?? false) ?? false)
                    //if (res_00_content.Contains("Incoming") && res_00_content.Contains("completed"))
                    {
                        if (eventRoot != null)
                        {
                            if (eventRoot._links != null)
                            {
                                hendle = true;

                                List <UcwaSfboConsole3.Sender> sender = eventRoot.sender.FindAll(x => x.rel.Equals("conversation"));
                                if (sender != null)
                                {
                                    foreach (var item in sender)
                                    {
                                        List <UcwaSfboConsole3.Event> msgInvitation = item.events.FindAll(x => x.link.rel.Equals("message"));
                                        if (msgInvitation != null)
                                        {
                                            foreach (var item1 in msgInvitation)
                                            {
                                                if (item1._embedded != null && item1._embedded.message != null && item1._embedded.message.direction == "Incoming")
                                                {
                                                    string SendMessageUrl = item1._embedded.message._links.messaging.href;
                                                    ConfigData.ucwaEvents = eventRoot._links.next.href;

                                                    string message = string.Empty;

                                                    if (item1._embedded.message._links.htmlMessage != null)
                                                    {
                                                        message = Utilities.GetMessageFromHtml(item1._embedded.message._links.htmlMessage.href);
                                                    }
                                                    else if (item1._embedded.message._links.plainMessage != null)
                                                    {
                                                        message = Utilities.GetMessageFromHref(item1._embedded.message._links.plainMessage.href);
                                                    }

                                                    var conversationId = item.href.Split('/').Last();
                                                    var fromId         = item1._embedded.message._links.contact.href.Split('/').Last();

                                                    Activity activity = new Activity()
                                                    {
                                                        From = new ChannelAccount {
                                                            Id = fromId, Name = fromId
                                                        },
                                                        Conversation = new ConversationAccount {
                                                            Id = conversationId
                                                        },
                                                        Recipient = new ChannelAccount {
                                                            Id = "Bot"
                                                        },
                                                        ServiceUrl  = "https://skype.botframework.com",
                                                        ChannelId   = "skype",
                                                        ChannelData = SendMessageUrl
                                                    };

                                                    activity.Text = message;

                                                    using (var scope = Microsoft.Bot.Builder.Dialogs.Conversation
                                                                       .Container.BeginLifetimeScope(DialogModule.LifetimeScopeTag, builder => Configure(builder)))
                                                    {
                                                        scope.Resolve <IMessageActivity>
                                                            (TypedParameter.From((IMessageActivity)activity));
                                                        DialogModule_MakeRoot.Register
                                                            (scope, () => new EchoDialog());
                                                        var postToBot = scope.Resolve <IPostToBot>();
                                                        await postToBot.PostAsync(activity, CancellationToken.None);
                                                    }

                                                    //await UcwaSendMessage.SendIM_Step05(httpClient, "echo " + message, SendMessageUrl);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            GetIM_Step03_Events(httpClient);
                        }
                    }
                    else if (eventRoot.sender?.Exists(s => s.events?.Exists(e => (e?._embedded?.messagingInvitation?.state?.Equals("Connecting", StringComparison.OrdinalIgnoreCase) ?? false) && (e.type?.Equals("started", StringComparison.OrdinalIgnoreCase) ?? false) && (e._embedded?.messagingInvitation?.direction?.Equals("Incoming", StringComparison.OrdinalIgnoreCase) ?? false)) ?? false) ?? false)
                    //else if (res_00_content.Contains("Incoming") && res_00_content.Contains("Connecting"))
                    {
                        string message   = string.Empty;
                        string acceptUrl = string.Empty;
                        if (eventRoot != null)
                        {
                            if (eventRoot._links != null)
                            {
                                hendle = true;
                                ConfigData.ucwaEvents = eventRoot._links.next.href;

                                List <UcwaSfboConsole3.Sender> sender = eventRoot.sender.FindAll(x => x.rel.Equals("communication"));
                                if (sender != null)
                                {
                                    foreach (var item in sender)
                                    {
                                        List <UcwaSfboConsole3.Event> msgInvitation = item.events.FindAll(x => x.link.rel.Equals("messagingInvitation"));

                                        if (msgInvitation != null)
                                        {
                                            foreach (var item1 in msgInvitation)
                                            {
                                                if (item1._embedded != null && item1._embedded.messagingInvitation._links != null && item1._embedded.messagingInvitation._links.accept != null)
                                                {
                                                    acceptUrl = item1._embedded.messagingInvitation._links.accept.href;
                                                    message   = Utilities.GetMessageFromHref(item1._embedded.messagingInvitation._links.message.href);
                                                    await GetIM_Step04_MessageAccept(httpClient, acceptUrl, message);
                                                }
                                            }
                                        }
                                    }
                                }
                                GetIM_Step03_Events(httpClient);
                            }
                        }
                    }
                    else // if (hendle == false)
                    {
                        MessageRoot obj = new MessageRoot();
                        JsonConvert.PopulateObject(res_00_content, obj);
                        if (obj != null)
                        {
                            if (obj._links != null)
                            {
                                ConfigData.ucwaEvents = obj._links.next.href;
                            }
                        }
                        GetIM_Step03_Events(httpClient);
                    }
                }
                else
                {
                    ConfigData.Log("2", String.Format(">> Error in step 03. {0}", "No OK received"));
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "A task was canceled.")
                {
                    GetIM_Step03_Events(httpClient);
                }
                else
                {
                    ConfigData.Log("2", String.Format(">> Error in step 03. {0}", ex.InnerException.Message));
                }
            }
        }
Beispiel #9
0
        async public static void GetIM_Step03_Events(HttpClient httpClient, TelemetryClient tc)
        {
            // Generic GetService< T> method is an extension method. Add namespace Microsoft.Extensions.DependencyInjection
            var textExtractionService = DI._serviceProvider.GetService <ITextExtraction>();
            var ucwaSetTypingService  = DI._serviceProvider.GetService <IUCWASetTyping>();

            try
            {
                httpClient.DefaultRequestHeaders.Remove("Accept");
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", UCWAConfiguration.authToken.access_token);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

                string url_00 = DI._config.GetSection("UCWA:ucwa_applications_host").Value + UCWAConfiguration.ucwaEvents;
                var    res_00 = await httpClient.GetAsync(url_00);

                string res_00_request = res_00.RequestMessage.ToString();
                string res_00_headers = res_00.Headers.ToString();
                string res_00_status  = res_00.StatusCode.ToString();
                var    res_00_content = await res_00.Content.ReadAsStringAsync();

                if (res_00_status == "OK")
                {
                    bool hendle = false;

                    EventRoot eventRoot = JsonConvert.DeserializeObject <EventRoot>(res_00_content);
                    //JsonConvert.PopulateObject(res_00_content, eventRoot);
                    if (eventRoot.sender?.Exists(s => s.events?.Exists(e => (e.status?.Equals("Success", StringComparison.OrdinalIgnoreCase) ?? false) && (e.type?.Equals("completed", StringComparison.OrdinalIgnoreCase) ?? false) && (e._embedded?.message?.direction?.Equals("Incoming", StringComparison.OrdinalIgnoreCase) ?? false)) ?? false) ?? false)
                    //if (res_00_content.Contains("Incoming") && res_00_content.Contains("completed"))
                    {
                        if (eventRoot != null)
                        {
                            if (eventRoot._links != null)
                            {
                                hendle = true;

                                List <Models.CommonEventRoot.Sender> sender = eventRoot.sender.FindAll(x => x.rel.Equals("conversation"));
                                if (sender != null)
                                {
                                    foreach (var item in sender)
                                    {
                                        List <Models.CommonEventRoot.Event> msgInvitation = item.events.FindAll(x => x.link.rel.Equals("message"));
                                        if (msgInvitation != null)
                                        {
                                            foreach (var item1 in msgInvitation)
                                            {
                                                if (item1._embedded != null && item1._embedded.message != null && item1._embedded.message.direction == "Incoming")
                                                {
                                                    string sendMessageUrl = item1._embedded.message._links.messaging.href;
                                                    UCWAConfiguration.ucwaEvents = eventRoot._links.next.href;

                                                    string message = string.Empty;

                                                    if (item1._embedded.message._links.htmlMessage != null)
                                                    {
                                                        message = await textExtractionService.GetMessageFromHtml(item1._embedded.message._links.htmlMessage.href);
                                                    }
                                                    else if (item1._embedded.message._links.plainMessage != null)
                                                    {
                                                        message = await textExtractionService.GetMessageFromHref(item1._embedded.message._links.plainMessage.href);
                                                    }

                                                    var conversationId = item.href.Split('/').Last();
                                                    var fromId         = item1._embedded.message._links.participant.title;
                                                    var emailLink      = item1._embedded.message._links.participant.href;
                                                    var emailID        = emailLink.Substring(emailLink.LastIndexOf("/") + 1);

                                                    //Send the user an impression that the bot is typing a message
                                                    string ucwaSetTypingUrl = DI._config.GetSection("UCWA:ucwa_applications_host").Value + UCWAConfiguration.ucwaApplication +
                                                                              UCWAConfiguration.ucwaConversationsUri + "/" + conversationId + UCWAConfiguration.ucwaSetTypingUri;
                                                    await ucwaSetTypingService.SetTyping(UCWAConfiguration._httpClient, UCWAConfiguration.authToken, ucwaSetTypingUrl,
                                                                                         UCWAConfiguration._tc);

                                                    // Create the Skype For Business On-Premise Adapter, and add Conversation State
                                                    // to the Bot. The Conversation State will be stored in memory.
                                                    var skypeForBusinessAdapter = DI._serviceProvider.GetService <ISkypeForBusinessOnPremAdapter>();

                                                    // Create the instance of our Bot.
                                                    var echoBotService = DI._serviceProvider.GetService <IEchoBot>();

                                                    // Connect the Skype For Business On-Premise Adapter to the Bot.
                                                    skypeForBusinessAdapter.ProcessActivityAsync(fromId, conversationId, sendMessageUrl, message,
                                                                                                 async(turnContext, cancellationToken) => await echoBotService.OnTurnAsync(turnContext)).Wait();
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            GetIM_Step03_Events(httpClient, tc);
                        }
                    }
                    else if (eventRoot.sender?.Exists(s => s.events?.Exists(e => (e?._embedded?.messagingInvitation?.state?.Equals("Connecting", StringComparison.OrdinalIgnoreCase) ?? false) && (e.type?.Equals("started", StringComparison.OrdinalIgnoreCase) ?? false) && (e._embedded?.messagingInvitation?.direction?.Equals("Incoming", StringComparison.OrdinalIgnoreCase) ?? false)) ?? false) ?? false)
                    //else if (res_00_content.Contains("Incoming") && res_00_content.Contains("Connecting"))
                    {
                        string message   = string.Empty;
                        string acceptUrl = string.Empty;
                        if (eventRoot != null)
                        {
                            if (eventRoot._links != null)
                            {
                                hendle = true;
                                UCWAConfiguration.ucwaEvents = eventRoot._links.next.href;

                                List <Models.CommonEventRoot.Sender> sender = eventRoot.sender.FindAll(x => x.rel.Equals("communication"));
                                if (sender != null)
                                {
                                    foreach (var item in sender)
                                    {
                                        List <Models.CommonEventRoot.Event> msgInvitation = item.events.FindAll(x => x.link.rel.Equals("messagingInvitation"));

                                        if (msgInvitation != null)
                                        {
                                            foreach (var item1 in msgInvitation)
                                            {
                                                if (item1._embedded != null && item1._embedded.messagingInvitation._links != null && item1._embedded.messagingInvitation._links.accept != null)
                                                {
                                                    acceptUrl = item1._embedded.messagingInvitation._links.accept.href;
                                                    message   = await textExtractionService.GetMessageFromHref(item1._embedded.messagingInvitation._links.message.href);
                                                    await GetIM_Step04_MessageAccept(httpClient, tc, acceptUrl, message);
                                                }
                                            }
                                        }
                                    }
                                }
                                GetIM_Step03_Events(httpClient, tc);
                            }
                        }
                    }
                    else // if (hendle == false)
                    {
                        MessageRoot obj = new MessageRoot();
                        JsonConvert.PopulateObject(res_00_content, obj);
                        if (obj != null)
                        {
                            if (obj._links != null)
                            {
                                UCWAConfiguration.ucwaEvents = obj._links.next.href;
                            }
                        }
                        GetIM_Step03_Events(httpClient, tc);
                    }
                }
                else
                {
                    //ConfigData.Log("2", String.Format(">> Error in step 03. {0}", "No OK received"));
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "A task was canceled.")
                {
                    GetIM_Step03_Events(httpClient, tc);
                }
                else
                //ConfigData.Log("2", String.Format(">> Error in step 03. {0}", ex.InnerException.Message));
                {
                    //Send the exception to App Insights
                    tc.TrackException(ex);
                    //Throw the exception
                    Console.WriteLine("Error occured in " + MethodBase.GetCurrentMethod().Name + ":" + ex.Message +
                                      " TargetSite:" + ex.TargetSite + " StackTrace: " + ex.StackTrace);
                    //throw new CustomException("Error occured in " + MethodBase.GetCurrentMethod().Name + ":" + ex.Message +
                    //    " TargetSite:" + ex.TargetSite + " StackTrace: " + ex.StackTrace);
                }
            }
        }
    void ReadData()
    {
        if (_stream.CanRead)
        {
            if (_stream.DataAvailable)
            {
                try
                {
                    byte[] bLen = new byte[4];
                    int    data = _stream.Read(bLen, 0, 4);
                    if (data > 0)
                    {
                        int    len  = BitConverter.ToInt32(bLen, 0);
                        Byte[] buff = new byte[1024];
                        data = _stream.Read(buff, 0, len);
                        if (data > 0)
                        {
                            ByteBuffer  bb  = new ByteBuffer(buff);
                            MessageRoot msg = MessageRoot.GetRootAsMessageRoot(bb);
                            switch (msg.DataType)
                            {
                            case Data.NONE:
                                // Do nothing
                                break;

                            case Data.InitialConnectCommand:
                            {
                                var player = msg.Data <InitialConnectCommand>().Value.Player.Value;

                                if (_spawnCount == 0)
                                {
                                    // Spawn the player
                                    // Set player's ID
                                    Id           = player.Id;
                                    _idText.text = player.Id;
                                    _playerGo    = Instantiate(PlayerPrefab, new Vector3(player.Pos.Value.X, player.Pos.Value.Y, player.Pos.Value.Z),
                                                               new Quaternion(0, 0, 0, 0));
                                    SendInitialConnectionAck();
                                }
                                else
                                {
                                    _networkPlayers.AddPlayer(player.Id, new Vector3(player.Pos.Value.X, player.Pos.Value.Y, player.Pos.Value.Z),
                                                              new Quaternion(0, 0, 0, 0));
                                }

                                Debug.Log(this.name + ": Command<" + msg.DataType + ">" + "   -  Player ID : " + player.Id);
                                _spawnCount++;
                            }
                            break;

                            case Data.MovementCommand:
                            {
                                // Move the player
                                var player = msg.Data <MovementCommand>().Value.Player.Value;
                                _networkPlayers.MovePlayer(player.Id, new Vector3(player.Pos.Value.X, player.Pos.Value.Y, player.Pos.Value.Z),
                                                           new Quaternion(player.Rot.Value.X, player.Rot.Value.Y, player.Rot.Value.Z, player.Rot.Value.W));
                                Debug.Log(this.name + ": Command<" + msg.DataType + ">" + "   -  Player ID : " + player.Id);
                            }
                            break;

                            case Data.MeetCommand:
                            {
                                // Player entered another player's area of interest
                                var otherPlayer = msg.Data <MeetCommand>().Value.OtherPlayer.Value;
                                Debug.Log(this.name + ": Command<" + msg.DataType + ">" + "   -  Player ID : " + otherPlayer.Id);
                            }
                            break;

                            case Data.PlayerInfo:
                            {
                            }
                            break;
                            }
                            _stream.Flush();
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
            }
        }
    }