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);
            }
Beispiel #2
0
 internal static async void Upload(ListItem listItem, HtmlCollection <File> files)
 {
     for (int i = 0; i < files.Length; i++)
     {
         if (!await LazyWindow.ShowWaiting(string.Format("{0}: uploading...", files[i].Name),
                                           delegate(CancellationToken cancellationToken)
         {
             return(listItem.AddAttachment(UriUtility.GetFileName(files[i].Name), files[i], cancellationToken));
         }))
         {
             break;
         }
     }
 }
Beispiel #3
0
        private IEnumerable <PivotItem> ProcessItems(String imageBase)
        {
            foreach (PivotItem item in this.Source.Items)
            {
                if ((item.Image == null) || (item.Image.IsDeepZoomIndex == false))
                {
                    yield return(item);

                    continue;
                }

                String dzcIndex = item.Image.SourcePath.Substring(1);
                String imageUri = this.GetImageUri(imageBase, dzcIndex);
                if (imageUri == null)
                {
                    item.Image = null;
                }
                else if (UriUtility.GetFileName(imageUri).EndsWith("dzi"))
                {
                    item.Image.SourcePath = m_imageCreator.UnDeepZoomImage(imageUri);
                }
                yield return(item);
            }
        }
 public void TestGetFileNameWithUri()
 {
     AssertEqual("documentation", UriUtility.GetFileName("http://pauthor.codeplex.com/documentation"));
     AssertEqual("documentation", UriUtility.GetFileName("sample/foo/documentation"));
     AssertNull(UriUtility.GetFileName("http://pauthor.codeplex.com"));
 }
 public void TestGetFileNameWithLocalPath()
 {
     AssertEqual("PauthorTestRunner.exe", UriUtility.GetFileName(@"PauthorTestRunner.exe"));
     AssertEqual("sample.cxml", UriUtility.GetFileName(@"..\..\Resources\DeepZoom\sample.cxml"));
     AssertEqual("PauthorTestRunner.exe", UriUtility.GetFileName(Path.GetFullPath("PauthorTestRunner.exe")));
 }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        internal WebsNode(WebNode parent)
        {
            this.parent = parent;
            sorter      = new ListView <Web, string, string>(JMapFactories.String,
                                                             delegate(Web web) { return(UriUtility.GetFileName(web.Url).ToLowerInvariant()); },
                                                             null,
                                                             delegate(Web web) { return(web.Title); },
                                                             String.Compare);

            lazyList = new LazyLoadingList(LoadChildren);
            Children = lazyList;
            parent.Webs.Advise(Notify);
        }