//ui 갱신 public void RefreshData() { #if GLOBAL OldT.Text = "OldT"; NewT.Text = "NewT"; Title.Text = User.CacheData.BibleName + " " + User.CacheData.Chapter.ToString() + "Chapter"; #else OldT.Text = "구약"; NewT.Text = "신약"; Title.Text = User.CacheData.BibleName + " " + User.CacheData.Chapter.ToString() + "장"; #endif MainLayout.Children.Clear(); DrawMainText(MainLayout); SQLLiteDB.Upsert(User.CacheData); GotoFocusLabel(scrollView, User.CacheData.Verse); }
static public void Loop() { if (client.socket == null || client.socket.Connected == false) { return; } CompletePacket data; if (client.PacketQueue.TryDequeue(out data) == true) { try { switch (data.Protocol) { case (int)PROTOCOL.IdPktVersionRes: { VERSION_RES res = new VERSION_RES(); res = VERSION_RES.Parser.ParseFrom(data.Data); var currentVersion = VersionTracking.CurrentVersion; double myversion; if (double.TryParse(currentVersion, out myversion) == false) { } const Double Eps = 0.000000000000001; User.Version = res.VarVersion; if (Math.Abs(res.VarVersion - myversion) > Eps) { //첫 검수라 임시 주석 2번째 패치 부터는 활성화 if (Device.RuntimePlatform == Device.Android && User.OnceVersionNotify == false) { Device.BeginInvokeOnMainThread(() => { User.OnceVersionNotify = true; DependencyService.Get <Toast>().Notification("New Version Updated"); }); } } SQLLiteDB.LoadCacheData(); if (User.CacheData.UserName != null) { NetProcess.SendLogin(User.CacheData.UserName, User.CacheData.Passwd); } } break; case (int)PROTOCOL.IdPktLoginRes: { LOGIN_RES res = new LOGIN_RES(); res = LOGIN_RES.Parser.ParseFrom(data.Data); var mainpage = (MainPage)Application.Current.MainPage; if (res.VarCode == ErrorCode.Success) { User.LoginSuccess = true; SQLLiteDB.Upsert(User.CacheData.FontSize, User.CacheData.BibleName, User.CacheData.Chapter, User.CacheData.Verse, User.CacheData.UserName, User.CacheData.Passwd); Device.BeginInvokeOnMainThread(() => { mainpage.setting.UpdateLoginState("(Success)"); mainpage.setting.UpdateNameEntry(User.CacheData.UserName); var page = mainpage.CurrentView(); var settingview = page as SettingView; if (settingview == null) { mainpage.LoadLobby(); } }); } else { Device.BeginInvokeOnMainThread(() => { mainpage.setting.UpdateLoginState("(Failed)"); }); User.LoginSuccess = false; } } break; case (int)PROTOCOL.IdPktRoomListRes: { ROOM_LIST_RES res = new ROOM_LIST_RES(); res = ROOM_LIST_RES.Parser.ParseFrom(data.Data); Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView; roompage?.LoadRoomList(res); }); } break; case (int)PROTOCOL.IdPktNoticeRes: { NOTICE_RES res = new NOTICE_RES(); res = NOTICE_RES.Parser.ParseFrom(data.Data); Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; mainpage.alarm.LoadList(res); }); } break; case (int)PROTOCOL.IdPktMailListRes: { MAIL_LIST_RES res = new MAIL_LIST_RES(); res = MAIL_LIST_RES.Parser.ParseFrom(data.Data); Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; mainpage.mail.LoadList(res); }); } break; case (int)PROTOCOL.IdPktPrayMessageRes: { PRAY_MESSAGE_RES res = new PRAY_MESSAGE_RES(); res = PRAY_MESSAGE_RES.Parser.ParseFrom(data.Data); Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; PrayView prayview = mainpage.lobby.praypage as PrayView; prayview?.LoadPrayList(res); }); } break; case (int)PROTOCOL.IdPktCreateRoomRes: { CREATE_ROOM_RES res = new CREATE_ROOM_RES(); res = CREATE_ROOM_RES.Parser.ParseFrom(data.Data); if (res.VarCode != ErrorCode.Success) { break; } Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView; User.RoomIdList.Add(res.VarRoomId); { User.CurrentChatViewNumber = res.VarRoomId; var chatview = new MainChatView(); mainpage.lobby.chatpage.Add(res.VarRoomId, chatview); MainChatView chatpage = chatview; mainpage.LoadView(chatpage); } }); } break; case (int)PROTOCOL.IdPktEnterRoomRes: { ENTER_ROOM_RES res = new ENTER_ROOM_RES(); res = ENTER_ROOM_RES.Parser.ParseFrom(data.Data); if (res.VarCode != ErrorCode.DuplicateEnterRoom && res.VarCode != ErrorCode.Success) { break; } Device.BeginInvokeOnMainThread(() => { try { var mainpage = (MainPage)Application.Current.MainPage; RoomsPageView roompage = mainpage.lobby.roompage as RoomsPageView; User.RoomIdList.Add(res.VarRoomId); { User.CurrentChatViewNumber = res.VarRoomId; MainChatView outivew; mainpage.lobby.chatpage.TryGetValue(res.VarRoomId, out outivew); if (outivew == null) //없으면 새로 만들어서 넣는다. { var chatview = new MainChatView(); mainpage.lobby.chatpage.Add(res.VarRoomId, chatview); mainpage.LoadView(chatview); foreach (var msg in res.VarMessages) { chatview.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime); } chatview.ScrollEnd(); } else //이미 존재하는 방이면 해당 방에 넣는다. { mainpage.LoadView(outivew); outivew.ScrollEnd(); } } } catch (Exception e) { } }); } break; case (int)PROTOCOL.IdPktRoomPassThroughRes: { ROOM_PASS_THROUGH_RES res = new ROOM_PASS_THROUGH_RES(); res = ROOM_PASS_THROUGH_RES.Parser.ParseFrom(data.Data); Device.BeginInvokeOnMainThread(() => { var mainpage = (MainPage)Application.Current.MainPage; MainChatView outivew; mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew); if (outivew == null) { return; } foreach (var msg in res.VarMessages) { outivew.ReceiveMessage(msg.VarMessage, msg.VarName, msg.VarTime); } outivew.ScrollEnd(); }); } break; case (int)PROTOCOL.IdPktLeaveRoomRes: { LEAVE_ROOM_RES res = new LEAVE_ROOM_RES(); res = LEAVE_ROOM_RES.Parser.ParseFrom(data.Data); var mainpage = (MainPage)Application.Current.MainPage; Device.BeginInvokeOnMainThread(() => { MainChatView outivew; mainpage.lobby.chatpage.TryGetValue(res.VarRoomNumber, out outivew); if (outivew == null) { return; } outivew.UserList.Remove(res.VarName); if (res.VarName == User.CacheData.UserName) { User.RoomIdList.Remove(res.VarRoomNumber); mainpage.lobby.chatpage.Remove(res.VarRoomNumber); mainpage.lobby.LoadRoomPageView(); } else { MainChatView chatpage = outivew as MainChatView; chatpage.ReceiveMessage(res.VarName + " leaved.", res.VarName, Message.type.Info); } }); } break; case (int)PROTOCOL.IdPktAudioMessageRes: { AUDIO_MESSAGE_RES res = new AUDIO_MESSAGE_RES(); res = AUDIO_MESSAGE_RES.Parser.ParseFrom(data.Data); foreach (var msg in res.VarMessage) { StreamWrapper wra = new StreamWrapper(); wra.stream = new MemoryStream(msg.ToByteArray()); wra.pos = res.VarPos; AudioStream.Enqueue(wra); } } break; case (int)PROTOCOL.IdPktBitmapMessageRes: { BITMAP_MESSAGE_RES res = new BITMAP_MESSAGE_RES(); res = BITMAP_MESSAGE_RES.Parser.ParseFrom(data.Data); foreach (var msg in res.VarMessage) { StreamWrapper wra = new StreamWrapper(); wra.stream = new MemoryStream(msg.ToByteArray()); wra.pos = res.VarPos; JpegStream.Enqueue(wra); } } break; case (int)PROTOCOL.IdPktNewUserInRoomNty: { NEW_USER_IN_ROOM_NTY res = new NEW_USER_IN_ROOM_NTY(); res = NEW_USER_IN_ROOM_NTY.Parser.ParseFrom(data.Data); var mainpage = (MainPage)Application.Current.MainPage; Device.BeginInvokeOnMainThread(() => { MainChatView outivew; mainpage.lobby.chatpage.TryGetValue(res.VarRoomUser.VarRoomNumber, out outivew); if (outivew == null) { return; } outivew.UserList.Add(res.VarRoomUser.VarName); if (res.VarType == 1) { if (res.VarRoomUser.VarName != User.CacheData.UserName) { outivew.ReceiveMessage(res.VarRoomUser.VarName + " entered.", res.VarRoomUser.VarName, Message.type.Info); } } }); } break; } } catch (Exception ex) { Console.Write(ex.ToString()); } } }