Exemple #1
0
        private void btnSelectExecutable_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();

            dlg.DefaultExt  = "exe";
            dlg.Filter      = "Executable files (*.exe)|*.exe|All Files (*.*)|*.*";
            dlg.Multiselect = true;

            if (File.Exists(txtExecutable.Text))
            {
                dlg.FileName = txtExecutable.Text;
            }

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (dlg.FileNames.Count() == 1)
                {
                    txtExecutable.Text            = dlg.FileName;
                    chkNewBinary.IsChecked        = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled       = true;
                }
                else if (dlg.FileNames.Count() > 1)
                {
                    // Create a ZipPackage
                    string fn = Path.GetTempFileName();

                    ZipPackage pkg = (ZipPackage)ZipPackage.Open(fn, FileMode.Create);

                    string mainFile  = "";
                    int    exe_count = 0;
                    foreach (string f in dlg.FileNames)
                    {
                        if (f.EndsWith(".exe"))
                        {
                            mainFile = f;
                            exe_count++;
                        }
                    }

                    if (exe_count != 1)
                    {
                        SelectMainExe sme = new SelectMainExe();
                        foreach (string f in dlg.FileNames)
                        {
                            sme.lbFiles.Items.Add(f);
                        }
                        sme.Owner            = this;
                        Mouse.OverrideCursor = null;
                        if (sme.ShowDialog() == true)
                        {
                            mainFile = sme.selectedFile;
                        }
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    }

                    foreach (string f in dlg.FileNames)
                    {
                        Uri            uri = PackUriHelper.CreatePartUri(new Uri(Path.GetFileName(f), UriKind.Relative));
                        ZipPackagePart p   = (ZipPackagePart)pkg.CreatePart(uri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
                        CopyStream(new FileStream(f, FileMode.Open, FileAccess.Read), p.GetStream());
                        if (f == mainFile)
                        {
                            pkg.CreateRelationship(uri, TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/meta data/thumbnail");
                        }
                    }

                    pkg.Close();

                    txtExecutable.Text            = fn;
                    chkNewBinary.IsChecked        = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled       = true;
                }
            }

            Mouse.OverrideCursor = null;
        }
Exemple #2
0
        private void btnSelectExecutable_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();

            dlg.DefaultExt = "exe";
            dlg.Filter = "Executable files (*.exe)|*.exe|All Files (*.*)|*.*";
            dlg.Multiselect = true;

            if (File.Exists(txtExecutable.Text))
                dlg.FileName = txtExecutable.Text;

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (dlg.FileNames.Count() == 1)
                {
                    txtExecutable.Text = dlg.FileName;
                    chkNewBinary.IsChecked = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled = true;
                }
                else if (dlg.FileNames.Count() > 1)
                {
                    // Create a ZipPackage
                    string fn = Path.GetTempFileName();

                    ZipPackage pkg = (ZipPackage)ZipPackage.Open(fn, FileMode.Create);

                    string mainFile = "";
                    int exe_count = 0;
                    foreach (string f in dlg.FileNames)
                    {
                        if (f.EndsWith(".exe"))
                        {
                            mainFile = f;
                            exe_count++;
                        }
                    }

                    if (exe_count != 1)
                    {
                        SelectMainExe sme = new SelectMainExe();
                        foreach (string f in dlg.FileNames)
                            sme.lbFiles.Items.Add(f);
                        sme.Owner = this;
                        Mouse.OverrideCursor = null;
                        if (sme.ShowDialog() == true)
                            mainFile = sme.selectedFile;
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    }

                    foreach (string f in dlg.FileNames)
                    {
                        Uri uri = PackUriHelper.CreatePartUri(new Uri(Path.GetFileName(f), UriKind.Relative));
                        ZipPackagePart p = (ZipPackagePart)pkg.CreatePart(uri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
                        CopyStream(new FileStream(f, FileMode.Open, FileAccess.Read), p.GetStream());
                        if (f == mainFile)
                            pkg.CreateRelationship(uri, TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/meta data/thumbnail");
                    }

                    pkg.Close();

                    txtExecutable.Text = fn;
                    chkNewBinary.IsChecked = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled = true;
                }
            }

            Mouse.OverrideCursor = null;
        }
        private void btnSelectExecutable_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();

            dlg.DefaultExt  = "exe";
            dlg.Filter      = "Executable files (*.exe;*.dll)|*.exe;*.dll|All Files (*.*)|*.*";
            dlg.Multiselect = true;

            if (File.Exists(txtExecutable.Text))
            {
                dlg.FileName = txtExecutable.Text;
            }

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (dlg.FileNames.Count() == 1)
                {
                    txtExecutable.Text            = dlg.FileName;
                    chkNewBinary.IsChecked        = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled       = true;
                }
                else if (dlg.FileNames.Count() > 1)
                {
                    string mainFile  = "";
                    int    exe_count = 0;
                    foreach (string f in dlg.FileNames)
                    {
                        if (f.EndsWith(".exe"))
                        {
                            mainFile = f;
                            exe_count++;
                        }
                    }

                    if (exe_count != 1)
                    {
                        SelectMainExe sme = new SelectMainExe();
                        foreach (string f in dlg.FileNames)
                        {
                            sme.lbFiles.Items.Add(f);
                        }
                        sme.Owner            = this;
                        Mouse.OverrideCursor = null;
                        if (sme.ShowDialog() == true)
                        {
                            mainFile = sme.selectedFile;
                        }
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    }

                    string fn = Path.GetTempFileName();
                    SubmissionLib.SubmissionWorker.mkZip(fn, dlg.FileNames, mainFile);

                    txtExecutable.Text            = fn;
                    chkNewBinary.IsChecked        = true;
                    chkMostRecentBinary.IsChecked = false;
                    txtExecutable.IsEnabled       = true;
                }
            }

            Mouse.OverrideCursor = null;
        }
Exemple #4
0
        private void showUpdateBinaryCommand(object target, ExecutedRoutedEventArgs e)
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();

            dlg.DefaultExt = "exe";
            dlg.Filter = "Executable files (*.exe)|*.exe|All Files (*.*)|*.*";
            dlg.Multiselect = true;

            string exe = null;

            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (dlg.FileNames.Count() == 1)
                {
                    exe = dlg.FileName;
                }
                else if (dlg.FileNames.Count() > 1)
                {
                    // Create a ZipPackage
                    string fn = System.IO.Path.GetTempFileName();

                    ZipPackage pkg = (ZipPackage)ZipPackage.Open(fn, FileMode.Create);

                    string mainFile = "";
                    int exe_count = 0;
                    foreach (string f in dlg.FileNames)
                    {
                        if (f.EndsWith(".exe"))
                        {
                            mainFile = f;
                            exe_count++;
                        }
                    }

                    if (exe_count != 1)
                    {
                        SelectMainExe sme = new SelectMainExe();
                        foreach (string f in dlg.FileNames)
                            sme.lbFiles.Items.Add(f);
                        sme.Owner = this;
                        Mouse.OverrideCursor = null;
                        if (sme.ShowDialog() == true)
                            mainFile = sme.selectedFile;
                        Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                    }

                    foreach (string f in dlg.FileNames)
                    {
                        Uri uri = PackUriHelper.CreatePartUri(new Uri(System.IO.Path.GetFileName(f), UriKind.Relative));
                        ZipPackagePart p = (ZipPackagePart)pkg.CreatePart(uri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Maximum);
                        CopyStream(new FileStream(f, FileMode.Open, FileAccess.Read), p.GetStream());
                        if (f == mainFile)
                            pkg.CreateRelationship(uri, TargetMode.Internal, "http://schemas.openxmlformats.org/package/2006/relationships/meta data/thumbnail");
                    }

                    pkg.Close();

                    exe = fn;
                }
            }

            if (exe != null)
            {

                WindowInteropHelper helper = new WindowInteropHelper(this);
                SubmissionWorker w = new SubmissionWorker(helper.Handle, 0);
                bool haveBinID = false;
                int binID = 0;
                w.UploadBinary(txtDatabase.Text, exe, ref haveBinID, ref binID);

                if (!haveBinID || binID == 0)
                    System.Windows.MessageBox.Show("Error uploading binary.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                else
                {
                    foreach (DataRowView j in dataGrid.SelectedItems)
                    {
                        SqlCommand cmd = new SqlCommand("UPDATE Experiments SET Binary=" + binID + ";", sql);
                        cmd.CommandTimeout = 0;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            else
                System.Windows.MessageBox.Show("No binary selected; did not update database.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);

            Mouse.OverrideCursor = null;
        }