Ejemplo n.º 1
0
        // ReSharper restore InconsistentNaming

        protected ServiceProviderTestBase(params IRegistrar[] registrars)
        {
            var tmp = registrars.ToList();

            tmp.Add(new InternalRegistrar());
            _serviceProvider = SkimurContext.BuildServiceProvider(tmp.ToArray());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            SkimurContext.Initialize(new Program(),
                                     new Skimur.App.Registrar());

            Args.InvokeAction <Tasks>(args);
        }
Ejemplo n.º 3
0
 public void ConfigureContainer()
 {
     SkimurContext.Initialize(new Infrastructure.Registrar(),
                              new Infrastructure.Membership.Registrar(),
                              new Infrastructure.Email.Registrar(),
                              new Infrastructure.Messaging.Registrar(),
                              new Infrastructure.Messaging.RabbitMQ.Registrar(),
                              new Registrar(),
                              new Subs.Registrar(), this);
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            SkimurContext.ContainerInitialized += Skimur.Cassandra.Migrations.Migrations.Run;
            SkimurContext.ContainerInitialized += Skimur.Postgres.Migrations.Migrations.Run;
            SkimurContext.Initialize(new Skimur.Markdown.Registrar(),
                                     new Skimur.Scraper.Registrar(),
                                     new Subs.Registrar(),
                                     new Registrar(),
                                     new Membership.Registrar());

            using (SkimurContext.Resolve <IBusLifetime>())
            {
                Console.WriteLine("Press enter to end process...");
                Console.ReadLine();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            SkimurContext.Initialize(new Infrastructure.Registrar(),
                                     new Infrastructure.Membership.Registrar(),
                                     new Infrastructure.Email.Registrar(),
                                     new Infrastructure.Messaging.Registrar(),
                                     new Infrastructure.Messaging.RabbitMQ.Registrar(),
                                     new Subs.Registrar(),
                                     new Registrar());

            using (SkimurContext.Resolve <IBusLifetime>())
            {
                Console.WriteLine("Press enter to end process...");
                Console.ReadLine();
            }
        }
Ejemplo n.º 6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            SkimurContext.Initialize(
                new ServiceCollectionRegistrar(services, 0),
                this,
                new Registrar(),
                new App.Handlers.Registrar(),
                new Skimur.Markdown.Registrar(),
                new Skimur.Scraper.Registrar());



            // this will start the command listeners for subs, email, etc.
            SkimurContext.ServiceProvider.GetService <Messaging.IBusLifetime>();

            return(SkimurContext.ServiceProvider);
        }
Ejemplo n.º 7
0
        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);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            SkimurContext.ContainerInitialized += Skimur.Cassandra.Migrations.Migrations.Run;
            SkimurContext.ContainerInitialized += Skimur.Postgres.Migrations.Migrations.Run;
            SkimurContext.Initialize(new Skimur.Markdown.Registrar(),
                                     new Skimur.Scraper.Registrar(),
                                     new Subs.Registrar(),
                                     new Subs.Worker.Registrar(),
                                     new Membership.Registrar());

            using (SkimurContext.Resolve <IBusLifetime>())
            {
                var subDao            = SkimurContext.Resolve <ISubDao>();
                var membershipService = SkimurContext.Resolve <IMembershipService>();
                var postDao           = SkimurContext.Resolve <IPostDao>();
                var commentDao        = SkimurContext.Resolve <ICommentDao>();

                var defaultUser = membershipService.GetUserByUserName("skimur");
                if (defaultUser == null)
                {
                    Console.WriteLine("You must have a user with the username 'skimur' created to insert test data.");
                    return;
                }

                foreach (var subToExamine in new List <string>
                {
                    "/r/news",
                    "/r/pics"
                })
                {
                    ExamineSubreddit(subToExamine,
                                     subreddit =>
                    {
                        var sub = subDao.GetSubByName(subreddit.Name);

                        if (sub != null)
                        {
                            return(sub);
                        }

                        var response = SkimurContext.Resolve <ICommandHandlerResponse <CreateSub, CreateSubResponse> >()
                                       .Handle(new CreateSub
                        {
                            Name            = subreddit.Name,
                            CreatedByUserId = defaultUser.Id,
                            Description     = subreddit.Description,
                            SidebarText     = subreddit.Description,
                            Type            = Subs.SubType.Public
                        });

                        if (!string.IsNullOrEmpty(response.Error))
                        {
                            Console.WriteLine("Couldn't create the news sub. " + response.Error);
                            return(null);
                        }

                        return(subDao.GetSubByName(response.SubName));
                    },
                                     (sub, redditPost) =>
                    {
                        var response = SkimurContext.Resolve <ICommandHandlerResponse <CreatePost, CreatePostResponse> >()
                                       .Handle(new CreatePost
                        {
                            Url             = redditPost.Url.OriginalString,
                            SubName         = sub.Name,
                            PostType        = redditPost.IsSelfPost ? Subs.PostType.Text : Subs.PostType.Link,
                            Title           = redditPost.Title,
                            Content         = redditPost.SelfText,
                            CreatedByUserId = defaultUser.Id,
                            IpAddress       = "127.0.0.1",
                            NotifyReplies   = true
                        });

                        if (!string.IsNullOrEmpty(response.Error))
                        {
                            Console.WriteLine("Error creating post. " + response.Error);
                            return(null);
                        }

                        if (!response.PostId.HasValue)
                        {
                            Console.WriteLine("No post id returned.");
                            return(null);
                        }

                        return(postDao.GetPostById(response.PostId.Value));
                    },
                                     (post, redditComment, parentComment) =>
                    {
                        var response = SkimurContext.Resolve <ICommandHandlerResponse <CreateComment, CreateCommentResponse> >()
                                       .Handle(new CreateComment
                        {
                            PostId          = post.Id,
                            ParentId        = parentComment != null ? parentComment.Id : (Guid?)null,
                            DateCreated     = redditComment.CreatedUTC,
                            AuthorUserName  = defaultUser.UserName,
                            AuthorIpAddress = "127.0.0.1",
                            Body            = redditComment.Body,
                            SendReplies     = true
                        });

                        if (!string.IsNullOrEmpty(response.Error))
                        {
                            Console.WriteLine("Error creating comment. " + response.Error);
                            return(null);
                        }

                        if (!response.CommentId.HasValue)
                        {
                            Console.WriteLine("No comment id returned.");
                            return(null);
                        }

                        return(commentDao.GetCommentById(response.CommentId.Value));
                    });
                }
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            SkimurContext.Initialize(new Program(), new DataRegistrar());

            Args.InvokeAction <CommandHandler>(args);
        }