private void DownloadMessageCommandExecute()
        {
            string queueName = (FolderTree.SelectedItem as TreeItem).Text;

            bool abort = false;
            bool proceed = false;

            System.Windows.Forms.FolderBrowserDialog dlg = new System.Windows.Forms.FolderBrowserDialog();
            dlg.Description = "Choose a folder location to download messages to.";
            if (DownloadDirectory != null)
            {
                dlg.SelectedPath = DownloadDirectory;
            }

            HwndSource source = PresentationSource.FromVisual(MainWindow.Window) as HwndSource;
            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);

            System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                Cursor = Cursors.Wait;

                DownloadDirectory = dlg.SelectedPath;

                try
                {
                    string folder = dlg.SelectedPath;
                    string subfolder;
                    string messagename;
                    string filename = String.Empty;
                    bool firstOverwrite = true;
                    bool overwriteAll = false;
                    List<CloudQueueMessage> messageList = new List<CloudQueueMessage>();
                    List<string> filenameList = new List<string>();

                    foreach (CloudQueueMessage message in MessageList.SelectedItems)
                    {
                        proceed = true;

                        subfolder = folder;
                        filename = folder;
                        if (!filename.EndsWith("\\"))
                        {
                            filename += "\\";
                        }
                        messagename = message.Id;
                        if (messagename.StartsWith("_"))
                        {
                            messagename = messagename.Substring(1);
                        }
                        filename += messagename + ".xml";

                        if (File.Exists(filename))
                        {
                            if (firstOverwrite)
                            {
                                firstOverwrite = false;
                                switch (MessageBox.Show("One or more local files will be overwritten by this action. Do you want to overwrite existing files?\r\n\r\n" +
                                   "Press Yes to overwrite all files, No to prompt file-by-file, or Cancel to stop downloading.",
                                   "Overwrite Local Files?", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
                                {
                                    case MessageBoxResult.Yes:
                                        overwriteAll = true;
                                        break;
                                    case MessageBoxResult.No:
                                        overwriteAll = false;
                                        break;
                                    case MessageBoxResult.Cancel:
                                        abort = true;
                                        break;
                                }
                            }

                            if (!abort)
                            {
                                if (overwriteAll)
                                {
                                    proceed = true;
                                }
                                else
                                {
                                    switch (MessageBox.Show("File " + filename + " exists, do you want to overwrite it?\r\n\r\n" +
                                        "Press Yes to overwrite, No to skip, or Cancel to stop downloading.",
                                        "Confirm Local File Overwrite", MessageBoxButton.YesNoCancel, MessageBoxImage.Question))
                                    {
                                        case MessageBoxResult.Yes:
                                            proceed = true;
                                            break;
                                        case MessageBoxResult.No:
                                            proceed = false;
                                            break;
                                        case MessageBoxResult.Cancel:
                                            proceed = false;
                                            abort = true;
                                            break;
                                    }
                                }
                            }
                        }

                        if (proceed)
                        {
                            messageList.Add(message);
                            filenameList.Add(filename);
                        }

                        if (abort) break;
                    }

                    if (!abort && messageList.Count > 0)
                    {
                        ViewModel.DownloadMessages(queueName, messageList.ToArray(), filenameList.ToArray());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The message download failed due to an error.\r\n\r\n" + ex.ToString(),
                        "Update Failed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }

                Cursor = Cursors.Arrow;
            }
        }
        private void Browse_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dlg2 = new System.Windows.Forms.OpenFileDialog();
            dlg2.Title = "Choose Upload File Name";
            if (FormatCSV.IsChecked.Value)
            {
                dlg2.Filter = "Comma-separated Value Files (*.csv)|*.csv|Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                dlg2.FileName = TableName.Text + ".csv";
            }
            else if (FormatPlainXML.IsChecked.Value)
            {
                dlg2.Filter = "XML Files (*.xml)|*.xml|Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                dlg2.FileName = TableName.Text + ".xml";
            }
            else if (FormatAtomPub.IsChecked.Value)
            {
                dlg2.Filter = "XML Files (*.xml)|*.xml|Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
                dlg2.FileName = TableName.Text + ".xml";
            }

            HwndSource source = PresentationSource.FromVisual(MainWindow.Window) as HwndSource;
            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);

            System.Windows.Forms.DialogResult result = dlg2.ShowDialog(win);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                FileName.Text = dlg2.FileName;
            }
        }
        private void UploadMessageCommandExecute()
        {
            if (FolderTree.SelectedItem == null)
            {
                MessageBox.Show("To upload a message, select the queue to upload to then click the Upload Message button.",
                    "Selection Required", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            string queueName = (FolderTree.SelectedItem as TreeItem).Text;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Title = "Upload Messages(s)";
            dlg.Multiselect = true;

            HwndSource source = PresentationSource.FromVisual(MainWindow.Window) as HwndSource;
            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);

            System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                Cursor = Cursors.Wait;

                try
                {
                    ViewModel.UploadMessages(queueName, dlg.FileNames);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The message upload failed due to an error.\r\n\r\n" + ex.ToString(),
                        "Update Failed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }

                Cursor = Cursors.Arrow;
            }
        }
        private void UploadVideo_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Title = "Upload Video File to Blob";
            dlg.InitialDirectory = VideoDirectory;

            HwndSource source = PresentationSource.FromVisual(MainWindow.Window) as HwndSource;
            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);

            System.Windows.Forms.DialogResult result = dlg.ShowDialog(win);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                Cursor = Cursors.Wait;

                try
                {
                    ViewModel.SaveVideoFile(dlg.FileName);
                    MessageBox.Show("The blob has been updated", "Update Successful", MessageBoxButton.OK);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The blob update failed due to an error.\r\n\r\n" + ex.ToString(),
                        "Update Failed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }

                Cursor = Cursors.Arrow;
            }
        }