当前位置: 首页>>代码示例>>C#>>正文


C# IPostService.GetPostById方法代码示例

本文整理汇总了C#中IPostService.GetPostById方法的典型用法代码示例。如果您正苦于以下问题:C# IPostService.GetPostById方法的具体用法?C# IPostService.GetPostById怎么用?C# IPostService.GetPostById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IPostService的用法示例。


在下文中一共展示了IPostService.GetPostById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            try
            {
                SkimurContext.Initialize(
                    new Program(),
                    new Skimur.App.Registrar());

                _mirrorSettings = SkimurContext.ServiceProvider.GetRequiredService<ISettingsProvider<MirrorSettings>>().Settings;
                _subService = SkimurContext.ServiceProvider.GetRequiredService<ISubService>();
                _postService = SkimurContext.ServiceProvider.GetRequiredService<IPostService>();
                _membershipService = SkimurContext.ServiceProvider.GetRequiredService<IMembershipService>();
                _commandBus = SkimurContext.ServiceProvider.GetRequiredService<ICommandBus>();

                if (_mirrorSettings.SubsToMirror == null || _mirrorSettings.SubsToMirror.Count == 0)
                    return;

                var botUser = _membershipService.GetUserByUserName(_mirrorSettings.BotName);
                if (botUser == null) return;

                var reddit = new Reddit();

                foreach (var subToMirror in _mirrorSettings.SubsToMirror)
                {
                    Console.WriteLine("Attempting to mirror " + subToMirror + ".");

                    var sub = _subService.GetSubByName(subToMirror);
                    if (sub == null)
                    {
                        Console.WriteLine("Sub doesn't exist.");
                        continue;
                    }

                    var redditSub = reddit.GetSubreddit("/r/" + subToMirror);
                    if (redditSub == null)
                    {
                        Console.WriteLine("Couldn't find reddit sub.");
                        continue;
                    }

                    foreach (var redditPost in redditSub.GetTop(_mirrorSettings.FromTime).Take(_mirrorSettings.PostsPerSub))
                    {
                        Console.WriteLine("Syncing " + redditPost.Title);

                        var existing = _postService.QueryPosts(redditPost.Title, sub.Id).Select(x => _postService.GetPostById(x)).ToList();
                        var exists = false;
                        if (existing.Count > 0)
                        {
                            foreach (var item in existing)
                            {
                                if (item.Title == redditPost.Title && item.Mirrored == "reddit")
                                    exists = true;
                            }
                        }
                        if (exists)
                        {
                            Console.WriteLine("Already exists.");
                            continue;
                        }

                        var createPostResponse = _commandBus.Send<CreatePost, CreatePostResponse>(
                            new CreatePost
                            {
                                CreatedByUserId = botUser.Id,
                                Title = redditPost.Title,
                                Url = redditPost.Url.ToString(),
                                Content = redditPost.SelfText,
                                PostType = redditPost.IsSelfPost ? PostType.Text : PostType.Link,
                                SubName = subToMirror,
                                NotifyReplies = false,
                                Mirror = "reddit",
                                OverrideDateCreated = redditPost.CreatedUTC
                            });

                        if (!string.IsNullOrEmpty(createPostResponse.Error))
                        {
                            Console.WriteLine("Couldn't create post. " + createPostResponse.Error);
                            continue;
                        }

                        if (!createPostResponse.PostId.HasValue)
                        {
                            Console.WriteLine("No post id");
                            continue;
                        }

                        var createCommentResponse = _commandBus.Send<CreateComment, CreateCommentResponse>(
                           new CreateComment
                           {
                               PostId = createPostResponse.PostId.Value,
                               DateCreated = Common.CurrentTime(),
                               AuthorUserName = botUser.UserName,
                               Body = string.Format("Mirrored from [here]({0}).", redditPost.Shortlink),
                               SendReplies = false
                           });

                        if (!string.IsNullOrEmpty(createCommentResponse.Error))
                        {
                            Console.WriteLine("Couldn't create comment. " + createCommentResponse.Error);
                        }
//.........这里部分代码省略.........
开发者ID:skimur,项目名称:skimur,代码行数:101,代码来源:Program.cs


注:本文中的IPostService.GetPostById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。