Exemple #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();
			}
		}
Exemple #2
0
        public void TestBrokenRelatedLinks()
        {
            PivotCollection collection = new PivotCollection();

            collection.FacetCategories.Add(new PivotFacetCategory("alpha", PivotFacetType.String));

            PivotItem item = new PivotItem("0", collection);

            item.AddFacetValues("alpha", "alpha");
            item.AddRelatedLink(new PivotLink(null, "http://pauthor.codeplex.com"));
            collection.Items.Add(item);

            item = new PivotItem("1", collection);
            item.AddFacetValues("alpha", "bravo");
            item.AddRelatedLink(new PivotLink("charlie", null));
            collection.Items.Add(item);

            PivotCollectionBuffer buffer     = new PivotCollectionBuffer(collection);
            String targetPath                = Path.Combine(WorkingDirectory, "sample.cxml");
            LocalCxmlCollectionTarget target = new LocalCxmlCollectionTarget(targetPath);

            target.Write(buffer);

            AssertCxmlSchemaValid(targetPath);

            CxmlCollectionSource targetAsSource = new CxmlCollectionSource(targetPath);

            buffer.Write(targetAsSource);

            AssertEqual("Related Link", buffer.Collection.Items[0].RelatedLinks.First().Title);
            AssertEqual("http://pauthor.codeplex.com", buffer.Collection.Items[0].RelatedLinks.First().Url);
            AssertEqual(0, buffer.Collection.Items[1].RelatedLinks.Count());
        }
Exemple #3
0
        public void TestCsvToCxmlWithTemplate()
        {
            String sourcePath   = Path.Combine(this.ResourceDirectory, @"CSV\sample_missing_images.csv");
            String templatePath = Path.Combine(this.ResourceDirectory, @"CSV\template-1.htm");
            String targetPath   = Path.Combine(WorkingDirectory, "sample.cxml");

            PauthorProgram.Main(new String[] {
                "/source", "csv", sourcePath, "/html-template", templatePath, "/target", "cxml", targetPath
            });

            AssertCxmlSchemaValid(targetPath);
            AssertFileExists(@"sample.cxml");
            AssertFileExists(@"sample_images\0.png");

            IPivotCollectionSource source         = new CsvCollectionSource(sourcePath);
            IPivotCollectionSource targetAsSource = new CxmlCollectionSource(targetPath);
            PivotCollectionBuffer  buffer         = new PivotCollectionBuffer();

            buffer.Write(source);
            PivotCollection expected = buffer.Collection;

            buffer.Write(targetAsSource);
            PivotCollection actual = buffer.Collection;

            AssertEqual(expected.Name, actual.Name);
            AssertEqual(expected.Icon, actual.Icon);
            AssertEqual(expected.FacetCategories[0].Name, actual.FacetCategories[0].Name);
            AssertEqual(expected.FacetCategories.Count, actual.FacetCategories.Count);
            AssertEqual(expected.Items[0].Name, actual.Items[0].Name);
            AssertNotEqual(expected.Items[0].Image, actual.Items[0].Image);
        }
Exemple #4
0
        private void ParseFacet(XmlReader xmlReader, PivotItem item)
        {
            PivotCollection cachedData = this.CachedCollectionData;

            String         facetCategoryName = null;
            PivotFacetType facetType         = null;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (xmlReader.LocalName == "Facet")
                {
                    facetCategoryName = xmlReader.GetAttribute("Name");
                    PivotFacetCategory facetCategory = cachedData.FacetCategories[facetCategoryName];
                    facetType = facetCategory.Type;
                }
                else if ((facetType != null) && (xmlReader.LocalName == facetType.ToString()))
                {
                    if (facetType == PivotFacetType.Link)
                    {
                        PivotLink link = new PivotLink(xmlReader.GetAttribute("Name"), xmlReader.GetAttribute("Href"));
                        item.AddFacetValues(facetCategoryName, link);
                    }
                    else
                    {
                        String value = xmlReader.GetAttribute("Value");
                        item.AddFacetValues(facetCategoryName, facetType.ParseValue(value));
                    }
                }
            }
        }
Exemple #5
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);
		}
Exemple #6
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);
			}
		}
Exemple #7
0
        protected override void LoadHeaderData()
        {
            PivotCollection cachedData = this.CachedCollectionData;

            using (FileStream fileStream = new FileStream(this.BasePath, FileMode.Open, FileAccess.Read))
            {
                using (XmlReader xmlReader = XmlReader.Create(fileStream))
                {
                    while (xmlReader.Read())
                    {
                        if (xmlReader.NodeType != XmlNodeType.Element)
                        {
                            continue;
                        }

                        if (xmlReader.LocalName == "Collection")
                        {
                            cachedData.Name = xmlReader.GetAttribute("Name");
                            cachedData.AdditionalSearchText = xmlReader.GetAttribute("AdditionalSearchText");
                            cachedData.SchemaVersion        = xmlReader.GetAttribute("SchemaVersion");

                            String value = null;
                            if ((value = xmlReader.GetAttribute("Icon", PivotNamespace)) != null)
                            {
                                cachedData.Icon = new PivotImage(new Uri(this.BasePathAsUri, value).ToString());
                            }
                            if ((value = xmlReader.GetAttribute("BrandImage", PivotNamespace)) != null)
                            {
                                cachedData.BrandImage = new PivotImage(new Uri(this.BasePathAsUri, value).ToString());
                            }
                        }
                        else if (xmlReader.LocalName == "Items")
                        {
                            String imageBase = xmlReader.GetAttribute("ImgBase");
                            if (imageBase != null)
                            {
                                cachedData.ImageBase = new Uri(this.BasePathAsUri, imageBase).ToString();
                                xmlReader.Skip();
                            }
                        }
                        else if (xmlReader.LocalName == "Copyright")
                        {
                            cachedData.Copyright =
                                new PivotLink(xmlReader.GetAttribute("Name"), xmlReader.GetAttribute("Href"));
                        }
                        else if (xmlReader.LocalName == "FacetCategory")
                        {
                            PivotFacetCategory facetCategory = this.ParseFacetCategory(xmlReader.ReadSubtree());
                            cachedData.FacetCategories.Add(facetCategory);
                        }
                    }
                }
            }
        }
Exemple #8
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;
		}
Exemple #9
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);
			}
		}
        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);
            }
        }
Exemple #11
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;
		}
Exemple #12
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;
		}
Exemple #13
0
        private PivotItem ParseItem(XmlReader xmlReader)
        {
            PivotCollection cachedData = this.CachedCollectionData;

            PivotItem item = null;

            while (xmlReader.Read())
            {
                if (xmlReader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                if (xmlReader.LocalName == "Item")
                {
                    String id = xmlReader.GetAttribute("Id");
                    item = new PivotItem(id, this);

                    String imagePath = xmlReader.GetAttribute("Img");
                    if (imagePath != null)
                    {
                        if (cachedData.ImageBase == null)
                        {
                            imagePath = new Uri(this.BasePathAsUri, imagePath).ToString();
                        }
                        item.Image = new PivotImage(imagePath);
                    }

                    item.Name = xmlReader.GetAttribute("Name");
                    item.Href = xmlReader.GetAttribute("Href");
                }
                else if (xmlReader.LocalName == "Description")
                {
                    item.Description = xmlReader.ReadElementContentAsString();
                }
                else if (xmlReader.LocalName == "Facet")
                {
                    this.ParseFacet(xmlReader.ReadSubtree(), item);
                }
                else if (xmlReader.LocalName == "Related")
                {
                    List <PivotLink> relatedLinks = this.ParseRelatedLinks(xmlReader.ReadSubtree());
                    item.RelatedLinks = relatedLinks;
                }
            }
            return(item);
        }
Exemple #14
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;
		}
        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);
            }
        }
Exemple #16
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);
		}
Exemple #17
0
		private CxmlSerializer(PivotCollection collection)
		{
			_collection = collection;
		}
Exemple #18
0
		private DzcSerializer(PivotCollection collection)
		{
			_collection = collection;
		}
Exemple #19
0
		public void Add(string key, PivotCollection collection)
		{
			if (collection != null)
				HttpRuntime.Cache.Insert(key, collection, null, Cache.NoAbsoluteExpiration, s_cacheExpiryDuration);
		}
Exemple #20
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);
		}
Exemple #21
0
 /// <summary>
 /// Creates a new collection buffer with an existing collection as its basis.
 /// </summary>
 /// <param name="collection">the collection to serve as the basis for the new buffer</param>
 public PivotCollectionBuffer(PivotCollection collection)
 {
     this.Collection = collection;
 }