Beispiel #1
0
 public int Insert(TwitterApp entity)
 {
     using (_connection = Utilities.Database.GetProfiledOpenConnection())
     {
         return(_connection.Insert(entity).Value);
     }
 }
        public SearchResultWithRateLimit Search(string query, long sinceid, TwitterApp keys)
        {
            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);

            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var options = new SearchOptions
            {
                Q          = System.Web.HttpUtility.UrlEncode(query),
                Count      = 100,
                Lang       = "en",
                Resulttype = TwitterSearchResultType.Mixed,
                SinceId    = sinceid
            };

            // Geocode = new TwitterGeoLocationSearch(39.6456, -79.9433, 30, TwitterGeoLocationSearch.RadiusType.Mi),

            var result = new SearchResultWithRateLimit();

            result.SearchResult    = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = sinceid;
            }

            return(result);
        }
Beispiel #3
0
 public void Update(TwitterApp entity)
 {
     using (_connection = Utilities.Database.GetProfiledOpenConnection())
     {
         _connection.Update(entity);
     }
 }
Beispiel #4
0
        private SearchResultWithRateLimit GetTweets(string query, TwitterApp app)
        {
            if (HttpContext.Application[query + "Last"] == null)
            {
                HttpContext.Application[query + "Last"] = 10;
            }
            var results = _twitterSearchRepository.Search(query, Convert.ToInt64(HttpContext.Application[query + "Last"]), app);

            HttpContext.Application[query + "Last"] = results.LastId;
            return(results);
        }
Beispiel #5
0
 public TwitterApp SaveOrUpdate(TwitterApp entity)
 {
     if (entity.ApiApplicationId == 0)
     {
         entity.ApiApplicationId = _apiApplicationRepository.Insert(entity);
     }
     else
     {
         _apiApplicationRepository.Update(entity);
     }
     return(entity);
 }
        public SearchResultWithRateLimit Search(SearchOptions options, TwitterApp keys)
        {
            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);

            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var result = new SearchResultWithRateLimit();

            result.SearchResult    = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = options.SinceId.Value;
            }

            return(result);
        }
Beispiel #7
0
        public void Insert(TwitterApp.Models.User entity, ActionState actionState)
        {
            MongoServer server = null;
            MongoDatabase database = null;
            try
            {
                server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]);
                database = server.GetDatabase(CommonConstants.DatabaseName);
                var dataCollection = database.CollectionExists(UserConstants.UserCollection);
                if (Convert.ToBoolean(dataCollection) == false)
                {
                    database.CreateCollection(UserConstants.UserCollection);
                }
                else
                {
                    MongoCollection<BsonDocument> user = database.GetCollection<BsonDocument>(UserConstants.UserCollection);
                    BsonDocument userEntity = new BsonDocument {
                { UserConstants.Name, entity.Name },
                { UserConstants.Username, entity.Username },
                { UserConstants.Password, entity.Password },
                { UserConstants.CreatedDate, entity.CreatedDate }
                };
                    user.Insert(userEntity);
                    actionState.SetSuccess();

                }
            }
            catch (Exception ex)
            {
                actionState.SetFail(ActionStateEnum.Exception, ex.Message);
            }
            finally
            {
                server.Disconnect();
                server = null;
                database = null;

            }
        }
Beispiel #8
0
 public void Delete(TwitterApp.Models.User entity, ActionState actionState)
 {
     MongoServer server = null;
     MongoDatabase database = null;
     try
     {
         server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]);
         database = server.GetDatabase(CommonConstants.DatabaseName);
         MongoCollection<BsonDocument> user = database.GetCollection<BsonDocument>(UserConstants.UserCollection);
         user.Remove(new QueryDocument(UserConstants.ID, ObjectId.Parse(entity.ID)));
         actionState.SetSuccess();
     }
     catch (Exception ex)
     {
         actionState.SetFail(ActionStateEnum.Exception, ex.Message);
     }
     finally
     {
         server.Disconnect();
         server = null;
         database = null;
     }
 }
Beispiel #9
0
        void ucLogin_LoginCompleted(object sender, LoginCompletedEventArgs e)
        {
            // retrieve logged in user
            ExtendedUser loggedInUser = e.LoggedInUser;

            // apply user settings after login completed
            UserSetting setting = ConfigurationManager.Default.GetUserSetting(loggedInUser.ScreenName);
            Left = setting.WindowLocation.X;
            Top = setting.WindowLocation.Y;
            Width = setting.WindowSize.Width;
            Height = setting.WindowSize.Height;
            _timerInterval = setting.RefreshTimerInterval;
            _isWebPagePreviewEnabled = setting.IsWebPagePreviewEnabled;

            // show twitter main view
            LoginView.Visibility = Visibility.Hidden;
            MainView.Visibility = Visibility.Visible;

            // init twitter application logic
            _twitter = new TwitterApp(e.Username, e.Password, loggedInUser);

            // hook up twitter app event handlers
            _twitter.TinyUrlCompleted += new TwitterApp.TinyUrlCompletedHandler(TinyUrlCompleted);
            _twitter.TwitPicCompleted += new TwitterApp.TwitPicCompletedHandler(TwitPicCompleted);
            _twitter.TweetsManager.TweetsManagerOperationCompleted += new TweetsManager.TweetsManagerCompletedHandler(TweetsManager_OperationCompleted);
            _twitter.TweetsManager.OperationError += new BaseCollectionManager<Status>.OperationErrorHandler(Twitter_OperationError);
            _twitter.RepliesManager.OperationCompleted += new BaseCollectionManager<Status>.OperationCompletedHandler(RepliesManager_OperationCompleted);
            _twitter.RepliesManager.OperationError += new BaseCollectionManager<Status>.OperationErrorHandler(Twitter_OperationError);
            _twitter.DirectMessageManager.OperationCompleted += new BaseCollectionManager<DirectMessage>.OperationCompletedHandler(DirectMessagesManager_OperationCompleted);
            _twitter.DirectMessageManager.OperationError += new BaseCollectionManager<DirectMessage>.OperationErrorHandler(Twitter_OperationError);
            _twitter.UserProfileManager.UserProfileOperationCompleted += new UserProfileManager.UserProfileOperationCompletedHandler(UserProfileOperationCompleted);
            _twitter.UserProfileManager.OperationError += new BaseManager.OperationErrorHandler(Twitter_OperationError);
            _twitter.FriendsManager.OperationCompleted += new BaseManager.OperationCompletedHandler(FriendsManager_OperationCompleted);
            _twitter.FriendsManager.OperationError += new BaseManager.OperationErrorHandler(Twitter_OperationError);
            //_twitter.SearchManager.OperationCompleted += new BaseManager.OperationCompletedHandler(SearchManager_OperationCompleted);
            //_twitter.SearchManager.OperationError += new BaseManager.OperationErrorHandler(SearchManager_OperationError);
            //_twitter.SavedSearchesManager.Initialize(
            //    ConfigurationManager.Default.SavedSearches,
            //    SearchManager_OperationCompleted,
            //    SearchManager_OperationError);
            _twitter.FavouritesManager.OperationCompleted += new BaseManager.OperationCompletedHandler(FavouritesManager_OperationCompleted);
            _twitter.FavouritesManager.OperationError += new BaseManager.OperationErrorHandler(FavouritesManager_OperationError);

            // create system tray icon
            _trayIcon = new System.Windows.Forms.NotifyIcon();
            _trayIcon.Icon = new System.Drawing.Icon(@"Images\tray.ico");
            _trayIcon.Click += new EventHandler(trayIcon_Click);
            _trayIcon.Visible = true;

            // set data context and data source
            SelectedUser = loggedInUser;
            ddpProfile.DataContext = this;
            icAllTweets.ItemsSource = AllTweets;
            icAllReplies.ItemsSource = AllReplies;
            icDirectMessages.ItemsSource = AllDirectMessages;
            icFriends.ItemsSource = AllFriends;
            icUserTweets.ItemsSource = SelectedUserTweets;
            icAllFavourites.ItemsSource = AllFavourites;
            lbFollowing.ItemsSource = AllFriends;

            // get data from twitter api
            _twitter.TweetsManager.RefreshAllAsync();
            _twitter.RepliesManager.RefreshAllAsync();
            _twitter.DirectMessageManager.RefreshAllAsync();
            _twitter.UserProfileManager.GetUserDetailsAsync(LoggedInUser.Id);
            _twitter.FriendsManager.GetFriendsAsync();
            _twitter.FavouritesManager.GetFavouritesAsync();

            // init categories manager and create tab for each categories
            CategoriesManager.Initialize(loggedInUser.ScreenName, AllTweets);
            foreach (string categoryName in CategoriesManager.GetCategoryNames())
            {
                // init tweets panel control for category
                TweetsPanelControl tweetsPanel = new TweetsPanelControl();
                tweetsPanel.ItemsSource = CategoriesManager.GetCategoryView(categoryName);
                tweetsPanel.IsShowMoreButton = Visibility.Collapsed;
                tweetsPanel.AvatarClicked += new MouseButtonEventHandler(imgAvatar_MouseDown);
                tweetsPanel.TweetTextLoaded += new RoutedEventHandler(TextBlock_Loaded);
                tweetsPanel.ReplyClicked += new RoutedEventHandler(btnReply_Click);
                tweetsPanel.DirectMessageClicked += new RoutedEventHandler(btnDirectMessage_Click);
                tweetsPanel.RetweetClicked += new RoutedEventHandler(btnRetweet_Click);
                tweetsPanel.DeleteClicked += new RoutedEventHandler(btnDelete_Click);
                tweetsPanel.FavouriteClicked += new RoutedEventHandler(cbFavourite_Click);

                // init tab for cateogry
                CategoryTabItem tab = CreateCategoryTab(categoryName, tweetsPanel);

                // add tab to tab host
                tcCategories.Items.Insert(tcCategories.Items.Count - 1, tab);
            }

            // load saved searches
            foreach (string keyword in ConfigurationManager.Default.SavedSearches)
            {
                TabItem searchTab = CreateSearch(keyword);
                tcSearches.Items.Add(searchTab);
                tcSearches.SelectedItem = searchTab;
            }
            tcSearches.SelectedIndex = 0;

            // init refresh timer
            _timer  = new Timer(
                new TimerCallback(RefreshTimer),
                null,
                TimeSpan.FromSeconds((double)_timerInterval),
                TimeSpan.FromSeconds((double)_timerInterval));

            // init notification window
            _notififcation = new AlertWindow();

            // init url preview control
            _browser = new WebPagePreviewControl();
            _browser.Owner = this;

            // make sure unhandled exceptions will not crash app
            Application.Current.Dispatcher.UnhandledException += new DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
        }
        public SearchResultWithRateLimit Search(string queryTerm, int resultType, long sinceId, TwitterApp keys)
        {
            SearchOptions options = new SearchOptions
            {
                Q          = System.Web.HttpUtility.UrlEncode(queryTerm),
                Count      = 100,
                Lang       = "en",
                Resulttype = (TwitterSearchResultType)resultType,
                SinceId    = sinceId
            };

            var service = new TwitterService(keys.ConsumerKey, keys.ConsumerKeySecret);

            service.AuthenticateWith(keys.Token, keys.TokenSecret);
            var result = new SearchResultWithRateLimit();

            result.SearchResult    = service.Search(options);
            result.RateLimitStatus = service.Response.RateLimitStatus;
            if (result.SearchResult.Statuses.Any())
            {
                result.LastId = result.SearchResult.Statuses.OrderByDescending(f => f.Id).FirstOrDefault().Id;
            }
            else
            {
                result.LastId = options.SinceId.Value;
            }

            return(result);
        }
Beispiel #11
0
        public void Update(TwitterApp.Models.User entity, ActionState actionState)
        {
            MongoServer server = null;
            MongoDatabase database = null;
            try
            {
                server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]);
                database = server.GetDatabase(CommonConstants.DatabaseName);
                MongoCollection<BsonDocument> user = database.GetCollection<BsonDocument>(UserConstants.UserCollection);
                var userEntity = user.FindOneById(ObjectId.Parse(entity.ID));
                userEntity[UserConstants.Name] = entity.Name;
                userEntity[UserConstants.Password] = entity.Password;
                user.Save(userEntity);
                actionState.SetSuccess();

            }
            catch (Exception ex)
            {
                actionState.SetFail(ActionStateEnum.Exception, ex.Message);
            }
            finally
            {
                server.Disconnect();
                server = null;
                database = null;
            }
        }
Beispiel #12
0
 public bool IsExist(TwitterApp.Models.User entity, ActionState actionState)
 {
     MongoServer server = null;
     MongoDatabase database = null;
     bool isExist = false;
     try
     {
         server = MongoServer.Create(ConfigurationManager.AppSettings[CommonConstants.ConnictionString]);
         database = server.GetDatabase(CommonConstants.DatabaseName);
         MongoCollection<BsonDocument> user = database.GetCollection<BsonDocument>(UserConstants.UserCollection);
         MongoCursor<BsonDocument> userEntity = user.Find(new QueryDocument(UserConstants.Username, entity.Username));
         if (userEntity.Count() == 0)
         {
             isExist = false;
         }
         else
         {
             isExist = true;
         }
     }
     catch (Exception ex)
     {
         actionState.SetFail(ActionStateEnum.Exception, ex.Message);
     }
     finally
     {
         server.Disconnect();
         server = null;
         database = null;
     }
     return isExist;
 }