void Difficulty() { float diffRate = ScoreController.instance.difficultyRate; switch (WaveController.instance.waveNumber) { case 1: asteroidSpawnRate = UtilitiesMethods.CalculateDifficultyMetric(init_asteroidSpawnRate, limit_asteroidSpawnRate, diffRate); asteroidSpeed = UtilitiesMethods.CalculateDifficultyMetric(init_asteroidSpeed, limit_asteroidSpeed, diffRate); break; case 2: shooterSpawnRate = UtilitiesMethods.CalculateDifficultyMetric(init_ShooterSpawnRate, limit_ShooterSpawnRate, diffRate); shooterSpeed = UtilitiesMethods.CalculateDifficultyMetric(init_ShooterSpeed, limit_ShooterSpeed, diffRate); shooterWaitTime = UtilitiesMethods.CalculateDifficultyMetric(init_ShooterWaitTime, limit_ShooterWaitTime, diffRate); shooterTimeBtwShoots = UtilitiesMethods.CalculateDifficultyMetric(init_ShooterTimeBtwShoots, limit_ShooterTimeBtwShoots, diffRate); break; case 3: missileSpawnRate = UtilitiesMethods.CalculateDifficultyMetric(init_MissileSpawnRate, limit_MissileSpawnRate, diffRate); missileSpeed = UtilitiesMethods.CalculateDifficultyMetric(init_MissileSpeed, limit_MissileSpeed, diffRate); break; case 4: guidedMissileTimer = UtilitiesMethods.CalculateDifficultyMetric(init_GuidedMissileTimer, limit_GuidedMissileTimer, diffRate); guidedMissileSpeed = UtilitiesMethods.CalculateDifficultyMetric(init_GuidedMissileSpeed, limit_GuidedMissileSpeed, diffRate); break; default: break; } }
public bool Update(string tableName, Tuple <string, string> whereKey, Dictionary <string, string> stringData) { List <string> setStrings = new List <string>(); foreach (KeyValuePair <string, string> stringParam in stringData) { setStrings.Add(String.Format("{0} = '{1}'", stringParam.Key, doubleApostraphes(stringParam.Value))); } string setString = UtilitiesMethods.CommaSeparatedString(setStrings); string commandString = String.Format("update {0} set {1} where {2} = '{3}';", tableName, setString, whereKey.Item1, whereKey.Item2); SQLiteCommand command = new SQLiteCommand(Connection); command.CommandText = commandString; if (command.ExecuteNonQuery() > 0) { return(true); } else { logger.Error("Update failed. Command: {0}", command.CommandText); return(false); } }
internal bool New(TECScopeManager scopeManager) { if (!UtilitiesMethods.IsFileLocked(path)) { if (File.Exists(path)) { File.Delete(path); } if (scopeManager is TECBid) { DatabaseGenerator.CreateBidDatabase(path); } else if (scopeManager is TECTemplates) { DatabaseGenerator.CreateTemplateDatabase(path); } else { throw new Exception("Generator can only create bid or template DBs"); } List <UpdateItem> newStack = DatabaseNewStacker.NewStack(scopeManager); bool success = DatabaseUpdater.Update(path, newStack); if (!success) { MessageBox.Show("Not all items saved properly, check logs for more details."); } return(true); } else { logger.Error("Could not open file " + path + " File is open elsewhere."); return(false); } }
void OnEnable() { currentTargetPos = UtilitiesMethods.XYRandomVector3(X_MIN_SPAWN_POS, X_MAX_SPAWN_POS, Y_MIN_SPAWN_POS, Y_MAX_SPAWN_POS, transform.position.z); spr.material.color = GameAssets.i.defaultSprite.color; col.enabled = true; countTimeBtwShoot = DifficultyController.instance.shooterTimeBtwShoots; health = DifficultyController.instance.shooterHealth; defeated = false; }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value is string str) { return(UtilitiesMethods.StringToEnum <IOType>(str)); } else { throw new NotImplementedException(); } }
//Report Bug protected override void reportBugExecute() { string reportPrompt = "Please describe the bug and how to reproduce it."; string logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EstimateBuilder\\logs"); string logPath = UtilitiesMethods.GetMostRecentFilePathFromDirectoryPath(logDirectory); BugReportWindow reportWindow = new BugReportWindow("Estimate Builder Bug", reportPrompt, logPath); reportWindow.ShowDialog(); }
internal bool Save(List <UpdateItem> updates) { if (!UtilitiesMethods.IsFileLocked(path)) { bool success = DatabaseUpdater.Update(path, updates); if (!success) { MessageBox.Show("Some items might not have saved properly, check logs for more details."); } return(success); } else { logger.Error("Could not open file " + path + " File is open elsewhere."); return(false); } }
//Export Summary private void exportSummaryExecute() { string path = UIHelpers.GetSavePath(FileDialogParameters.WordDocumentFileParameters, Exporter.SummaryDefaultName(bid), defaultDirectory); if (path != null) { if (!UtilitiesMethods.IsFileLocked(path)) { Exporter.GenerateTurnover(path, bid, estimate); logger.Info("Exported to summary turnover document."); } else { notifyFileLocked(path); } } }
//Export Points List (CSV) private void exportPointsListCSVExecute() { string path = UIHelpers.GetSavePath(FileDialogParameters.CSVFileParameters, Exporter.PointsListDefaultName(bid), defaultDirectory); if (path != null) { if (!UtilitiesMethods.IsFileLocked(path)) { Exporter.GeneratePointsListCSV(path, bid, EBSettings.OpenFileOnExport); logger.Info("Points saved to csv."); } else { logger.Warn("Could not open file {0}. File is open elsewhere.", path); } } }
//Export Budget private void exportBOMExecute() { string path = UIHelpers.GetSavePath(FileDialogParameters.ExcelFileParameters, Exporter.BOMDefaultName(bid), defaultDirectory); if (path != null) { if (!UtilitiesMethods.IsFileLocked(path)) { Exporter.GenerateBOM(path, bid, EBSettings.OpenFileOnExport); logger.Info("Exported to BOM document."); } else { notifyFileLocked(path); } } }
//Export Templates private void exportTemplatesExecute() { string path = UIHelpers.GetSavePath(FileDialogParameters.ExcelFileParameters, Exporter.TemplateSummaryDefaultName(), defaultDirectory); if (path != null) { if (!UtilitiesMethods.IsFileLocked(path)) { Exporter.GenerateTemplateSummary(path, templates, TBSettings.OpenFileOnExport); logger.Info("Exported templates spreadsheet."); } else { notifyFileLocked(path); } } }
public bool Insert(string tableName, Dictionary <string, string> stringData, Dictionary <string, byte[]> byteData = null) { string commandString = "insert into " + tableName + " ("; List <string> colNames = new List <string>(); List <string> stringVals = new List <string>(); List <string> byteRefs = new List <string>(); SQLiteCommand command = new SQLiteCommand(Connection); foreach (KeyValuePair <string, string> stringParam in stringData) { colNames.Add(stringParam.Key); stringVals.Add("'" + doubleApostraphes(stringParam.Value) + "'"); } if (byteData != null) { foreach (KeyValuePair <string, byte[]> byteParam in byteData) { colNames.Add(byteParam.Key); string byteRef = "@" + byteParam.Key; byteRefs.Add("(" + byteRef + ")"); command.Parameters.Add(byteRef, DbType.Binary).Value = byteParam.Value; } } commandString += UtilitiesMethods.CommaSeparatedString(colNames) + ") values (" + UtilitiesMethods.CommaSeparatedString(stringVals); if (byteData != null) { commandString += ", " + UtilitiesMethods.CommaSeparatedString(byteRefs); } commandString += ")"; command.CommandText = commandString; return(command.ExecuteNonQuery() > 0); }
private void logUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { logger.Fatal("Unhandled exception: {0}", e.Exception.Message); logger.Fatal("Inner exception: {0}", e.Exception.InnerException.Message); logger.Fatal("Stack trace: {0}", e.Exception.StackTrace); string reportPrompt = "A crash has occured. Please describe to the best of your ability the actions leading up to the crash."; string logDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TemplateBuilder\\logs"); string logPath = UtilitiesMethods.GetMostRecentFilePathFromDirectoryPath(logDirectory); BugReportWindow reportWindow = new BugReportWindow("Template Builder Crash", reportPrompt, logPath); reportWindow.ShowDialog(); //MessageBox.Show("Fatal error occured, view logs for more information.", "Fatal Error!", MessageBoxButton.OK, MessageBoxImage.Error); System.Environment.Exit(0); }
//Export Proposal private void exportProposalExecute() { var bidDirectory = currentBidPath != "" ? Path.GetDirectoryName(currentBidPath) : defaultDirectory; string path = UIHelpers.GetSavePath(FileDialogParameters.WordDocumentFileParameters, Exporter.ProposalDefaultName(bid), bidDirectory); if (path != null) { if (!UtilitiesMethods.IsFileLocked(path)) { Exporter.GenerateProposal(path, bid, estimate, EBSettings.OpenFileOnExport); logger.Info("Scope saved to document."); } else { notifyFileLocked(path); } } }
void WaveManager() { obstacleCount = UtilitiesMethods.CheckEnableList(obstaclesList); if (obstacleCount == 0) { obstaclesList.Clear(); spawnTimer = 0; if (waveCount.Count == TOTAL_NUMBER_OF_WAVES) { waveCount.Clear(); } else { previousWave = waveNumber; waveNumber = UtilitiesMethods.RandomIntegerException(1, (TOTAL_NUMBER_OF_WAVES + 1), previousWave, waveCount); countWaveDuration = waveDuration; waveCount.Add(waveNumber); } } }
void EnemyMovement() { if (!defeated) { if (arrivedPos == false && countWaitTime <= 0) { transform.position = Vector2.MoveTowards(transform.position, currentTargetPos, DifficultyController.instance.shooterSpeed * Time.deltaTime); if (transform.position == currentTargetPos) { arrivedPos = true; countWaitTime = DifficultyController.instance.shooterWaitTime; } } else if (countWaitTime > 0) { countWaitTime -= Time.deltaTime; } else { currentTargetPos = UtilitiesMethods.XYRandomVector3(X_MIN_SPAWN_POS, X_MAX_SPAWN_POS, Y_MIN_SPAWN_POS, Y_MAX_SPAWN_POS, transform.position.z); arrivedPos = false; } } }
private void StartButton_Click(object sender, EventArgs e) { this.Invoke(FireToggleButtons, false); try { var problemToSolve = TaskGetter.Invoke(); SimulatedAnnealingAlgorithm simulatedAnnealing; switch (problemToSolve.ProblemName) { case "Quadratic": simulatedAnnealing = new SimulatedAnnealingAlgorithm(new QuadraticFunction(), 2, 10, 0.01, 1000, 0.99); break; case "Rastrigin": simulatedAnnealing = new SimulatedAnnealingAlgorithm(new RastriginFunction(), problemToSolve.DefaultDimensions, problemToSolve.Parameters); break; case "Rosenbrock": simulatedAnnealing = new SimulatedAnnealingAlgorithm(new RosenbrockFunction(), problemToSolve.DefaultDimensions, problemToSolve.Parameters); break; case "IHCP": UtilitiesMethods utilitiesMethods = new UtilitiesMethods(); DirectProblem directProblem = new DirectProblem(utilitiesMethods.f, utilitiesMethods.g, utilitiesMethods.h, 1, 1, 15, 480, 1, 1, 1); InverseHeatConductionProblemFunction inverseHeatConductionProblemFunction = new InverseHeatConductionProblemFunction(directProblem, 0); simulatedAnnealing = new SimulatedAnnealingAlgorithm(inverseHeatConductionProblemFunction, 3, problemToSolve.Parameters); break; default: throw new Exception("Problem not implemented."); } Task <double> task = null; var parent = this; SetResultText("Calculating..."); task = Task.Run(() => { cts = new CancellationTokenSource(); CancellationToken token = cts.Token; try { Task.Run(() => { try { while (true) { Thread.Sleep(100); token.ThrowIfCancellationRequested(); } } catch (Exception ep) { parent.Invoke(tmpEvent, "Process stoped."); parent.Invoke(FireToggleButtons, true); } }, token); } catch (Exception exc) { MessageBox.Show(exc.Message, "Information"); } double solutionValue = 0; if (simulatedAnnealing != null) { solutionValue = simulatedAnnealing.Solve(); parent.Invoke(tmpEvent, "Problem name: " + problemToSolve.ProblemName + ", Dimensions: " + problemToSolve.DefaultDimensions + Environment.NewLine + "Real solution: " + simulatedAnnealing.Function.Solution + Environment.NewLine + "Founded solution: " + solutionValue + Environment.NewLine + simulatedAnnealing.GetCurrentProblemGUISolution()); parent.Invoke(FireToggleButtons, true); } return(solutionValue); }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Information"); } }
public static List <T> GetSearchResult <T>(this IEnumerable <T> source, string searchString) where T : ITECObject { searchString = searchString != null ? searchString : ""; bool isOr = false; if (searchString.Length > 0 && searchString[0] == '*') { isOr = true; searchString = searchString.Remove(0, 1); } char[] dilemeters = { ',', ' ' }; string[] searchCriteria = searchString.ToUpper().Split(dilemeters, StringSplitOptions.RemoveEmptyEntries); var outCollection = new List <T>(); foreach (T item in source) { if (item is TECTagged scope) { string[] references = { scope.Name.ToUpper(), scope.Description.ToUpper() }; foreach (TECTag tag in scope.Tags) { references.Append(tag.Label); } if (scope is TECHardware hardware) { references.Append(hardware.Manufacturer.Label.ToUpper()); } if (isOr) { if (UtilitiesMethods.StringsContainsAnyStrings(references, searchCriteria)) { outCollection.Add(item); } } else { if (UtilitiesMethods.StringsContainStrings(references, searchCriteria)) { outCollection.Add(item); } } } else if (item is TECLabeled labeled) { string[] references = { labeled.Label.ToUpper() }; if (isOr) { if (UtilitiesMethods.StringsContainsAnyStrings(references, searchCriteria)) { outCollection.Add(item); } } else { if (UtilitiesMethods.StringsContainStrings(references, searchCriteria)) { outCollection.Add(item); } } } } return(outCollection); }