/// <summary>
        /// Intended for a thread to collect the image and display it on the screen.
        ///
        /// Using as a thread routine is causing some issues, but there was no need to thread in the
        /// first place since the image has already been downloaded.
        /// </summary>
        /// <param name="unused"></param>
        private void ThreadCollectImage(object unused)
        {
            // Give up 30% of the height to the text boxes
            double height = this.ParentHeight * .75;
            double width  = this.ParentWidth * .75;

            double usable = Math.Min(height, width);

            try
            {
                this.ImagePanel.Dispatcher.Invoke(() =>
                {
                    System.IO.MemoryStream downloadFile = FileUtils.GetFileStream(this.Item.CurrentSource.DiskLocation);
                    this.ItemImage = ElementCreation.CreateUiImage(this.Item, usable, usable, downloadFile);
                    this.ImagePanel.Children.Add(this.ItemImage);
                });

                this.ImageSize.Dispatcher.Invoke(() =>
                {
                    this.ImageSize.Text = String.Format("{0}w x {1}h", this.Item.OriginalSize.Width, this.Item.OriginalSize.Height);
                });
            }
            catch (Exception ex)
            {
                // Eat the error as it's likely the file was removed from storage, but interestingly, only got this when I was
                // trying to thread this load.
            }
        }
Beispiel #2
0
        public void SerializeElementCreation()
        {
            var toCreate = new Semaphore()
            {
                Id = 1
            };
            var change = new ElementCreation(toCreate);
            var before = new ModelChangeCollection();

            before.Changes.Add(change);
            var after = Serialize(before, typeof(ElementCreation));

            // We can't use SerializeAndAssert, because ElementCreation.Equals
            // compares the Semaphores, which don't implement Equals.

            Assert.AreEqual(1, after.Changes.Count);
            Assert.IsInstanceOfType(after.Changes[0], typeof(ElementCreation));
            var afterChange = (ElementCreation)after.Changes[0];

            Assert.IsInstanceOfType(afterChange.Element, typeof(Semaphore));
            Assert.AreEqual(toCreate.Id, ((Semaphore)afterChange.Element).Id);
        }
        /// <summary>
        /// Generic move used for both next and previous.
        /// </summary>
        /// <param name="file"></param>
        private void MoveImage(SourceFile file)
        {
            this.CurrentSourceFile.CurrentSource = file;

            // Clear settings
            this.Clear();

            // Get the size of the parent
            double height = 450;
            double width  = 600;

            FrameworkElement fe = this.Parent as FrameworkElement;

            if (fe != null)
            {
                height = fe.ActualHeight;
                width  = fe.ActualWidth;

                // Have to account for height of other controls here
                height -= ((this.ImageLabel.ActualHeight + this.ImageSizeData.ActualHeight + this.NavigationPanel.ActualHeight));
            }

            // Get the stream on the file
            System.IO.MemoryStream downloadFile = FileUtils.GetFileStream(file.DiskLocation);

            // Call the image changed so that the base can update what it needs.
            this.ImageChanged?.Invoke(file);

            // Add the image to the stack panel for viewing and the image name
            this.ImageLabel.Text = String.Format("Current Image: {0}", file.Name);
            this.ImagePanel.Children.Add(ElementCreation.CreateUiImage(this.CurrentSourceFile, width, height, downloadFile));

            // UPdate the image information
            this.UpdateSizeInformation();

            // Update the navigation buttons
            this.ButtonNext.IsEnabled     = this.DataSource.CanMoveNext;
            this.ButtonPrevious.IsEnabled = this.DataSource.CanMovePrevious;
        }