public void loadFromCache(bool _forceReload, bool _loadFromServer, ImportManager.ProgressEventHandler _progressMessage) { if (_forceReload) { m_folders.Clear(); } else if (File.Exists(cacheFileName())) { try { Type objectType = m_folders.GetType(); XmlSerializer xmlSerializer = new XmlSerializer(objectType); using (StreamReader sr = new StreamReader(cacheFileName())) { m_folders = xmlSerializer.Deserialize(sr) as List <LibrarySection>; } } catch { } } if (m_folders.Count == 0 && _loadFromServer) { if (_progressMessage != null) { _progressMessage(String.Format("PlexMediaServer: loading folders from section {0}.....", Title), true); } loadFolders(Owner.baseUrl, _progressMessage); } }
protected void addFolder(string _url, string _baseUrl, string _parentTitle, ImportManager.ProgressEventHandler _progressMessage) { if (!String.IsNullOrEmpty(_url)) { if (_progressMessage != null) { _progressMessage(_parentTitle, false); } XElement folderElements = Utils.elementFromURL(_url); var elements = from element in folderElements.Elements(PMSBase.DIRECTORY) select element; foreach (XElement folderSection in elements) { LibrarySection librarySection = new LibrarySection() { Key = PMSBase.attributeValue(folderSection, PMSBase.KEY), Title = _parentTitle + PMSBase.attributeValue(folderSection, PMSBase.TITLE), IsMusic = this.IsMusic }; librarySection.SectionUrl = Utils.getSectionUrl(librarySection.Key, _url, _baseUrl, ""); m_folders.Add(librarySection); Debug.WriteLine(String.Format("{0} - {1}", librarySection.Key, librarySection.Title)); addFolder(Utils.getSectionUrl(librarySection.Key, _url, _baseUrl, ""), _baseUrl, String.Format("{0}{1}", librarySection.Title, PMSServer.DirectorySeparator), _progressMessage); } } }
public void loadFolders(string _baseUrl, ImportManager.ProgressEventHandler _progressMessage) { if (m_folders.Count == 0) { m_folders.Clear(); string sectionUrl = String.Format("{0}{1}", SectionUrl, FOLDER); LibrarySection librarySection = new LibrarySection() { Key = sectionUrl.Remove(0, _baseUrl.Length), Title = "", IsMusic = this.IsMusic }; librarySection.SectionUrl = Utils.getSectionUrl(librarySection.Key, sectionUrl, _baseUrl, ""); m_folders.Add(librarySection); addFolder(String.Format("{0}/", sectionUrl), _baseUrl, "", _progressMessage); saveToCache(); } }
public void setSectionLocation(SectionLocation _sectionLocation, bool _usePlexLocation, ImportManager.ProgressEventHandler _progressMessage) { string relativePath = RelativePath(_usePlexLocation ? _sectionLocation.PlexLocation : _sectionLocation.MappedLocation); MainSection = _sectionLocation.Owner(); MainSection.loadFromCache(false, true, _progressMessage); var folders = from folder in MainSection.folders where folder.Title.Equals(relativePath, StringComparison.OrdinalIgnoreCase) select folder; FolderSection = folders.FirstOrDefault(); char directorySeparatorFrom = PMSServer.DirectorySeparator == PMSBase.BACKWARD_SLASH ? PMSBase.FORWARD_SLASH : PMSBase.BACKWARD_SLASH; m_fullPlexFileName = FullFileName; if (!_usePlexLocation && !String.IsNullOrEmpty(_sectionLocation.MappedLocation)) { if (m_fullPlexFileName.StartsWith(_sectionLocation.MappedLocation, StringComparison.OrdinalIgnoreCase)) { m_fullPlexFileName = _sectionLocation.PlexLocation + m_fullPlexFileName.Remove(0, _sectionLocation.MappedLocation.Length); } m_fullPlexFileName = normalizePath(m_fullPlexFileName, directorySeparatorFrom, PMSServer.DirectorySeparator); } }