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); }
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 }); }
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); }
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); }
public static Task <WebFileInfo> ProcessAsync(IOwinContext context, WebMediaType mediatype, WebFileType filetype, string id, int offset) { ISet <Guid> necessaryMIATypes = new HashSet <Guid>(); necessaryMIATypes.Add(MediaAspect.ASPECT_ID); necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID); necessaryMIATypes.Add(ImporterAspect.ASPECT_ID); MediaItem item = MediaLibraryAccess.GetMediaItemById(context, id, necessaryMIATypes, null); if (item == null) { throw new NotFoundException("GetFileInfo: no media item found"); } var files = ResourceAccessUtils.GetResourcePaths(item); var ra = GetResourceAccessor(files[offset]); IFileSystemResourceAccessor fsra = ra as IFileSystemResourceAccessor; if (fsra == null) { throw new InternalServerException("GetFileInfo: failed to create IFileSystemResourceAccessor"); } WebFileInfo webFileInfo = new WebFileInfo { Exists = fsra.Exists, Extension = fsra.Path.Split('.').Last(), IsLocalFile = true, IsReadOnly = true, LastAccessTime = DateTime.Now, LastModifiedTime = fsra.LastChanged, Name = fsra.ResourceName, OnNetworkDrive = false, Path = files[offset].FileName, Size = fsra.Size, }; return(Task.FromResult(webFileInfo)); }
public Stream RetrieveFile(int?provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { try { string path = GetPathList(provider, mediatype, filetype, id).ElementAt(offset); WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); // first try to read the file if (info.IsLocalFile && File.Exists(path)) { return(new FileStream(path, FileMode.Open, FileAccess.Read)); } // maybe the plugin has some magic if (!info.IsLocalFile && info.Exists && !info.OnNetworkDrive) { return(GetLibrary(provider, mediatype).GetFile(path)); } // try to load it from a network drive if (info.OnNetworkDrive && info.Exists) { using (NetworkShareImpersonator impersonation = new NetworkShareImpersonator()) { return(new FileStream(path, FileMode.Open, FileAccess.Read)); } } // fail Log.Warn("Requested non-existing or non-accessible file mediatype={0} filetype={1} id={2} offset={3}", mediatype, filetype, id, offset); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound); return(Stream.Null); } catch (Exception ex) { Log.Info("Failed to retrieve file for mediatype=" + mediatype + ", filetype=" + filetype + ", id=" + id + " and offset=" + offset, ex); WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError); return(Stream.Null); } }
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()); }
public CachedInfoWrapper(WebMediaInfo mediaInfo, WebFileInfo fileInfo) { CachedDate = DateTime.Now; Size = fileInfo.Size; Info = mediaInfo; }
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()); }
private void Upload(HttpContext context) { var result = OpResult.Denied; string jsonResult = serializer.Serialize(result); bool doUpload = true; if (context.Request.Files.Count > 0) { fileUploaded = context.Request.Files[0]; if (fileUploaded.ContentLength > fileSystem.Permission.MaxSizePerFile) { log.Info("upload rejected due to fileSystem.Permission.MaxSizePerFile"); doUpload = false; jsonResult = serializer.Serialize(OpResult.FileSizeLimitExceed); } else if (fileSystem.CountAllFiles() >= fileSystem.Permission.MaxFiles) { log.Info("upload rejected due to fileSystem.Permission.MaxFiles"); doUpload = false; jsonResult = serializer.Serialize(OpResult.FileLimitExceed); } else if (fileSystem.GetTotalSize() + fileUploaded.ContentLength >= fileSystem.Permission.Quota) { log.Info("upload rejected due to fileSystem.Permission.Quota"); doUpload = false; jsonResult = serializer.Serialize(OpResult.QuotaExceed); } if (!fileSystem.Permission.IsExtAllowed(VirtualPathUtility.GetExtension(fileUploaded.FileName))) { log.Info("upload rejected due to not allowed file extension"); doUpload = false; jsonResult = serializer.Serialize(OpResult.FileTypeNotAllowed); //RenderJsonResult(context, OpResult.FileTypeNotAllowed); //return; } virtualPath = VirtualPathUtility.AppendTrailingSlash(virtualPath); if (doUpload) { try { if (OnFileUploading(virtualPath, fileUploaded, ref result)) { result = fileSystem.SaveFile(virtualPath, fileUploaded, overwriteExistingFiles); if (result == OpResult.Succeed) { jsonResult = serializer.Serialize( WebFileInfo.FromPostedFile(fileUploaded, System.IO.Path.GetFileName(fileUploaded.FileName).ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles)).ToJson()); } else { jsonResult = serializer.Serialize(result); } } } catch (Exception ex) { log.Error(ex); result = OpResult.Error; jsonResult = serializer.Serialize(result); } } } else { // no file posted jsonResult = serializer.Serialize(OpResult.Error); } //this is supposed to be an html response not a json response context.Response.ContentType = "text/html"; Encoding encoding = new UTF8Encoding(); context.Response.ContentEncoding = encoding; context.Response.Write(BuildHtmlWrapper(context, jsonResult)); }
public static string GetFullInfoString(WebMediaInfo info, WebFileInfo fileInfo) { return(GetFullInfoString(fileInfo.Exists, info, fileInfo.Size)); }
public static string GetFullInfoString(bool accessible, WebMediaInfo info, WebFileInfo fileInfo) { return(GetFullInfoString(accessible, info, fileInfo.Size)); }
public bool IsLocalFile(int?provider, WebMediaType mediatype, WebFileType filetype, string id, int offset) { WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset); return(info.Exists && info.IsLocalFile); }