private void AddFile(string fileName, ImageType type)
        {
            byte[] data;
            try
            {
                data = File.ReadAllBytes(fileName);
            }
            catch
            {
                Dialogs.Error("Unable to read file!");
                this.comboAddItem.SelectedIndex = 0;
                return;
            }

            Image image = new Image()
            {
                Type      = type,
                Extension = Path.GetExtension(fileName),
                MimeType  = MimeHelper.GetMimeTypeForExtension(Path.GetExtension(fileName))
            };

            if (this.AddImage(image, data))
            {
                this.Release.Images.Add(image);
            }
        }
Ejemplo n.º 2
0
        private void ExportImage(XmlWriter writer, Image image)
        {
            writer.WriteStartElement(Keys.Image);

            writer.WriteAttributeString(Keys.Type, image.Type.ToString());
            if (image.MimeType == "application/unknown")
            {
                image.MimeType = MimeHelper.GetMimeTypeForExtension(image.Extension);
            }
            writer.WriteAttributeString(Keys.MimeType, image.MimeType);
            writer.WriteAttributeString(Keys.Extension, image.Extension);
            writer.WriteAttributeString(Keys.Description, image.Description);
            writer.WriteAttributeString(Keys.IsMain, image.IsMain.ToString());

            byte[] imageBytes = this.collectionManager.ImageHandler.LoadImage(image);
            writer.WriteBase64(imageBytes, 0, imageBytes.Length);

            writer.WriteEndElement();
        }
        private void btnStudio_Click(object sender, RoutedEventArgs e)
        {
            ImageStudioImportWindow studioWindow = new ImageStudioImportWindow();

            if (studioWindow.ShowDialog(Window.GetWindow(this)) == true)
            {
                foreach (OutputImage outputImage in studioWindow.OutputImages)
                {
                    Image image = new Image()
                    {
                        Extension = outputImage.Extension,
                        MimeType  = MimeHelper.GetMimeTypeForExtension(outputImage.Extension)
                    };

                    if (this.AddImage(image, outputImage.Bytes))
                    {
                        this.Release.Images.Add(image);
                    }
                }
            }
        }
        private void UpdateImageForRelease(ReleaseData releaseData, ImageViewModel selectedItem)
        {
            string        extension = Path.GetExtension(selectedItem.DiscogsImage.Uri);
            string        mimeType  = MimeHelper.GetMimeTypeForExtension(extension);
            DatabaseImage image     = new DatabaseImage()
            {
                Description = "Auto import from Discogs",
                Extension   = extension,
                IsMain      = true,
                MimeType    = mimeType,
                Type        = ImageType.FrontCover
            };

            releaseData.Release.Images.Add(image);
            releaseData.Release.DateModified = DateTime.Now;
            this.CollectionManager.ImageHandler.StoreImage(image, selectedItem.Data);
            ThumbnailGenerator.UpdateReleaseThumbnail(releaseData.Release, this.CollectionManager.ImageHandler);
            this.CollectionManager.Save(releaseData.Release);

            this.CollectionManager.Operations.WriteTags(releaseData.Release);
        }