public ICollection <IFileSystemResourceAccessor> GetChildDirectories() { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); ICollection <ResourcePathMetadata> directoriesData = rris.GetChildDirectories(_nativeSystemId, _nativeResourcePath); return(WrapResourcePathsData(directoriesData, false)); }
public bool ResourceExists(string path) { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); ResourcePath resourcePath = rris.ConcatenatePaths(_nativeSystemId, _nativeResourcePath, path); return(rris.ResourceExists(_nativeSystemId, resourcePath)); }
protected bool BuildBaseUrl() { IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>(); // In case we lost the connection clear the url so it can be looked up later again if (!scm.IsHomeServerConnected) { _baseUrl = null; return(false); } if (!string.IsNullOrWhiteSpace(_baseUrl)) { return(true); } // We need to know the base url of the server's remote access service, so we can use the IP and port number. try { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); string resourceUrl; IPAddress localIpAddress; if (!rris.GetFileHttpUrl(scm.HomeServerSystemId, ResourcePath.BuildBaseProviderPath(Guid.Empty, string.Empty), out resourceUrl, out localIpAddress)) { return(false); } _baseUrl = resourceUrl.Substring(0, resourceUrl.IndexOf(ResourceHttpAccessUrlUtils.RESOURCE_ACCESS_PATH)); return(true); } catch { return(false); } }
public IFileSystemResourceAccessor GetResource(string path) { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); ResourcePath resourcePath = rris.ConcatenatePaths(_nativeSystemId, _nativeResourcePath, path); IFileSystemResourceAccessor result; return(ConnectFileSystem(_nativeSystemId, resourcePath, out result) ? result : null); }
public void PrepareStreamAccess() { if (!_isFile || _underlayingStream != null) { return; } IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); string resourceURL; IPAddress localIpAddress; if (!rris.GetFileHttpUrl(_nativeSystemId, _nativeResourcePath, out resourceURL, out localIpAddress)) { return; } lock (_syncObj) _underlayingStream = new CachedMultiSegmentHttpStream(resourceURL, localIpAddress, Size); }
protected void FillCaches() { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); bool isFileSystemResource; bool isFile; string resourcePathName; string resourceName; DateTime lastChanged; long size; if (!rris.GetResourceInformation(_nativeSystemId, _nativeResourcePath, out isFileSystemResource, out isFile, out resourcePathName, out resourceName, out lastChanged, out size)) { throw new IOException(string.Format("Unable to get file information for resource '{0}' at system '{1}'", _nativeResourcePath, _nativeSystemId)); } _lastChangedCache = lastChanged; _sizeCache = isFile ? size : -1; }
public static bool ConnectFileSystem(string nativeSystemId, ResourcePath nativeResourcePath, out IFileSystemResourceAccessor result) { IRemoteResourceInformationService rris = ServiceRegistration.Get <IRemoteResourceInformationService>(); result = null; bool isFileSystemResource; bool isFile; string resourcePathName; string resourceName; long size; DateTime lastChanged; if (!rris.GetResourceInformation(nativeSystemId, nativeResourcePath, out isFileSystemResource, out isFile, out resourcePathName, out resourceName, out lastChanged, out size) || !isFileSystemResource) { return(false); } result = new RemoteFileSystemResourceAccessor(nativeSystemId, nativeResourcePath, isFile, resourcePathName, resourceName, size, lastChanged); return(true); }
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(); } }