Beispiel #1
0
        //Метод который добавляет в список раздачи новые посты
        public static PostID[] PublicList(this VkApi api, long fromGroupID, ulong count)
        {
            PostID[] Array = new PostID[] { };
            try
            {
                var FirstWall = api.Wall.Get(new WallGetParams
                {
                    OwnerId = fromGroupID,
                    Count   = count,
                });

                var            GoodWall = FirstWall.WallPosts.Where(p => p.Likes.Count >= FirstWall.WallPosts.Select(d => d.Likes.Count).ToArray().Mean()).ToArray();
                IList <PostID> PostID   = new List <PostID>();
                for (int i = 0; i < GoodWall.Length; i++)
                {
                    PostID.Add(new PostID()
                    {
                        PostBody = GoodWall[i], PostStringID = GoodWall[i].OwnerId.ToString() + GoodWall[i].Id.ToString()
                    });
                }


                return(PostID.ToArray());
            }
            catch (Exception ex)
            {
                Console.WriteLine("Произошла ошибка");
                return(Array);
            }
        }
Beispiel #2
0
        public static long FuncWallPost(this PostID post, VkApi api, string path, string PublicName, long GroupID)
        {
            long result = -1;

            IList <string> postKeyList = null;


            if (!File.Exists(path + PublicName + ".bin"))
            {
                File.Create(path + PublicName + ".bin").Close();
                postKeyList = new List <string>();
            }
            else
            {
                postKeyList = (IList <string>)DeseriaBinar(path + PublicName + ".bin") != null ? (IList <string>)DeseriaBinar(path + PublicName + ".bin") : new List <string>();
            }

            //если список больше 30, удаляем первый элемент
            //if (postKeyList.Count() > 30)
            //    postKeyList.Remove(postKeyList.First()); // Либо последний !!!!!!!!!!



            #region Непосредственный сбор контента в список перед отправкой

            IEnumerable <Attachment> groupList     = post.PostBody.Attachments;
            IEnumerable <Attachment> grListHistiry = post.PostBody.CopyHistory.Count() != 0 ? post.PostBody.CopyHistory.ElementAt(0).Attachments : null;

            List <MediaAttachment> newList = new List <MediaAttachment>();

            //копируем основной пост
            foreach (var item in groupList)
            {
                newList.Add((MediaAttachment)item.Instance);
            }

            //копируем, если есть репосты там
            if (grListHistiry != null)
            {
                foreach (var item in grListHistiry)
                {
                    newList.Add((MediaAttachment)item.Instance);
                }
            }

            #endregion

            #region  азмещение поста

            if (postKeyList.Where(p => p == post.PostStringID).Count() == 0)
            {
                try
                {
                    var newMyPost = api.Wall.Post(new WallPostParams
                    {
                        OwnerId     = GroupID,
                        Message     = post.PostBody.Text,
                        Attachments = newList,
                        FromGroup   = true
                    });

                    postKeyList.Add(post.PostStringID);
                    SeriaBinar(path + PublicName + ".bin", postKeyList);

                    result = newMyPost;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    result = -1;
                }
            }
            else
            {
                Console.WriteLine("Этот пост уже существует");
                result = -1;
            }



            #endregion

            return(result);
        }