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();
        }
        public override bool Equals(object obj)
        {
            ReleaseAdditionalFile file = obj as ReleaseAdditionalFile;

            if (file == null)
            {
                return(false);
            }
            return
                (file.Type == this.Type &&
                 file.OriginalFilename == this.OriginalFilename &&
                 file.Description == this.Description &&
                 Enumerable.SequenceEqual(file.File, this.File));
        }
        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);
        }
        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;
            }
        }