private void UpdateParentOnLibraryItemRemoved(object sender, LibraryRemovedEventArgs args)
        {
            LibraryModelItem item = args.RemovedItem as LibraryModelItem;

            if (args.RemovedItem is MediaItemsListModelItem)
            {
                CategoryModelItem parent = (from parentItem in CategoryItems where parentItem.Id == item.ParentId select parentItem).FirstOrDefault();
                if (parent != null)
                {
                    parent.RemoveChild(item as MediaItemsListModelItem);
                }
            }
            else if (args.RemovedItem is CategoryModelItem)
            {
                CatalogueModelItem parent = (from parentItem in CatalogueItems where parentItem.Id == item.ParentId select parentItem).FirstOrDefault();
                if (parent != null)
                {
                    int childrenCount = (from categoryItem in CategoryItems where categoryItem.ParentId == item.ParentId select categoryItem).Count();
                    parent.Subtitle = CatalogueModelItem.GetSubtitleString(childrenCount);
                }
            }
            // Currently there is no need to handle CatalogueModelItem removal
        }
        // Load library and return it's id
        public string LoadLibrary(Library library)
        {
            ActiveLibrary = library;

            LibraryDocument          = Library.GetLibraryContents(ActiveLibrary, App.Engine.LoggedUser);
            LibraryDocument.Changed += OnLibraryDocumentChanged;

            ChangedContent = Library.GetChangedContent(ActiveLibrary, App.Engine.LoggedUser);

            LibraryId = LibraryDocument.Root.Attribute(NedNodeIdAttribute).Value;

            var mediaItemsQuery =
                from nedNodeElements in LibraryDocument.Descendants(NedNodeTag)
                from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements()
                where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == CategoryTagType
                select new MediaItemsListModelItem()
            {
                Id            = nedNodeChildren.Attribute(NedNodeIdAttribute).Value,
                LibraryId     = this.LibraryId,
                ParentId      = nedNodeElements.Attribute(NedNodeIdAttribute).Value,
                Title         = nedNodeChildren.Element(TitleTag).Value,
                FileName      = nedNodeChildren.Attribute(NedNodeDataAttribute) != null?nedNodeChildren.Attribute(NedNodeDataAttribute).Value : String.Empty,
                ItemType      = MediaItemsListModelItem.GetTypeFromString(nedNodeChildren.Attribute(NedNodeTypeAttribute).Value),
                Description   = nedNodeChildren.Element(NedNodeDescriptionTag) != null?nedNodeChildren.Element(NedNodeDescriptionTag).Value : String.Empty,
                ExternalLinks = (from linkElement in nedNodeChildren.Elements(NedNodeLinkTag) select linkElement.Value).ToList(),
                Keywords      = (from keywordElement in nedNodeChildren.Elements(NedNodeKeywordTag) select keywordElement.Value).ToList(),
                IsChanged     = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag)
                                                              where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value
                                                          select changedElements).Count() > 0 : false
            };
            ObservableCollection <MediaItemsListModelItem> AllMediaItemsTemp = new ObservableCollection <MediaItemsListModelItem>();

            foreach (MediaItemsListModelItem item in mediaItemsQuery)
            { // To avoid multiple observers notifications on initialization
                AllMediaItemsTemp.Add(item);
            }
            MediaItems = AllMediaItemsTemp;

            var categoryItemsQuery =
                from nedNodeElements in LibraryDocument.Descendants(NedNodeTag)
                from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements()
                where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == CatalogueTagType
                select new CategoryModelItem()
            {
                Id        = nedNodeChildren.Attribute(NedNodeIdAttribute).Value,
                ParentId  = nedNodeElements.Attribute(NedNodeIdAttribute).Value,
                Title     = nedNodeChildren.Element(TitleTag).Value,
                IsChanged = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag)
                                                      where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value
                                                      select changedElements).Count() > 0 : false
            };
            ObservableCollection <CategoryModelItem> AllCategoryItemsTemp = new ObservableCollection <CategoryModelItem>();

            foreach (CategoryModelItem item in categoryItemsQuery)
            { // To avoid multiple observers notifications on initialization
                AllCategoryItemsTemp.Add(item);
            }
            CategoryItems = AllCategoryItemsTemp;
            foreach (CategoryModelItem catItem in CategoryItems)
            {
                catItem.AddChildren((from catChild in MediaItems where catChild.ParentId == catItem.Id select catChild).ToList());
            }

            var catalogueItemsQuery =
                from nedNodeElements in LibraryDocument.Descendants(NedNodeTag)
                from nedNodeChildren in nedNodeElements.Element(NedNodeChildrenTag).Elements()
                where (string)nedNodeElements.Attribute(NedNodeTypeAttribute) == LibraryTagType
                select new CatalogueModelItem()
            {
                Id        = nedNodeChildren.Attribute(NedNodeIdAttribute).Value,
                ParentId  = nedNodeElements.Attribute(NedNodeIdAttribute).Value,
                Title     = nedNodeChildren.Element(TitleTag).Value,
                Subtitle  = CatalogueModelItem.GetSubtitleString(nedNodeChildren.Element(NedNodeChildrenTag).Elements().Count <XElement>()),
                IsChanged = ChangedContent != null ? (from changedElements in ChangedContent.Root.Descendants(NedNodeTag)
                                                      where changedElements.Attribute(NedNodeIdAttribute).Value == nedNodeChildren.Attribute(NedNodeIdAttribute).Value
                                                      select changedElements).Count() > 0 : false
            };
            ObservableCollection <CatalogueModelItem> CatalogueItemsTemp = new ObservableCollection <CatalogueModelItem>();

            foreach (CatalogueModelItem item in catalogueItemsQuery)
            { // To avoid multiple observers notifications on initialization
                CatalogueItemsTemp.Add(item);
            }
            CatalogueItems = CatalogueItemsTemp;
            CatalogueItems.CollectionChanged += OnCatalogueItemsPropertyChanged;

            LibraryName = LibraryDocument.Root.Element(TitleTag).Value;
            UpdateMediaItemsDownloadedStatus();

            return(LibraryId);
        }