Example #1
0
        private void ExportAdditionalFile(XmlWriter writer, ReleaseAdditionalFile additionalFile)
        {
            writer.WriteStartElement(Keys.AdditionalFile);

            writer.WriteAttributeString(Keys.Type, additionalFile.Type.ToString());
            writer.WriteAttributeString(Keys.Description, additionalFile.Description);
            writer.WriteAttributeString(Keys.OriginalFilename, additionalFile.OriginalFilename);
            writer.WriteBase64(additionalFile.File, 0, additionalFile.File.Length);

            writer.WriteEndElement();
        }
        private void btnSave_Clicked(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.FileName = Path.GetFileName(this.AssociatedFile.OriginalFilename);
            dialog.Filter   = ReleaseAdditionalFile.GetFilterForType(this.AssociatedFile.Type);
            if (dialog.ShowDialog() == true)
            {
                File.WriteAllBytes(dialog.FileName, this.FileBytes);
            }
        }
Example #3
0
        private void ReadAdditionalFiles(XmlReader reader, Release release)
        {
            reader.AssertElementStart(Keys.AdditionalFiles);

            if (reader.IsEmptyElement)
            {
                return;
            }

            bool skipRead = false;

            while (skipRead || reader.Read())
            {
                skipRead = false;

                if (reader.IsElementEnd(Keys.AdditionalFiles))
                {
                    break;
                }

                reader.AssertElementStart(Keys.AdditionalFile);
                ReleaseAdditionalFile file = new ReleaseAdditionalFile()
                {
                    Type             = Utility.ParseEnum <ReleaseAdditionalFileType>(reader.GetAttributeOrNull(Keys.Type)),
                    Description      = reader.GetAttributeOrNull(Keys.Description),
                    OriginalFilename = reader.GetAttributeOrNull(Keys.OriginalFilename)
                };

                byte[] resultBuffer = new byte[0];
                int    read;
                while ((read = reader.ReadElementContentAsBase64(this.readBuffer, 0, this.readBuffer.Length)) > 0)
                {
                    byte[] newResultBuffer = new byte[resultBuffer.Length + read];
                    Array.Copy(resultBuffer, newResultBuffer, resultBuffer.Length);
                    Array.Copy(this.readBuffer, 0, newResultBuffer, resultBuffer.Length, read);
                    resultBuffer = newResultBuffer;
                }
                file.File = resultBuffer;

                release.AdditionalFiles.Add(file);

                skipRead = true;
            }
        }
        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                return;
            }
            string[] droppedItems = (string[])e.Data.GetData(DataFormats.FileDrop);
            Array.Sort(droppedItems);
            foreach (string file in droppedItems)
            {
                if (!File.Exists(file))
                {
                    break;
                }

                ReleaseAdditionalFileType type = ReleaseAdditionalFile.GetTypeForExtension(Path.GetExtension(file));
                this.AddFile(file, type);
            }
        }
        private void comboAddItem_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (this.comboAddItem.SelectedItem is ReleaseAdditionalFileType)
            {
                ReleaseAdditionalFileType type = (ReleaseAdditionalFileType)this.comboAddItem.SelectedItem;

                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Multiselect = true;
                dialog.Filter      = ReleaseAdditionalFile.GetFilterForType(type);
                if (dialog.ShowDialog() == true)
                {
                    foreach (string file in dialog.FileNames)
                    {
                        this.AddFile(file, type);
                    }
                }

                this.comboAddItem.SelectedIndex = 0;
            }
        }
        private void AddItem(ReleaseAdditionalFile file)
        {
            this.grid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength()
            });

            AdditionalFileEditor editor = CreateFileEditor();

            editor.FileType = file.Type;
            editor.SetFile(file.OriginalFilename, file.File);
            editor.FileDescription = file.Description;

            editor.DeleteClicked += new EventHandler(file_DeleteClicked);
            editor.AssociatedFile = file;
            editor.DataChanged   += new EventHandler(editor_DataChanged);
            items.Add(editor);
            this.grid.Children.Add(editor);

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

            ReleaseAdditionalFile file = new ReleaseAdditionalFile()
            {
                Type             = type,
                File             = data,
                OriginalFilename = fileName
            };

            this.Release.AdditionalFiles.Add(file);
            this.AddItem(file);
        }