public DataBackupWindow(string databasename) { // TODO: Complete member initialization this.databasename = databasename; InitializeComponent(); db = new DataBackup(); }
public async Task <IActionResult> GetTaskData(string id) { DataBackup db = new DataBackup(); string check = db.DataCheck(id, this._context); if (check.Length > 0) { return(BadRequest(check)); } try { string fileName = id + "_backup.zip"; byte[] dataBytes = db.GetTaskData(id, this._context); if (dataBytes == null) { return(View()); } else if (dataBytes.Length == 0) { return(View()); } var mimeType = "application/...."; return(new FileContentResult(dataBytes, mimeType) { FileDownloadName = fileName }); } catch (Exception ex) { Log.Warning(ex, "Error downloading task data."); return(BadRequest("Invalid data request.")); } }
public void DataCheckTest() { this._context = this.InitContext().Result; TaskServiceTest tst = new TaskServiceTest(); tst.FileSetup(); Workflow newWorkflow = new Workflow() { id = "test12345678", inputFolder = "app_files\\TestFiles\\Input", outputFolder = "app_files\\TestFiles\\Output", active = true, name = "workflow_test123456", processor = "masslynx", interval = 10, message = "" }; this._context.Workflows.Add(newWorkflow); LimsServer.Entities.Task tsk = new LimsServer.Entities.Task() { id = "001", workflowID = "test12345678", start = DateTime.Now.AddMinutes(5), taskID = "1234567890", status = "SCHEDULED" }; LimsServer.Entities.Task tsk2 = new LimsServer.Entities.Task() { id = "002", workflowID = "test12345678", start = DateTime.Now.AddMinutes(5), taskID = "1234567890", status = "SCHEDULED" }; this._context.Tasks.Add(tsk); this._context.Tasks.Add(tsk2); this._context.SaveChanges(); TaskService ts = new TaskService(this._context); var tsResult = ts.RunTask(tsk.id); DataBackup db = new DataBackup(); var results = db.DataCheck("000", this._context); Assert.Contains("No task ID found", results); var results2 = db.DataCheck(tsk.id, this._context); Assert.Equal("", ""); var results3 = db.DataCheck(tsk2.id, this._context); Assert.Contains("Backup expired.", results3); }
public void CleanupTest() { this._context = this.InitContext().Result; DataBackup db = new DataBackup(); var result = db.Cleanup(); Assert.True(result); }
public void SearchUserNameTest() { DataBackup dbp = new DataBackup(); var excepted = UserNames; var actual = dbp.SearchUserName(); Assert.AreEqual(excepted[0], actual[0]); Assert.AreEqual(excepted[1], actual[1]); Assert.AreEqual(excepted[2], actual[2]); Assert.AreEqual(excepted[3], actual[3]); }
private void button_Export_Click(object sender, EventArgs e) { DataBaseInformation dbInfo = new DataBaseInformation { DbType = textBox_DbType.Text, UID = textBox_UID.Text, DSN = textBox_DSN.Text }; DataBackup bk = new DataBackup(dbInfo); Process p = new Process(); bk.Export(); }
public void ScheduleRestore([NotNull] DataBackup dataBackup) { if (dataBackup == null) { throw new ArgumentNullException(nameof(dataBackup)); } var dialogResult = MessageBox.Show( "Selected backup will be restored after Wurm Assistant is restarted. Current data will be overwritten.", "Confirmation needed", MessageBoxButton.OKCancel); if (dialogResult == MessageBoxResult.Cancel || dialogResult == MessageBoxResult.None) { return; } userSettings.RestoreBackupRequested = true; userSettings.RestoreBackupName = dataBackup.BackupName; userSettings.Save(); RefreshBackupSystemStatus(); }
/// <summary> /// Get all task IDs for the specified workflow, get the input bytes and run a MD5 hash, compare to the inputFile /// </summary> /// <param name="inputFilePath"></param> /// <param name="workflowID"></param> /// <returns></returns> protected async System.Threading.Tasks.Task <bool> InputFileCheck(string inputFilePath, string workflowID) { var tasks = await _context.Tasks.Where(t => t.workflowID == workflowID && t.status == "COMPLETED").ToListAsync(); bool match = false; if (tasks.Count >= 1) { byte[] inputFile = File.ReadAllBytes(inputFilePath); byte[] inputData = MD5.Create().ComputeHash(inputFile); StringBuilder ib = new StringBuilder(); for (int i = 0; i < inputData.Length; i++) { ib.Append(inputData[i].ToString("x2")); } string inputHash = ib.ToString(); Log.Debug("Input file compare. WorkflowID: {0}, InputFile: {1}, InputFile Hash: {2}", workflowID, inputFilePath, inputHash); DataBackup db = new DataBackup(); foreach (Task t in tasks) { Dictionary <string, byte[]> previousTask = db.GetData(t.id); byte[] previousData = MD5.Create().ComputeHash(previousTask["input"]); StringBuilder jb = new StringBuilder(); for (int j = 0; j < previousData.Length; j++) { jb.Append(previousData[j].ToString("x2")); } string previousHash = jb.ToString(); Log.Debug("Input file compare. WorkflowID: {0}, Previous Input Hash: {1}", workflowID, previousHash); if (StringComparer.OrdinalIgnoreCase.Compare(inputHash, previousHash) == 0) { match = true; } } } return(match); }
private async void StartBackup(Regions regions, string _user, Person oPerson, string _TargetPath, CancellationToken token) { try { string source = string.Empty; if (!string.IsNullOrWhiteSpace(oPerson.CustomHomeDirectory)) { source = oPerson.CustomHomeDirectory; } mtlstbxBackup.Items.Clear(); if (settings.SharedDevices) { ISharedResourceHelper regVal = new SharedResourceHelper(); regVal.OnNetworkSharesBackupStart += RegVal_OnNetworkSharesBackupStart; regVal.OnNetworkSharesBackupCompleted += RegVal_OnNetworkSharesBackupCompleted; regVal.OnNetworkPrintersBackupStart += RegVal_OnNetworkPrintersBackupStart; regVal.OnNetworkPrintersBackupCompleted += RegVal_OnNetworkPrintersBackupCompleted; regVal.OnNetworkAtomicChange += RegVal_OnNetworkAtomicChange; regVal.OnPrinterAtomicChange += RegVal_OnPrinterAtomicChange; CurrentOperationModel = await regVal.GetResourcesBackupAsync(_user, custompaths, _TargetPath, token); if (custompaths.Count > 0) { CurrentOperationModel.CustomPaths = new System.Collections.Generic.List <string>(); CurrentOperationModel.CustomPaths.AddRange(custompaths.ToList()); } } IDataBackup dbval = new DataBackup(); dbval.OnBackupStart += Dbval_OnBackupStart; dbval.OnCalculationStart += Dbval_OnCalculationStart; dbval.OnBackupComplete += Dbval_OnBackupComplete; dbval.OnAtomicCurrentCopyStatus += Dbval_OnAtomicCurrentCopyStatus; dbval.OnAtomicTotalCounts += Dbval_OnAtomicTotalCounts; //ASYNC METHOD switch (settings.BROperationType) { case "Auto": settings.ResourceUtilization = settings.ResourceUtilization; break; case "Full": switch (settings.ResourceUtilization) { case 4: settings.ResourceUtilization = 1; break; case 5: settings.ResourceUtilization = 2; break; case 6: settings.ResourceUtilization = 3; break; default: settings.ResourceUtilization = settings.ResourceUtilization; break; } break; case "Difference": switch (settings.ResourceUtilization) { case 1: settings.ResourceUtilization = 4; break; case 2: settings.ResourceUtilization = 5; break; case 3: settings.ResourceUtilization = 6; break; default: settings.ResourceUtilization = settings.ResourceUtilization; break; } break; } switch (settings.ResourceUtilization) { case 1: await dbval.BackupAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; case 2: await dbval.BackupPartialParallelAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; case 3: await dbval.BackupParallelAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; case 4: await dbval.DifferenceBackupAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; case 5: await dbval.DifferenceBackupPartialParallelAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; case 6: await dbval.DifferenceBackupParallelAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; default: await dbval.BackupAsync(regions, _TargetPath, source, _user, settings.LogOptions, settings.LogType, LogOperation.BackupOperation, token); break; } } catch (OperationCanceledException OEx) { InitiatlizeUICancelled(OEx.Message); } catch (Exception Ex) { InitializeUIException(Ex.Message); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.Use(async(HttpContext context, Func <Task> next) => { await next.Invoke(); if (context.Response.StatusCode == 404) { context.Request.Path = new PathString("/index.html"); await next.Invoke(); } }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } //app.UseStatusCodePages(); app.UseSerilogRequestLogging(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "LIMS API v1"); }); app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions { OnPrepareResponse = context => { if (context.File.Name == "index.html") { context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store"); context.Context.Response.Headers.Add("Expires", "-1"); } } }); // global cors policy app.UseCors(x => x .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); app.UseAuthentication(); //app.UseMvc(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.UseHangfireServer(additionalProcesses: new[] { new ProcessMonitor(checkInterval: TimeSpan.FromSeconds(30)) }); app.UseHangfireDashboard("/dashboard", new DashboardOptions { Authorization = new [] { new HangfireAuthorizationFilter() }, }); DataBackup db = new DataBackup(); db.ScheduleCleanup(); }
public async System.Threading.Tasks.Task RunTask(string id) { var task = await _context.Tasks.SingleAsync(t => t.id == id); Log.Information("Executing Task. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}", task.workflowID, task.id, task.taskID); // Step 1: If status!="SCHEDULED" cancel task if (!task.status.Equals("SCHEDULED")) { Log.Information("Task Cancelled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Current Status: {3}, Message: {4}", task.workflowID, task.id, task.taskID, task.status, "Task status is not marked as schedulled."); await this.UpdateStatus(task.id, "CANCELLED", "Task status was set to: " + task.status); return; } // Step 2: Change status to "STARTING" await this.UpdateStatus(task.id, "STARTING", ""); var workflow = await _context.Workflows.Where(w => w.id == task.workflowID).FirstOrDefaultAsync(); if (workflow == null) { Log.Information("Task Cancelled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Message: {3}", task.workflowID, task.id, task.taskID, "Unable to find Workflow for the Task."); await this.UpdateStatus(task.id, "CANCELLED", "Error attempting to get workflow of this task. Workflow ID: " + task.workflowID); return; } // Step 3: Check source directory for files List <string> files = new List <string>(); string dirFileMessage = ""; if (new DirectoryInfo(@workflow.inputFolder).Exists) { files = Directory.GetFiles(@workflow.inputFolder).ToList(); } else { dirFileMessage = String.Format("Input directory {0} not found", workflow.inputFolder); Log.Information(dirFileMessage); } // Step 4: If directory or files do not exist reschedule task if (files.Count == 0) { dirFileMessage = (dirFileMessage.Length > 0) ? dirFileMessage : String.Format("No files found in directory: {0}", workflow.inputFolder); await this.UpdateStatus(task.id, "SCHEDULED", dirFileMessage); var newSchedule = new Hangfire.States.ScheduledState(TimeSpan.FromMinutes(workflow.interval)); task.start = DateTime.Now.AddMinutes(workflow.interval); await _context.SaveChangesAsync(); try { BackgroundJobClient backgroundClient = new BackgroundJobClient(); backgroundClient.ChangeState(task.taskID, newSchedule); Log.Information("Task Rescheduled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Input Directory: {3}, Message: {4}", task.workflowID, task.id, task.taskID, workflow.inputFolder, "No files found in input directory."); } catch (Exception) { Log.Warning("Error attempting to reschedule Hangfire job. Workflow ID: {0}, task ID: {1}", task.workflowID, task.id); } return; } // Step 5: If file does exist, update task inputFile then compare against previous Tasks. task.inputFile = files.First(); task.status = "PROCESSING"; await _context.SaveChangesAsync(); bool alreadyCompleted = await this.InputFileCheck(task.inputFile, task.workflowID); if (alreadyCompleted) { Log.Information("Hash input file match for WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Input File: {3}, Message: {4}", task.workflowID, task.id, task.taskID, task.inputFile, "Rerunning task after removing file."); try { File.Delete(task.inputFile); Log.Information("Hash input file match successfully deleted. WorkflowID: {0}, ID: {1}, Input File: {2}", task.workflowID, task.id, task.inputFile); } catch (FileNotFoundException ex) { Log.Warning("Error unable to delete input file after hash file match with previous input file. Workflow ID: {0}, ID: {1}", task.workflowID, task.id); } string statusMessage = String.Format("Input file: {0} matches previously processed input file", task.inputFile); await this.UpdateStatus(task.id, "SCHEDULED", statusMessage); await this.RunTask(task.id); return; } ProcessorManager pm = new ProcessorManager(); string config = "./app_files/processors"; ProcessorDTO processor = pm.GetProcessors(config).Find(p => p.Name.ToLower() == workflow.processor.ToLower()); if (processor == null) { Log.Information("Task Cancelled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Message: {3}, Processor: {4}", task.workflowID, task.id, task.taskID, "Unable to find Processor for the Task.", workflow.processor); await this.UpdateStatus(task.id, "CANCELLED", "Error, invalid processor name. Name: " + workflow.processor); return; } try { // Step 6: Run processor on source file if (!new DirectoryInfo(@workflow.outputFolder).Exists) { Directory.CreateDirectory(@workflow.outputFolder); } } catch (UnauthorizedAccessException ex) { Log.Warning("Task unable to create output directory, unauthorized access exception. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Output Directory: {3}", task.workflowID, task.id, task.taskID, workflow.outputFolder); } Dictionary <string, ResponseMessage> outputs = new Dictionary <string, ResponseMessage>(); string file = task.inputFile; DataTableResponseMessage result = pm.ExecuteProcessor(processor.Path, processor.Name, file); GC.Collect(); GC.WaitForPendingFinalizers(); if (result.ErrorMessage == null && result.TemplateData != null) { var output = pm.WriteTemplateOutputFile(workflow.outputFolder, result.TemplateData); outputs.Add(file, output); } else { string errorMessage = ""; string logMessage = ""; if (result.TemplateData == null) { errorMessage = "Processor results template data is null. "; } if (result.ErrorMessage != null) { errorMessage = errorMessage + result.ErrorMessage; logMessage = errorMessage; } if (result.LogMessage != null) { logMessage = result.LogMessage; } await this.UpdateStatus(task.id, "CANCELLED", "Error processing data: " + errorMessage); Log.Information("Task Cancelled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Message: {3}", task.workflowID, task.id, task.taskID, logMessage); return; } // Step 7: Check if output file exists bool processed = false; for (int i = 0; i < outputs.Count; i++) { var output = outputs.ElementAt(i); string outputPath = output.Value.OutputFile; // Step 8: If output file does exist, update task outputFile and delete input file if (File.Exists(outputPath)) { processed = true; string fileName = System.IO.Path.GetFileName(output.Key); string inputPath = System.IO.Path.Combine(workflow.inputFolder, fileName); DataBackup dbBackup = new DataBackup(); dbBackup.DumpData(id, inputPath, outputPath); try { File.Delete(inputPath); } catch (Exception ex) { Log.Warning("Error unable to delete input file after successful processing. Workflow ID: {0}, ID: {1}", task.workflowID, task.id); } task.outputFile = outputPath; await _context.SaveChangesAsync(); } else { await this.UpdateStatus(task.id, "SCHEDULED", "Error unable to export output. Error Messages: " + output.Value.ErrorMessage); } } // Step 9: Change task status to COMPLETED // Step 10: Create new Task and schedule string newStatus = ""; if (processed) { newStatus = "COMPLETED"; Log.Information("Task Completed. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}", task.workflowID, task.id, task.taskID); try { if (files.Count > 1) { await this.CreateNewTask(workflow.id, 0); } else { await this.CreateNewTask(workflow.id, workflow.interval); } } catch (Exception) { Log.Warning("Error creating new Hangfire job after successful job. Workflow ID: {0}, ID: {1}", task.workflowID, task.id); } } else { newStatus = "CANCELLED"; Log.Information("Task Cancelled. WorkflowID: {0}, ID: {1}, Hangfire ID: {2}, Message: {3}", task.workflowID, task.id, task.taskID, "Failed to process input file."); } await this.UpdateStatus(task.id, newStatus); }
public DataBackupWindow() { InitializeComponent(); db = new DataBackup(); }
private void RosterizeButton_Click(object sender, RoutedEventArgs e) { var rosters = new List <Roster>(); rosters.Add(new InchBackByEfficiency2().Run(allPlayers)); rosters.AddRange(new RosterVarier().Vary(rosters.First(), allPlayers)); mostPickedRosters.ItemsSource = rosters .GroupBy(r => r) .Select(g => new { Count = g.Count(), Roster = g.Key }) .OrderByDescending(g => g.Count) .ToArray(); var mostPickedPlayers = rosters.SelectMany(r => r).GroupBy(p => p).Select(g => new { Count = g.Count(), g.Key.Position, g.Key.Name, g.Key.Team, g.Key.Projection, g.Key.Salary, g.Key.Matchup, g.Key.PointPerCost, Player = g.Key }) .OrderByDescending(x => x.Count); pickGrid.ItemsSource = mostPickedPlayers; var permutator = new PlayerPermutator(); Task.Run(() => { permutator.Progress += Permutator_Progress; var pr = permutator.Permutations(mostPickedPlayers.Select(p => p.Player).ToArray()); return(pr); }).ContinueWith(t => { rosters.AddRange(t.Result); var distinctRosters = rosters.Distinct().OrderByDescending(r => r.Projection).ToArray(); Application.Current.Dispatcher.Invoke(() => { progress.Text = "Done"; items.ItemsSource = distinctRosters.OrderByDescending(r => r.Projection); rosterCount.Text = distinctRosters.Length.ToString(); allRosters = distinctRosters.ToArray(); }); var backup = new DataBackup { TopRosters = distinctRosters.Select( r => new RosterBackup() { Players = r.Select(p => p.ToBackup()) }), MostPlayedPlayers = mostPickedPlayers.Select( x => new MostPlayedPlayerBackup { PlayedCount = x.Count, Player = x.Player.ToBackup() }), Players = allPlayers.Select(p => p.ToBackup()) }; var json = JsonConvert.SerializeObject(backup); File.WriteAllText("bak.json", json); }); }