Ejemplo n.º 1
0
        async Task test()
        {
            applicationStart = DateTime.UtcNow;

            using (StreamReader sr = new StreamReader(new FileStream("data//Config.json", FileMode.Open)))
                Config = JsonConvert.DeserializeObject <Dictionary <string, string> >(sr.ReadToEnd());

            using (StreamReader sr = new StreamReader(new FileStream("data//FlairConfig.json", FileMode.Open)))
                FlairConfig = JsonConvert.DeserializeObject <Dictionary <string, int> >(sr.ReadToEnd());

            var webAgent = new BotWebAgent(Config["botAcc"], Config["botPw"], Config["clientId"], Config["clientSecret"], Config["redirectURI"]);

            reddit = new Reddit(webAgent, false);
            await reddit.InitOrUpdateUserAsync();

            subreddit = await reddit.GetSubredditAsync(Config["subreddit"]);

            CancellationTokenSource source     = new CancellationTokenSource();
            CancellationToken       token      = source.Token;
            ListingStream <Post>    postStream = subreddit.GetPosts(Subreddit.Sort.New).Stream();

            postStream.Subscribe(async post => await newPost(post));
            ListingStream <Comment> commentStream = subreddit.GetComments().Stream();

            commentStream.Subscribe(async comment => await newComment(comment));

            ListingStream <VotableThing> removedStream = subreddit.GetRemoved().Stream();

            removedStream.Subscribe(async thing => await removedThing(thing));

            await Task.WhenAll(new Task[] {
                postStream.Enumerate(token),
                commentStream.Enumerate(token),
                removedStream.Enumerate(token)
            });
        }