public VkAlbum GetVkGroupAlbum(VkGroup owningGroup, Int64 aid) { return new VkAlbum(aid) { OwnerId = -owningGroup.Id, }; }
/// <summary> /// Возвращает список групп указанного пользователя. /// </summary> /// <param name="user">ID пользователя, группы которого необходимо получить.</param> /// <returns></returns> public List<VkGroup> GetGroupsForUser(VkUser user) { var cmd = GetVkXmlCommand("groups.get", new Dictionary<string, object> {{"uid", user.Id}, {"extended", "1"}}, true); var response = cmd.GetResponseAsString(); var xml = new XmlDocument(); try { xml.LoadXml(response); } catch (Exception ex) { Logger.ErrorFormat("({0}) {1}", ex.GetType().Name, ex.Message); Logger.Debug(response); throw new ApplicationException("Сервер вернул некорректный ответ"); } if (String.Compare(xml.DocumentElement.Name, "error", StringComparison.OrdinalIgnoreCase) == 0) { Logger.Debug(response); throw new ApplicationException("Ошибка. Вызов процедуры "); } var result = new List<VkGroup>(); foreach (XmlElement groupXml in xml.DocumentElement.GetElementsByTagName("group")) { long gid; try { gid = Int32.Parse(groupXml["gid"].InnerText); } catch { continue; } var g = new VkGroup(gid); if (groupXml["name"] != null) g.Name = groupXml["name"].InnerText; if (groupXml["photo"] != null) g.PhotoUrl = groupXml["photo"].InnerText; if (groupXml["screen_name"] != null) g.ScreenName = groupXml["screen_name"].InnerText; if(groupXml["is_admin"] != null) g.IsAdmin = String.Compare(groupXml["is_admin"].InnerText, "1") == 0; g.Owner = user; result.Add(g); } return result; }
/// <summary> /// Возвращает список альбомов в группе пользователя. /// </summary> /// <param name="group">Группа альбомы которой запрашиваются</param> /// <returns></returns> public List<VkAlbum> GetAlbumsForGroup(VkGroup group) { var parameters = new Dictionary<string, object> { { "gid", group.Id } }; var cmd = GetVkXmlCommand("photos.getAlbums", parameters, false); string response; try { response = cmd.GetResponseAsString(); } catch (Exception e) { Logger.ErrorFormat("({0}) {1}", e.GetType().Name, e.Message); throw new VkMethodInvocationException((int) VkMethodInvocationErrorCode.FailedGetResponse, "Не удалось получить ответ от сервера"); } var xml = new XmlDocument(); try { xml.LoadXml(response); } catch (Exception ex) { Logger.ErrorFormat("XML parsing failed. ({0}) {1}", ex.GetType().Name, ex.Message); Logger.Debug(response); throw new VkMethodInvocationException((int)VkMethodInvocationErrorCode.IncorrectReplyFormat, "Сервер вернул некорректный ответ"); } if (VkErrorResponse.HasErrorInResponse(xml)) { var err = VkErrorResponse.Parse(xml); Logger.DebugFormat("VK Error ({0}) : {1}", err.ErrorCode, err.Message); throw new VkMethodInvocationException(err.ErrorCode, err.Message); } var result = new List<VkAlbum>(); foreach (XmlElement albumXml in xml.DocumentElement.GetElementsByTagName("album")) { long aid; try { aid = Int64.Parse(albumXml["aid"].InnerText); } catch (Exception e) { Logger.ErrorFormat("Cant parse album ID. ({0}) {1}", e.GetType().Name, e.Message); continue; } var g = new VkAlbum(aid); if (albumXml["created"] != null) { try { g.CreationDate = GetDateTimeFromUnix(Int32.Parse(albumXml["created"].InnerText)); } catch { Logger.DebugFormat("Cant parse 'created' property of album '{0}' : {1}", g.Id, albumXml["created"].InnerText); } } if (albumXml["updated"] != null) { try { g.UpdateDate = GetDateTimeFromUnix(Int32.Parse(albumXml["updated"].InnerText)); } catch { Logger.DebugFormat("Cant parse 'updated' property of album '{0}' : {1}", g.Id, albumXml["updated"].InnerText); } } if (albumXml["size"] != null) { try { g.Size = Int32.Parse(albumXml["size"].InnerText); } catch { Logger.DebugFormat("Cant parse 'size' property of album '{0}' : {1}", g.Id, albumXml["size"].InnerText); } } if (albumXml["owner_id"] != null) { try { g.OwnerId = Int32.Parse(albumXml["owner_id"].InnerText); } catch { Logger.DebugFormat("Cant parse 'owner_id' property of album '{0}' : {1}", g.Id, albumXml["owner_id"].InnerText); } } if (albumXml["title"] != null) { g.Title = albumXml["title"].InnerText; } if (albumXml["description"] != null) { g.Description = albumXml["description"].InnerText; } if (albumXml["thumb_src"] != null) { g.ThumbUrl = albumXml["thumb_src"].InnerText; } result.Add(g); } return result; }