public void Initialize()
 {
     myPremiumXML = new EncodingPremiumXML();
 }
        /// <summary>
        /// 
        /// </summary>
        private async void DoEditFile()
        {
            var SelectedAssetFiles = ReturnSelectedAssetFiles();

            if (SelectedAssetFiles.Count == 1 && SelectedAssetFiles.FirstOrDefault() != null)
            {
                IAssetFile assetFileToEdit = SelectedAssetFiles.FirstOrDefault();

                if (assetFileToEdit.ContentFileSize > 500 * 1024)
                {
                    MessageBox.Show("File is to big to edit it online.");
                    return;
                }

                try
                {
                    progressBarUpload.Maximum = 100;
                    progressBarUpload.Visible = true;
                    string tempPath = System.IO.Path.GetTempPath();
                    string filePath = Path.Combine(tempPath, assetFileToEdit.Name);

                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    await Task.Factory.StartNew(() => ProcessDownloadFileToAsset(assetFileToEdit, filePath));

                    progressBarUpload.Visible = false;

                    StreamReader streamReader = new StreamReader(filePath);
                    Encoding fileEncoding = streamReader.CurrentEncoding;
                    string datastring = streamReader.ReadToEnd();
                    streamReader.Close();

                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }

                    var editform = new EncodingPremiumXML(string.Format("Online edit of '{0}'", assetFileToEdit.Name), datastring, true);
                    if (editform.Display() == DialogResult.OK)
                    { // OK
                       
                        StreamWriter outfile = new StreamWriter(filePath, false, fileEncoding);

                        outfile.Write(editform.PremiumXML);
                        outfile.Close();

                        string assetFileName = assetFileToEdit.Name;
                        bool assetFilePrimary = assetFileToEdit.IsPrimary;
                        assetFileToEdit.Delete();

                        progressBarUpload.Visible = true;

                        await Task.Factory.StartNew(() => ProcessUploadFileToAsset(Path.GetFileName(filePath), filePath, myAsset));

                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }

                        if (assetFilePrimary)
                        {
                            AssetInfo.SetFileAsPrimary(myAsset, assetFileName);
                        }
                        // Refresh the asset.
                        myAsset = Mainform._context.Assets.Where(a => a.Id == myAsset.Id).FirstOrDefault();
                        progressBarUpload.Visible = false;

                        ListAssetFiles();
                    }
                }

                catch
                {
                    MessageBox.Show("Error when accessing/editing asset file.");
                }

            }
        }
 public void Initialize()
 {
     myPremiumXML = new EncodingPremiumXML();
 }