Example #1
0
        public WebRecordingFileInfo GetRecordingFileInfo(int id)
        {
            string filename = String.Empty;

            try
            {
                filename = GetRecordingById(id).FileName;

                bool tryImpersonation = false;
                try
                {
                    var fileInfo = new WebRecordingFileInfo(new FileInfo(filename));
                    if (fileInfo != null && fileInfo.Exists)
                    {
                        return(fileInfo);
                    }

                    tryImpersonation = PathUtil.MightBeOnNetworkDrive(filename);
                }
                catch (UnauthorizedAccessException)
                {
                    tryImpersonation = true;
                }

                if (tryImpersonation && Configuration.Services.NetworkImpersonation.IsEnabled())
                {
                    using (var context = NetworkContextFactory.CreateImpersonationContext())
                    {
                        var ret = new WebRecordingFileInfo(context.RewritePath(filename));
                        ret.IsLocalFile    = true;
                        ret.OnNetworkDrive = true;
                        return(ret);
                    }
                }
            }
            catch (FileNotFoundException)
            {
                Log.Info("Failed to load fileinfo for recording {0} because it does not exists at path {1}", id, filename);
            }
            catch (Exception ex)
            {
                Log.Warn("Failed to load fileinfo for recording", ex);
            }

            return(new WebRecordingFileInfo());
        }
Example #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);
        }
Example #3
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);
        }
Example #4
0
        public static Task <WebRecordingFileInfo> ProcessAsync(IOwinContext context, string id)
        {
            ISet <Guid> necessaryMIATypes = new HashSet <Guid>();

            necessaryMIATypes.Add(MediaAspect.ASPECT_ID);
            necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID);
            necessaryMIATypes.Add(ImporterAspect.ASPECT_ID);
            necessaryMIATypes.Add(RecordingAspect.ASPECT_ID);

            MediaItem item = MediaLibraryAccess.GetMediaItemById(context, Guid.Parse(id), necessaryMIATypes, null);

            if (item == null)
            {
                throw new BadRequestException("GetRecordingFileInfo: no media item found");
            }

            var resourcePathStr = item.PrimaryProviderResourcePath();
            var resourcePath    = ResourcePath.Deserialize(resourcePathStr.ToString());

            var ra = GetResourceAccessor(resourcePath);
            IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor;

            if (fsra == null)
            {
                throw new InternalServerException("GetRecordingFileInfo: failed to create IFileSystemResourceAccessor");
            }

            WebRecordingFileInfo webFileInfo = new WebRecordingFileInfo
            {
                Exists           = fsra.Exists,
                Extension        = fsra.Path.Split('.').Last(),
                IsLocalFile      = true,
                IsReadOnly       = true,
                LastAccessTime   = DateTime.Now,
                LastModifiedTime = fsra.LastChanged,
                Name             = fsra.ResourceName,
                OnNetworkDrive   = false,
                Path             = resourcePath.FileName,
                Size             = fsra.Size,
            };

            return(Task.FromResult(webFileInfo));
        }
Example #5
0
 public static string GetFullInfoString(WebMediaInfo info, WebRecordingFileInfo fileInfo)
 {
     return(GetFullInfoString(fileInfo.Exists, info, fileInfo.Size));
 }
Example #6
0
 public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebRecordingFileInfo fileInfo)
 {
     return(GetFullInfoString(accessible, info, fileInfo.Size));
 }