Beispiel #1
0
        public override void SetUp()
        {
            base.SetUp();

            root  = CreateOneItem <RootNode>(1, "root", null);
            start = CreateOneItem <RootNode>(2, "start", root);
            host  = new Host(new ThreadContext(), root.ID, start.ID);

            fs          = new FakeMappedFileSystem();
            fs.BasePath = AppDomain.CurrentDomain.BaseDirectory + @"\FileSystem\";

            vnf    = new VirtualNodeFactory();
            config = new EditSection();

            injector = new FakeDependencyInjector();
            injector.injectors.Add(new EntityDependencySetter <IFileSystem>(fs));
            injector.injectors.Add(new EntityDependencySetter <IDependencyInjector>(injector));
            var sizeCache = new ImageSizeCache(new ConfigurationManagerWrapper {
                Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, config)
            });

            injector.injectors.Add(new EntityDependencySetter <ImageSizeCache>(sizeCache));
            //nodeProvider = new FolderNodeProvider(fs, persister, injector);
            //initializer = new VirtualFolderInitializer(host, persister, fs, vnf, new Plugin.ConnectionMonitor().SetConnected(SystemStatusLevel.UpAndRunning), config, new ImageSizeCache(new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, config) }), nodeProvider);
            //nodeProvider = new FolderNodeProvider(fs, persister, injector);
            //nodeProvider = new FolderNodeProvider(fs, persister, injector);
            nodeProvider = new FolderNodeProvider(fs, persister.Repository, injector);
            initializer  = new VirtualFolderInitializer(host, persister, fs, vnf, monitor = new Plugin.ConnectionMonitor().SetConnected(SystemStatusLevel.UpAndRunning), new UploadFolderSource(host, config), nodeProvider);
        }
		public override void SetUp()
		{
			base.SetUp();

			root = CreateOneItem<RootNode>(1, "root", null);
			start = CreateOneItem<RootNode>(2, "start", root);
			host = new Host(new ThreadContext(), root.ID, start.ID);

			fs = new FakeMappedFileSystem();
			fs.BasePath = AppDomain.CurrentDomain.BaseDirectory + @"\FileSystem\";

			vnf = new VirtualNodeFactory();
			config = new EditSection();

			injector = new FakeDependencyInjector();
			injector.injectors.Add(new EntityDependencySetter<IFileSystem>(fs));
			injector.injectors.Add(new EntityDependencySetter<IDependencyInjector>(injector));
			var sizeCache = new ImageSizeCache(new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, config) });
			injector.injectors.Add(new EntityDependencySetter<ImageSizeCache>(sizeCache));
            //nodeProvider = new FolderNodeProvider(fs, persister, injector);
            //initializer = new VirtualFolderInitializer(host, persister, fs, vnf, new Plugin.ConnectionMonitor().SetConnected(SystemStatusLevel.UpAndRunning), config, new ImageSizeCache(new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(null, null, null, config) }), nodeProvider);
            //nodeProvider = new FolderNodeProvider(fs, persister, injector);
			//nodeProvider = new FolderNodeProvider(fs, persister, injector);
			nodeProvider = new FolderNodeProvider(fs, persister.Repository, injector);
            initializer = new VirtualFolderInitializer(host, persister, fs, vnf, monitor = new Plugin.ConnectionMonitor().SetConnected(SystemStatusLevel.UpAndRunning), new UploadFolderSource(host, config), nodeProvider);
		}
        /// <summary>
        /// Gets the size of the image.
        /// </summary>
        /// <param name="keyName">Name of the key.</param>
        /// <param name="imagePath">The image path.</param>
        /// <returns>ImageSize.</returns>
        private ImageSize GetImageSize(string keyName, string imagePath)
        {
            // Now check the file system cache
            var fullCachePath = ImageSizeCache.GetResourcePath(keyName, ".pb");

            try
            {
                var result = _protobufSerializer.DeserializeFromFile <int[]>(fullCachePath);

                return(new ImageSize {
                    Width = result[0], Height = result[1]
                });
            }
            catch (FileNotFoundException)
            {
                // Cache file doesn't exist no biggie
            }

            var size = ImageHeader.GetDimensions(imagePath, _logger);

            var imageSize = new ImageSize {
                Width = size.Width, Height = size.Height
            };

            // Update the file system cache
            CacheImageSize(fullCachePath, size.Width, size.Height);

            return(imageSize);
        }
Beispiel #4
0
        private InlineUIContainer RenderImage(HTML.Element e, ParagraphSizeTracker pst)
        {
            Uri ImageURI;

            if (e.Attributes.ContainsKey("src") &&
                Uri.TryCreate(e.Attributes["src"], UriKind.RelativeOrAbsolute, out ImageURI))
            {
                Image image = new Image()
                {
                    Stretch = Stretch.Fill
                };
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.UriSource = ImageURI;
                bitmapImage.EndInit();
                image.Source = bitmapImage;
                if (ImageSizeCache.ContainsKey(ImageURI))
                {
                    Tuple <int, int> size = ImageSizeCache[ImageURI];
                    image.Width  = size.Item1;
                    image.Height = size.Item2;
                }
                // This hack forces image size to match pixel size,
                // which undermines WPF's preference for honoring the
                // embedded DPI value which leads to upscaled and
                // mildly blurry images where that doesn't match
                // the local display.  Very high resolution displays
                // might need another approach.
                bitmapImage.DownloadCompleted += (s, ee) =>
                {
                    ImageSizeCache[ImageURI] = new Tuple <int, int>(bitmapImage.PixelWidth, bitmapImage.PixelHeight);
                    image.Width  = bitmapImage.PixelWidth;
                    image.Height = bitmapImage.PixelHeight;
                };
                // Communicate image size info back up to the container
                if (pst != null)
                {
                    pst.Add(image);
                }
                if (e.Attributes.ContainsKey("title"))
                {
                    image.ToolTip = e.Attributes["title"];
                }
                else if (e.Attributes.ContainsKey("alt"))
                {
                    image.ToolTip = e.Attributes["alt"];
                }
                // TODO arrange to display alt value if image can't be loaded
                // (or before it has loaded)
                return(new InlineUIContainer()
                {
                    Child = image
                });
            }
            else
            {
                return(null);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualFolderInitializer"/> class.
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="persister">The persister.</param>
 /// <param name="fs">The fs.</param>
 /// <param name="virtualNodes">The virtual nodes.</param>
 /// <param name="editConfig">The edit config.</param>
 public VirtualFolderInitializer(IHost host, IPersister persister, IFileSystem fs, VirtualNodeFactory virtualNodes, ConnectionMonitor monitor, EditSection editConfig, ImageSizeCache imageSizes, FolderNodeProvider nodeProvider)
 {
     this.host = host;
     this.persister = persister;
     this.virtualNodes = virtualNodes;
     this.monitor = monitor;
     this.folders = editConfig.UploadFolders;
     this.nodeProvider = nodeProvider;
 }
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected void Dispose(bool dispose)
 {
     if (dispose)
     {
         ImageSizeCache.Dispose();
         ResizedImageCache.Dispose();
         CroppedImageCache.Dispose();
         EnhancedImageCache.Dispose();
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="VirtualFolderInitializer"/> class.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="persister">The persister.</param>
        /// <param name="fs">The fs.</param>
        /// <param name="virtualNodes">The virtual nodes.</param>
        /// <param name="editConfig">The edit config.</param>
        public VirtualFolderInitializer(IHost host, IPersister persister, IFileSystem fs, VirtualNodeFactory virtualNodes, DatabaseStatusCache dbStatus, EditSection editConfig, ImageSizeCache imageSizes)
        {
            this.host = host;
            this.persister = persister;
            this.fs = fs;
            this.virtualNodes = virtualNodes;
            this.dbStatus = dbStatus;
            this.folders = editConfig.UploadFolders;

            nodeProvider = new FolderNodeProvider(fs, persister, imageSizes);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualFolderInitializer"/> class.
 /// </summary>
 /// <param name="host">The host.</param>
 /// <param name="persister">The persister.</param>
 /// <param name="fs">The fs.</param>
 /// <param name="virtualNodes">The virtual nodes.</param>
 /// <param name="editConfig">The edit config.</param>
 public VirtualFolderInitializer(IHost host, IPersister persister, IFileSystem fs, VirtualNodeFactory virtualNodes, ConnectionMonitor monitor, EditSection editConfig, ImageSizeCache imageSizes, FolderNodeProvider nodeProvider)
 {
     this.host         = host;
     this.persister    = persister;
     this.virtualNodes = virtualNodes;
     this.monitor      = monitor;
     this.folders      = editConfig.UploadFolders;
     this.nodeProvider = nodeProvider;
 }
 public FolderNodeProvider(IFileSystem fs, IPersister persister, ImageSizeCache imageSizes)
 {
     UploadFolderPaths = new FolderPair[0];
     this.fs = fs;
     this.persister = persister;
     this.imageSizes = imageSizes;
 }
Beispiel #10
0
 internal static Items.Directory New(DirectoryData dir, ContentItem parent, IFileSystem fs, ImageSizeCache sizes)
 {
     var node = new Directory(dir, parent);
     node.Set(fs);
     node.Set(sizes);
     return node;
 }
Beispiel #11
0
        /// <summary>
        /// Gets the size of the image.
        /// </summary>
        /// <param name="keyName">Name of the key.</param>
        /// <param name="imagePath">The image path.</param>
        /// <returns>ImageSize.</returns>
        private async Task <ImageSize> GetImageSize(string keyName, string imagePath)
        {
            // Now check the file system cache
            var fullCachePath = ImageSizeCache.GetResourcePath(keyName, ".txt");

            try
            {
                var result = File.ReadAllText(fullCachePath).Split('|').Select(i => double.Parse(i, UsCulture)).ToArray();

                return(new ImageSize {
                    Width = result[0], Height = result[1]
                });
            }
            catch (IOException)
            {
                // Cache file doesn't exist or is currently being written to
            }

            var semaphore = GetLock(fullCachePath);

            await semaphore.WaitAsync().ConfigureAwait(false);

            try
            {
                var result = File.ReadAllText(fullCachePath).Split('|').Select(i => double.Parse(i, UsCulture)).ToArray();

                return(new ImageSize {
                    Width = result[0], Height = result[1]
                });
            }
            catch (FileNotFoundException)
            {
                // Cache file doesn't exist no biggie
            }
            catch (DirectoryNotFoundException)
            {
                // Cache file doesn't exist no biggie
            }
            catch
            {
                semaphore.Release();

                throw;
            }

            try
            {
                var size = await ImageHeader.GetDimensions(imagePath, _logger).ConfigureAwait(false);

                var parentPath = Path.GetDirectoryName(fullCachePath);

                if (!Directory.Exists(parentPath))
                {
                    Directory.CreateDirectory(parentPath);
                }

                // Update the file system cache
                File.WriteAllText(fullCachePath, size.Width.ToString(UsCulture) + @"|" + size.Height.ToString(UsCulture));

                return(new ImageSize {
                    Width = size.Width, Height = size.Height
                });
            }
            finally
            {
                semaphore.Release();
            }
        }