public RepositoryDllJsonStrategy() { this.Subfolder = "Strategies" + Path.DirectorySeparatorChar + ""; this.PathMask = "*.dll"; this.StrategiesInFolders = new Dictionary<string, List<Strategy>>(); this.ScriptsInDlls = new Dictionary<string, List<Script>>(); this.ScriptRepositoryFoundInFolderDataStrategies = new ScriptRepository(); this.ScriptRepositoryFoundInFolderAppStartup = new ScriptRepository(); }
public void Can_Instantiate_Repository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); // Act var repository = new ScriptRepository(unitOfWork, _fileSystem); // Assert Assert.That(repository, Is.Not.Null); }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var script = repository.Get("test-script.js"); repository.Delete(script); unitOfWork.Commit(); // Assert }
public void Can_Perform_Add_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var script = new Script("test-add-script.js") {Content = "/// <reference name=\"MicrosoftAjax.js\"/>"}; repository.AddOrUpdate(script); unitOfWork.Commit(); //Assert Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True); }
static void Main(string[] args) { Console.WriteLine("Hello"); IScriptRepository repository = new ScriptRepository(); ScriptLog log = new ScriptLog(); log.AppName = "Test"; log.Author = "test"; repository.AddScriptLog(log); var logs = repository.Browse(); foreach (ScriptLog tmpLog in logs) { Console.WriteLine($"ID: {tmpLog.Id}\tApp Name: {tmpLog.AppName}\t{(tmpLog.Author != null ? $"Author: {tmpLog.Author}" : "")}"); } Console.ReadKey(); }
public void Can_Perform_Get_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var exists = repository.Get("test-script.js"); // Assert Assert.That(exists, Is.Not.Null); Assert.That(exists.Alias, Is.EqualTo("test-script")); Assert.That(exists.Name, Is.EqualTo("test-script.js")); } }
public void Can_Perform_Add_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var script = new Script("test-add-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script); unitOfWork.Commit(); //Assert Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True); }
public ScriptCalculatorTestEngine() { var logger = new Mock <ILogger <CalculateCommand.Handler> >(); ScriptInterpreterDbContext = new ScriptInterpreterDbContext( new DbContextOptions <ScriptInterpreterDbContext>()); ParameterRepository = new ParameterRepository(context: ScriptInterpreterDbContext); var config = new MapperConfiguration(cfg => { cfg.AddProfile(new ScriptMappingProfile()); }); ScriptRepository = new ScriptRepository(ScriptInterpreterDbContext); TranslationService = new TranslationService(new TranslationRepository(ScriptInterpreterDbContext)); Mapper = new Mapper(config); CalculateCommand = new CalculateCommand.Handler(ScriptRepository, ParameterRepository, TranslationService, Mapper); }
public void Can_Perform_Delete_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var script = repository.Get("test-script.js"); repository.Delete(script); // Assert Assert.IsFalse(repository.Exists("test-script.js")); } }
protected Dictionary <Assembly, List <Script> > StrategiesScanDllsInitDeserialized(string dataOrStartupPath) { ScriptRepository repo = new ScriptRepository(); repo.InitializeAndScan(dataOrStartupPath); Dictionary <Assembly, List <Script> > ret = repo.CloneableInstancesByAssemblies; foreach (Assembly assembly in ret.Keys) { List <Script> cloneableInstancesForAssembly = ret[assembly]; // WONT_BE_EMPTY if (cloneableInstancesForAssembly.Count == 0) continue; string assemblyName = Path.GetFileName(assembly.Location); if (this.StrategiesInFolders.ContainsKey(assemblyName) == false) { //this.StrategiesInFolders.Add(assemblyName, new List<Strategy>()); this.FolderAdd(assemblyName, false); //} else { // string msg = "StrategyRepository::StrategiesScanDllsInitDeserialized(" + dataOrStartupPath + "):" // + " Assembly [" + assembly.Location + "] wasn't added to this.StrategiesInFolders" // + " because already existed among AllFoldersAvailable[" + AllFoldersAvailable + "]"; // Assembler.Constructed.StatusReporter.PopupException(msg); // continue; } List <Strategy> strategiesForAssmbly = this.StrategiesInFolders[assemblyName]; foreach (Script script in cloneableInstancesForAssembly) { string scriptName = script.GetType().Name; Strategy strategyFound = this.LookupByName(scriptName, assemblyName); if (strategyFound == null) { strategyFound = new Strategy(scriptName); strategyFound.StoredInJsonAbspath = Path.Combine(this.FolderAbsPathFor(assemblyName), scriptName + ".json"); strategiesForAssmbly.Add(strategyFound); } strategyFound.Script = script; strategyFound.DllPathIfNoSourceCode = assembly.Location; this.StrategySave(strategyFound); } } return(ret); }
public void Can_Perform_Add_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); // Act var script = new Script("test-add-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.Save(script); //Assert Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True); } }
public void Can_Perform_Update_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); // Act var script = new Script("test-updated-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script); unitOfWork.Commit(); script.Content = "/// <reference name=\"MicrosoftAjax-Updated.js\"/>"; repository.AddOrUpdate(script); unitOfWork.Commit(); var scriptUpdated = repository.Get("test-updated-script.js"); // Assert Assert.That(_fileSystem.FileExists("test-updated-script.js"), Is.True); Assert.That(scriptUpdated.Content, Is.EqualTo("/// <reference name=\"MicrosoftAjax-Updated.js\"/>")); }
public void AtualizaBancoFotos(string ibgemun, string ibgefotos, int?id_command) { try { int ultimoComando = 0; if (id_command != null) { ultimoComando = (int)id_command - 1; //usa o numero da versão passada via parametro } else { ultimoComando = Helpers.HelperConnection.ExecuteCommand(ibgemun, conn => conn.QueryFirstOrDefault <int>(_command.GetUltimoCodigoScript)); //recupera ultimo comando } var proximos = ScriptRepository.GetScriptBancoFotos(ultimoComando); foreach (var item in proximos) { try { Helpers.HelperConnection.ExecuteCommand(ibgefotos, conn => conn.Execute(item.script)); } catch (Exception ex) { throw new Exception($"Erro ao Executar script de nº {item.codigo}. {ex.Message}"); } ultimoComando = (int)item.codigo; string scriptAtualizaVersao = _command.UpdateCodigoScript.Replace("@versao", ultimoComando.ToString()); Helpers.HelperConnection.ExecuteCommandBloco(ibgemun, scriptAtualizaVersao); } } catch (Exception ex) { throw ex; } }
public void Can_Perform_GetAll_With_Params_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script); var script2 = new Script("test-script2.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script2); var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script3); unitOfWork.Commit(); // Act var scripts = repository.GetAll("test-script1.js", "test-script2.js"); // Assert Assert.That(scripts, Is.Not.Null); Assert.That(scripts.Any(), Is.True); Assert.That(scripts.Any(x => x == null), Is.False); Assert.That(scripts.Count(), Is.EqualTo(2)); }
public void Can_Perform_GetAll_With_Params_On_ScriptRepository() { // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.Save(script); var script2 = new Script("test-script2.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.Save(script2); var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.Save(script3); // Act var scripts = repository.GetMany("test-script1.js", "test-script2.js"); // Assert Assert.That(scripts, Is.Not.Null); Assert.That(scripts.Any(), Is.True); Assert.That(scripts.Any(x => x == null), Is.False); Assert.That(scripts.Count(), Is.EqualTo(2)); } }
public void Can_Perform_Move_On_ScriptRepository() { const string content = "/// <reference name=\"MicrosoftAjax.js\"/>"; // Arrange var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); var script = new Script("test-move-script.js") { Content = content }; repository.Save(script); // Act script = repository.Get("test-move-script.js"); script.Path = "moved/test-move-script.js"; repository.Save(script); var existsOld = repository.Exists("test-move-script.js"); var existsNew = repository.Exists("moved/test-move-script.js"); script = repository.Get("moved/test-move-script.js"); // Assert Assert.IsNotNull(script); Assert.IsFalse(existsOld); Assert.IsTrue(existsNew); Assert.AreEqual(content, script.Content); } }
public void Init() { myExecutionRepository = ServiceResolver.Resolve <ExecutionRepository>(); myPlaneRepository = ServiceResolver.Resolve <PlaneRepository>(); myScriptRepository = ServiceResolver.Resolve <ScriptRepository>(); }
private void LoadTreeViewData(object sender, JavascriptMethodEventArgs e) { try { JSTreeNode areaRootNode; JSTreeNode creatureRootNode; JSTreeNode itemRootNode; JSTreeNode placeableRootNode; JSTreeNode conversationRootNode; JSTreeNode scriptRootNode; JSTreeNode tilesetRootNode; // Get each category's children for each object type using (AreaRepository repo = new AreaRepository()) { areaRootNode = repo.GenerateJSTreeHierarchy(); } using (CreatureRepository repo = new CreatureRepository()) { creatureRootNode = repo.GenerateJSTreeHierarchy(); } using (ItemRepository repo = new ItemRepository()) { itemRootNode = repo.GenerateJSTreeHierarchy(); } using (PlaceableRepository repo = new PlaceableRepository()) { placeableRootNode = repo.GenerateJSTreeHierarchy(); } using (ConversationRepository repo = new ConversationRepository()) { conversationRootNode = repo.GenerateJSTreeHierarchy(); } using (ScriptRepository repo = new ScriptRepository()) { scriptRootNode = repo.GenerateJSTreeHierarchy(); } using (TilesetRepository repo = new TilesetRepository()) { tilesetRootNode = repo.GenerateJSTreeHierarchy(); } AsyncJavascriptCallback("LoadTreeViews_Callback", JsonConvert.SerializeObject(areaRootNode), JsonConvert.SerializeObject(creatureRootNode), JsonConvert.SerializeObject(itemRootNode), JsonConvert.SerializeObject(placeableRootNode), JsonConvert.SerializeObject(conversationRootNode), JsonConvert.SerializeObject(scriptRootNode), JsonConvert.SerializeObject(tilesetRootNode)); } catch { throw; } }
public void UpsertInDatabase(GameObjectBase gameObject, string connectionString = "") { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Upsert(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Upsert(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Upsert(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Upsert(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Upsert(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Upsert(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Upsert(gameObject as Tileset); } } else { throw new NotSupportedException(); } }
public GameObjectBase GetFromDatabaseByID(int resourceID, GameObjectTypeEnum gameResourceType) { if (gameResourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository()) { return repo.GetByID(resourceID); } } else if (gameResourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository()) { return repo.GetByID(resourceID); } } else { throw new NotSupportedException(); } }
/// <summary> /// Returns all objects from the database that have a matching resource category. /// </summary> /// <param name="resourceCategory">The resource category all return values must match</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public List<GameObjectBase> GetAllFromDatabaseByResourceCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { List<GameObjectBase> retList = new List<GameObjectBase>(); if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.GetAllByResourceCategory(resourceCategory).ConvertAll(x => (GameObjectBase)x); } } else { throw new NotSupportedException(); } }
/// <summary> /// Returns True if an object exists in the database. /// Returns False if an object does not exist in the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The resource type to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> /// <returns></returns> public bool DoesObjectExistInDatabase(string resref, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { return repo.Exists(resref); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { return repo.Exists(resref); } } else { throw new NotSupportedException(); } }
public void Can_Perform_GetAll_With_Params_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); var script = new Script("test-script1.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script); var script2 = new Script("test-script2.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script2); var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" }; repository.AddOrUpdate(script3); unitOfWork.Commit(); // Act var scripts = repository.GetAll("test-script1.js", "test-script2.js"); // Assert Assert.That(scripts, Is.Not.Null); Assert.That(scripts.Any(), Is.True); Assert.That(scripts.Any(x => x == null), Is.False); Assert.That(scripts.Count(), Is.EqualTo(2)); }
/// <summary> /// Deletes an object with the specified resref from the database. /// </summary> /// <param name="resref">The resource reference to search for.</param> /// <param name="resourceType">The type of resource to remove.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabase(int resourceID, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.Delete(resourceID); } } else if (resourceType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { repo.Delete(resourceID); } } else { throw new NotSupportedException(); } }
protected Dictionary<Assembly, List<Script>> StrategiesScanDllsInitDeserialized(string dataOrStartupPath) { ScriptRepository repo = new ScriptRepository(); repo.InitializeAndScan(dataOrStartupPath); Dictionary<Assembly, List<Script>> ret = repo.CloneableInstancesByAssemblies; foreach (Assembly assembly in ret.Keys) { List<Script> cloneableInstancesForAssembly = ret[assembly]; // WONT_BE_EMPTY if (cloneableInstancesForAssembly.Count == 0) continue; string assemblyName = Path.GetFileName(assembly.Location); if (this.StrategiesInFolders.ContainsKey(assemblyName) == false) { //this.StrategiesInFolders.Add(assemblyName, new List<Strategy>()); this.FolderAdd(assemblyName, false); //} else { // string msg = "StrategyRepository::StrategiesScanDllsInitDeserialized(" + dataOrStartupPath + "):" // + " Assembly [" + assembly.Location + "] wasn't added to this.StrategiesInFolders" // + " because already existed among AllFoldersAvailable[" + AllFoldersAvailable + "]"; // Assembler.Constructed.StatusReporter.PopupException(msg); // continue; } List<Strategy> strategiesForAssmbly = this.StrategiesInFolders[assemblyName]; foreach (Script script in cloneableInstancesForAssembly) { string scriptName = script.GetType().Name; Strategy strategyFound = this.LookupByName(scriptName, assemblyName); if (strategyFound == null) { strategyFound = new Strategy(scriptName); strategyFound.StoredInJsonAbspath = Path.Combine(this.FolderAbsPathFor(assemblyName), scriptName + ".json"); strategiesForAssmbly.Add(strategyFound); } strategyFound.Script = script; strategyFound.DllPathIfNoSourceCode = assembly.Location; this.StrategySave(strategyFound); } } return ret; }
public ScriptController(LoggingService myLoggingService, PreferenceRepository myPreferenceRepository, ScriptRepository myScriptRepository, ActionRepository myActionRepository) { _LoggingService = myLoggingService; _PreferenceRepository = myPreferenceRepository; _ScriptRepository = myScriptRepository; _ActionRepository = myActionRepository; }
public void AtualizaBanco(string ibge, int?id_command) { try { //verifica se tabela de ver~soa existe var existetabelaversao = Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.QueryFirstOrDefault <int>(_command.VerificaTabelaVersaoExiste)); if (existetabelaversao == 0) { //cria tabela de versão Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.Execute(_command.CriaTabelaVersao)); //cria constraint de tabela de versão Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.Execute(_command.CriaContraintTabelaVersao)); } //verifica se ja existe algum registro na tabela var existeregistrotabversao = Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.QueryFirstOrDefault <int>(_command.VerificaExisteRegistroTabelaVersao)); //caso não exista, cria o primeiro = 0 if (existeregistrotabversao == 0) { Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.Execute(_command.InserePrimeiroRegTabVersao)); } int ultimoComando = 0; if (id_command != null) { ultimoComando = (int)id_command - 1; //usa o numero da versão passada via parametro } else { ultimoComando = Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.QueryFirstOrDefault <int>(_command.GetUltimoCodigoScript)); //recupera ultimo comando } var proximos = ScriptRepository.GetScript(ultimoComando); foreach (var item in proximos) { try { Helpers.HelperConnection.ExecuteCommandBloco(ibge, item.script); } catch (Exception ex) { throw new Exception($"Erro ao Executar script de nº {item.codigo}. {ex.Message}"); } ultimoComando = (int)item.codigo; Helpers.HelperConnection.ExecuteCommand(ibge, conn => conn.Execute(_command.UpdateCodigoScript, new { @versao = ultimoComando })); } } catch (Exception ex) { throw ex; } }
public void Can_Perform_Exists_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var exists = repository.Exists("test-script.js"); // Assert Assert.That(exists, Is.True); }
private void PopulateToolsetViewModel() { ClearViewModelPopulation(); using (GameModuleRepository repo = new GameModuleRepository()) { ViewModel.ActiveModule = repo.GetModule(); } using (ContentPackageResourceRepository repo = new ContentPackageResourceRepository()) { ViewModel.TilesetSpriteSheetsList = repo.GetAllUIObjects(ContentPackageResourceTypeEnum.Tileset, false); } using (ItemRepository repo = new ItemRepository()) { ViewModel.ItemList = repo.GetAllUIObjects(); } using (ScriptRepository repo = new ScriptRepository()) { ViewModel.ScriptList = repo.GetAllUIObjects(); } using (GenderRepository repo = new GenderRepository()) { ViewModel.GenderList = repo.GetAllUIObjects(); } using (ConversationRepository repo = new ConversationRepository()) { ViewModel.ConversationList = repo.GetAllUIObjects(); } using (RaceRepository repo = new RaceRepository()) { ViewModel.RaceList = repo.GetAllUIObjects(); } using (FactionRepository repo = new FactionRepository()) { ViewModel.FactionList = repo.GetAllUIObjects(); } using (TilesetRepository repo = new TilesetRepository()) { ViewModel.TilesetList = repo.GetAllUIObjects(); } using (AbilityRepository repo = new AbilityRepository()) { ViewModel.AbilityList = repo.GetAll(); } using (SkillRepository repo = new SkillRepository()) { ViewModel.SkillList = repo.GetAll(); } using (LevelRequirementRepository repo = new LevelRequirementRepository()) { ViewModel.LevelRequirementList = repo.GetAll(); } }
/// <summary> /// Delete all objects from database that match a specified resource category. /// </summary> /// <param name="resourceCategory">The resource category to remove all objects from.</param> /// <param name="resourceType">The type of resource to look for.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public void DeleteFromDatabaseByCategory(Category resourceCategory, GameObjectTypeEnum resourceType, string connectionString = "") { if (resourceType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else if (resourceType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { repo.DeleteAllByCategory(resourceCategory); } } else { throw new NotSupportedException(); } // Now remove the category itself. using (CategoryRepository repo = new CategoryRepository()) { Category dbCategory = repo.GetByID(resourceCategory.ResourceID); repo.Delete(dbCategory); } }
public void Can_Perform_Get_On_ScriptRepository() { // Arrange var provider = new FileUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem); // Act var exists = repository.Get("test-script.js"); // Assert Assert.That(exists, Is.Not.Null); Assert.That(exists.Alias, Is.EqualTo("test-script")); Assert.That(exists.Name, Is.EqualTo("test-script.js")); }
public void PathTests() { // unless noted otherwise, no changes / 7.2.8 var provider = new FileUnitOfWorkProvider(Mock.Of<IScopeProvider>()); var unitOfWork = provider.GetUnitOfWork(); var repository = new ScriptRepository(unitOfWork, _fileSystem, Mock.Of<IContentSection>()); var script = new Script("test-path-1.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("test-path-1.js")); Assert.AreEqual("test-path-1.js", script.Path); Assert.AreEqual("/scripts/test-path-1.js", script.VirtualPath); //ensure you can prefix the same path as the root path name script = new Script("scripts/path-2/test-path-2.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("scripts/path-2/test-path-2.js")); Assert.AreEqual("scripts\\path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2/test-path-2.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.js")); Assert.AreEqual("path-2\\test-path-2.js", script.Path); // fixed in 7.3 - 7.2.8 does not update the path Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = repository.Get("path-2/test-path-2.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2\\test-path-3.js") { Content = "// script" }; repository.AddOrUpdate(script); unitOfWork.Commit(); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.js")); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2/test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2\\test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = new Script("\\test-path-4.js") { Content = "// script" }; Assert.Throws<FileSecurityException>(() => // fixed in 7.3 - 7.2.8 used to strip the \ { repository.AddOrUpdate(script); }); script = repository.Get("missing.js"); Assert.IsNull(script); // fixed in 7.3 - 7.2.8 used to... Assert.Throws<FileSecurityException>(() => { script = repository.Get("\\test-path-4.js"); // outside the filesystem, does not exist }); Assert.Throws<FileSecurityException>(() => { script = repository.Get("../packages.config"); // outside the filesystem, exists }); }
public void PathTests() { // unless noted otherwise, no changes / 7.2.8 var provider = TestObjects.GetScopeProvider(Logger); using (var scope = ScopeProvider.CreateScope()) { var repository = new ScriptRepository(_fileSystems, Mock.Of <IContentSection>()); var script = new Script("test-path-1.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("test-path-1.js")); Assert.AreEqual("test-path-1.js", script.Path); Assert.AreEqual("/scripts/test-path-1.js", script.VirtualPath); //ensure you can prefix the same path as the root path name script = new Script("scripts/path-2/test-path-2.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("scripts/path-2/test-path-2.js")); Assert.AreEqual("scripts\\path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2/test-path-2.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.js")); Assert.AreEqual("path-2\\test-path-2.js", script.Path); // fixed in 7.3 - 7.2.8 does not update the path Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = repository.Get("path-2/test-path-2.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-2.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath); script = new Script("path-2\\test-path-3.js") { Content = "// script" }; repository.Save(script); Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.js")); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2/test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = repository.Get("path-2\\test-path-3.js"); Assert.IsNotNull(script); Assert.AreEqual("path-2\\test-path-3.js", script.Path); Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath); script = new Script("\\test-path-4.js") { Content = "// script" }; Assert.Throws <UnauthorizedAccessException>(() => // fixed in 7.3 - 7.2.8 used to strip the \ { repository.Save(script); }); script = repository.Get("missing.js"); Assert.IsNull(script); // fixed in 7.3 - 7.2.8 used to... Assert.Throws <UnauthorizedAccessException>(() => { script = repository.Get("\\test-path-4.js"); // outside the filesystem, does not exist }); Assert.Throws <UnauthorizedAccessException>(() => { script = repository.Get("../packages.config"); // outside the filesystem, exists }); } }
/// <summary> /// Adds a game object to the database. /// </summary> /// <param name="gameObject">The game object to add to the database. This will be type-converted and added to the correct table when run.</param> /// <param name="connectionString">If you need to connect to a specific database, use this to pass the connection string. Otherwise, the default connection string will be used (WinterConnectionInformation.ActiveConnectionString)</param> public GameObjectBase AddToDatabase(GameObjectBase gameObject, string connectionString = "") { GameObjectBase resultGameObject; try { if (gameObject.GameObjectType == GameObjectTypeEnum.Area) { using (AreaRepository repo = new AreaRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Area); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Conversation) { using (ConversationRepository repo = new ConversationRepository()) { resultGameObject = repo.Add(gameObject as Conversation); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Creature) { using (CreatureRepository repo = new CreatureRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Creature); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Item) { using (ItemRepository repo = new ItemRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Item); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Placeable) { using (PlaceableRepository repo = new PlaceableRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Placeable); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Script) { using (ScriptRepository repo = new ScriptRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Script); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.Tileset) { using (TilesetRepository repo = new TilesetRepository(connectionString)) { resultGameObject = repo.Add(gameObject as Tileset); } } else if (gameObject.GameObjectType == GameObjectTypeEnum.GameModule) { using (GameModuleRepository repo = new GameModuleRepository()) { resultGameObject = repo.Add(gameObject as GameModule); } } else { throw new NotSupportedException(); } } catch { throw; } return resultGameObject; }
private void SaveScript(object sender, GameObjectSaveEventArgs e) { using (ScriptRepository repo = new ScriptRepository()) { repo.Upsert(e.ActiveScript); } }
public void Init() { myScriptRepository = ServiceResolver.Resolve <ScriptRepository>(); myActionRepository = ServiceResolver.Resolve <ActionRepository>(); }