Example #1
0
		private void Build(PivotCollection collection, Stream stream)
		{
			try
			{
				int mortonStart = MortonHelpers.LevelXYToMortonStart(Level, X, Y, AllTileDefaults.CollectionTileMaxLevel);

				// Draw the sub-tiles into the tile
				int subTileCount = MortonHelpers.LevelToSubTileCount(Level, AllTileDefaults.CollectionTileMaxLevel);
				int subTileSize = AllTileDefaults.CollectionTileSize / subTileCount;
				using (CollectionTile tile = new CollectionTile(AllTileDefaults.CollectionTileSize, subTileSize))
				{
					for (int subTileX = 0; subTileX < subTileCount; ++subTileX)
					{
						for (int subTileY = 0; subTileY < subTileCount; ++subTileY)
						{
							int uniqueID = mortonStart + MortonHelpers.XYToMorton(subTileX, subTileY);
							Item item = collection.FindItem(uniqueID);
							if (item == null)
								continue;
							ImageProviderBase imageProvider = item.ItemImage.GetImageProvider();
							tile.Draw(imageProvider, subTileX * subTileSize, subTileY * subTileSize);
						}
					}

					tile.Save(stream, ImageFormat.Png);
				}
			}
			catch (Exception ex)
			{
				ex.GetType();
			}
		}
Example #2
0
		// Write a collection object as CXML to a stream
		public static void Serialize(Stream outputStream, PivotCollection collection)
		{
			CxmlSerializer serializer = new CxmlSerializer(collection);
			XmlWriterSettings settings = new XmlWriterSettings();
			settings.Indent = true;
			settings.IndentChars = string.Empty;
			settings.NewLineChars = Environment.NewLine;
			using (XmlWriter writer = XmlWriter.Create(outputStream, settings))
				serializer.Write(writer);
		}
Example #3
0
		// Write a collection's image data as a DZC to a Stream
		public static void Serialize(PivotCollection collection, Stream stream)
		{
			XmlWriterSettings settings = new XmlWriterSettings();
			settings.Indent = true;
			settings.IndentChars = string.Empty;
			settings.NewLineChars = Environment.NewLine;
			using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings))
			{
				Serialize(collection, xmlWriter);
			}
		}
Example #4
0
		// Create a single item collection that displays the error message from an exception.
		public static PivotCollection FromException(Exception ex)
		{
			PivotCollection collection = new PivotCollection("Error");
			collection.Name = "Error";

			string title = ex.Message;
			string description = (ex.InnerException == null ? null : ex.InnerException.Message);
			Item item = new Item(0, title, null, description, null);
			collection.AddItem(item);
			return collection;
		}
Example #5
0
		public static void AnticipateServe(HttpContext cxmlContext, PivotCollection collection)
		{
			if (collection == null)
				return;

			string CachePath = Path.GetDirectoryName(cxmlContext.Request.PhysicalPath) + "\\" + collection.CollectionKey + ".dzc";
			using (MemoryStream memoryStream = new MemoryStream())
			{
				DzcSerializer.Serialize(collection, memoryStream);
				CacheFile.Save(memoryStream, CachePath);
			}
		}
Example #6
0
		public bool Serve(PivotCollection collection, HttpContext context, bool cacheToDisk)
		{
			if (collection == null)
				return false;
			using (MemoryStream memoryStream = new MemoryStream())
			{
				Build(collection, memoryStream);
				memoryStream.Position = 0; // Rewind the stream, ready for reading
				memoryStream.WriteTo(context.Response.OutputStream);
				context.Response.ContentType = "image/jpeg";
				if (cacheToDisk)
					CacheFile.Save(memoryStream, CachePath);
			}

			return true;
		}
Example #7
0
		public bool Serve(HttpContext context, PivotCollection collection)
		{
			if (collection == null)
				return false;

			using (MemoryStream memoryStream = new MemoryStream())
			{
				DzcSerializer.Serialize(collection, memoryStream);
				memoryStream.Position = 0; // Rewind the stream, ready for reading
				memoryStream.WriteTo(context.Response.OutputStream);
				context.Response.ContentType = "text/xml";
				CacheFile.Save(memoryStream, CachePath);
			}

			return true;
		}
Example #8
0
		public bool Serve(HttpContext context, PivotCollection collection, bool cacheToDisk)
		{
			if (collection == null)
				return false;

			CachePath = Path.GetDirectoryName(CachePath) + "\\" + collection.CollectionKey + ".cxml";
			using (MemoryStream memoryStream = new MemoryStream())
			{
				collection.ToCxml(memoryStream);
				memoryStream.Position = 0; // Rewind the stream, ready for reading
				memoryStream.WriteTo(context.Response.OutputStream);
				context.Response.ContentType = "text/xml";
				if (cacheToDisk)
					CacheFile.Save(memoryStream, CachePath);
			}

			return true;
		}
Example #9
0
        static void Main(string[] args)
        {
            try
            {
                var pivotCollection = new PivotCollection<Track>();
                pivotCollection.CollectionName = "iTunes Library";

                var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var dataDir = dir + Path.DirectorySeparatorChar + "data";
                var cacheDir = dir + Path.DirectorySeparatorChar + "cache";
                if (!Directory.Exists(cacheDir)) Directory.CreateDirectory(cacheDir);
                if (!Directory.Exists(dataDir)) Directory.CreateDirectory(dataDir);                

                //var parser = new ITunesLibraryParser();
                //parser.ParseLibrary();
                //foreach (var t in parser.Tracks)
                //{
                //    pivotCollection.Add(t);
                //}

                var itunes = new ITunesRemote();
                itunes.Connect();
#if DEBUG
                pivotCollection.AddRange(itunes.GetMusicTracks(cacheDir).GetRange(0,10));
                pivotCollection.Write(dataDir + Path.DirectorySeparatorChar + @"iTunesLibrary_d.cxml");
#else
                pivotCollection.AddRange(itunes.GetMusicTracks(cacheDir));
                pivotCollection.Write(dataDir + Path.DirectorySeparatorChar + @"iTunesLibrary.cxml");
#endif

                var htmlFiles = Directory.GetFiles(dir + Path.DirectorySeparatorChar + @"Html");
                foreach (var path in htmlFiles)
                {
                    var fi = new FileInfo(path);
                    File.Copy(path, dataDir + Path.DirectorySeparatorChar + fi.Name, true);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
Example #10
0
		// Write a collection object as CXML into an XmlWriter
		public static void Serialize(XmlWriter writer, PivotCollection collection)
		{
			CxmlSerializer serializer = new CxmlSerializer(collection);
			serializer.Write(writer);
		}
Example #11
0
		private CxmlSerializer(PivotCollection collection)
		{
			_collection = collection;
		}
Example #12
0
		public void Add(string key, PivotCollection collection)
		{
			if (collection != null)
				HttpRuntime.Cache.Insert(key, collection, null, Cache.NoAbsoluteExpiration, s_cacheExpiryDuration);
		}
Example #13
0
		// Write a collection's image data as a DZC to an XmlWriter
		public static void Serialize(PivotCollection collection, XmlWriter xmlWriter)
		{
			DzcSerializer serializer = new DzcSerializer(collection);
			serializer.Write(xmlWriter);
		}
Example #14
0
		private DzcSerializer(PivotCollection collection)
		{
			_collection = collection;
		}