public void Handle(IConsoleAdapter console, IErrorAdapter error) { //Connect to the local, default instance of SQL Server. var srv = new Server(Server); ReportDatabases(console, srv); var db = srv.Databases.Enumerate().SingleOrDefault(d => d.Name == Database); if (db != null) { if (!Replace && !console.Confirm($"Drop {Database.Yellow()}?".Cyan())) { error.WrapLine($"Database {Database.Yellow()} already exists. Specify -r to replace it.".Red()); Environment.ExitCode = -100; return; } console.WrapLine($"Dropping {Database.Yellow()}".Cyan()); db.Drop(); } console.WrapLine($"Creating {Database.Yellow()}".Cyan()); var database = new Database(srv, Database); database.Create(); var connectionString = $"Server={Server};Database={Database};Trusted_Connection=True;"; var upgradeCommand = UpgradeDb(console, error, connectionString); if (!NoConfig) { GenerateTestingConfig(console, error, connectionString); } }
public void Handler(IConsoleAdapter console, IErrorAdapter error) { if (!Silent) { if (!File.Exists(InputFile)) { console.WrapLine("Input map file does not exist...".Red()); return; } if (File.Exists($"{OutputFile}.N2SMAP")) { if (!console.Confirm("Output file exists... Would you like to overwrite it?".Red())) { return; } } } string jsonText; if (Xml) { console.WrapLine("Loading map from XML..."); var doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(InputFile)); jsonText = JsonConvert.SerializeXmlNode(doc.FirstChild); } else { console.WrapLine("Loading map from JSON..."); jsonText = File.ReadAllText(InputFile); } var deserialized = JsonConvert.DeserializeObject <MapT>(jsonText); deserialized.GameVersion += ":N2SMap_Viewer"; var fb = new FlatBufferBuilder(1); console.WrapLine("Packing map..."); fb.Finish(N2S.FileFormat.Map.Pack(fb, deserialized).Value); var buf = fb.SizedByteArray(); using (var outputStream = new MemoryStream()) { //Here we're compressing the data to make it smaller console.WrapLine("Compressing map..."); using (var gZipStream = new GZipStream(outputStream, CompressionMode.Compress)) gZipStream.Write(buf, 0, buf.Length); //Writing compressed data to a file console.WrapLine("Writing map to file..."); File.WriteAllBytes(OutputFile + ".N2SMAP", outputStream.ToArray()); } console.WrapLine($"Complete! File written to {OutputFile}.N2SMAP"); }
public void Handler(IConsoleAdapter console, IErrorAdapter error) { if (!Silent) { if (!File.Exists(InputFile)) { console.WrapLine("Input map file does not exist...".Red()); return; } if (File.Exists($"{OutputFile}.xml") && Xml) { if (!console.Confirm("Output file exists... Would you like to overwrite it?".Red())) { return; } } else if (File.Exists($"{OutputFile}.json") && !Xml) { if (!console.Confirm("Output file exists... Would you like to overwrite it?".Red())) { return; } } } console.WrapLine("Reading map file..."); var bytes = File.ReadAllBytes(InputFile); console.WrapLine("Decompressing map..."); byte[] lengthBuffer = new byte[4]; Array.Copy(bytes, bytes.Length - 4, lengthBuffer, 0, 4); int uncompressedSize = BitConverter.ToInt32(lengthBuffer, 0); var buffer = new byte[uncompressedSize]; using (var ms = new MemoryStream(bytes)) { using (var gzip = new GZipStream(ms, CompressionMode.Decompress)) { gzip.Read(buffer, 0, uncompressedSize); } } ByteBuffer bb = new ByteBuffer(buffer); if (!N2S.FileFormat.Map.MapBufferHasIdentifier(bb)) { if (!console.Confirm( "The input map might be corrupted or not be in the correct format, would you like to continue?" .Red())) { return; } } console.WrapLine("Unpacking map..."); var data = N2S.FileFormat.Map.GetRootAsMap(bb).UnPack(); console.WrapLine("Serialized into JSON..."); string output = JsonConvert.SerializeObject(data, Formatting.Indented); if (Xml) { console.WrapLine("Converting into XML"); XmlDocument xmlDocument = (XmlDocument)JsonConvert.DeserializeXmlNode(output, "Map"); xmlDocument.Save($"{OutputFile}.xml"); console.WrapLine($"Complete! File written to {OutputFile}.xml"); } else { File.WriteAllText($"{OutputFile}.json", output); console.WrapLine($"Complete! File written to {OutputFile}.json"); } }