public void Run(string[] args) { SubmissionWorker w = new SubmissionWorker(IntPtr.Zero, 0); w.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged); w.WorkerReportsProgress = true; w.WorkerSupportsCancellation = false; Configuration config; if (args.Count() == 1) { if (args[0] == "-h" || args[0] == "--help" || args[0] == "/?") { Console.WriteLine("Usage: ClusterSubmit [config-file]"); return; } else config = new Configuration(args[0]); } else config = new Configuration("config.xml"); string executable = findBinary(config.z3_drop_dir, config.z3_release_dir, config.z3_exe); if (executable == "") { Console.WriteLine(now() + ": Z3 not found."); return; } else if (File.Exists("last_binary")) { FileStream lf = File.OpenRead("last_binary"); StreamReader sr = new StreamReader(lf); long last = Convert.ToInt64(sr.ReadLine()); if (last >= File.GetLastWriteTime(executable).ToFileTimeUtc()) { Console.WriteLine(now() + ": No new binary."); return; } sr.Close(); lf.Close(); } bool haveBinId = false; int binId = 0; try { string bestCluster = SubmissionWorker.FindCluster(config.cluster, config.alternativeClusters); Console.WriteLine(now() + ": Submitting job to " + bestCluster + " with the following binary: " + executable); w.UploadBinary(config.db, executable, ref haveBinId, ref binId); string sExecutor = ""; int jid = w.SetupExperiment(config.db, config.category, config.sharedDir, config.memout, config.timeout, config.executor, config.parameters, bestCluster, config.nodegroup, config.locality, config.minResources, config.maxResources, config.username, config.priority, config.extension, config.note, ref haveBinId, ref binId, ref sExecutor); w.SubmitHPCJob(config.db, true, jid, config.cluster, config.nodegroup, config.priority, config.locality, config.minResources, config.maxResources, config.sharedDir, sExecutor); saveBinaryDate(executable); uint retries = 0; if (File.Exists(config.fuzzer_target)) { retry: if (File.GetLastWriteTime(executable) > File.GetLastWriteTime(config.fuzzer_target)) { try { File.Copy(executable, config.fuzzer_target, true); } catch (Exception ex) { retries++; if (retries < config.fuzzer_max_retries) goto retry; else throw ex; } } } } catch (Exception ex) { Console.WriteLine(now() + ": Exception caught: " + ex.Message); } }
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; }