public static bool SyncUncachedData() { long? lastLocalNuntiasId = NuntiasRepository.Instance.LastLocalNuntiasId; JObject requestData = new JObject(); requestData["user_id"] = Consumer.LoggedIn.Id; requestData["last_local_nuntiasId"] = lastLocalNuntiasId; requestData["sender_mac_address"] = Universal.SystemMACAddress; List <JObject> nuntiasJsonList = null; ServerHub.WorkingInstance.ServerHubProxy.Invoke <List <JObject> >("GetAllNuntiasOf", requestData).ContinueWith(task => { if (!task.IsFaulted) { nuntiasJsonList = task.Result; } }).Wait(); if (nuntiasJsonList == null) { return(false); } List <Nuntias> nuntiasList = new List <Nuntias>(); foreach (JObject nuntiasJson in nuntiasJsonList) { nuntiasList.Add(new Nuntias(nuntiasJson) { DeliveryTime = Time.CurrentTime }); } if (!ServerRequest.SyncUncachedConversations(nuntiasList)) { return(false); } foreach (Nuntias nuntias in nuntiasList) { NuntiasRepository.Instance.Insert(nuntias); ServerRequest.UpdateNuntiasStatus(nuntias); } return(true); }
public static Consumer GetConsumer(long id) { ServerRequest.SyncConsumer(id); return(ConsumerRepository.Instance.Get(id)); }
public static bool SyncUncachedConversations(List <Nuntias> nuntiasList) { Console.WriteLine("SyncUncachedConversations()"); HashSet <long> conversationIdSet = new HashSet <long>(); foreach (Nuntias nuntias in nuntiasList) { conversationIdSet.Add(nuntias.NativeConversationID); } List <long> unlistedConversationIdList = new List <long>(); foreach (long conversationId in conversationIdSet) { bool?exists = ConversationRepository.Instance.ExistsConversation(conversationId); if (exists == false) { unlistedConversationIdList.Add(conversationId); } } if (unlistedConversationIdList.Count == 0) { return(true); } List <JObject> conversationJsonList = null; ServerHub.WorkingInstance.ServerHubProxy.Invoke <List <JObject> >("GetConversations", unlistedConversationIdList).ContinueWith(task => { if (!task.IsFaulted) { conversationJsonList = task.Result; } }).Wait(); if (conversationJsonList == null) { return(false); } foreach (JObject conversationJson in conversationJsonList) { long id = (long)conversationJson["id"]; string type = (string)conversationJson["type"]; Conversation conversation = null; if (type == "duet") { Consumer member1 = ServerRequest.GetConsumer((long)conversationJson["member_id_1"]); Consumer member2 = ServerRequest.GetConsumer((long)conversationJson["member_id_2"]); if (member1 == null || member2 == null) { continue; } conversation = new DuetConversation(id, member1, member2); DuetConversationRepository.Instance.Insert(conversation); } else if (type == "group") { List <Consumer> memberList = new List <Consumer>(); int member_count = (int)conversationJson["member_counter"]; for (int i = 1; i <= member_count; i++) { memberList.Add(ServerRequest.GetConsumer((long)conversationJson["member_id_" + i])); } conversation = new GroupConversation(id, conversationJson["name"].ToString(), memberList); GroupConversationRepository.Instance.Insert(conversation); } } return(true); }