示例#1
0
        private void SendVideoPost(IPostModel post)
        {
            if (post.Attachments == null)
            {
                throw new ArgumentException("Images Post: post.attachments = null");
            }

            if (post.Attachments.Length == 0)
            {
                throw new ArgumentException("Images Post: post.attachments.length = 0");
            }

            if (post.Attachments[0] == null)
            {
                throw new ArgumentException("Images Post: post.attachments[0] = null");
            }

            var temp = bot.SendVideoAsync(
                ChannelID,
                new InputMedia(post.Attachments[0]),
                caption: post.Text,
                parseMode: ParseMode.Markdown);

            temp.Wait();
            Console.WriteLine(temp.Result.Text);
        }
示例#2
0
        private void SendContactPost(IPostModel post)
        {
            if (post.Text == null)
            {
                throw new ArgumentException("Images Post: post.text = null");
            }

            if (post.Attachments == null)
            {
                throw new ArgumentException("Images Post: post.attachments = null");
            }

            if (post.Attachments.Length == 0)
            {
                throw new ArgumentException("Images Post: post.attachments.length = 0");
            }

            var temp = bot.SendContactAsync(
                ChannelID,
                post.Attachments[0],
                post.Text);

            temp.Wait();
            Console.WriteLine(temp.Result);
        }
        /// <summary>
        /// Posts the message, asynchronously.
        /// </summary>
        /// <returns>
        /// The completion task.
        /// </returns>
        public static async Task PostMessageAsync(this IPostModel model)
        {
            model.ThrowIfNull(nameof(model));
            string messageText = model.ReplyMessage;

            model.ReplyMessage = string.Empty;

            try
            {
                if (!string.IsNullOrEmpty(messageText))
                {
                    PostRequest request = new PostRequest(messageText);
                    if (model.GroupId.HasValue)
                    {
                        request.GroupId = model.GroupId;
                    }

                    if (model.ReplyTo != null)
                    {
                        request.ReplyToId = model.ReplyTo.Id;
                    }

                    System.Diagnostics.Debug.Assert(request.GroupId.HasValue || request.ReplyToId.HasValue);

                    MessageFeed feed = await YammerService.Instance.PostMessageAsync(request);

                    System.Diagnostics.Debug.Assert(feed.Messages.Length == 1);
                    model.MessagePosted(feed);
                }
            }
            catch
            {
                model.ReplyMessage = messageText;
            }
        }
示例#4
0
 public PostModel(IPostModel postModel)
 {
     Id        = postModel.Id;
     CreatedAt = postModel.CreatedAt;
     Body      = postModel.Body;
     Likes     = postModel.Likes;
     Title     = postModel.Title;
     UserId    = postModel.UserId;
 }
示例#5
0
        public void UpdatePostTest(IPostModel post)
        {
            var response        = _systemRequests.UpdatePost(post);
            var responseFromGet = _systemRequests.GetPost(post.Id);

            Assert.Multiple(() =>
            {
                post.GetJObject().AssertJObjects(response, "response of updating");
                post.GetJObject().AssertJObjects(responseFromGet, "response from GET request");
                Assert.AreEqual(post.GetJObject().Count, response.Count, "Check that qty of params are the same");
            });
        }
示例#6
0
        public static void ConvertToIPost(object input, IPostModel model)
        {
            var type = input.GetType().GetRealType();

            model.FullType     = type.FullName;
            model.ThisAssembly = type.Assembly.FullName;
            int  lang    = 0;
            long modelId = 0;

            if (model is ContentPostModel)
            {
                (model as ContentPostModel).ViewPath = type.Name;
                lang = (input as IContentModel).Lang;
            }
            modelId = (input as IInt64Key).Id;
            var resultProperty = model.GetType().GetRealType().GetProperties().Where(b => b.BaseProperty()).ToList();
            var properties     = input.GetType().GetRealType().GetProperties();

            foreach (var p in properties)
            {
                if (p.SkippedProperty())
                {
                    continue;
                }
                if (p.BaseProperty())
                {
                    var baseP = resultProperty.Where(b => b.Name == p.Name).FirstOrDefault();
                    if (baseP == null)
                    {
                        continue;
                    }
                    var inputValue = p.GetValue(input);
                    if (inputValue == null)
                    {
                        continue;
                    }

                    baseP.SetValue(model, inputValue);
                    continue;
                }
                var prop = p.GetContentPropertyByPropertyInfo(input, lang, modelId);
                if (prop == null)
                {
                    continue;
                }
                model.Properties.Add(prop);
            }
            model.Properties = model.Properties.OrderByDescending(b => b.SortOrder).ToList();
        }
示例#7
0
        private void SendTextPost(IPostModel post)
        {
            if (post.Text == null)
            {
                throw new ArgumentException("Text Post: post.text = null");
            }

            var temp = bot.SendTextMessageAsync(
                ChannelID,
                post.Text,
                ParseMode.Markdown);

            temp.Wait();
            Console.WriteLine(temp.Result);
        }
示例#8
0
        public static object ConvertBaseTypeToEnity(this IPostModel input, out string typeName, out string assemblyName)
        {
            var type = Type.GetType($"{input.FullType},{input.ThisAssembly}");

            typeName     = input.FullType;
            assemblyName = input.ThisAssembly;
            if (type == null)
            {
                return(null);
            }
            var result     = Activator.CreateInstance(type);
            var properties = result.GetType().GetRealType().GetProperties();

            return(result);
        }
示例#9
0
        public void AddPostTest(IPostModel post)
        {
            var _newPostId = _systemRequests.GetLastPostId() + 1;
            var response   = _systemRequests.AddPost(post);

            //Can assert all json by one assert
            Assert.Multiple(() =>
            {
                Assert.AreEqual(post.Title, response["title"].ToString(), "Check response param: title");
                Assert.AreEqual(post.UserId, (int)response["userId"], "Check response param: userId");
                Assert.AreEqual(post.Body, response["body"].ToString(), "Check response param: body");
                Assert.AreEqual(_newPostId, (int)response["id"], "Check response param: id");
            });
            //I've skipped all new post param verification by get request for test task. Check just that new post is returned by GET request.
            Assert.AreEqual(_newPostId, _systemRequests.GetLastPostId(), "Check that new post is returned by GET request");
        }
示例#10
0
        public void SendPost(IPostModel post)
        {
            if (post == null)
            {
                throw new ArgumentNullException("post");
            }

            try
            {
                switch (post.Type)
                {
                case PostType.Text:
                    SendTextPost(post);
                    break;

                case PostType.Image:
                    SendImagePost(post);
                    break;

                case PostType.Video:
                    SendVideoPost(post);
                    break;

                case PostType.Images:
                    SendImagesPost(post);
                    break;

                case PostType.Videos:
                    SendVideosPost(post);
                    break;

                case PostType.Audio:
                    SendAudioPost(post);
                    break;

                case PostType.Contact:
                    SendContactPost(post);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#11
0
        private void SendVideosPost(IPostModel post)
        {
            if (post.Attachments == null)
            {
                throw new ArgumentException("Images Post: post.attachments = null");
            }

            if (post.Attachments.Length < 2)
            {
                throw new ArgumentException("Images Post: post.attachments.length < 2");
            }

            var temp = bot.SendMediaGroupAsync(
                post.Attachments.Select(x => new InputMediaVideo(new InputMedia(x))),
                ChannelID);

            temp.Wait();
            Console.WriteLine(temp.Result);
        }
示例#12
0
        public static object ConvertToBaseModel(this IPostModel input, object result, bool deleteExistFile = true, List <string> oldFiles = null, List <string> newFiles = null)
        {
            var type = input.FullType;
            var asm  = input.ThisAssembly;

            var properties   = result.GetType().GetRealType().GetProperties();
            var baseProperty = input.GetType().GetRealType().GetProperties().Where(b => b.BaseProperty()).ToList();

            foreach (var p in properties)
            {
                try
                {
                    if (p.BaseProperty())
                    {
                        var inputBaseProperty = baseProperty.Where(b => b.Name == p.Name).FirstOrDefault();
                        if (inputBaseProperty == null)
                        {
                            continue;
                        }
                        p.SetValue(result, inputBaseProperty.GetValue(input));
                        continue;
                    }
                    if (p.SkippedProperty())
                    {
                        continue;
                    }

                    p.SetPropertyValue(input, result, deleteExistFile, oldFiles, newFiles);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(result);
        }
示例#13
0
        public static object ConvertToBaseModel(this IPostModel input, bool deleteExistFile = true, List <string> oldFiles = null, List <string> newFiles = null)
        {
            var result = input.ConvertBaseTypeToEnity(out var typeName, out var assemblyName);

            return(input.ConvertToBaseModel(result, deleteExistFile, oldFiles, newFiles));
        }
示例#14
0
 public PostListController()
 {
     postModel = PostModel.GetPostModel();
 }
 public PostController(IPostModel model)
 {
     _model = model;
 }
示例#16
0
 /// <summary>
 /// Delete the given post.
 /// </summary>
 /// <param name="post">
 /// The post to delete.
 /// </param>
 /// <exception cref="NotImplementedException">
 /// Because this is not yet implemented !
 /// </exception>
 public void Delete(IPostModel post)
 {
     // TODO: mark as deleted
     this.Storage.Msg.Remove(post.Id);
 }
示例#17
0
 public static JObject GetJObject(this IPostModel postModel)
 {
     return(JObject.Parse(JsonConvert.SerializeObject(postModel)));
 }
 public PostListActionFilterAttribute(IPostModel model)
 {
     _model = model;
 }
示例#19
0
 public PostController(IPostModel postModel)
 {
     _postModel = postModel;
 }
示例#20
0
        //Add Post and Verify success status code
        public JObject AddPost(IPostModel post)
        {
            var context = _apiClient.Post(UriConst.Posts, JsonConvert.SerializeObject(post));

            return(context.VerifyCode().GetJObject());
        }