Пример #1
0
        public void AddContext(TwitterAccountData data)
        {
            LogTo.Info($"Adding account data for {data.AccountName} ({data.UserId})");
            Contexts.Add(new ContextEntry(Notifier, data, Cache));

            SaveToFile();

            ContextsChanged?.Invoke(this, EventArgs.Empty);
        }
Пример #2
0
        /// <summary>
        ///     Only pass decrypted data to this method.
        /// </summary>
        /// <param name="data"></param>
        public void UpdateAccount(TwitterAccountData data)
        {
            LogTo.Info($"Updating account data for {data.AccountName} ({data.UserId})");
            var context = Contexts.FirstOrDefault(c => c.UserId == data.UserId);

            Contexts.Remove(context);

            Contexts.Add(new ContextEntry(Notifier, data, Cache));
            SaveToFile();
        }
Пример #3
0
        private void SaveToFile()
        {
            var json = Serializer.Serialize(Contexts.Select(ctx =>
            {
                var result = new TwitterAccountData
                {
                    AccountName      = ctx.AccountName,
                    ImageUrl         = ctx.ProfileImageUrl.AbsoluteUri,
                    OAuthToken       = ctx.Twitter.Authorizer.CredentialStore.OAuthToken,
                    OAuthTokenSecret = ctx.Twitter.Authorizer.CredentialStore.OAuthTokenSecret,
                    UserId           = ctx.UserId,
                    IsDefault        = ctx.IsDefault,
                    RequiresConfirm  = ctx.RequiresConfirmation
                };

                result.Encrypt();
                return(result);
            }).ToList());

            File.WriteAllText(FileName, json);
        }
Пример #4
0
        public ContextEntry(INotifier notifier, TwitterAccountData data, ICache cache)
        {
            Data     = data;
            Notifier = notifier;

            AccountName          = data.AccountName;
            UserId               = data.UserId;
            ProfileImageUrl      = new Uri(data.ImageUrl);
            IsDefault            = data.IsDefault;
            RequiresConfirmation = data.RequiresConfirm;

            Twitter = new TwitterContextWrapper(new TwitterContext(new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ScreenName       = data.AccountName,
                    UserID           = data.UserId,
                    ConsumerKey      = Constants.Auth.ConsumerKey,
                    ConsumerSecret   = Constants.Auth.ConsumerSecret,
                    OAuthToken       = data.OAuthToken,
                    OAuthTokenSecret = data.OAuthTokenSecret
                }
            }), cache);
        }
Пример #5
0
 internal ContextEntry(INotifier notifier, TwitterAccountData data, ICache cache, ITwitterContext context)
 {
     Data     = data;
     Notifier = notifier;
     Twitter  = context;
 }