public void getPhoto(List<uint> uids, string size) { string s = ""; string zap = ""; string separ; ArrayList arrResp; contactJob Refresh = new contactJob(myContactList.ContactList.Refresh); if (uids.Count == 1) separ = ""; else separ = ","; foreach (uint item in uids) zap = item.ToString() + separ + zap; WebClient user = new WebClient(); string uri = "getProfiles?fields=" + size + "&format=JSON&uids=" + zap; s = vk_call(uri); if (!Directory.Exists(vars.VARS.Directory + size + "\\")) // если для такого размера ещё нет папки, создаём... Directory.CreateDirectory(vars.VARS.Directory + size + "\\"); if (s != "" && s.IndexOf("error") == -1) { Hashtable resp = (Hashtable)JSON.JsonDecode(s); arrResp = (ArrayList)resp["response"]; foreach (Hashtable item in arrResp) { try { user.DownloadFile(Convert.ToString(item["photo"]), vars.VARS.Directory + size + "\\" + Convert.ToString(item["uid"])); // загружаем if (vars.VARS.SmallPhoto.Images.ContainsKey(Convert.ToString(item["uid"]))) { // добавляем новое изображение к контакту vars.VARS.SmallPhoto.Images.RemoveByKey(Convert.ToString(item["uid"])); vars.VARS.SmallPhoto.Images.Add(Convert.ToString(item["uid"]), Image.FromFile(vars.VARS.Directory + size + "\\" + Convert.ToString(item["uid"]))); } else vars.VARS.SmallPhoto.Images.Add(Convert.ToString(item["uid"]), Image.FromFile(vars.VARS.Directory + size + "\\" + Convert.ToString(item["uid"]))); } catch (WebException exe) { GeneralMethods.WriteError(exe.Source, exe.Message, exe.TargetSite); } } } myContactList.ContactList.Invoke(Refresh); // обновляем контакт лист }
/// <summary> /// Получение непрочитанных сообщений /// </summary> public void messageGet() { string s; string uri = "messages.get?filters=1&format=JSON&preview_length=0&uids=" + vars.VARS.Mid; s = vk_call(uri); if (!(s.Length <= 15) && s.IndexOf("error") == -1) { Hashtable jsonResp = (Hashtable)JSON.JsonDecode(s); ArrayList arrResp = (ArrayList)jsonResp["response"]; Hashtable msg = new Hashtable(); uint uid, mid; contactJob show = new contactJob(vars.VARS.Chat.Show); for (int i = 0; i < Convert.ToInt32(arrResp[0]); i++) { msg = (Hashtable)arrResp[i + 1]; uid = Convert.ToUInt32(msg["uid"]); mid = Convert.ToUInt32(msg["mid"]); if (vars.VARS.Chat.richtbox.ContainsKey(uid) == false) { newTab tab = new newTab(ChatForm.chat.chatIn); vars.VARS.Chat.Invoke(tab, uid, vars.VARS.Contact[uid].UserName, true); //chatIn(uid, vars.VARS.Contact[uid].UserName, true); history1 getHist = new history1(getHistory); IAsyncResult res1 = getHist.BeginInvoke(uid, 10, null, null); vars.VARS.Chat.Invoke(show); } if (vars.VARS.NumbMass.ContainsKey(uid)) vars.VARS.NumbMass[uid].Add(mid); else { vars.VARS.NumbMass.Add(uid, new List<uint>()); vars.VARS.NumbMass[uid].Add(mid); } } foreach (uint item in vars.VARS.NumbMass.Keys) markAsRead(item); show = new contactJob(vars.VARS.Chat.Activate); vars.VARS.Chat.Invoke(show); } }
/// <summary> /// Загрузка иконок /// </summary> public void getIcon() { if (!Directory.Exists(vars.VARS.Directory + "photo\\")) Directory.CreateDirectory(vars.VARS.Directory + "photo\\"); WebClient webClient = new WebClient(); Image newImage; contactJob Refresh = new contactJob(myContactList.ContactList.Refresh); SortedDictionary<uint, profile> temp = new SortedDictionary<uint,profile>(vars.VARS.Contact); foreach (KeyValuePair<uint, profile> item in temp) { try { webClient.DownloadFile(item.Value.photo, vars.VARS.Directory + "photo\\" + item.Value.uid); newImage = Image.FromFile(vars.VARS.Directory + "photo\\" + item.Value.uid, true); vars.VARS.SmallPhoto.Images.Add(item.Key.ToString(), newImage); if ((myContactList.ContactList.Items.IndexOf(item.Key) >= myContactList.ContactList.Offset / HEIGHT_ITEM) & (myContactList.ContactList.Items.IndexOf(item.Key) <= (myContactList.ContactList.Offset / HEIGHT_ITEM + myContactList.ContactList.Height / HEIGHT_ITEM))) // если контакт видим, перерисовываем, если нет, то незачем обновлять лишний раз myContactList.ContactList.Invoke(Refresh); } catch (WebException exe) { GeneralMethods.WriteError(exe.Source, exe.Message, exe.TargetSite); vars.VARS.SmallPhoto.Images.Add(item.Key.ToString(), Properties.Resources.redBall); } } }