示例#1
0
        public override WebFileInfo GetFileInfo()
        {
            if ((MediaType == WebMediaType.TV || MediaType == WebMediaType.Recording) && FileType == WebFileType.Logo)
            {
                if (fileInfoCache != null)
                    return fileInfoCache;

                if (_logos == null)
                    _logos = new ChannelLogos();

                // get display name
                int idChannel = MediaType == WebMediaType.TV ?
                    Int32.Parse(Id) :
                    Connections.TAS.GetRecordingById(Int32.Parse(Id)).ChannelId;
                var channel = Connections.TAS.GetChannelBasicById(idChannel);
                string location = _logos.FindLocation(channel.Title);
                if(location == null)
                {
                    Log.Debug("Did not find tv logo for channel {0} with id {1}", channel.Title, idChannel);
                    fileInfoCache = new WebFileInfo() { Exists = false };
                    return fileInfoCache;
                }

                // great, return it
                fileInfoCache = new WebFileInfo(location);
                return fileInfoCache;
            }

            return path != null ? new WebFileInfo(path) : base.GetFileInfo();
        }
示例#2
0
        public virtual WebFileInfo GetFileInfo()
        {
            if (fileInfoCache != null)
                return fileInfoCache;

            if (MediaType == WebMediaType.Recording && FileType == WebFileType.Content)
            {
                WebRecordingFileInfo info = Connections.TAS.GetRecordingFileInfo(Int32.Parse(Id));
                fileInfoCache = new WebFileInfo()
                {
                    Exists = info.Exists,
                    Extension = info.Extension,
                    IsLocalFile = info.IsLocalFile,
                    IsReadOnly = info.IsReadOnly,
                    LastAccessTime = info.LastAccessTime,
                    LastModifiedTime = info.LastModifiedTime,
                    Name = info.Name,
                    OnNetworkDrive = info.OnNetworkDrive,
                    Path = PathUtil.StripFileProtocolPrefix(info.Path),
                    PID = -1,
                    Size = info.Size
                };
                return fileInfoCache;
            }

            if (MediaType == WebMediaType.TV && FileType == WebFileType.Content)
            {
                fileInfoCache = new WebFileInfo(new FileInfo(Id))
                {
                    Exists = true,
                    IsLocalFile = true,
                    IsReadOnly = true,
                    OnNetworkDrive = false,
                    PID = -1
                };
                fileInfoCache.Path = PathUtil.StripFileProtocolPrefix(fileInfoCache.Path);
                return fileInfoCache;
            }

            fileInfoCache = Connections.MAS.GetFileInfo(Provider, MediaType, FileType, Id, Offset);
            return fileInfoCache;
        }
示例#3
0
        public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
        {
            string path = "";
            try
            {
                path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset);
                WebFileInfo retVal = null;

                bool tryImpersonation = false;
                try
                {
                    // first try it the usual way
                    retVal = GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype);
                    tryImpersonation = retVal == null || !retVal.Exists;
                }
                catch (UnauthorizedAccessException)
                {
                    // access denied, try impersonation
                    tryImpersonation = true;
                }

                if (tryImpersonation && new Uri(path).IsUnc && !FileUtil.IsAccessible(path))
                {
                    using (var impersonator = new NetworkShareImpersonator())
                    {
                        retVal = new WebFileInfo(path);
                        retVal.IsLocalFile = Configuration.Services.NetworkImpersonation.ReadInStreamingService;
                        retVal.OnNetworkDrive = true;
                    }
                }

                // Make sure to always the path property, even if the file doesn't exist. This makes debugging a lot easier, as you get actual paths in your logs now.
                retVal.Path = path;
                return retVal;
            }
            catch (ArgumentOutOfRangeException)
            {
                Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset);
            }
            catch (FileNotFoundException)
            {
                Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider);
            }
            catch (Exception ex)
            {
                Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex);
            }

            return new WebFileInfo()
            {
                Exists = false,
                Path = String.IsNullOrWhiteSpace(path) ? null : path
            };
        }
示例#4
0
 public static string GetFullInfoString(WebMediaInfo info, WebFileInfo fileInfo)
 {
     return GetFullInfoString(info, fileInfo.Size);
 }
示例#5
0
        public virtual WebFileInfo GetFileInfo()
        {
            if (fileInfoCache != null)
                return fileInfoCache;

            if (MediaType == WebMediaType.Recording && FileType == WebFileType.Content)
            {
                WebRecordingFileInfo info = Connections.TAS.GetRecordingFileInfo(Int32.Parse(Id));
                fileInfoCache = new WebFileInfo()
                {
                    Exists = info.Exists,
                    Extension = info.Extension,
                    IsLocalFile = info.IsLocalFile,
                    IsReadOnly = info.IsReadOnly,
                    LastAccessTime = info.LastAccessTime,
                    LastModifiedTime = info.LastModifiedTime,
                    Name = info.Name,
                    OnNetworkDrive = info.OnNetworkDrive,
                    Path = PathUtil.StripFileProtocolPrefix(info.Path),
                    PID = -1,
                    Size = info.Size
                };
                return fileInfoCache;
            }

            if (MediaType == WebMediaType.TV && FileType == WebFileType.Content)
            {
                fileInfoCache = new WebFileInfo(new FileInfo(Id))
                {
                    Exists = true,
                    IsLocalFile = true,
                    IsReadOnly = true,
                    OnNetworkDrive = false,
                    PID = -1,
                    // This field should not be read for the TV mediatype, since we can't know the size of timeshiftings. However, since
                    // there might slip a usage through and this has broken live TV streaming over WAN in the Direct profile for months
                    // in the past, let's assume they're infinitely large for practical purposes here.
                    // TODO: Maybe use a childclass of WebFileInfo that throws in the Size.get accessor? At least we get clear logs then.
                    Size = Int64.MaxValue
                };
                fileInfoCache.Path = PathUtil.StripFileProtocolPrefix(fileInfoCache.Path);
                return fileInfoCache;
            }

            fileInfoCache = Connections.MAS.GetFileInfo(Provider, MediaType, FileType, Id, Offset);
            return fileInfoCache;
        }
示例#6
0
        public virtual WebFileInfo GetFileInfo()
        {
            if(fileInfoCache != null)
            {
                return fileInfoCache;
            }

            if (MediaType == WebStreamMediaType.Recording && FileType == WebArtworkType.Content)
            {
                WebRecordingFileInfo info = MPEServices.TAS.GetRecordingFileInfo(Int32.Parse(Id));
                fileInfoCache = new WebFileInfo()
                {
                    Exists = info.Exists,
                    Extension = info.Extension,
                    IsLocalFile = info.IsLocalFile,
                    IsReadOnly = info.IsReadOnly,
                    LastAccessTime = info.LastAccessTime,
                    LastModifiedTime = info.LastModifiedTime,
                    Name = info.Name,
                    OnNetworkDrive = info.OnNetworkDrive,
                    Path = info.Path,
                    PID = -1,
                    Size = info.Size
                };
                return fileInfoCache;
            }

            if (MediaType == WebStreamMediaType.TV && FileType == WebArtworkType.Content)
            {
                fileInfoCache = new WebFileInfo(new FileInfo(Id))
                {
                    Exists = true,
                    IsLocalFile = true,
                    IsReadOnly = true,
                    OnNetworkDrive = false,
                    PID = -1
                };
                return fileInfoCache;
            }

            fileInfoCache = MPEServices.MAS.GetFileInfo(Provider, (WebMediaType)MediaType, (WebFileType)FileType, Id, Offset);
            return fileInfoCache;
        }
示例#7
0
 public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebFileInfo fileInfo)
 {
     return accessible ? GetFullInfoString(info, fileInfo) : UIStrings.FileInaccessible;
 }
        public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
        {
            string path = "";
            try
            {
                path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset);
                WebFileInfo retVal = null;

                bool tryImpersonation = false;
                try
                {
                    // first try it the usual way
                    retVal = GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype);
                    tryImpersonation = PathUtil.MightBeOnNetworkDrive(path) && (retVal == null || !retVal.Exists);
                }
                catch (UnauthorizedAccessException)
                {
                    // access denied, try impersonation
                    tryImpersonation = true;
                }

                if (tryImpersonation && Configuration.Services.NetworkImpersonation.IsEnabled())
                {
                    using (var context = NetworkContextFactory.CreateImpersonationContext())
                    {
                        retVal = new WebFileInfo(context.RewritePath(path));
                        retVal.IsLocalFile = true;
                        retVal.OnNetworkDrive = true;
                    }
                }

                // Make sure to always the path property, even if the file doesn't exist. This makes debugging a lot easier, as you get actual paths in your logs now.
                if (String.IsNullOrEmpty(retVal.Path))
                    retVal.Path = PathUtil.StripFileProtocolPrefix(path);
                retVal.PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider);
                return retVal;
            }
            catch (ArgumentOutOfRangeException)
            {
                Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset);
            }
            catch (FileNotFoundException)
            {
                Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider);
            }
            catch (Exception ex)
            {
                Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex);
            }

            return new WebFileInfo()
            {
                Exists = false,
                PID = ProviderHandler.GetProviderId(mediatype.ToProviderType(), provider),
                Path = String.IsNullOrWhiteSpace(path) ? null : PathUtil.StripFileProtocolPrefix(path)
            };
        }
示例#9
0
        public WebFileInfo GetFileInfo(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
        {
            string path = "";
            try
            {
                path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset);

                try
                {
                    // first try it the usual way
                    return GetLibrary(provider, mediatype).GetFileInfo(path).Finalize(provider, mediatype);
                }
                catch (UnauthorizedAccessException)
                {
                    // access denied, try impersonation
                    if (new Uri(path).IsUnc)
                    {
                        using (NetworkShareImpersonator impersonation = new NetworkShareImpersonator())
                        {
                            var ret = new WebFileInfo(path);
                            ret.IsLocalFile = Configuration.Services.NetworkImpersonation.ReadInStreamingService;
                            ret.OnNetworkDrive = true;
                            return ret;
                        }
                    }
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                Log.Info("Cannot resolve mediatype={0}, filetype={1}, provider={2}, id={3}, offset={4}", mediatype, filetype, provider, id, offset);
            }
            catch (FileNotFoundException)
            {
                Log.Info("Failed to load fileinfo for non-existing file mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider);
            }
            catch (Exception ex)
            {
                Log.Info(String.Format("Failed to load fileinfo for mediatype={0}, filetype={1}, provider={5}, id={2}, offset={3} (resulting in path={4})", mediatype, filetype, id, offset, path, provider), ex);
            }

            return new WebFileInfo()
            {
                Exists = false
            };
        }
示例#10
0
 public CachedInfoWrapper(WebMediaInfo mediaInfo, WebFileInfo fileInfo)
 {
     CachedDate = DateTime.Now;
     Size = fileInfo.Size;
     Info = mediaInfo;
 }
示例#11
0
 public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebFileInfo fileInfo)
 {
     return GetFullInfoString(accessible, info, fileInfo.Size);
 }
示例#12
0
        public override WebFileInfo GetFileInfo()
        {
            if (fileInfoCache != null)
                return fileInfoCache;

            if (path != null)
            {
                fileInfoCache = new WebFileInfo(path);
                return fileInfoCache;
            }

            if ((MediaType == WebMediaType.TV || MediaType == WebMediaType.Recording || MediaType == WebMediaType.Radio) && FileType == WebFileType.Logo)
            {
                if (_logos == null)
                    _logos = new ChannelLogos();

                // get display name
                int idChannel = MediaType == WebMediaType.TV || MediaType == WebMediaType.Radio ?
                    Int32.Parse(Id) :
                    Connections.TAS.GetRecordingById(Int32.Parse(Id)).ChannelId;
                var channel = Connections.TAS.GetChannelBasicById(idChannel);
                string location = _logos.FindLocation(channel.Title);
                if(location == null)
                {
                    Log.Debug("Did not find tv logo for channel {0} with id {1}", channel.Title, idChannel);
                    fileInfoCache = new WebFileInfo() { Exists = false };
                    return fileInfoCache;
                }

                // great, return it
                fileInfoCache = new WebFileInfo(location);
                return fileInfoCache;
            }

            if (Offset < 0)
            {
                var artwork = Connections.MAS.GetArtwork(Provider, MediaType, Id);
                var preferedItem = artwork.Where(x => x.Type == FileType)
                                          .OrderByDescending(x => x.Rating)
                                          .Skip(-1 - Offset)
                                          .FirstOrDefault();
                if (preferedItem == null)
                {
                    Log.Debug("Requested prefered artwork item for provider={0} mediatype={1} filetype={2} id={3}, but no artwork found",
                        Provider, MediaType, FileType, Id);
                    fileInfoCache = new WebFileInfo()
                    {
                        Exists = false
                    };
                    return fileInfoCache;
                }

                fileInfoCache = Connections.MAS.GetFileInfo(Provider, MediaType, FileType, Id, preferedItem.Offset);
                return fileInfoCache;
            }

            return base.GetFileInfo();
        }