Exemple #1
0
        public static void AddLiveTile(Category cat)
        {
            // Look to see whether the Tile already exists; if so, don't try to create it again.
            ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("/Category/" +
                cat.CategoryID.ToString()));

            // Create the Tile if we didn't find that it already exists.
            if (tileToFind == null)
            {
                // Create an image for the category if there isnt one.
                if (cat.ImageURL == null || cat.ImageURL == String.Empty)
                {
                    cat.ImageURL = ImageGrabber.GetDefaultImage();
                }

                // Create the Tile object and set some initial properties for the Tile.
                StandardTileData newTileData = new StandardTileData
                {
                    BackgroundImage = new Uri(cat.ImageURL, UriKind.RelativeOrAbsolute),
                    Title = cat.CategoryTitle,
                    Count = 0,
                    BackTitle = cat.CategoryTitle,
                    BackContent = "Read the latest in " + cat.CategoryTitle + "!",
                };

                // Create the Tile and pin it to Start. This will cause a navigation to Start and a deactivation of our application.
                ShellTile.Create(new Uri("/Category/" + cat.CategoryID, UriKind.Relative), newTileData);
                // note: Tile URI could have listed the full path to the Category page. For example --> /Views/CategoryPage.xaml?id=

                cat.IsPinned = true;
                App.DataBaseUtility.SaveChangesToDB();
            }
        }
        /// <summary>
        /// User has clicked save. Category is added to database along with it's associated feeds.
        /// </summary>
        private void OnSaveClick(object sender, EventArgs e)
        {
            string text = CategoryNameTextBox.Text;
            if (!string.IsNullOrWhiteSpace(text))
            {
                Category newCat = new Category() { CategoryTitle = text };
                App.DataBaseUtility.AddCategory(newCat);

                App.DataBaseUtility.SaveChangesToDB();

                foreach (Feed f in FeedPicker.SelectedItems)
                {
                    App.DataBaseUtility.AddFeed(f, newCat);
                }

                App.DataBaseUtility.SaveChangesToDB();

                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Enable URI Mapper
            RootFrame.UriMapper = Resources["UriMapper"] as UriMapper;

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = false;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            // Initialize application wide settings and DataBase utilities.
            using (LocalDatabaseDataContext db = new LocalDatabaseDataContext(DBLocation))
            {
                //Inorder to clean the db uncomment the next line (or, if debugging, rebuild solution)
                //db.DeleteDatabase();
                if (!db.DatabaseExists())
                {
                    db.CreateDatabase();
                }
                db.SubmitChanges();
            }

            // Needs to be called AFTER DatabaseContext is Disposed above.
            DataBaseUtility = new DataUtils(DBLocation);

            Favorites = new Category { CategoryTitle = "Favorites" };
            App.DataBaseUtility.AddCategory(Favorites);
            App.DataBaseUtility.SaveChangesToDB();

            ApplicationSettings = new Settings();

            // WebTools object used for initial download and refreshing.
            SynFeedDownloader = new WebTools(new SynFeedParser());

            // ArticleSource array used to keep track of article page source.
            ArticleSource = new string[2];

            // Create the background agent if it does not already exist on the scheduler.
            BackgroundAgentTools BGTools = new BackgroundAgentTools();
            BGTools.StartPeriodicAgent();

            // Redirect initial navigation.
            RootFrame.Navigating += new NavigatingCancelEventHandler(RootFrame_Navigating);
        }
Exemple #4
0
        //Delete a category.
        public void DeleteCategory(Category deleteCategory)
        {
            //If the category is not favorites
            if (deleteCategory.CategoryID != 1)
            {
                //Get all the pairings of the category
                var q = from o in db.Category_Feed
                        where o.CategoryID == deleteCategory.CategoryID
                        select o;
                //Foreach of the pairings
                foreach (Category_Feed deleteCat_Feed in q)
                {
                    //Check if the feed has any other association
                    if (checkDelete(Convert.ToInt32(deleteCat_Feed.FeedID)))
                    {
                        //If not, delete it.
                        Feed feed = QueryFeed(Convert.ToInt32(deleteCat_Feed.FeedID));
                        DeleteFeed(feed);
                    }
                }

                //Remove the cat_feeds even if they are associated with Favorites Category.
                List<Category_Feed> catfeed = q.ToList();
                int max = catfeed.Count;
                for (int i = 0; i < max; i++)
                {
                    if (catfeed[i].CategoryID == 1)
                    {
                        catfeed.RemoveAt(i);
                        max--;
                        i--;
                    }
                }
                db.Category_Feed.DeleteAllOnSubmit(catfeed);
                db.Category.DeleteOnSubmit(deleteCategory);
                SaveChangesToDB();
            }
        }
Exemple #5
0
        //Add a feed to the feed table, and a corresponding entry in Category_Feed Table
        public bool AddFeed(Feed newFeed, Category cat)
        {
            dbMutex.WaitOne();

            bool checkfeed = checkFeed(newFeed.FeedBaseURI, cat.CategoryID);
            bool feedexists = checkIfFeedExists(newFeed.FeedBaseURI);

            //Checks if the feed is in the database
            if (feedexists)
            {
                newFeed.SharedCount = 0;
                newFeed.UnreadCount = 0;
                newFeed.ViewCount = 0;
                newFeed.FavoritedCount = 0;
                newFeed.IsPinned = false;
                db.Feed.InsertOnSubmit(newFeed);
                SaveChangesToDB();
                Category_Feed newCat_Feed = new Category_Feed { CategoryID = cat.CategoryID, FeedID = newFeed.FeedID };
                db.Category_Feed.InsertOnSubmit(newCat_Feed);
                SaveChangesToDB();

            }
            //If it does, but not to the category, add it to the category
            else if (checkfeed)
            {
                Category_Feed newCat_Feed = new Category_Feed { CategoryID = cat.CategoryID, FeedID = newFeed.FeedID };
                db.Category_Feed.InsertOnSubmit(newCat_Feed);
                SaveChangesToDB();
            }
            //Else do nothing.
            dbMutex.ReleaseMutex();
            return (feedexists);
        }
Exemple #6
0
        //Add a category to the category table
        public bool AddCategory(Category newCategory)
        {
            dbMutex.WaitOne();

            var c = from q in db.Category
                    where q.CategoryTitle == newCategory.CategoryTitle
                    select q;
            bool checkCategory = (c.Count() == 0);
            if (checkCategory)
            {
                newCategory.IsPinned = false;
                if (newCategory.CategoryID != 1)
                {
                    newCategory.IsRemovable = true;
                }
                else
                {
                    newCategory.IsRemovable = false;
                }

                db.Category.InsertOnSubmit(newCategory);
                SaveChangesToDB();
            }

            dbMutex.ReleaseMutex();
            return checkCategory;
        }
Exemple #7
0
 /// <summary>
 /// Navigate to the previous category.
 /// </summary>
 private void OnPreviousClick(object sender, EventArgs e)
 {
     if (null != _allCategories && _allCategories.Count > 0)
     {
         int prevCatIndex = _allCategories.IndexOf(SelectedCategory) - 1;
         if (prevCatIndex >= 0)
         {
             Category previousCategory = _allCategories[prevCatIndex];
             List<Article> categoryArticles = App.DataBaseUtility.GetCategoryArticles(previousCategory.CategoryID);
             if (null != categoryArticles)
             {
                 this.SelectedCategory = previousCategory;
                 this.DataContext = categoryArticles;
                 _nextButton.IsEnabled = true;
                 _previousButton.IsEnabled = (prevCatIndex > 0);
             }
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Retrieve the category clicked by the user and it's corresponding articles.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string idStr;
            if (NavigationContext.QueryString.TryGetValue("id", out idStr))
            {
                SelectedCategory = App.DataBaseUtility.QueryCategory(Convert.ToInt32(idStr));
                _allCategoryArticles = App.DataBaseUtility.GetCategoryArticles(Convert.ToInt32(idStr));
                List<Article> firstSetOfArticles = new List<Article>(_allCategoryArticles);
                if (firstSetOfArticles.Count > 10)
                {
                    firstSetOfArticles.RemoveRange(10, firstSetOfArticles.Count - 10);
                }
                CategoryArticles = new ObservableCollection<Article>(firstSetOfArticles);
                DataContext = CategoryArticles;
            }

            _allCategories = App.DataBaseUtility.GetAllCategories();
            _allCategories.Sort();

            ApplicationBar appBar = new ApplicationBar();

            int index = _allCategories.IndexOf(SelectedCategory);

            _previousButton = new ApplicationBarIconButton
            {
                IconUri = new Uri("/Icons/appbar.back.rest.png", UriKind.Relative),
                Text = AppResources.AppBarButtonPreviousText,
                IsEnabled = (index > 0)
            };

            _previousButton.Click += OnPreviousClick;

            ApplicationBarMenuItem addMenu = new ApplicationBarMenuItem(AppResources.AppBarMenuItemAddText);

            addMenu.Click += OnAddMenuClick;

            _nextButton = new ApplicationBarIconButton
            {
                IconUri = new Uri("/Icons/appbar.next.rest.png", UriKind.Relative),
                Text = AppResources.AppBarButtonNextText,
                IsEnabled = (index < _allCategories.Count - 1)
            };

            _nextButton.Click += OnNextClick;

            appBar.Buttons.Add(_previousButton);
            appBar.Buttons.Add(_nextButton);
            appBar.MenuItems.Add(addMenu);

            this.ApplicationBar = appBar;
        }
 partial void DeleteCategory(Category instance);
 partial void UpdateCategory(Category instance);
 partial void InsertCategory(Category instance);