//(Stream request, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse) public byte[] HandleGetUserFriendList2(Stream requestStream, string path, string param, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 took", TimeSpan.FromMilliseconds(1000)); try { // Check IP Endpoint Access if (!TrustManager.Instance.IsTrustedPeer(httpRequest.RemoteIPEndPoint)) { httpResponse.StatusCode = 401; return(new byte[0]); } // Request/response succeeded. FriendsListRequest request = ProtoBuf.Serializer.Deserialize <FriendsListRequest>(requestStream); UUID friendlistowner = request.ToUUID(); // Now perform the actual friends lookup. List <FriendListItem> returndata = m_userDataBaseService.GetUserFriendList(friendlistowner); // Generate and send the response. if (returndata == null) { returndata = new List <FriendListItem>(); } httpResponse.StatusCode = 200; return(FriendsListResponse.ToBytes(returndata)); } finally { slowCheck.Complete(); } }
static void walkFriendsTree(int levelsDeep, int maxLevels, SteamUser user) { if (levelsDeep < maxLevels) { FriendsListResponse rootFriends = GetPlayerFriends(user.steamid); // chunk the friends in groups of 100 // put this call in a loop with a second delay between each // dump the data out to a format useable by whatever mapping utility List <PlayerSummaryResponse> responses = new List <PlayerSummaryResponse>(); foreach (List <string> steamIdChunk in rootFriends.friendslist.friends.Select(x => x.steamid).ChunkBy(100)) { responses.Add(GetPlayerSummaries(steamIdChunk)); Thread.Sleep(5000); } foreach (PlayerSummaryResponse response in responses) { foreach (SteamUser foundUser in response.response.players) { user.friends.Add(foundUser); walkFriendsTree(levelsDeep++, maxLevels, foundUser); } } } }
static SteamUser startFriendsTree(int maxLevels, string rootSteamKey) { SteamUser rootUser = GetPlayerSummary(rootSteamKey).response.players.First(); FriendsListResponse rootFriends = GetPlayerFriends(rootSteamKey); List <PlayerSummaryResponse> responses = new List <PlayerSummaryResponse>(); foreach (List <string> steamIdChunk in rootFriends.friendslist.friends.Select(x => x.steamid).ChunkBy(100)) { responses.Add(GetPlayerSummaries(steamIdChunk)); Thread.Sleep(3000); } foreach (PlayerSummaryResponse response in responses) { foreach (SteamUser foundUser in response.response.players) { rootUser.friends.Add(foundUser); walkFriendsTree(0, maxLevels, foundUser); } } return(rootUser); }
private void FriendsListUpdated(object sender, MessageEventArgs e) { Debug.Log("HEY COOL, Friends List Response! Server says: " + e.Data); FriendsListResponse friendslist = FriendsListResponse.CreateFromJSON(e.Data); textString = "Friends:\n\n"; foreach (string friend in friendslist.usernames) { textString += "- " + friend + "\n"; } }
void OnGetFriendsList(bool success, string response) { if (success) { FriendsListResponse Response = JsonUtility.FromJson <FriendsListResponse> (response); foreach (TweetUser user in Response.users) { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters ["user_id"] = user.id.ToString(); parameters ["count"] = 1.ToString (); StartCoroutine(Client.Get("statuses/user_timeline", parameters, new TwitterCallback(this.OnGetStatusesUserTimeline))); } } else { } }
protected override void OnViewStateChanged(string key) { #region LoadList if (key == "LoadList") { bool isRefrsh = Convert.ToBoolean(ViewData["IsRefresh"]); if (isRefrsh) { LoadingControlInterface lc = LoadingControl.CreateLoading(Resources.DataLoading); Thread asyncDataThread = new Thread(delegate { AsyncGetViewData(lc); }); asyncDataThread.IsBackground = true; asyncDataThread.Start(); lc.ShowLoading(true); if (lc.Abort) { asyncDataThread.Abort(); } } else { try { FriendsListResponse newFriendsListResponse = Globals.BaseLogic.LoadFriendsList(false, false); if (newFriendsListResponse != null) { FriendsListResponse additionalFrendListResponse = LoadAdditionalDataFromCache(); ViewData["OriginalFrendListResponse"] = newFriendsListResponse; ViewData["AdditionalFrendListResponse"] = additionalFrendListResponse; FillListModel(newFriendsListResponse, additionalFrendListResponse, string.Empty); Globals.BaseLogic.ICommunicationLogic.ClearImagesInDictionary(); } else { view.Model.Clear(); } ViewData["ListID"] = Globals.BaseLogic.IDataLogic.GetUid(); // сохраняем ID пользователя для которого был построен список view.UpdateView("LoadListResponse"); } catch { // } } } #endregion #region ReloadList if (key == "ReloadList") { view.UpdateView("ReloadListResponse"); } #endregion #region RefreshList if (key == "RefreshList") { view.UpdateView("RefreshListResponse"); } #endregion #region GoToSendMessage if (key == "GoToSendMessage") { MasterForm.Navigate <SendMessageController>("FriendList", ViewData["Uid"]); } #endregion #region FilterFriendList if (key == "FilterFriendList") { using (new WaitWrapper(false)) { if ((string)ViewData["FilterString"] == string.Empty) { ViewData["OriginalModel"] = OriginalModel; view.UpdateView("ResetState"); } else { FillListModel((FriendsListResponse)ViewData["OriginalFrendListResponse"], (FriendsListResponse)ViewData["AdditionalFrendListResponse"], (string)ViewData["FilterString"]); ViewData["OriginalModel"] = view.Model; view.UpdateView("ResetState"); } } } #endregion #region CallNumber if (key == "CallNumber") { try { if (ViewData["ABTelephone"] != null) { Phone phone = new Phone(); phone.Talk((string)ViewData["ABTelephone"], true); } } catch { // CallNumberResponseMessage_Unsuccess ViewData["CallNumberResponseMessage"] = Resources.CallNumberResponseMessage_Unsuccess; view.UpdateView("CallNumberResponse"); } } #endregion #region SaveNumber if (key == "SaveNumber") { using (OutlookSession os = new OutlookSession()) { try { if (ViewData["ABFirstName"] != null && ViewData["ABLastName"] != null && ViewData["ABTelephone"] != null) { Contact contact = null; foreach (var val in os.Contacts.Items) { if (val.FirstName == (string)ViewData["ABFirstName"] && val.LastName == (string)ViewData["ABLastName"]) { contact = val; } } if (contact == null) { contact = new Contact(); contact.FirstName = (string)ViewData["ABFirstName"]; contact.LastName = (string)ViewData["ABLastName"]; os.Contacts.Items.Add(contact); } contact.MobileTelephoneNumber = (string)ViewData["ABTelephone"]; if (ViewData["ABBD"] != null) { contact.Birthday = (DateTime)ViewData["ABBD"]; } if (ViewData["ImagePath"] != null) { contact.SetPicture((string)ViewData["ImagePath"]); } contact.Update(); ViewData["SaveNumberResponseMessage"] = Resources.SaveNumberResponseMessage_Succsess; } else { throw new Exception(); } } catch (Exception) { ViewData["SaveNumberResponseMessage"] = Resources.SaveNumberResponseMessage_Unsuccess; } } view.UpdateView("SaveNumberResponse"); //contact.B //contact.MobileTelephoneNumber //using (new WaitWrapper(false)) //{ // if ((string)ViewData["FilterString"] == string.Empty) // { // ViewData["OriginalModel"] = OriginalModel; // view.UpdateView("ResetState"); // } // else // { // FillListModel((FriendsListResponse) ViewData["OriginalFrendListResponse"], null, (string) ViewData["FilterString"]); // ViewData["OriginalModel"] = view.Model; // view.UpdateView("ResetState"); // } //} } #endregion #region GoToNews if (key == "GoToNews") { MasterForm.Navigate <StatusUpdatesListController>(); } #endregion #region GoToMessages if (key == "GoToMessages") { MasterForm.Navigate <MessagesChainsListController>(); } #endregion #region GoToPhotos if (key == "GoToPhotos") { MasterForm.Navigate <ShareController>(); } #endregion #region GoToExtras if (key == "GoToExtras") { MasterForm.Navigate <ExtraController>(); } #endregion #region ListActualization if (key == "ListActualization") { string currentID = Globals.BaseLogic.IDataLogic.GetUid(); string listID = (string)ViewData["ListID"]; if (currentID != listID) { ViewData["IsRefresh"] = false; OnViewStateChanged("LoadList"); } } #endregion #region GoToSettings if (key == "GoToSettings") { using (new WaitWrapper(false)) { Configuration.LoadConfigSettings(); MasterForm.Navigate <SettingsController>(); } } #endregion #region GoToUserData if (key == "GoToUserData") { using (new WaitWrapper(false)) { MasterForm.Navigate <UserDataController>(); } } #endregion #region GoToAbout if (key == "GoToAbout") { using (new WaitWrapper(false)) { MasterForm.Navigate <AboutController>(); } } #endregion #region GoToExit if (key == "GoToExit") { using (new WaitWrapper(false)) { if (SystemConfiguration.DeleteOnExit) { Globals.BaseLogic.IDataLogic.ClearPass(); } Application.Exit(); } } #endregion if (key == "GoGoToLogin") { MasterForm.Navigate <LoginController>(); } }
private void AsyncGetViewData(LoadingControlInterface lc) { try { timerKeepAwake.Enabled = true; lc.Current = 0; FriendsListResponse newFriendsListResponse = null; try { lc.Current = 5; newFriendsListResponse = Globals.BaseLogic.LoadFriendsList(true, false); lc.Current = 95; } catch (VKException ex) { timerKeepAwake.Enabled = false; string error = ExceptionTranslation.TranslateException(ex); if (!string.IsNullOrEmpty(error)) { ViewData["LoadListResponseMessage"] = error; view.UpdateView("LoadListResponseNegative"); //newFriendsListResponse = LoadDataFromCache(); if (ex.LocalizedMessage.Equals(ExceptionMessage.IncorrectLoginOrPassword)) { Globals.BaseLogic.IDataLogic.SetToken(string.Empty); view.UpdateView("GoToLogin"); } } } catch (OutOfMemoryException) { ViewData["LoadListResponseMessage"] = Resources.OutOfMemory; view.UpdateView("LoadListResponseNegative"); } if (newFriendsListResponse != null) { FriendsListResponse additionalFrendListResponse = LoadAdditionalDataFromCache(); ViewData["OriginalFrendListResponse"] = newFriendsListResponse; ViewData["AdditionalFrendListResponse"] = additionalFrendListResponse; FillListModel(newFriendsListResponse, additionalFrendListResponse, string.Empty); } else { //view.Model.Clear(); } ViewData["ListID"] = Globals.BaseLogic.IDataLogic.GetUid(); // сохраняем ID пользователя для которого был построен список view.UpdateView("LoadListResponse"); // запускаем поток || прогрузки фотографий var t = new Thread(delegate { Globals.BaseLogic.ICommunicationLogic.LoadImagesInDictionary(); }) { IsBackground = true }; t.Start(); lc.Current = 100; } finally { timerKeepAwake.Enabled = false; } }
private void FillListModel(FriendsListResponse newFriendsListResponse, FriendsListResponse additionalFriendsListResponse, string filter) { if (additionalFriendsListResponse == null) { additionalFriendsListResponse = new FriendsListResponse(); } view.Model.Clear(); FriendListViewItem newFriendListViewItem = null; if (filter == string.Empty) { foreach (User newUser in newFriendsListResponse.Users) { newFriendListViewItem = new FriendListViewItem { Uid = newUser.Uid, FirstName = newUser.FirstName, LastName = newUser.LastName, IsOnline = newUser.IsOnline == "1", Group = string.IsNullOrEmpty(newUser.LastName) ? Resources.FriendList_Noname : SetGroup(newUser.LastName[0].ToString()), Avatar = SystemConfiguration.AppInstallPath + @"\Cache\Files\Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px) }; bool result = Globals.BaseLogic.ICommunicationLogic.LoadImage(newUser.Photo100px, @"Thumb\" + HttpUtility.GetMd5Hash( newUser.Photo100px), false, _afterLoadImageEventHandler, UISettings.CalcPix(50), newUser.LastName, "string"); newFriendListViewItem.IsAvatarLoaded = result; // доп. дата string telephone = string.Empty; DateTime bd = new DateTime(0); User additionalUserData = additionalFriendsListResponse.GetUserByID(newUser.Uid); if (additionalUserData != null) { if (!string.IsNullOrEmpty(additionalUserData.MobilePhone)) { newFriendListViewItem.Telephone = GetValidTelephoneNumber(additionalUserData.MobilePhone); } if (!additionalUserData.Birthday.Equals(bd)) { newFriendListViewItem.Birthday = additionalUserData.Birthday; } } view.Model.Add(newFriendListViewItem); } view.Model.Sort(); OriginalModel = new List <FriendListViewItem>(); foreach (FriendListViewItem item in view.Model) { OriginalModel.Add(item); } } else { foreach (User newUser in newFriendsListResponse.Users) { newFriendListViewItem = new FriendListViewItem(); if ((newUser.FirstName + newUser.LastName).ToLower().IndexOf(filter.ToLower()) != -1) { newFriendListViewItem.Uid = newUser.Uid; newFriendListViewItem.FirstName = newUser.FirstName; newFriendListViewItem.LastName = newUser.LastName; newFriendListViewItem.IsOnline = newUser.IsOnline == "1"; newFriendListViewItem.Group = SetGroup(string.IsNullOrEmpty(newUser.LastName) ? Resources.FriendList_Noname : SetGroup(newUser.LastName[0].ToString())); newFriendListViewItem.Avatar = SystemConfiguration.AppInstallPath + @"\Cache\Files\Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px); bool result = Globals.BaseLogic.ICommunicationLogic.LoadImage(newUser.Photo100px, @"Thumb\" + HttpUtility.GetMd5Hash( newUser.Photo100px), false, _afterLoadImageEventHandler, UISettings.CalcPix(50), newUser.LastName, "string"); newFriendListViewItem.IsAvatarLoaded = result; // доп. дата string telephone = string.Empty; DateTime bd = new DateTime(0); User additionalUserData = additionalFriendsListResponse.GetUserByID(newUser.Uid); if (additionalUserData != null) { if (!string.IsNullOrEmpty(additionalUserData.MobilePhone)) { newFriendListViewItem.Telephone = GetValidTelephoneNumber(additionalUserData.MobilePhone); } if (!additionalUserData.Birthday.Equals(bd)) { bd = additionalUserData.Birthday; newFriendListViewItem.Birthday = bd; } } view.Model.Add(newFriendListViewItem); } } view.Model.Sort(); } }
/// <summary> /// Returns a list of FriendsListItems that describe the friends and permissions in the friend /// relationship for UUID friendslistowner. For faster lookup, we index by friend's UUID. /// </summary> /// <param name="friendlistowner">The agent that we're retreiving the friends Data for.</param> private GetUserFriendListResult GetUserFriendList2(UUID friendlistowner, out Dictionary <UUID, FriendListItem> results) { Util.SlowTimeReporter slowCheck = new Util.SlowTimeReporter("[FRIEND]: GetUserFriendList2 for " + friendlistowner.ToString() + " took", TimeSpan.FromMilliseconds(1000)); try { Dictionary <UUID, FriendListItem> EMPTY_RESULTS = new Dictionary <UUID, FriendListItem>(); string uri = m_cfg.UserServerURL + "/get_user_friend_list2/"; HttpWebRequest friendListRequest = (HttpWebRequest)WebRequest.Create(uri); friendListRequest.Method = "POST"; friendListRequest.ContentType = "application/octet-stream"; friendListRequest.Timeout = FriendsListRequest.TIMEOUT; // Default results are empty results = EMPTY_RESULTS; // m_log.WarnFormat("[FRIEND]: Msg/GetUserFriendList2({0}) using URI '{1}'", friendlistowner, uri); FriendsListRequest request = FriendsListRequest.FromUUID(friendlistowner); try { // send the Post Stream os = friendListRequest.GetRequestStream(); ProtoBuf.Serializer.Serialize(os, request); os.Flush(); os.Close(); } catch (Exception e) { m_log.InfoFormat("[FRIEND]: GetUserFriendList2 call failed {0}", e); return(GetUserFriendListResult.ERROR); } // Let's wait for the response try { HttpWebResponse webResponse = (HttpWebResponse)friendListRequest.GetResponse(); if (webResponse == null) { m_log.Error("[FRIEND]: Null reply on GetUserFriendList2 put"); return(GetUserFriendListResult.ERROR); } //this will happen during the initial rollout and tells us we need to fall back to the old method if (webResponse.StatusCode == HttpStatusCode.NotFound) { m_log.WarnFormat("[FRIEND]: NotFound on reply of GetUserFriendList2"); return(GetUserFriendListResult.NOTIMPLEMENTED); } if (webResponse.StatusCode != HttpStatusCode.OK) { m_log.ErrorFormat("[FRIEND]: Error on reply of GetUserFriendList2 {0}", friendlistowner); return(GetUserFriendListResult.ERROR); } // We have a reply. FriendsListResponse response = ProtoBuf.Serializer.Deserialize <FriendsListResponse>(webResponse.GetResponseStream()); if (response == null) { m_log.ErrorFormat("[FRIEND]: Could not deserialize reply of GetUserFriendList2"); return(GetUserFriendListResult.ERROR); } // Request/response succeeded. results = response.ToDict(); // m_log.InfoFormat("[FRIEND]: Returning {0} friends for {1}", results.Count, friendlistowner); return(GetUserFriendListResult.OK); } catch (WebException ex) { HttpWebResponse webResponse = ex.Response as HttpWebResponse; if (webResponse != null) { //this will happen during the initial rollout and tells us we need to fall back to the //old method if (webResponse.StatusCode == HttpStatusCode.NotFound) { m_log.InfoFormat("[FRIEND]: NotFound exception on reply of GetUserFriendList2"); return(GetUserFriendListResult.NOTIMPLEMENTED); } } m_log.ErrorFormat("[FRIEND]: exception on reply of GetUserFriendList2 for {0}", request.FriendListOwner); } return(GetUserFriendListResult.ERROR); } finally { slowCheck.Complete(); } }
protected override void OnViewStateChanged(string key) { #region LoadList if (key == "LoadList") { //LoadingControlInterface lc = LoadingControl.CreateLoading(Resources.DataLoading); //var asyncDataThread = new Thread(() => AsyncGetViewData(lc)) {IsBackground = true}; //asyncDataThread.Start(); //lc.ShowLoading(true); //if (lc.Abort) //{ // asyncDataThread.Abort(); //} bool isRefrsh = Convert.ToBoolean(ViewData["IsRefresh"]); if (isRefrsh) { LoadingControlInterface lc = LoadingControl.CreateLoading(Resources.DataLoading); Thread asyncDataThread = new Thread(delegate { AsyncGetViewData(lc); }); asyncDataThread.IsBackground = true; asyncDataThread.Start(); lc.ShowLoading(true); if (lc.Abort) { asyncDataThread.Abort(); } } else { try { FriendsListResponse newFriendsListResponse = Globals.BaseLogic.LoadFriendsList(false, false); if (newFriendsListResponse != null) { //FriendsListResponse additionalFrendListResponse = LoadAdditionalDataFromCache(); ViewData["OriginalFrendListResponse"] = newFriendsListResponse; //ViewData["AdditionalFrendListResponse"] = additionalFrendListResponse; FillListModel(newFriendsListResponse, string.Empty); Globals.BaseLogic.ICommunicationLogic.ClearImagesInDictionary(); } else { //view.Model.Clear(); } //ViewData["ListID"] = Globals.BaseLogic.IDataLogic.GetUid(); // сохраняем ID пользователя для которого был построен список view.UpdateView("LoadListResponse"); } catch { // } } } #endregion #region ReloadList if (key == "ReloadList") { view.UpdateView("ReloadListResponse"); } #endregion #region RefreshList if (key == "RefreshList") { view.UpdateView("RefreshListResponse"); } #endregion #region UserChoise if (key == "UserChoise") { if ((string)ViewData["Uid"] != string.Empty) { using (new WaitWrapper(false)) { //var uid = (string) ViewData["Addressee"]; MasterForm.Navigate <SendMessageController>((string)ViewData["BackLink"], ViewData["Uid"]); } } } #endregion #region GoBack if (key == "GoBack") { using (new WaitWrapper(false)) { NavigationService.GoBack(); } } #endregion #region FilterFriendList if (key == "FilterFriendList") { using (new WaitWrapper(false)) { if ((string)ViewData["FilterString"] == string.Empty) { ViewData["OriginalModel"] = OriginalModel; view.UpdateView("ResetState"); } else { FillListModel((FriendsListResponse)ViewData["OriginalFrendListResponse"], (string)ViewData["FilterString"]); ViewData["OriginalModel"] = view.Model; view.UpdateView("ResetState"); } } } #endregion if (key == "GoGoToLogin") { MasterForm.Navigate <LoginController>(); } }
private void AsyncGetViewData(LoadingControlInterface lc) { lc.Current = 0; FriendsListResponse newFriendsListResponse = null; //bool isRefresh = Convert.ToBoolean((string)ViewData["IsRefresh"]); try { lc.Current = 5; //if (lc.Abort) //{ // isRefresh = false; //} newFriendsListResponse = Globals.BaseLogic.LoadFriendsList(true, false); lc.Current = 95; } catch (VKException ex) { string error = ExceptionTranslation.TranslateException(ex); if (!string.IsNullOrEmpty(error)) { ViewData["LoadListResponseMessage"] = error; view.UpdateView("LoadListResponseNegative"); if (ex.LocalizedMessage.Equals(ExceptionMessage.IncorrectLoginOrPassword)) { Globals.BaseLogic.IDataLogic.SetToken(string.Empty); view.UpdateView("GoToLogin"); } } } catch (OutOfMemoryException) { ViewData["LoadListResponseMessage"] = Resources.OutOfMemory; view.UpdateView("LoadListResponseNegative"); } if (newFriendsListResponse != null) { ViewData["OriginalFrendListResponse"] = newFriendsListResponse; FillListModel(newFriendsListResponse, string.Empty); } view.UpdateView("LoadListResponse"); //// запускаем поток || прогрузки фотографий //var t = new Thread(() => Globals.BaseLogic.ICommunicationLogic.LoadImagesInDictionary()) //{ // IsBackground = true //}; //t.Start(); lc.Current = 100; }
private void FillListModel(FriendsListResponse newFriendsListResponse, string filter) { view.Model.Clear(); FriendListViewItem newFriendListViewItem; if (filter == string.Empty) { foreach (User newUser in newFriendsListResponse.Users) { newFriendListViewItem = new FriendListViewItem { Uid = newUser.Uid, FirstName = newUser.FirstName, LastName = newUser.LastName, IsOnline = newUser.IsOnline == "1", Group = SetGroup(newUser.LastName[0].ToString()), Avatar = SystemConfiguration.AppInstallPath + @"\Cache\Files\Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px) }; //bool result = Globals.BaseLogic.ICommunicationLogic.LoadImage(newUser.Photo100px, // @"Thumb\" + // HttpUtility.GetMd5Hash( // newUser.Photo100px), false, // _afterLoadImageEventHandler, // UISettings.CalcPix(32), // newUser.LastName, "string"); bool result = File.Exists(newFriendListViewItem.Avatar); newFriendListViewItem.IsAvatarLoaded = result; view.Model.Add(newFriendListViewItem); } view.Model.Sort(); OriginalModel = new List <FriendListViewItem>(); foreach (FriendListViewItem item in view.Model) { OriginalModel.Add(item); } } else { foreach (User newUser in newFriendsListResponse.Users) { newFriendListViewItem = new FriendListViewItem(); if ((newUser.FirstName + newUser.LastName).ToLower().IndexOf(filter.ToLower()) != -1) { newFriendListViewItem.Uid = newUser.Uid; newFriendListViewItem.FirstName = newUser.FirstName; newFriendListViewItem.LastName = newUser.LastName; newFriendListViewItem.IsOnline = newUser.IsOnline == "1"; newFriendListViewItem.Group = SetGroup(newUser.LastName[0].ToString()); newFriendListViewItem.Avatar = SystemConfiguration.AppInstallPath + @"\Cache\Files\Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px); //bool result = Globals.BaseLogic.ICommunicationLogic.LoadImage(newUser.Photo100px, // @"Thumb\" + // HttpUtility.GetMd5Hash( // newUser.Photo100px), false, // _afterLoadImageEventHandler, // UISettings.CalcPix(32), // newUser.LastName, "string"); bool result = File.Exists(newFriendListViewItem.Avatar); newFriendListViewItem.IsAvatarLoaded = result; view.Model.Add(newFriendListViewItem); } } view.Model.Sort(); } }
private void AsyncGetViewData(LoadingControlInterface lc) { string isFirstStart = (string)ViewData["IsFirstStart"]; ViewData["IsFirstStart"] = "0"; lc.Current = 2; ActivityResponse newActivityResponse = null; UpdatesPhotosResponse newUpdatesPhotosResponse = null; // первичные данные формы try { // загружаем новые новости newActivityResponse = Globals.BaseLogic.LoadActivityDataList(25, true, false); lc.Current = 4; // загружаем новые фото newUpdatesPhotosResponse = Globals.BaseLogic.LoadUpdatesPhotos(25, true, false); lc.Current = 10; ViewData["FirstActivate"] = string.Empty; } catch (VKException ex) { timerKeepAwake.Enabled = false; string error = ExceptionTranslation.TranslateException(ex); if (!string.IsNullOrEmpty(error)) { ViewData["GetViewDataResponseMessage"] = error; view.UpdateView("GetViewDataResponseNegative"); if (ex.LocalizedMessage.Equals(ExceptionMessage.IncorrectLoginOrPassword)) { Globals.BaseLogic.IDataLogic.SetToken(string.Empty); //view.UpdateView("GoToLogin"); OnViewStateChanged("GoToLogin"); } } } catch (OutOfMemoryException) { ViewData["GetViewDataResponseMessage"] = Resources.OutOfMemory; view.UpdateView("GetViewDataResponseNegative"); } if (newActivityResponse != null) { FillListModel(newActivityResponse, true); } if (newUpdatesPhotosResponse != null) { FillListModel(newUpdatesPhotosResponse, true); } ViewData["ListID"] = Globals.BaseLogic.IDataLogic.GetUid(); // сохраняем ID пользователя для которого был построен список view.UpdateView("LoadListResponse"); // прочие данные при старте приложения if (isFirstStart.Equals("1") && Configuration.DataRenewType != DataRenewVariants.DontUpdate) { try { int totalCount; int alreadyGet; bool isData; // список друзей Globals.BaseLogic.LoadFriendsList(true, false); lc.Current = 12; // список комментариев к фотографиям пользователя Globals.BaseLogic.LoadPhotosComments(25, true, false); lc.Current = 14; // список заголовков цепочек сообщений пользователя Globals.BaseLogic.GetShortCorrespondence(true, false); lc.Current = 16; // список статусов пользователя (для формы поделиться) Globals.BaseLogic.LoadUserActivityDataList(25, true, false); lc.Current = 18; // список фотографий пользователя Globals.BaseLogic.ReloadUserPhotos(true, false); lc.Current = 20; // З А Г Р У З К А Ц Е П О Ч Е К П Е Р Е П И С О К Globals.BaseLogic.ClearMessageCorrespondence(); totalCount = Globals.BaseLogic.PredictCorrespondCount(); alreadyGet = 0; isData = false; MessShortCorrespondence newMessShortCorrespondence = DataModel.Data.MessageShortCorrespondence; if (newMessShortCorrespondence == null) { newMessShortCorrespondence = new MessShortCorrespondence(); } MessCorrespondence newMessCorrespondence = DataModel.Data.MessageCorrespondence; if (newMessCorrespondence == null) { newMessCorrespondence = new MessCorrespondence(); } do { isData = Globals.BaseLogic.UploadNextUserCorrespond(newMessShortCorrespondence, newMessCorrespondence); if (isData) { alreadyGet++; if (totalCount > 0) { lc.Current = 40 - (int)(20 * (((double)(totalCount - alreadyGet)) / ((double)totalCount))); } } }while (isData); DataModel.Data.MessageCorrespondence = newMessCorrespondence; // З А Г Р У З К А К О М М Е Н Т А Р И Е В Globals.BaseLogic.ClearAllPhotoComments(); totalCount = Globals.BaseLogic.PredictPhotoCommentsCount(); alreadyGet = 0; isData = false; PhotosCommentsResponseHistory newPhotosCommentsRespounseHistory = DataModel.Data.PhotosCommentsResponseHistoryData; if (newPhotosCommentsRespounseHistory == null) { newPhotosCommentsRespounseHistory = new PhotosCommentsResponseHistory(); } PhotosCommentsResponse newPhotosCommentsRespounse = DataModel.Data.PhotosCommentsResponseData; if (newPhotosCommentsRespounse == null) { newPhotosCommentsRespounse = new PhotosCommentsResponse(); } UpdatesPhotosResponse nwUpdatesPhotosResponse = DataModel.Data.UpdatesPhotosResponseData; if (nwUpdatesPhotosResponse == null) { nwUpdatesPhotosResponse = new UpdatesPhotosResponse(); } do { isData = Globals.BaseLogic.UploadNextPhotoComments(newPhotosCommentsRespounseHistory, newPhotosCommentsRespounse, nwUpdatesPhotosResponse); if (isData) { alreadyGet++; if (totalCount > 0) { lc.Current = 60 - (int)(20 * (((double)(totalCount - alreadyGet)) / ((double)totalCount))); } } }while (isData); DataModel.Data.PhotosCommentsResponseHistoryData = newPhotosCommentsRespounseHistory; // З А Г Р У З К А П Р О Ф И Л Е Й П О Л Ь З О В А Т Е Л Е Й totalCount = Globals.BaseLogic.PredictFriendsCount(); alreadyGet = 0; isData = false; FriendsListResponse additionalFriendsListResponse = additionalFriendsListResponse = DataModel.Data.FriendsListAdditionalResponseData; if (additionalFriendsListResponse == null) { additionalFriendsListResponse = new FriendsListResponse(); } FriendsListResponse oldFriendsListResponse = DataModel.Data.FriendsListResponseData; if (oldFriendsListResponse == null) { oldFriendsListResponse = new FriendsListResponse(); } do { isData = Globals.BaseLogic.GetNextFriendsInfo(true, false, additionalFriendsListResponse, oldFriendsListResponse); if (isData) { alreadyGet++; if (totalCount > 0) { lc.Current = 98 - (int)(38 * (((double)(totalCount - alreadyGet)) / ((double)totalCount))); } } } while (isData); DataModel.Data.FriendsListAdditionalResponseData = additionalFriendsListResponse; // все фото Globals.BaseLogic.DownloadAllPhotoData(); lc.Current = 99; } catch (VKException) { DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения"); } catch (OutOfMemoryException) { DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения"); } catch (Exception) { DebugHelper.WriteLogEntry("Ошибка при загрузке данных при старте приложения"); } } // запускаем поток || прогрузки фотографий var t = new Thread(delegate { Globals.BaseLogic.ICommunicationLogic.LoadImagesInDictionary(); }) { IsBackground = true }; t.Start(); lc.Current = 100; }
protected override void OnViewStateChanged(string key) { #region LoadList if (key == "LoadList") { FriendsListResponse newFriendsListResponse = null; try { newFriendsListResponse = Globals.BaseLogic.LoadFriendsOnlineList(false); } catch (VKException ex) { switch (ex.LocalizedMessage) { case ExceptionMessage.UnknownError: ViewData["LoadListResponseMessage"] = Resources.VK_ERRORS_UnknownError; break; case ExceptionMessage.ServerUnavalible: ViewData["LoadListResponseMessage"] = Resources.VK_ERRORS_ServerUnavalible; break; case ExceptionMessage.NoConnection: ViewData["LoadListResponseMessage"] = Resources.VK_ERRORS_NoConnection; break; } view.UpdateView("LoadListResponseNegative"); return; } catch (OutOfMemoryException) { ViewData["LoadListResponseMessage"] = Resources.OutOfMemory; view.UpdateView("LoadListResponseNegative"); return; } if (newFriendsListResponse != null) { view.Model.Clear(); foreach (User newUser in newFriendsListResponse.Users) { FriendListViewItem newFriendListViewItem = new FriendListViewItem(); newFriendListViewItem.Uid = newUser.Uid; //newFriendListViewItem.UserName = newUser.FullName; newFriendListViewItem.Avatar = SystemConfiguration.AppInstallPath + @"\Cache\Files\Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px); bool result = Globals.BaseLogic.ICommunicationLogic.LoadImage(newUser.Photo100px, @"Thumb\" + HttpUtility.GetMd5Hash(newUser.Photo100px), false, _afterLoadImageEventHandler, 100, 0, "int"); newFriendListViewItem.IsAvatarLoaded = result; view.Model.Add(newFriendListViewItem); } view.Model.Sort(); view.UpdateView("LoadListResponse"); // запускаем поток || прогрузки фотографий var t = new Thread(() => Globals.BaseLogic.ICommunicationLogic.LoadImagesInDictionary()) { IsBackground = true }; t.Start(); } else { ViewData["LoadListResponseMessage"] = Resources.FriendsList_Messages_OperationDoneUnsuccsessfully; view.UpdateView("LoadListResponseNegative"); } } #endregion #region ReloadList if (key == "ReloadList") { view.UpdateView("ReloadListResponse"); } #endregion #region GoToMain if (key == "GoToMain") { MasterForm.Navigate <MainController>(); } #endregion #region GoToNews if (key == "GoToNews") { MasterForm.Navigate <StatusUpdatesListController>(); } #endregion #region GoToMessages if (key == "GoToMessages") { MasterForm.Navigate <MessagesChainsListController>(); } #endregion #region GoToExtras if (key == "GoToExtras") { MasterForm.Navigate <ExtraController>(); } #endregion #region GoToFriends if (key == "GoToFriends") { MasterForm.Navigate <FriendsListController>(); } #endregion }