Exemple #1
0
        static int DoShowAll(ParsedOpts args)
        {
            var profileStore   = new UserProfileStore();
            var aggregateStore = new AggregateRiverStore();

            UserProfile profile = profileStore.GetProfileFor(args["user"].Value).Result;

            foreach (RiverDefinition rd in profile.Rivers)
            {
                Console.WriteLine("Loading {0} ({1})...", rd.Name, rd.Id);
                River river = aggregateStore.LoadAggregate(rd.Id).Result;
                if (river.UpdatedFeeds.Feeds.Count > 0)
                {
                    foreach (FeedSegment feed in river.UpdatedFeeds.Feeds)
                    {
                        DumpFeed(feed);
                    }
                }
                else
                {
                    Console.WriteLine("No data for {0}", rd.Name);
                }
            }

            return(0);
        }
Exemple #2
0
        static int DoResetLogins(ParsedOpts args)
        {
            string user = args["user"].Value;

            var profileStore = new UserProfileStore();
            var profile      = profileStore.GetProfileFor(user).Result;
            var newProfile   = profile.With(logins: new LoginCookie[0]);

            profileStore.SaveProfileFor(user, newProfile).Wait();
            Console.WriteLine("OK");
            return(0);
        }
Exemple #3
0
        static int DoSetPassword(ParsedOpts args)
        {
            string user     = args["user"].Value;
            string password = args["password"].Value;

            var profileStore = new UserProfileStore();
            var profile      = profileStore.GetProfileFor(user).Result;
            var newProfile   = profile.With(
                password: AuthenticationManager.EncryptPassword(password),
                logins: new LoginCookie[0]);

            profileStore.SaveProfileFor(user, newProfile).Wait();
            Console.WriteLine("OK");
            return(0);
        }
Exemple #4
0
        static int DoSetEmail(ParsedOpts args)
        {
            string user  = args["user"].Value;
            string email = args["email"].Value;

            var profileStore = new UserProfileStore();
            var profile      = profileStore.GetProfileFor(user).Result;
            var newProfile   = profile.With(
                email: email,
                emailVerified: false);

            profileStore.SaveProfileFor(user, newProfile).Wait();
            Console.WriteLine("OK");
            return(0);
        }
Exemple #5
0
        static int DoUpdateForUser(ParsedOpts args)
        {
            string user = args["user"].Value;

            var subscriptionStore = new UserProfileStore();
            var parser            = new RiverLoader();

            Console.WriteLine("Refreshing for {0}...", user);
            Stopwatch loadTimer = Stopwatch.StartNew();

            UserProfile profile = subscriptionStore.GetProfileFor(user).Result;
            var         tasks   = from rd in profile.Rivers select parser.RefreshAggregateRiverWithFeeds(rd.Id, rd.Feeds);

            Task.WhenAll(tasks).Wait();

            Console.WriteLine("Refreshed {0} rivers in {1}", profile.Rivers.Count, loadTimer.Elapsed);
            return(0);
        }
Exemple #6
0
        static int DoSubscribe(ParsedOpts args)
        {
            string user      = args["user"].Value;
            string feed      = args["feed"].Value;
            string riverName = args["river"].Value;

            // Check feed.
            var   parser    = new RiverLoader();
            var   feedStore = new RiverFeedStore();
            River feedRiver = parser.FetchAndUpdateRiver(new Uri(feed)).Result;

            if (feedRiver.Metadata.LastStatus < (HttpStatusCode)200 ||
                feedRiver.Metadata.LastStatus >= (HttpStatusCode)400)
            {
                Console.Error.WriteLine("Could not fetch feed {0}", feed);
                return(-1);
            }

            var             subscriptionStore = new UserProfileStore();
            UserProfile     profile           = subscriptionStore.GetProfileFor(user).Result;
            RiverDefinition river             = profile.Rivers.FirstOrDefault(r => r.Name == riverName);

            UserProfile newProfile;

            if (river == null)
            {
                newProfile = profile.With(
                    rivers: profile.Rivers.Add(
                        new RiverDefinition(
                            name: riverName,
                            id: SyndicationUtil.MakeID(),
                            feeds: new Uri[] { feedRiver.Metadata.OriginUrl })));
            }
            else
            {
                var newRiver = river.With(feeds: river.Feeds.Add(feedRiver.Metadata.OriginUrl));
                newProfile = profile.With(rivers: profile.Rivers.Replace(river, newRiver));
            }

            subscriptionStore.SaveProfileFor(user, newProfile).Wait();

            Console.WriteLine("OK");
            return(0);
        }
Exemple #7
0
        static int DoUnsubscribe(ParsedOpts args)
        {
            string user      = args["user"].Value;
            Uri    feed      = new Uri(args["feed"].Value);
            string riverName = args["river"].Value;

            var             subscriptionStore = new UserProfileStore();
            UserProfile     profile           = subscriptionStore.GetProfileFor(user).Result;
            RiverDefinition river             = profile.Rivers.FirstOrDefault(r => r.Name == riverName);

            if (river == null)
            {
                Console.WriteLine("River {0} not found.", riverName);
                return(0);
            }

            RiverDefinition newRiver   = river.With(feeds: river.Feeds.Remove(feed));
            UserProfile     newProfile = profile.With(rivers: profile.Rivers.Replace(river, newRiver));

            subscriptionStore.SaveProfileFor(user, newProfile).Wait();
            Console.WriteLine("OK");
            return(0);
        }
Exemple #8
0
        static int DoList(ParsedOpts args)
        {
            string      user    = args["user"].Value;
            UserProfile profile = new UserProfileStore().GetProfileFor(user).Result;

            foreach (var river in profile.Rivers)
            {
                Console.WriteLine("{0} ({1}):", river.Name, river.Id);
                if (river.Feeds.Count > 0)
                {
                    foreach (var feed in river.Feeds)
                    {
                        Console.WriteLine("  {0}", feed);
                    }
                }
                else
                {
                    Console.WriteLine("  No feeds.");
                }
                Console.WriteLine();
            }
            return(0);
        }