protected override object DoDeserializeValue(XmlReader reader, bool isSimpleValue) { ICollection <MPClientMetadata> result = new List <MPClientMetadata>(); if (SoapHelper.ReadEmptyStartElement(reader)) // Read start of enclosing element { return(result); } while (reader.NodeType != XmlNodeType.EndElement) { result.Add(MPClientMetadata.Deserialize(reader)); } reader.ReadEndElement(); // End of enclosing element return(result); }
protected override void NavigateToLocalRootView(Share localShare, NavigateToViewDlgt navigateToViewDlgt) { // We need to simulate the logic from method ReLoadItemsAndSubViewSpecifications IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>(); if (!IsSingleSeat(serverConnectionManager)) { string viewName; if (localShare.SystemId == serverConnectionManager.HomeServerSystemId) { viewName = serverConnectionManager.LastHomeServerName; } else { MPClientMetadata clientMetadata = ServerCommunicationHelper.GetClientMetadata(localShare.SystemId); viewName = clientMetadata == null ? null : clientMetadata.LastClientName; } if (viewName != null) { navigateToViewDlgt(new SystemSharesViewSpecification(localShare.SystemId, viewName, _necessaryMIATypeIds, _optionalMIATypeIds)); } } IContentDirectory cd = serverConnectionManager.ContentDirectory; if (cd == null) { return; } Guid? userProfile = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser.ProfileId; } MediaItem parentDirectory = cd.LoadItemAsync(localShare.SystemId, localShare.BaseResourcePath, SystemSharesViewSpecification.DIRECTORY_MIA_ID_ENUMERATION, SystemSharesViewSpecification.EMPTY_ID_ENUMERATION, userProfile).Result; if (parentDirectory == null) { return; } navigateToViewDlgt(new MediaLibraryBrowseViewSpecification(localShare.Name, parentDirectory.MediaItemId, localShare.SystemId, localShare.BaseResourcePath, _necessaryMIATypeIds, _optionalMIATypeIds)); }
public static MPClientMetadata GetClientMetadata(string systemId) { IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>(); if (scm == null) { return(null); } IServerController sc = scm.ServerController; if (sc == null) { return(null); } MPClientMetadata clientData = sc.GetAttachedClients().FirstOrDefault(client => client.SystemId == systemId); if (clientData != null) { return(clientData); } return(null); }
protected void UpdateSharesList_NoLock(bool create) { lock (_syncObj) if (create) { _sharesList = new ItemsList(); } else { _sharesList.Clear(); } try { IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>(); IContentDirectory cd = scm.ContentDirectory; IServerController sc = scm.ServerController; if (cd == null || sc == null) { return; } IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); ICollection <Share> allShares = cd.GetShares(null, SharesFilter.All); IDictionary <string, ICollection <Share> > systems2Shares = new Dictionary <string, ICollection <Share> >(); foreach (Share share in allShares) { ICollection <Share> systemShares; if (systems2Shares.TryGetValue(share.SystemId, out systemShares)) { systemShares.Add(share); } else { systems2Shares[share.SystemId] = new List <Share> { share } }; } ICollection <Guid> importingShares = cd.GetCurrentlyImportingShares() ?? new List <Guid>(); ICollection <string> onlineSystems = sc.GetConnectedClients(); onlineSystems = onlineSystems == null ? new List <string> { scm.HomeServerSystemId } : new List <string>(onlineSystems) { scm.HomeServerSystemId }; foreach (KeyValuePair <string, ICollection <Share> > system2Shares in systems2Shares) { string systemId = system2Shares.Key; ICollection <Share> systemShares = system2Shares.Value; string systemName; string hostName; if (systemId == scm.HomeServerSystemId) { systemName = scm.LastHomeServerName; hostName = scm.LastHomeServerSystem.HostName; } else { MPClientMetadata clientMetadata = ServerCommunicationHelper.GetClientMetadata(systemId); if (clientMetadata == null) { systemName = null; hostName = null; } else { systemName = clientMetadata.LastClientName; hostName = clientMetadata.LastSystem.HostName; } } ListItem systemSharesItem = new ListItem(Consts.KEY_NAME, systemName); systemSharesItem.AdditionalProperties[Consts.KEY_SYSTEM] = systemId; systemSharesItem.AdditionalProperties[Consts.KEY_HOSTNAME] = hostName; bool isConnected = onlineSystems.Contains(systemId); systemSharesItem.AdditionalProperties[Consts.KEY_IS_CONNECTED] = isConnected; ItemsList sharesItemsList = new ItemsList(); foreach (Share share in systemShares) { ListItem shareItem = new ListItem(Consts.KEY_NAME, share.Name); shareItem.AdditionalProperties[Consts.KEY_SHARE] = share; string resourcePathName; try { bool isFileSystemResource; bool isFile; string resourceName; DateTime lastChanged; long size; if (!rris.GetResourceInformation(share.SystemId, share.BaseResourcePath, out isFileSystemResource, out isFile, out resourcePathName, out resourceName, out lastChanged, out size)) { // Error case: The path is invalid resourcePathName = LocalizationHelper.Translate(Consts.RES_INVALID_PATH, share.BaseResourcePath); } } catch (Exception) // NotConnectedException when remote system is not connected at all, UPnPDisconnectedException when remote system gets disconnected during the call { resourcePathName = share.BaseResourcePath.ToString(); } shareItem.SetLabel(Consts.KEY_PATH, resourcePathName); string categories = StringUtils.Join(", ", share.MediaCategories); shareItem.SetLabel(Consts.KEY_MEDIA_CATEGORIES, categories); UpdateShareImportState_NoLock(shareItem, importingShares.Contains(share.ShareId)); Share shareCopy = share; shareItem.Command = new MethodDelegateCommand(() => ReImportShare(shareCopy)); shareItem.AdditionalProperties[Consts.KEY_REIMPORT_ENABLED] = isConnected; sharesItemsList.Add(shareItem); } systemSharesItem.AdditionalProperties[Consts.KEY_SYSTEM_SHARES] = sharesItemsList; lock (_syncObj) _sharesList.Add(systemSharesItem); } } finally { _sharesList.FireChange(); } }