当前位置: 首页>>代码示例>>C#>>正文


C# WebMediaType类代码示例

本文整理汇总了C#中WebMediaType的典型用法代码示例。如果您正苦于以下问题:C# WebMediaType类的具体用法?C# WebMediaType怎么用?C# WebMediaType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebMediaType类属于命名空间,在下文中一共展示了WebMediaType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Download

        public ActionResult Download(WebMediaType type, string item)
        {
            // Create URL to GetMediaItem
            Log.Debug("User wants to download type={0}; item={1}", type, item);
            var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
            queryString["clientDescription"] = String.Format("WebMediaPortal download (user {0})", HttpContext.User.Identity.Name);
            queryString["type"] = ((int)type).ToString();
            queryString["itemId"] = item;
            string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
            string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
            UriBuilder fullUri = new UriBuilder(fullUrl);

            // If we connect to the services at localhost, actually give the extern IP address to users
            if (NetworkInformation.IsLocalAddress(fullUri.Host, false))
                fullUri.Host = NetworkInformation.GetIPAddress(false);

            // Do the actual streaming
            if (GetStreamMode() == StreamType.Proxied)
            {
                Log.Debug("Proxying download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeStreaming();
                ProxyStream(fullUri.ToString());
            }
            else if (GetStreamMode() == StreamType.Direct)
            {
                Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
                return Redirect(fullUri.ToString());
            }
            return new EmptyResult();
        }
开发者ID:cpriebe,项目名称:MPExtended,代码行数:31,代码来源:StreamController.cs

示例2: ArtworkImplementation

 private static string ArtworkImplementation(this UrlHelper helper, WebMediaType mediaType, string id, Func<string, string, RouteValueDictionary, string> actionMethod)
 {
     switch (mediaType)
     {
         case WebMediaType.Movie:
             return actionMethod("Cover", "MovieLibrary", new RouteValueDictionary(new { movie = id }));
         case WebMediaType.MusicAlbum:
             return actionMethod("AlbumImage", "MusicLibrary", new RouteValueDictionary(new { album = id }));
         case WebMediaType.MusicArtist:
             return actionMethod("ArtistImage", "MusicLibrary", new RouteValueDictionary(new { artist = id }));
         case WebMediaType.MusicTrack:
             return actionMethod("TrackImage", "MusicLibrary", new RouteValueDictionary(new { track = id }));
         case WebMediaType.Radio:
         case WebMediaType.TV:
             return actionMethod("ChannelLogo", "Television", new RouteValueDictionary(new { channelId = id }));
         case WebMediaType.Recording:
             // TODO: Make width configurable with a parameter (object attributes or something like it)
             return actionMethod("PreviewImage", "Recording", new RouteValueDictionary(new { id = id, width = 640 }));
         case WebMediaType.TVEpisode:
             return actionMethod("EpisodeImage", "TVShowsLibrary", new RouteValueDictionary(new { episode = id }));
         case WebMediaType.TVSeason:
             return actionMethod("SeasonImage", "TVShowsLibrary", new RouteValueDictionary(new { season = id }));
         case WebMediaType.TVShow:
             return actionMethod("SeriesPoster", "TVShowsLibrary", new RouteValueDictionary(new { season = id }));
         default:
             return String.Empty;
     }
 }
开发者ID:puenktchen,项目名称:MPExtended,代码行数:28,代码来源:UrlHelperExtensionMethods.cs

示例3: GetMediaName

 public static string GetMediaName(WebMediaType type, string id)
 {
     try
     {
         switch (type)
         {
             case WebMediaType.Movie:
                 return Connections.Current.MAS.GetMovieDetailedById(Settings.ActiveSettings.MovieProvider, id).Title;
             case WebMediaType.MusicAlbum:
                 return Connections.Current.MAS.GetMusicAlbumBasicById(Settings.ActiveSettings.MusicProvider, id).Title;
             case WebMediaType.MusicTrack:
                 return Connections.Current.MAS.GetMusicTrackDetailedById(Settings.ActiveSettings.MusicProvider, id).Title;
             case WebMediaType.Recording:
                 return Connections.Current.TAS.GetRecordingById(Int32.Parse(id)).Title;
             case WebMediaType.TV:
                 return Connections.Current.TAS.GetChannelDetailedById(Int32.Parse(id)).Title;
             case WebMediaType.TVEpisode:
                 return Connections.Current.MAS.GetTVEpisodeDetailedById(Settings.ActiveSettings.TVShowProvider, id).Title;
             case WebMediaType.TVShow:
                 return Connections.Current.MAS.GetTVShowDetailedById(Settings.ActiveSettings.TVShowProvider, id).Title;
             case WebMediaType.TVSeason:
             default:
                 return "";
         }
     }
     catch (Exception ex)
     {
         Log.Warn("Could not load display name of media", ex);
     }
     return "";
 }
开发者ID:puenktchen,项目名称:MPExtended,代码行数:31,代码来源:MediaName.cs

示例4: MediaSource

 public MediaSource(WebMediaType type, int? provider, string id)
 {
     this.MediaType = (WebStreamMediaType)type;
     this.Id = id;
     this.Offset = 0;
     this.Provider = provider;
 }
开发者ID:Thorsten1982,项目名称:MPExtended,代码行数:7,代码来源:MediaSource.cs

示例5: GetExternalMediaInfo

 public SerializableDictionary<string> GetExternalMediaInfo(WebMediaType type, string id)
 {
     return new SerializableDictionary<string>()
     {
         { "Type", "file" },
         { "Path", GetFileBasic(id).Path.First() }
     };
 }
开发者ID:Thorsten1982,项目名称:MPExtended,代码行数:8,代码来源:ShareLibrary.cs

示例6: Download

        //
        // Streaming
        public ActionResult Download(WebMediaType type, string item, string token = null)
        {
            // Check authentication
            if (!IsUserAuthenticated())
            {
                string expectedData = String.Format("{0}_{1}_{2}", type, item, HttpContext.Application["randomToken"]);
                byte[] expectedBytes = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(expectedData));
                string expectedToken = expectedBytes.ToHexString();
                if (token == null || expectedToken != token)
                {
                    Log.Error("Denying download type={0}, item={1}, token={2}, ip={3}: user is not logged in and token is invalid", type, item, token, Request.UserHostAddress);
                    return new HttpUnauthorizedResult();
                }
            }

            // Create URL to GetMediaItem
            Log.Debug("User wants to download type={0}; item={1}", type, item);
            var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
            var userDescription = !String.IsNullOrEmpty(HttpContext.User.Identity.Name) ? String.Format(" (user {0})", HttpContext.User.Identity) :
                                  // TODO: also grab the user from the Authorization header here
                                  !String.IsNullOrEmpty(token) ? " (token-based download)" : String.Empty;
            queryString["clientDescription"] = "WebMediaPortal download" + userDescription;
            queryString["type"] = ((int)type).ToString();
            queryString["itemId"] = item;
            string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
            string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
            UriBuilder fullUri = new UriBuilder(fullUrl);

            // If we can access the file without any problems, let IIS stream it; that is a lot faster
            if (NetworkInformation.IsLocalAddress(fullUri.Host) && type != WebMediaType.TV)
            {
                var path = type == WebMediaType.Recording ?
                    Connections.Current.TAS.GetRecordingFileInfo(Int32.Parse(item)).Path :
                    Connections.Current.MAS.GetMediaItem(GetProvider(type), type, item).Path[0];
                if (System.IO.File.Exists(path))
                    return File(path, MIME.GetFromFilename(path, "application/octet-stream"), Path.GetFileName(path));
            }

            // If we connect to the services at localhost, actually give the extern IP address to users
            if (NetworkInformation.IsLocalAddress(fullUri.Host))
                fullUri.Host = NetworkInformation.GetIPAddressForUri();

            // Do the actual streaming
            if (GetStreamMode() == StreamType.Proxied)
            {
                Log.Debug("Proxying download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeStreaming();
                ProxyStream(fullUri.ToString());
            }
            else if (GetStreamMode() == StreamType.Direct)
            {
                Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
                return Redirect(fullUri.ToString());
            }
            return new EmptyResult();
        }
开发者ID:Ollienator,项目名称:MPExtended,代码行数:59,代码来源:StreamController.cs

示例7: GetDownloadArguments

 public object GetDownloadArguments(WebMediaType mediaType, string itemId)
 {
     return new
     {
         item = itemId,
         type = mediaType,
         token = GenerateDownloadToken(mediaType, itemId)
     };
 }
开发者ID:puenktchen,项目名称:MPExtended,代码行数:9,代码来源:SkinHelper.cs

示例8: GetExternalMediaInfo

 public SerializableDictionary<string> GetExternalMediaInfo(WebMediaType type, string id)
 {
     string path = GetFileBasic(id).Path.First();
     return new SerializableDictionary<string>()
     {
         { "Type", File.Exists(path) ? "file" : "folder" },
         { "Path", path },
         { "Extensions", ".*" }
     };
 }
开发者ID:aredon,项目名称:MPExtended,代码行数:10,代码来源:LocalFileSystem.cs

示例9: AddPlaylistItems

 public WebBoolResult AddPlaylistItems(int? provider, string playlistId, WebMediaType type, int? position, string ids)
 {
     IList<WebPlaylistItem> playlist = GetAllPlaylistItems(provider, playlistId).Finalize(provider, type);
     int pos = position != null ? (int)position : playlist.Count - 1;
     string[] splitIds = ids.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
     for (int i = 0; i < splitIds.Length; i++)
     {
         AddPlaylistItemToPlaylist(provider, splitIds[i], pos + i, playlist);
     }
     return PlaylistLibraries[provider].SavePlaylist(playlistId, playlist);
 }
开发者ID:Shukuyen,项目名称:MPExtended,代码行数:11,代码来源:MediaAccessService.cs

示例10: Download

        public Stream Download(string clientDescription, WebMediaType type, int? provider, string itemId, long? position)
        {
            // validate source first
            MediaSource source = new MediaSource(type, provider, itemId);
            if (!source.Exists)
            {
                throw new FileNotFoundException();
            }

            // create context
            DownloadContext context = new DownloadContext()
            {
                ClientDescription = clientDescription,
                Source = source,
                StartTime = DateTime.Now,
                Stream = new ReadTrackingStreamWrapper(source.Retrieve()),
                MediaInfo = MediaInfoHelper.LoadMediaInfoOrSurrogate(source) // for playerposition view
            };

            // seek to start position if wanted/needed
            if (position != null && position > 0)
            {
                if (context.Stream.CanSeek)
                {
                    context.Stream.Seek(position.Value, SeekOrigin.Begin);
                }
                else
                {
                    Log.Warn("Download: Cannot seek on stream, failed to set start position to {0}", position);
                }
            }

            // see comment in Streaming.cs:151
            string realIp = WCFUtil.GetHeaderValue("forwardedFor", "X-Forwarded-For");
            context.ClientIP = realIp == null ? WCFUtil.GetClientIPAddress() : String.Format("{0} (via {1})", realIp, WCFUtil.GetClientIPAddress());

            // set headers for downloading
            WCFUtil.AddHeader("Content-Disposition", "attachment; filename=\"" + source.GetFileInfo().Name + "\"");
            if (source.MediaType != WebMediaType.TV)
                WCFUtil.SetContentLength(source.GetFileInfo().Size);

            // FIXME: there has to be a better way to do this
            string mime = MIME.GetFromFilename(source.GetFileInfo().Name);
            if (mime != null)
            {
                WCFUtil.SetContentType(mime);
            }

            // finally, save the context and return
            runningDownloads.Add(context);
            return context.Stream;
        }
开发者ID:puenktchen,项目名称:MPExtended,代码行数:52,代码来源:Downloads.cs

示例11: AddPlaylistItem

        public WebBoolResult AddPlaylistItem(int? provider, string playlistId, WebMediaType type, string id, int? position)
        {
            IList<WebPlaylistItem> playlist = GetAllPlaylistItems(provider, playlistId).Finalize(provider, type);

            if (AddPlaylistItemToPlaylist(provider, id, position, playlist))
            {
                return PlaylistLibraries[provider].SavePlaylist(playlistId, playlist);
            }
            else
            {
                return false;
            }
        }
开发者ID:Shukuyen,项目名称:MPExtended,代码行数:13,代码来源:MediaAccessService.cs

示例12: MediaSource

        public MediaSource(WebMediaType type, int? provider, string id, WebFileType filetype, int offset)
        {
            this.MediaType = type;
            this.Id = id;
            this.Provider = provider;
            this.Offset = offset;
            this.FileType = filetype;

            if (!CheckArguments(type, filetype))
            {
                throw new ArgumentException("Invalid combination of mediatype and filetype");
            }
        }
开发者ID:jpykie,项目名称:MPExtended,代码行数:13,代码来源:MediaSource.cs

示例13: ReturnFromService

        public static ActionResult ReturnFromService(WebMediaType mediaType, string id, WebFileType artworkType, int maxWidth, int maxHeight, string defaultFile = null)
        {
            IStreamingService service;
            int? provider = null;

            switch (mediaType)
            {
                case WebMediaType.Drive:
                case WebMediaType.File:
                case WebMediaType.Folder:
                    service = Connections.Current.MASStream;
                    provider = Settings.ActiveSettings.FileSystemProvider;
                    break;
                case WebMediaType.Movie:
                    service = Connections.Current.MASStream;
                    provider = Settings.ActiveSettings.MovieProvider;
                    break;
                case WebMediaType.MusicAlbum:
                case WebMediaType.MusicArtist:
                case WebMediaType.MusicTrack:
                    service = Connections.Current.MASStream;
                    provider = Settings.ActiveSettings.MusicProvider;
                    break;
                case WebMediaType.Picture:
                    service = Connections.Current.MASStream;
                    provider = Settings.ActiveSettings.PicturesProvider;
                    break;
                case WebMediaType.TVShow:
                case WebMediaType.TVSeason:
                case WebMediaType.TVEpisode:
                    service = Connections.Current.MASStream;
                    provider = Settings.ActiveSettings.TVShowProvider;
                    break;
                case WebMediaType.TV:
                    service = Connections.Current.TASStream;
                    break;
                case WebMediaType.Recording:
                    service = Connections.Current.TASStream;
                    return ReturnFromService(service, () => service.ExtractImageResized(mediaType, provider, id, 15, maxWidth, maxHeight), defaultFile);
                default:
                    throw new ArgumentException("Tried to load image for unknown mediatype " + mediaType);
            }

            string etag = String.Format("{0}_{1}_{2}_{3}_{4}_{5}", mediaType, provider, id, artworkType, maxWidth, maxHeight);
            return ReturnFromService(service, () => service.GetArtworkResized(mediaType, provider, id, artworkType, 0, maxWidth, maxHeight), defaultFile, etag);
        }
开发者ID:brownard,项目名称:MPExtended,代码行数:46,代码来源:Images.cs

示例14: Download

        public ActionResult Download(WebMediaType type, string item)
        {
            // Create URL to GetMediaItem
            Log.Debug("User wants to download type={0}; item={1}", type, item);
            var queryString = HttpUtility.ParseQueryString(String.Empty); // you can't instantiate that class manually for some reason
            queryString["clientDescription"] = String.Format("WebMediaPortal download (user {0})", HttpContext.User.Identity.Name);
            queryString["type"] = ((int)type).ToString();
            queryString["itemId"] = item;
            string address = type == WebMediaType.TV || type == WebMediaType.Recording ? Connections.Current.Addresses.TAS : Connections.Current.Addresses.MAS;
            string fullUrl = String.Format("http://{0}/MPExtended/StreamingService/stream/GetMediaItem?{1}", address, queryString.ToString());
            UriBuilder fullUri = new UriBuilder(fullUrl);

            // If we can access the file without any problems, let IIS stream it; that is a lot faster
            if (NetworkInformation.IsLocalAddress(fullUri.Host, false) && type != WebMediaType.TV)
            {
                var path = type == WebMediaType.Recording ?
                    Connections.Current.TAS.GetRecordingFileInfo(Int32.Parse(item)).Path :
                    Connections.Current.MAS.GetMediaItem(GetProvider(type), type, item).Path[0];
                if (System.IO.File.Exists(path))
                    return File(path, MIME.GetFromFilename(path, "application/octet-stream"), Path.GetFileName(path));
            }

            // If we connect to the services at localhost, actually give the extern IP address to users
            if (NetworkInformation.IsLocalAddress(fullUri.Host, false))
                fullUri.Host = NetworkInformation.GetIPAddress(false);

            // Do the actual streaming
            if (GetStreamMode() == StreamType.Proxied)
            {
                Log.Debug("Proxying download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeStreaming();
                ProxyStream(fullUri.ToString());
            }
            else if (GetStreamMode() == StreamType.Direct)
            {
                Log.Debug("Redirecting user to download at {0}", fullUri.ToString());
                GetStreamControl(type).AuthorizeRemoteHostForStreaming(HttpContext.Request.UserHostAddress);
                return Redirect(fullUri.ToString());
            }
            return new EmptyResult();
        }
开发者ID:jpykie,项目名称:MPExtended,代码行数:41,代码来源:StreamController.cs

示例15: IsLocalFile

 public WebBoolResult IsLocalFile(int? provider, WebMediaType mediatype, WebFileType filetype, string id, int offset)
 {
     WebFileInfo info = GetFileInfo(provider, mediatype, filetype, id, offset);
     return info.Exists && info.IsLocalFile;
 }
开发者ID:Shukuyen,项目名称:MPExtended,代码行数:5,代码来源:MediaAccessService.cs


注:本文中的WebMediaType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。