public void TestExpandRelativeUriWithAbsoluteAndRelativeUris()
 {
     AssertEqual("http://pauthor.codeplex.com/license.html",
                 UriUtility.ExpandRelativeUri("http://pauthor.codeplex.com/documentation", "license.html"));
     AssertEqual("http://pauthor.codeplex.com/documentation",
                 UriUtility.ExpandRelativeUri("http://pauthor.codeplex.com/sample/foobar", "../documentation"));
 }
            private PivotImage CopyCollectionImage(PivotImage sourceImage, String suffix)
            {
                if (sourceImage == null)
                {
                    return(null);
                }

                PivotImage newImage = new PivotImage(
                    UriUtility.ExpandRelativeUri(this.BasePath, sourceImage.SourcePath));

                String sourceFileName = UriUtility.GetFileName(newImage.SourcePath);
                String targetFileName = Path.GetFileNameWithoutExtension(m_localTarget.BasePath);

                targetFileName += suffix + Path.GetExtension(sourceFileName);
                String targetDirectoryPath = Directory.GetParent(m_localTarget.BasePath).FullName;
                String targetFilePath      = Path.Combine(targetDirectoryPath, targetFileName);

                if (File.Exists(targetFilePath) == false)
                {
                    newImage.Save(targetFilePath);
                }

                newImage.SourcePath = targetFileName;
                return(newImage);
            }
        public void TestExpandRelativeUriWithAbsoluteAndRelativeLocalPaths()
        {
            String binDirectory = Path.GetFullPath(@"..\..\bin");

            AssertEqual(Path.GetFullPath(@"..\..\Resources\DeepZoom\sample.cxml"),
                        UriUtility.ExpandRelativeUri(binDirectory, @"Resources\DeepZoom\sample.cxml"));
            AssertEqual(Path.GetFullPath(@"..\..\PauthorTestRunner.csproj"),
                        UriUtility.ExpandRelativeUri(binDirectory, "PauthorTestRunner.csproj"));
        }
 public void TestExpandRelativeUriWithTwoLocalPaths()
 {
     AssertEqual(Path.GetFullPath(@"..\..\Resources"),
                 UriUtility.ExpandRelativeUri("PauthorTestRunner.exe", @"..\..\Resources"));
     AssertEqual(Path.GetFullPath(@"..\..\Resources\DeepZoom\sample_images"),
                 UriUtility.ExpandRelativeUri(@"..\..\Resources\DeepZoom\sample.cxml", @"sample_images"));
     AssertEqual(Path.GetFullPath(@"..\..\Resources\Excel\sample.xlsx"),
                 UriUtility.ExpandRelativeUri(@"..\..\Resources\DeepZoom", @"Excel\sample.xlsx"));
 }
Beispiel #5
0
        private String GetImageUri(String imageBase, String dzcIndex)
        {
            if (m_dzcReader == null)
            {
                m_dzcReader = XmlReader.Create(imageBase);
                m_dzcReader.MoveToContent();
            }

            int attempts = 0;

            while (attempts <= 1)
            {
                while (m_dzcReader.Read())
                {
                    if (m_dzcReader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }
                    if (m_dzcReader.LocalName != "I")
                    {
                        continue;
                    }
                    if (m_dzcReader.GetAttribute("Id") != dzcIndex)
                    {
                        continue;
                    }
                    return(UriUtility.ExpandRelativeUri(imageBase, m_dzcReader.GetAttribute("Source")));
                }

                m_dzcReader.Close();
                m_dzcReader = XmlReader.Create(imageBase);
                m_dzcReader.MoveToContent();
                attempts++;
            }

            return(null);
        }
        private PivotItem ReadItem(OleDbDataReader dataReader, int rowId)
        {
            PivotItem item = new PivotItem(rowId.ToString(), this);

            for (int column = 0; column < dataReader.FieldCount; column++)
            {
                if (dataReader.IsDBNull(column))
                {
                    continue;
                }

                String columnName = dataReader.GetName(column).ToLowerInvariant();
                String value      = dataReader.GetValue(column).ToString();
                if (String.IsNullOrEmpty(value))
                {
                    continue;
                }

                if (columnName == OleDbSchemaConstants.Item.Name)
                {
                    item.Name = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Image)
                {
                    String imagePath = UriUtility.ExpandRelativeUri(this.BasePath, value);
                    item.Image = new PivotImage(imagePath);
                }
                else if (columnName == OleDbSchemaConstants.Item.Description)
                {
                    item.Description = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.Href)
                {
                    item.Href = value;
                }
                else if (columnName == OleDbSchemaConstants.Item.RelatedLinks)
                {
                    StringReader valueReader = new StringReader(value);
                    String       singleValue = null;
                    while ((singleValue = valueReader.ReadLine()) != null)
                    {
                        String[] parts = singleValue.Split(
                            new String[] { OleDbSchemaConstants.LinkPartDelimiter }, StringSplitOptions.None);
                        if (parts.Length > 0)
                        {
                            String name = null, url = null;
                            if (parts.Length == 1)
                            {
                                url = parts[0];
                            }
                            else if (parts.Length >= 2)
                            {
                                name = parts[0];
                                url  = parts[1];
                            }
                            item.AddRelatedLink(new PivotLink(name, url));
                        }
                    }
                }
                else
                {
                    PivotFacetCategory facetCategory = null;
                    foreach (PivotFacetCategory currentFacetCategory in m_facetCategoryMap.Values)
                    {
                        if (columnName == currentFacetCategory.Name.Replace('.', '#').ToLowerInvariant())
                        {
                            facetCategory = currentFacetCategory;
                            break;
                        }
                    }

                    if (facetCategory != null)
                    {
                        item.AddFacetValues(facetCategory.Name, this.SplitJoinedStrings(value).ToArray());
                    }
                }
            }

            return(item);
        }
        private void LoadCollectionData(OleDbConnection connection)
        {
            String collectionCommandString = this.CollectionDataQuery;

            if (collectionCommandString == null)
            {
                return;
            }

            OleDbCommand    command    = new OleDbCommand(collectionCommandString, connection);
            OleDbDataReader dataReader = command.ExecuteReader();

            if (dataReader.Read())
            {
                for (int column = 0; column < dataReader.FieldCount; column++)
                {
                    if (dataReader.IsDBNull(column))
                    {
                        continue;
                    }

                    String columnName = dataReader.GetName(column).ToLowerInvariant();
                    String value      = dataReader.GetValue(column).ToString();

                    if (columnName == OleDbSchemaConstants.Collection.Name)
                    {
                        this.CachedCollectionData.Name = value;
                    }
                    else if (columnName == OleDbSchemaConstants.Collection.Icon)
                    {
                        String iconPath = UriUtility.ExpandRelativeUri(this.BasePath, value);
                        this.CachedCollectionData.Icon = new PivotImage(iconPath);
                    }
                    else if (columnName == OleDbSchemaConstants.Collection.BrandImage)
                    {
                        String brandImagePath = UriUtility.ExpandRelativeUri(this.BasePath, value);
                        this.CachedCollectionData.BrandImage = new PivotImage(brandImagePath);
                    }
                    else if (columnName == OleDbSchemaConstants.Collection.AdditionalSearchText)
                    {
                        this.CachedCollectionData.AdditionalSearchText = value;
                    }
                    else if (columnName == OleDbSchemaConstants.Collection.CopyrightTitle)
                    {
                        if (this.CachedCollectionData.Copyright == null)
                        {
                            this.CachedCollectionData.Copyright = new PivotLink(value, "about:none");
                        }
                        this.CachedCollectionData.Copyright.Title = value;
                    }
                    else if (columnName == OleDbSchemaConstants.Collection.CopyrightUrl)
                    {
                        if (this.CachedCollectionData.Copyright == null)
                        {
                            this.CachedCollectionData.Copyright = new PivotLink("Copyright", value);
                        }
                        this.CachedCollectionData.Copyright.Url = value;
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Converts a DeepZoom image back into an ordinary bitmap.
        /// </summary>
        /// <param name="dziPath">the path (relative or absolute) to the DZI file to convert</param>
        /// <returns>an absolute path to the resulting image within this image creator's working directory</returns>
        public String UnDeepZoomImage(String dziUri)
        {
            try
            {
                using (WebClient webClient = new WebClient())
                {
                    String baseName       = Path.GetFileNameWithoutExtension(UriUtility.GetFileName(dziUri));
                    String finalImagePath = Path.Combine(this.WorkingDirectory, baseName + StandardImageFormatExtension);
                    if (File.Exists(finalImagePath))
                    {
                        return(finalImagePath);
                    }

                    String filesDirectoryUri = UriUtility.ExpandRelativeUri(dziUri, baseName + "_files");
                    String dziText           = UriUtility.DownloadString(webClient, dziUri);

                    XPathHelper dzi   = new XPathHelper(dziText);
                    String      xmlns = this.DetermineNamespace(dziText);
                    if (xmlns != null)
                    {
                        dzi.AddNamespace("d", xmlns);
                    }

                    String format   = dzi.FindString("//d:Image/@Format");
                    int    tileSize = dzi.FindInt("//d:Image/@TileSize");
                    int    overlap  = dzi.FindInt("//d:Image/@Overlap");
                    int    width    = dzi.FindInt("//d:Size/@Width");
                    int    height   = dzi.FindInt("//d:Size/@Height");

                    int maxLevel = (int)Math.Ceiling(Math.Log(Math.Max(width, height), 2));

                    Bitmap   finalImage         = new Bitmap(width, height);
                    Graphics finalImageGraphics = Graphics.FromImage(finalImage);

                    int colCount = (int)Math.Ceiling((double)width / tileSize);
                    int rowCount = (int)Math.Ceiling((double)height / tileSize);
                    for (int row = 0; row < rowCount; row++)
                    {
                        for (int col = 0; col < colCount; col++)
                        {
                            String tileName    = col + "_" + row + "." + format;
                            Uri    tileUri     = new Uri(filesDirectoryUri + "/" + maxLevel + "/" + tileName);
                            Stream imageStream = null;

                            try
                            {
                                imageStream = webClient.OpenRead(tileUri);
                                Bitmap tile  = new Bitmap(imageStream);
                                float  tileX = col * (tileSize);
                                float  tileY = row * (tileSize);
                                finalImageGraphics.DrawImage(tile, tileX, tileY);
                            }
                            catch (WebException)
                            {
                                Log.Warning("Could not find tile {0}, {1} for DZI {2}. " +
                                            "The image for this tile may be incomplete.", col, row, dziUri);
                                throw;
                            }
                            finally
                            {
                                if (imageStream != null)
                                {
                                    imageStream.Close();
                                }
                            }
                        }
                    }

                    finalImage.Save(finalImagePath, StandardImageFormat);
                    return(finalImagePath);
                }
            }
            catch (XPathException e)
            {
                throw new PauthorException("Unable to decode DZI: " + dziUri, e);
            }
            catch (Exception e)
            {
                throw new PauthorException("Unable to un-deepzoom DZI: " + dziUri, e);
            }
        }