예제 #1
0
        public ComicItem getComicModel(String comicId)
        {
            ComicItem c = (from ComicItem item in comicListDb.Items
                           where item.ComicId == comicId
                           select item).FirstOrDefault();

            return(c);
        }
예제 #2
0
        public void addComic(ComicItem comicItem)
        {
            var comicAlreadyInDB = (from ComicItem item in comicListDb.Items
                                    where item.ComicId == comicItem.ComicId
                                    select new { item }).SingleOrDefault();


            if (comicAlreadyInDB == null)
            {
                Debug.WriteLine("Item not found in DB, adding to DB and view model.");

                // Adding to DB.
                comicListDb.Items.InsertOnSubmit(comicItem);
                comicListDb.SubmitChanges();

                // And also immediately to the screen.
                m_showingComicsListModel.Add(comicItem);
                m_allComicsListModel.Add(comicItem);
                OnPropertyChanged("AllComicsListModel");
            }
        }
예제 #3
0
        public void addComic(ComicItem comicItem)
        {
            var comicAlreadyInDB = (from ComicItem item in comicListDb.Items
                                    where item.ComicId == comicItem.ComicId
                                    select new { item }).SingleOrDefault();

            if (comicAlreadyInDB == null)
            {
                Debug.WriteLine("Item not found in DB, adding to DB and view model.");

                // Adding to DB.
                comicListDb.Items.InsertOnSubmit(comicItem);
                comicListDb.SubmitChanges();

                // And also immediately to the screen.
                m_showingComicsListModel.Add(comicItem);
                m_allComicsListModel.Add(comicItem);
                OnPropertyChanged("AllComicsListModel");
            }
        }
예제 #4
0
 public void removeComicItem(ComicItem comic)
 {
     comicListDb.Items.DeleteOnSubmit(comic);
     comicListDb.SubmitChanges();
     refreshComicLists();
 }
예제 #5
0
 public void removeComicItem(ComicItem comic)
 {
     comicListDb.Items.DeleteOnSubmit(comic);
     comicListDb.SubmitChanges();
     refreshComicLists();
 }
예제 #6
0
        private void showNewComic(ComicItem currentComicModel, MemoryStream comicBytes)
        {
            BitmapImage comicImage = new BitmapImage();
            comicImage.SetSource(comicBytes);

            currentComicModel.ComicImage = comicImage;
        }
예제 #7
0
        private void ComicListFetchCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            WebClient wc = sender as WebClient;
            if (wc != null)
            {
                wc = null;
            }

            if (RESTError(e)) {
                Debug.WriteLine("Error fetching comic list! Error: " + e.Error.ToString());
                return;
            }

            // Process JSON to get interesting data.
            DataContractJsonSerializer jsonparser = new DataContractJsonSerializer(typeof(PivotComicsData));
            PivotComicsData serverComics = null;
            try
            {
                byte[] jsonArray = Encoding.UTF8.GetBytes(e.Result);
                MemoryStream jsonStream = new MemoryStream(jsonArray);
                serverComics = (PivotComicsData)jsonparser.ReadObject(jsonStream);
            }
            catch (SerializationException)
            {
                Debug.WriteLine("Cannot serialize the JSON. Giving up! Json: " + e.Result);
                return;
            }

            // Populate the model with comic data.
            IEnumerator<ComicInfo> enumerator = serverComics.comics.GetEnumerator();
            while (enumerator.MoveNext())
            {
                ComicInfo comic = enumerator.Current;
                ComicItem model = new ComicItem();

                model.ComicName = comic.name;
                model.ComicId = comic.comicid;
                Debug.WriteLine("Got comic from server. Name: " + comic.name + ", id: " + comic.comicid);

                App.comicListModel.addComic(model);
            }

            // Check to see if we have some comic in the DB which is not present on the server. Need to remove that.
            Collection<ComicItem> comicsInDB = App.comicListModel.AllComicsListModel;
            IEnumerator<ComicInfo> serverComicsEnum = serverComics.comics.GetEnumerator();
            foreach (ComicItem localComic in comicsInDB)
            {
                bool found = false;
                while (serverComicsEnum.MoveNext())
                {
                    ComicInfo serverComic = serverComicsEnum.Current;
                    if (localComic.ComicId == serverComic.comicid)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    Debug.WriteLine("Server does not contain the comic anymore. Removing locally: " + localComic.ComicName);
                    App.comicListModel.removeComicItem(localComic);
                }

                serverComicsEnum.Reset();
            }

            // Activate the first comic after the pivots have been populated.
            if (TopPivot.Items.Count > 0)
            {
                TopPivot.SelectedItem = TopPivot.Items[0];
            }
        }