public void MySQLResource_Returen_Right_DatabaseResource() { //Arrang string instance = "example"; MySqlCharset charset = MySqlCharset.utf8; string collation = "collation1"; string userName = "******"; string password = "******"; var db = new MySQLResource(instance, charset, collation, userName, password); var expected = new DatabaseResource { Instance = "example", Collation = "collation1", Charset = "utf8", UserName = "******", Password = "******" }; //Act var actual = db.Build(); //Assert Assert.AreEqual(expected, actual); }
public void ExecuteScript(DatabaseServer serverResource, DatabaseResource databaseResource, string script) { var connection = CreateServerConnection(serverResource); var database = connection.Databases[databaseResource.Metadata.Name]; database.ExecuteNonQuery(script); }
private static string ChooseCollation(DatabaseResource item) { if (string.IsNullOrEmpty(item.Spec.Collation) || item.Spec.Collation.Equals("default", StringComparison.InvariantCultureIgnoreCase)) { return("SQL_Latin1_General_CP1_CI_AS"); } return(item.Spec.Collation); }
public void Dispose() { DatabaseResource databaseResource = Interlocked.Exchange(ref _databaseResource, null); if (null != databaseResource) { databaseResource.Release(_isTmp); } }
public void UpdateDatabaseStatus(DatabaseResource resource, string reason, string message, DateTimeOffset date) { resource.Status = new DatabaseStatus { LastUpdate = date, Reason = reason, Message = message }; UpdateStatus(resource); }
public IActionResult GetDatabases() { // Project a list of DatabaseResource objects this._context.SmoServer.Databases.Refresh(); List <DatabaseResource> resources = new List <DatabaseResource>(); foreach (SMO.Database smoDb in this._context.SmoServer.Databases) { var resource = new DatabaseResource(this._context, smoDb.Name, @Url); resources.Add(resource); } return(Ok(resources)); }
public void CreateDatabase(DatabaseServer serverResource, DatabaseResource item) { logger.LogDebug("Processing create for {database}", item.Metadata.Name); var serverConn = CreateServerConnection(serverResource); var database = new Database(serverConn, item.Metadata.Name) { Collation = ChooseCollation(item) }; foreach (var groupEntry in item.Spec.DataFiles) { var fileGroupName = groupEntry.Key; if (fileGroupName.ToLower() == "primary") { fileGroupName = "PRIMARY"; } var fileGroup = new FileGroup(database, fileGroupName); database.FileGroups.Add(fileGroup); var fileCount = groupEntry.Value.Count; foreach (var file in groupEntry.Value) { logger.LogDebug("Adding data file {FileGroup}/{FileName} ({FilePath})", groupEntry.Key, file.Name, file.Path); var datafile = new DataFile(fileGroup, file.Name, file.Path); if (fileGroupName == "PRIMARY") { // We mark the SMO file as primary if either the API object is set as primary or if there is only one file in the group // If there isn't a primary file set in a primary filegroup, you will get an error datafile.IsPrimaryFile = file.IsPrimaryFile || fileCount == 1; } fileGroup.Files.Add(datafile); } } foreach (var logEntry in item.Spec.LogFiles) { logger.LogDebug("Adding log file {FileName} ({FilePath})", logEntry.Name, logEntry.Path); database.LogFiles.Add(new LogFile(database, logEntry.Name, logEntry.Path)); } logger.LogInformation("Creating database {database} on server {server}", item.Metadata.Name, serverConn.Name); database.Create(); }
private readonly bool _isTmp; // We won't hang onto the global session factory if we know we're temporary private ProteomeDb(String path, CancellationToken cancellationToken, bool isTmp) { _schemaVersionMajor = -1; // unknown _schemaVersionMinor = -1; // unknown _schemaVersionMajorAsRead = -1; // unknown _schemaVersionMinorAsRead = -1; // unknown _isTmp = isTmp; if (!File.Exists(path)) { // Do not try to open the file if it does not exist, because that would create a zero byte file. throw new FileLoadException(String.Format(Resources.ProteomeDb_ProteomeDb_The_file__0__does_not_exist_, path)); } _databaseResource = DatabaseResource.GetDbResource(path); CancellationToken = cancellationToken; using (var session = OpenSession()) { // Is this even a proper protDB file? (https://skyline.gs.washington.edu/labkey/announcements/home/issues/exceptions/thread.view?rowId=14893) using (IDbCommand command = session.Connection.CreateCommand()) { command.CommandText = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name='ProteomeDbProteinName'"; // Not L10N var obj = command.ExecuteScalar(); if (Convert.ToInt32(obj) == 0) { throw new FileLoadException( String.Format(Resources.ProteomeDb_ProteomeDb__0__does_not_appear_to_be_a_valid___protDB__background_proteome_file_, path)); } } // Do we need to update the db to current version? ReadVersion(session); } if (_schemaVersionMajor != SCHEMA_VERSION_MAJOR_CURRENT) { throw new FileLoadException( String.Format(Resources.SessionFactoryFactory_EnsureVersion_Background_proteome_file__0__has_a_format_which_is_newer_than_the_current_software___Please_update_to_the_latest_software_version_and_try_again_, Path)); } else if (_schemaVersionMinor < SCHEMA_VERSION_MINOR_CURRENT) { using (var session = OpenWriteSession()) { UpdateSchema(session); } } }
public void MySQL_Factory_Should_Save_SQL_Attributes() { //Arrang string _infrastructureName = "Test"; string _providerPath = "path"; string instance = "example"; MySqlCharset charset = MySqlCharset.utf32; string collation = "collation1"; string userName = "******"; string password = "******"; var expectedObject = new DatabaseResource { Instance = instance, Collation = collation, Charset = charset.ToString(), UserName = userName, Password = password }; string subPath = string.Concat(_providerPath, @"\", _infrastructureName, @"\", "Database"); var fileSystemMock = new Mock <IFileManager>(); fileSystemMock.Setup(w => w.WriteJsonFile(It.IsAny <object>(), It.IsAny <string>(), It.IsAny <string>())) .Verifiable(); //Act new DatabaseFactory(_infrastructureName, _providerPath, fileSystemMock.Object) .MySQL(instance, charset, collation, userName, password);; //Assert fileSystemMock .Verify(mock => mock.WriteJsonFile(expectedObject, subPath, "Test_MySQL.json"), Times.Once()); }
public void RestoreDatabase(DatabaseServer serverResource, DatabaseResource resource) { var serverConn = CreateServerConnection(serverResource); var restore = new Restore(); var backupFile = resource.Spec.BackupFiles.FirstOrDefault(); restore.Devices.AddDevice(backupFile.Path, DeviceType.File); restore.Database = resource.Metadata.Name; restore.Action = RestoreActionType.Database; restore.ReplaceDatabase = true; var files = resource.Spec.DataFiles.SelectMany(kvp => kvp.Value).Union(resource.Spec.LogFiles); foreach (var file in files) { logger.LogDebug("Relocating file {fileName} to {filePath}", file.Name, file.Path); restore.RelocateFiles.Add(new RelocateFile(file.Name, file.Path)); } logger.LogInformation("Restoring database {database} to server {server}", resource.Metadata.Name, serverConn.Name); restore.SqlRestore(serverConn); }
public void Provider_Should_Create_SQL_Database_Infrastructure_Json_File() { //Arrang string instance = "example"; SqlCharset charset = SqlCharset.utf32; string collation = "collation1"; string userName = "******"; string password = "******"; var expectedObject = new DatabaseResource { Instance = instance, Collation = collation, Charset = charset.ToString(), UserName = userName, Password = password }; var fileSystemMock = new Mock <IFileManager>(); fileSystemMock.Setup(w => w.WriteJsonFile(It.IsAny <object>(), It.IsAny <string>(), It.IsAny <string>())) .Verifiable(); //Act var provider = new Providers.Provider(_providerName, fileSystemMock.Object); var infra = provider.CreateInfrastructure("UAT"); infra.Database().SQL(instance, charset, collation, userName, password);; //Assert fileSystemMock.Verify(mock => mock.WriteJsonFile(expectedObject, @"c:\test\UAT\Database", "UAT_SQL.json"), Times.Once()); }
private static Task <int> Main(string[] args) { var configJsonOption = new Option <FileInfo?>("--config", "The config.json file."); configJsonOption.AddAlias("-c"); var input = new Argument <FileInfo>("Input file", "File to be extracted."); var outFile = new Option <FileInfo>("--output", "Path to write output file."); outFile.AddAlias("-o"); var outDirectory = new Option <DirectoryInfo>("--outdir", () => new DirectoryInfo("."), "Directory to write output."); outDirectory.AddAlias("--output"); outDirectory.AddAlias("-o"); var outJson = new Option <FileInfo?>("--json", "Path to write json file."); var outYaml = new Option <FileInfo?>("--yaml", "Path to write yaml file."); var outBinary = new Option <FileInfo?>("--binary", "Path to write binary file."); var outLipsync = new Option <FileInfo?>("--lipsync", "Path to write lipsync file."); var outVtt = new Option <FileInfo>("--vtt", "Path to write vtt file."); outVtt.AddAlias("--output"); outVtt.AddAlias("-o"); var imageType = new Option <Unity3dResource.ImageFormat>("--type", () => Unity3dResource.ImageFormat.Webp, "The image type to extract."); imageType.AddAlias("-t"); var intermediateFiles = new Option <bool>("--keep-intermediate", () => false, "Keep intermediate wav files."); intermediateFiles.AddAlias("-k"); var stepOption = new Option <bool>("--step", () => false, "Only check next version."); stepOption.AddAlias("-s"); var proxyOption = new Option <string?>("--proxy", "Proxy server to use."); var resourceVersion = new Command("resver", "Fetch latest resource version.") { configJsonOption, stepOption, proxyOption }; resourceVersion.SetHandler( (FileInfo? config, bool step, string?proxy) => GuessTruthVersion(config, step, proxy), configJsonOption, stepOption, proxyOption); var bundleVersion = new Command("bdlver", "Fetch latest bundle version.") { configJsonOption, stepOption, proxyOption }; bundleVersion.SetHandler( (FileInfo? config, bool step, string?proxy) => GuessBundleVersion(config, step, proxy), configJsonOption, stepOption, proxyOption); var fetch = new Command("fetch", "Fetch latest assets files.") { configJsonOption, outDirectory, stepOption, proxyOption, resourceVersion, bundleVersion }; fetch.SetHandler( (FileInfo? config, DirectoryInfo output, bool step, string?proxy) => DownloadManifests(config, output.FullName, step, proxy), configJsonOption, outDirectory, stepOption, proxyOption); var database = new Command("database", "Extract database file from unity3d.") { input, outFile }; database.SetHandler((FileInfo source, FileInfo dest) => DatabaseResource.ExtractMasterData(source, dest), input, outFile); var storyData = new Command("storydata", "Extract story data from unity3d.") { input, outJson, outYaml, outBinary, outLipsync }; storyData.SetHandler( (FileInfo source, FileInfo? json, FileInfo? yaml, FileInfo? binary, FileInfo? lipsync) => StoryResource.ExtractStoryData(source, json, yaml, binary, lipsync), input, outJson, outYaml, outBinary, outLipsync); var constText = new Command("consttext", "Extract const text from unity3d.") { input, outJson, outYaml }; constText.SetHandler((FileInfo source, FileInfo? json, FileInfo? yaml) => ConstTextResource.ExtractConstText(source, json, yaml), input, outJson, outYaml); var usm = new Command("usm", "Extract videos from usm.") { input, outDirectory, intermediateFiles }; usm.SetHandler( (FileInfo source, DirectoryInfo output, bool keepWav) => CriResource.ExtractUsmFinal(source, output, keepWav), input, outDirectory, intermediateFiles); var hca = new Command("hca", "Extract musics from hca.") { input, outFile }; hca.SetHandler((FileInfo source, FileInfo dest) => Audio.HcaToWav(source, dest), input, outFile); var adx = new Command("adx", "Extract musics from adx.") { input, outFile }; adx.SetHandler((FileInfo source, FileInfo dest) => Audio.AdxToWav(source, dest), input, outFile); var acb = new Command("acb", "Extract musics from acb.") { input, outDirectory }; acb.SetHandler((FileInfo source, DirectoryInfo output) => Audio.ExtractAcbCommand(source, output), input, outDirectory); var u3d = new Command("unity3d", "Extract all things in unity3d file.") { input, outDirectory, imageType }; u3d.SetHandler((FileInfo source, DirectoryInfo output, Unity3dResource.ImageFormat type) => Unity3dResource.ExtractUnity3dCommand(source, output, type), input, outDirectory, imageType); // TODO: do extract vtt according to MonoBehaviour var vtt = new Command("vtt", "Extract vtt from unity3d asset.") { input, outVtt }; vtt.SetHandler((FileInfo source, FileInfo dest) => VttResource.ExtractVtt(source, dest), input, outVtt); var extract = new Command("extract") { database, storyData, constText, usm, hca, adx, acb, u3d, vtt }; var rootCommand = new RootCommand("Redive Extractor\n" + "Download and extract assets from game Princess Connect! Re:Dive.") { fetch, extract }; return(rootCommand.InvokeAsync(args)); }
private static void Main(string[] args) { var rootCommand = new RootCommand("Redive Extractor\n" + "Download and extract assets from game Princess Connect! Re:Dive."); var configJsonOption = new Option <FileInfo>("--config", "The config.json file."); configJsonOption.AddAlias("-c"); var input = new Argument <FileInfo>("Input file", "File to be extracted."); var outFile = new Option <FileInfo>("--output", "Path to write output file."); outFile.AddAlias("-o"); var outDirectory = new Option <DirectoryInfo>("--outdir", () => new DirectoryInfo("."), "Directory to write output."); outDirectory.AddAlias("--output"); outDirectory.AddAlias("-o"); var outJson = new Option <FileInfo?>("--json", "Path to write json file."); var outYaml = new Option <FileInfo?>("--yaml", "Path to write yaml file."); var outBinary = new Option <FileInfo?>("--binary", "Path to write binary file."); var outLipsync = new Option <FileInfo?>("--lipsync", "Path to write lipsync file."); var outVtt = new Option <FileInfo>("--vtt", "Path to write vtt file."); outVtt.AddAlias("--output"); outVtt.AddAlias("-o"); var imageType = new Option <Unity3dResource.ImageFormat>("--type", () => Unity3dResource.ImageFormat.Webp, "The image type to extract."); imageType.AddAlias("-t"); var intermediateFiles = new Option <bool>("--keep-intermediate", () => false, "Keep intermediate wav files."); intermediateFiles.AddAlias("-k"); var fetch = new Command("fetch", "Fetch latest assets files.") { configJsonOption, outDirectory, }; fetch.SetHandler((FileInfo config, DirectoryInfo output) => DownloadManifests(config, output.FullName), configJsonOption, outDirectory); rootCommand.Add(fetch); var extract = new Command("extract"); var database = new Command("database", "Extract database file from unity3d.") { input, outFile }; database.SetHandler((FileInfo source, FileInfo dest) => DatabaseResource.ExtractMasterData(source, dest), input, outFile); extract.Add(database); var storyData = new Command("storydata", "Extract story data from unity3d.") { input, outJson, outYaml, outBinary, outLipsync }; storyData.SetHandler( (FileInfo source, FileInfo? json, FileInfo? yaml, FileInfo? binary, FileInfo? lipsync) => StoryResource.ExtractStoryData(source, json, yaml, binary, lipsync), input, outJson, outYaml, outBinary, outLipsync); extract.Add(storyData); var constText = new Command("consttext", "Extract const text from unity3d.") { input, outJson, outYaml }; constText.SetHandler((FileInfo source, FileInfo? json, FileInfo? yaml) => ConstTextResource.ExtractConstText(source, json, yaml), input, outJson, outYaml); extract.Add(constText); var usm = new Command("usm", "Extract videos from usm.") { input, outDirectory, intermediateFiles }; usm.SetHandler( (FileInfo source, DirectoryInfo output, bool keepWav) => CriResource.ExtractUsmFinal(source, output, keepWav), input, outDirectory, intermediateFiles); extract.Add(usm); var hca = new Command("hca", "Extract musics from hca.") { input, outFile }; hca.SetHandler((FileInfo source, FileInfo dest) => Audio.HcaToWav(source, dest), input, outFile); extract.Add(hca); var adx = new Command("adx", "Extract musics from adx.") { input, outFile }; adx.SetHandler((FileInfo source, FileInfo dest) => Audio.AdxToWav(source, dest), input, outFile); extract.Add(adx); var acb = new Command("acb", "Extract musics from acb.") { input, outDirectory }; acb.SetHandler((FileInfo source, DirectoryInfo output) => Audio.ExtractAcbCommand(source, output), input, outDirectory); extract.Add(acb); var u3d = new Command("unity3d", "Extract all things in unity3d file.") { input, outDirectory, imageType }; u3d.SetHandler((FileInfo source, DirectoryInfo output, Unity3dResource.ImageFormat type) => Unity3dResource.ExtractUnity3dCommand(source, output, type), input, outDirectory, imageType); extract.Add(u3d); // TODO: do extract vtt according to MonoBehaviour var vtt = new Command("vtt", "Extract vtt from unity3d asset.") { input, outVtt }; // vtt.Handler = // CommandHandler.Create<FileInfo, FileInfo>(Vtt.ExtractVtt); vtt.SetHandler((FileInfo source, FileInfo dest) => VttResource.ExtractVtt(source, dest), input, outVtt); extract.Add(vtt); rootCommand.Add(extract); rootCommand.InvokeAsync(args).Wait(); }