當前位置: 首頁>>代碼示例>>C#>>正文


C# Catalog.ToGzipCompressedJson方法代碼示例

本文整理匯總了C#中Catalog.ToGzipCompressedJson方法的典型用法代碼示例。如果您正苦於以下問題:C# Catalog.ToGzipCompressedJson方法的具體用法?C# Catalog.ToGzipCompressedJson怎麽用?C# Catalog.ToGzipCompressedJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Catalog的用法示例。


在下文中一共展示了Catalog.ToGzipCompressedJson方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: HandleRequest

		static Stream HandleRequest (string request, Catalog catalog, long? rangeStart, long? rangeEnd)
		{
			LoggingService.LogInfo ("Handling request: {0}", request);
			if (request.StartsWith (Messages.FetchTrack, StringComparison.Ordinal)) {
				var message = Newtonsoft.Json.JsonConvert.DeserializeObject<FetchTrackMessage> (request.Substring (Messages.FetchTrack.Length));
				var track = catalog.FindTrack (message.UUID);
				var stream = new MemoryStream (File.ReadAllBytes (track.FilePath), true);
				stream.Position = rangeStart ?? message.Offset;
				stream.SetLength (rangeEnd ?? stream.Length);
				return stream;
			} else if (request.StartsWith (Messages.FetchAlbumArt)) {
				var message = Newtonsoft.Json.JsonConvert.DeserializeObject<FetchAlbumArtMessage> (request.Substring (Messages.FetchAlbumArt.Length));
				var track = catalog.First (t => t.AlbumArtist == message.AlbumArtist && t.Album == message.Album);
				return File.OpenRead (track.AlbumArt);
			} else if (request.StartsWith (Messages.FetchArtistArt)) {
				var message = Newtonsoft.Json.JsonConvert.DeserializeObject<FetchArtistArtMessage> (request.Substring (Messages.FetchArtistArt.Length));
				var track = catalog.First (t => t.AlbumArtist == message.AlbumArtist && !string.IsNullOrEmpty (t.AlbumArt));
				return File.OpenRead (track.AlbumArt);
			} else if (request.StartsWith (Messages.FetchCatalog)) {
				var message = Newtonsoft.Json.JsonConvert.DeserializeObject<FetchCatalogMessage> (request.Substring (Messages.FetchCatalog.Length));
				if (message?.UUID == catalog.UUID)
					return new MemoryStream (new byte [0]);
				return new MemoryStream (catalog.ToJson ());
			} else if (request.StartsWith (Messages.FetchGzipCompressedCatalog)) {
				var message = Newtonsoft.Json.JsonConvert.DeserializeObject<FetchCatalogMessage> (request.Substring (Messages.FetchGzipCompressedCatalog.Length));
				if (message?.UUID == catalog.UUID)
					return new MemoryStream (new byte [0]);
				return new MemoryStream (catalog.ToGzipCompressedJson ());
			} else {
				return Stream.Null;
			}
		}
開發者ID:alanmcgovern,項目名稱:tunez,代碼行數:32,代碼來源:RequestHandler.cs


注:本文中的Catalog.ToGzipCompressedJson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。