public SourceScript Build(IList <string> validationMessages) { var script = new SourceScript(_name, _blocks); script.Validate(validationMessages); return(script); }
private void ExecSql(SourceScript script, SqlScriptPhase phase) { if (script.HasPhaseExecuted(phase)) { return; } var sql = script.RequestSqlScriptPhase(phase); if (sql == null) { return; } sql = PhaseDeploymentComment + sql; var configuration = script.GetConfiguration(); using (var command = _connectionManager.CreateCommand(sql)) { foreach (var catalog in GetCatalogs(script)) { _logger.PostEntryNoTimestamp(" {0}", catalog); if (configuration == null) { command.Execute(catalog); } else { command.Execute(catalog, configuration.Settings.Timeout); } } } }
private static void AddRecursive(List <SourceScript> target, SourceScript item, IEnumerable <SourceScript> source) { if (target.Any(i => i.Instance.Name == item.Instance.Name)) { return; } var dependencies = source.Where(src => src.Instance.Name != item.Instance.Name && item.Instance.Definition.Contains(src.Instance.Name)); foreach (var dependency in dependencies) { AddRecursive(target, dependency, source); } target.Add(item); }
private IEnumerable <string> GetCatalogs(SourceScript script) { var matchingDatabases = new List <string>(); foreach (var rgx in script.GetCatalogPatterns().Select(pattern => _patternLookup[pattern])) { matchingDatabases.AddRange( _connectionManager.DatabaseNames .Where(dbName => rgx.IsMatch(dbName)) ); } if (matchingDatabases.Count == 0) { throw new InvalidOperationException("No matching catalogs found for script '" + script.Name + "'. Check the 'catalog' directive."); } return(matchingDatabases.Distinct().OrderBy(x => x)); }
private void WriteScript(SourceScript script, SqlScriptPhase phase) { if (script.HasPhaseExecuted(phase)) { return; } var sql = script.RequestSqlScriptPhase(phase); if (sql == null) { return; } sql = PhaseDeploymentComment + sql; foreach (var catalog in GetCatalogs(script)) { _logger.PostEntryNoTimestamp(" {0}", catalog); WriteCommand(catalog, sql); } }
//Performs interaction with gameObject based on its tag //Executed when player is near interactables and presses "E" void Interact(GameObject interactable) { if (interactable != null) { //If interactable is a torch, check that we have enough light to activate it and that it is not already lit //If all conditions are met, light the torch, reduce lightAmt by cost if (interactable.CompareTag("Torch")) { TorchScript tScript = interactable.GetComponent <TorchScript>(); if (tScript != null) { if (lightAmt > torchCost && !tScript.lit) { tScript.LightTorch(); lightAmt -= torchCost; } } } else if (interactable.CompareTag("Campfire")) { CampfireScript cScript = interactable.GetComponent <CampfireScript>(); if (cScript != null) { if (lightAmt > torchCost && cScript.isLit == false) { cScript.LightCampfire(); lightAmt -= torchCost; } else if (lightAmt > torchCost && cScript.isLit == true) { lightAmt = (lightAmt + cScript.campLightAmt) / 2; cScript.campLightAmt = (lightAmt + cScript.campLightAmt) / 2; } } } //If interactable is a source, give player light from the source and destroy it else if (interactable.CompareTag("Source")) { SourceScript sScript = interactable.GetComponent <SourceScript>(); if (sScript != null) { lightAmt += sScript.lightStored; Destroy(interactable); } } else if (interactable.CompareTag("Bomb")) { Bomb bomb = interactable.GetComponent <Bomb>(); if (bomb != null) { bomb.Ignite(); } } else if (interactable.CompareTag("Zipline")) { Zipline zScript = interactable.GetComponentInParent <Zipline>(); if (zScript != null) { if (lightAmt > ziplineCost && !zScript.isActive) { zScript.Activate(); lightAmt -= ziplineCost; } else { if (zScript.isActive) { Vector3 startAnchor = interactable.transform.position; Vector3 endAnchor; if (interactable.transform == zScript.AnchorA) { endAnchor = zScript.AnchorB.position; } else { endAnchor = zScript.AnchorA.position; } StartCoroutine(UseZipline(startAnchor, endAnchor)); } } } } } }
private IEnumerable<string> GetCatalogs(SourceScript script) { var matchingDatabases = new List<string>(); foreach (var rgx in script.GetCatalogPatterns().Select(pattern => _patternLookup[pattern])) { matchingDatabases.AddRange( _connectionManager.DatabaseNames .Where(dbName => rgx.IsMatch(dbName)) ); } if(matchingDatabases.Count == 0) throw new InvalidOperationException("No matching catalogs found for script '" + script.Name + "'. Check the 'catalog' directive."); return matchingDatabases.Distinct().OrderBy(x => x); }
private void ExecSql(SourceScript script, SqlScriptPhase phase) { if (script.HasPhaseExecuted(phase)) return; var sql = script.RequestSqlScriptPhase(phase); if (sql == null) return; sql = PhaseDeploymentComment + sql; var configuration = script.GetConfiguration(); using (var command = _connectionManager.CreateCommand(sql)) { foreach (var catalog in GetCatalogs(script)) { _logger.PostEntryNoTimestamp(" {0}", catalog); if (configuration == null) command.Execute(catalog); else command.Execute(catalog, configuration.Settings.Timeout); } } }
public ProjectBuilder WithScript(SourceScript script) { _scripts.Add(script); return(this); }
internal string[] SyncronizeWith(DataBase source) { var list = new List <string>(); #region TABLES // удаляем таблицы, которых нет в source var existSourceTableNames = source.Tables.Select(t => t.Name); var delTargetTables = Tables.Where(t => !existSourceTableNames.Contains(t.Name)); var delTargetFkeys = delTargetTables.SelectMany( t => t.ParentTables.SelectMany(pt => pt.ForeignKeys.Where(fk => fk.ReferenceTable == t))); list.AddRange(delTargetFkeys.Select(fk => fk.DropSql)); list.AddRange(delTargetTables.Select(table => table.DropSql)); // добавляем новые таблицы, индексы и ключи var existTargetTableNames = Tables.Select(t => t.Name); var addSourceTables = source.Tables.Where(t => !existTargetTableNames.Contains(t.Name)); list.AddRange(addSourceTables.Select(table => table.CreateSql)); list.AddRange(addSourceTables.SelectMany(table => table.Defaults.Select(d => d.CreateSql))); list.AddRange(addSourceTables.SelectMany(table => table.ForeignKeys.Select(fkey => fkey.CreateSql))); list.AddRange(addSourceTables.SelectMany(table => table.Indexes.Where(index => !index.IsPrimaryKey).Select(index => index.CreateSql))); // проверяем на наличие изменений и модифицируем существующие таблицы var existSourceTables = source.Tables.Where(t => existTargetTableNames.Contains(t.Name)); foreach (var sourceTable in existSourceTables) { var targetTable = Tables.Single(t => t.Name == sourceTable.Name); list.AddRange(targetTable.SyncronizeWith(sourceTable)); } #endregion #region VIEWS & PROGRAMMED OBJECTS // удаление var existSourceViewNames = source.Views.Select(view => view.Name); var delTargetViews = Views.Where(view => !existSourceViewNames.Contains(view.Name)); list.AddRange(delTargetViews.Select(view => view.DropSql)); var existSourceObjNames = source.ProgrammedObjects.Select(pobj => pobj.Name); var delTargetObjs = ProgrammedObjects.Where(pobj => !existSourceObjNames.Contains(pobj.Name)); list.AddRange(delTargetObjs.Select(pobj => pobj.DropSql)); // объекты, которые нужно добавить или модифицировать var sourceViews = source.Views .Select(sview => { var tview = Views.SingleOrDefault(sv => sv.Name == sview.Name); return(new SourceScript { IsNew = tview == null, IsChanged = tview != null && !sview.Equals(tview), Instance = sview }); }); var sourceObjs = source.ProgrammedObjects .Select(sobj => { var tobj = ProgrammedObjects.SingleOrDefault(sv => sv.Name == sobj.Name); return(new SourceScript { IsNew = tobj == null, IsChanged = tobj != null && !sobj.Equals(tobj), Instance = sobj }); }); var sourceScripts = SourceScript.Sort(sourceViews.Union(sourceObjs).Where(i => i.IsNew || i.IsChanged)); list.AddRange(sourceScripts.Select(tscript => tscript.IsNew ? tscript.Instance.CreateSql : tscript.Instance.AlterSql)); /* * // добавление * var addSourceViews = source.Views.Where(view => !existTargetViewNames.Contains(view.Name)); * list.AddRange(addSourceViews.Select(view => view.CreateSql)); * var addSourceObjs = source.ProgrammedObjects.Where(pobj => !existTargetObjNames.Contains(pobj.Name)); * list.AddRange(addSourceObjs.Select(view => view.CreateSql)); * * // модификация * var existSourceViews = source.Views.Where(view => existTargetViewNames.Contains(view.Name)); * foreach (var sourceView in existSourceViews) * { * var targetView = Views.Single(view => view.Name == sourceView.Name); * if (!targetView.Equals(sourceView)) * list.Add(sourceView.AlterSql); * } * var existSourceObjs = source.ProgrammedObjects.Where(pobj => existTargetObjNames.Contains(pobj.Name)); * foreach (var sourceObj in existSourceObjs) * { * var targetObj = ProgrammedObjects.Single(pobj => pobj.Name == sourceObj.Name); * if (!targetObj.Equals(sourceObj)) * list.Add(sourceObj.AlterSql); * } */ #endregion #region PROGRAMMED OBJECTS // удаление // добавление // модификация #endregion return(list.ToArray()); }
private void WriteScript(SourceScript script, SqlScriptPhase phase) { if (script.HasPhaseExecuted(phase)) return; var sql = script.RequestSqlScriptPhase(phase); if (sql == null) return; sql = PhaseDeploymentComment + sql; foreach (var catalog in GetCatalogs(script)) { _logger.PostEntryNoTimestamp(" {0}", catalog); WriteCommand(catalog, sql); } }