Esempio n. 1
0
        private bool ReadLibraryFromJson()
        {
            var jsonFormatter = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(Books[]));

            using (var fs = new System.IO.FileStream("Library.json", System.IO.FileMode.OpenOrCreate))
            {
                if (fs.Length == 0)
                {
                    System.Console.WriteLine("JSON is empty");
                }
                else
                {
                    var newBooks = (Books[])jsonFormatter.ReadObject(fs);
                    var lst      = Enumerable.ToList(Enumerable.OfType <Books>(newBooks));
                    System.Console.WriteLine("Done reading from json");
                    foreach (var b in lst)
                    {
                        var book = new Books
                        {
                            Author          = b.Author,
                            Title           = b.Title,
                            Annotation      = b.Annotation,
                            Isbn            = b.Isbn,
                            PublicationDate = b.PublicationDate
                        };

                        _books.Add(book);
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
 void SourceCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == NotifyCollectionChangedAction.Reset)
     {
         OnCleared();
     }
     else
     {
         if (e.OldItems != null)
         {
             OnRemoveItems(SL.OfType <T>(e.OldItems));
         }
         if (e.NewItems != null)
         {
             OnAddItems(SL.OfType <T>(e.NewItems));
         }
     }
 }
Esempio n. 3
0
        private static void RemoveSortGlyph(GridViewColumnHeader columnHeader)
        {
            var adornerLayer = AdornerLayer.GetAdornerLayer(columnHeader);

            if (adornerLayer == null)
            {
                return;
            }

            var adorners = adornerLayer.GetAdorners(columnHeader);

            if (adorners == null)
            {
                return;
            }

            foreach (var adorner in Enumerable.OfType <SortGlyphAdorner>(adorners))
            {
                adornerLayer.Remove(adorner);
            }
        }
Esempio n. 4
0
 public override IEnumerator <T> GetEnumerator()
 {
     return(SL.OfType <T>(Source).GetEnumerator());
 }