Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from SqlQuantumLeap/Save-To-Clipboard
Save to clipboard
- Loading branch information
Showing
20 changed files
with
650 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,3 +301,4 @@ $RECYCLE.BIN/ | |
|
||
# Windows shortcuts | ||
*.lnk | ||
BinaryFormatter/Tests/SampleBinary.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
* BinaryFormatter | ||
* Version 2.0 | ||
* Copyright (c) 2009-2017 Solomon Rutzky. All rights reserved. | ||
* | ||
* Location: https://github.com/SqlQuantumLeap/BinaryFormatter | ||
* | ||
* Blog: https://SqlQuantumLeap.com/ | ||
* | ||
*/ | ||
using System; | ||
using System.IO; | ||
|
||
namespace SqlQuantumLeap.BinaryFormatter | ||
{ | ||
internal class Configuration | ||
{ | ||
private int _ChunkSize = 10000; | ||
private bool _ChunkSizeIsCustom = false; | ||
private string _FilePath = String.Empty; | ||
private string _OutFile = String.Empty; | ||
private bool _SaveToClipboard = false; | ||
private bool _SendToConsole = false; | ||
private bool _NoOutputFile = false; | ||
|
||
|
||
public int ChunkSize | ||
{ | ||
get | ||
{ | ||
return _ChunkSize; | ||
} | ||
} | ||
public bool ChunkSizeIsCustom | ||
{ | ||
get | ||
{ | ||
return _ChunkSizeIsCustom; | ||
} | ||
} | ||
public string FilePath | ||
{ | ||
get | ||
{ | ||
return _FilePath; | ||
} | ||
} | ||
public string OutFile | ||
{ | ||
get | ||
{ | ||
return _OutFile; | ||
} | ||
} | ||
public bool SaveToClipboard | ||
{ | ||
get | ||
{ | ||
return _SaveToClipboard; | ||
} | ||
} | ||
public bool SendToConsole | ||
{ | ||
get | ||
{ | ||
return _SendToConsole; | ||
} | ||
} | ||
public bool NoOutputFile | ||
{ | ||
get | ||
{ | ||
return _NoOutputFile; | ||
} | ||
} | ||
|
||
|
||
public Configuration(string[] InputParameters) | ||
{ | ||
foreach (string _Arg in InputParameters) | ||
{ | ||
int _TempSize; | ||
|
||
if (!_ChunkSizeIsCustom // Skip test if already found | ||
&& int.TryParse(_Arg, out _TempSize)) | ||
{ | ||
_ChunkSize = _TempSize; | ||
_ChunkSizeIsCustom = true; | ||
} | ||
else | ||
{ | ||
switch (_Arg.ToUpperInvariant()) | ||
{ | ||
case "-CLIPBOARD": | ||
case "/CLIPBOARD": | ||
_SaveToClipboard = true; | ||
break; | ||
|
||
case "-CONSOLE": | ||
case "/CONSOLE": | ||
_SendToConsole = true; | ||
break; | ||
|
||
case "-NOFILE": | ||
case "/NOFILE": | ||
_NoOutputFile = true; | ||
break; | ||
|
||
default: | ||
if (_FilePath == String.Empty) | ||
{ | ||
_FilePath = _Arg; | ||
} | ||
else if (_OutFile == String.Empty) | ||
{ | ||
_OutFile = _Arg; | ||
} | ||
break; | ||
} /* switch() */ | ||
} /* if (!_ChunkSizeIsCustom... */ | ||
} /* foreach(string _Arg... */ | ||
|
||
|
||
if (_FilePath == String.Empty) | ||
{ | ||
throw new ArgumentNullException("You must specify a source file."); | ||
} | ||
|
||
|
||
// Set default output file name | ||
if (!_NoOutputFile // Skip if user requested no output file | ||
&& _OutFile == String.Empty) | ||
{ | ||
_OutFile = Path.GetDirectoryName(_FilePath) + @"\" + | ||
Path.GetFileNameWithoutExtension(_FilePath) + @".sql"; | ||
} | ||
|
||
|
||
if (!_ChunkSizeIsCustom) | ||
{ | ||
string _CustomChunkSizeString; | ||
int _CustomChunkSizeInt; | ||
bool _GotValidAnswer = false; | ||
|
||
while (!_GotValidAnswer) | ||
{ | ||
Console.Write("Chunk Size [ {0} ]: ", _ChunkSize); | ||
_CustomChunkSizeString = Console.ReadLine(); | ||
if (String.IsNullOrWhiteSpace(_CustomChunkSizeString)) | ||
{ | ||
_GotValidAnswer = true; | ||
} | ||
else | ||
{ | ||
if (int.TryParse(_CustomChunkSizeString, out _CustomChunkSizeInt)) | ||
{ | ||
if (_CustomChunkSizeInt > 0) | ||
{ | ||
_GotValidAnswer = true; | ||
_ChunkSize = _CustomChunkSizeInt; | ||
_ChunkSizeIsCustom = true; // not used below, but don't leave in inconsistent state | ||
} | ||
else | ||
{ | ||
Display.Error("ChunkSize must be > 0."); | ||
} | ||
} | ||
else | ||
{ | ||
Display.Error("ChunkSize must be a number."); | ||
} | ||
} /* if (String.IsNullOrWhiteSpace(_CustomChunkSizeString)) ... else */ | ||
} /* while (!_GotValidAnswer) */ | ||
} /* if (!_ChunkSizeIsCustom) */ | ||
|
||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* BinaryFormatter | ||
* Version 2.0 | ||
* Copyright (c) 2009-2017 Solomon Rutzky. All rights reserved. | ||
* | ||
* Location: https://github.com/SqlQuantumLeap/BinaryFormatter | ||
* | ||
* Blog: https://SqlQuantumLeap.com/ | ||
* | ||
*/ | ||
using System; | ||
|
||
namespace SqlQuantumLeap.BinaryFormatter | ||
{ | ||
internal class Display | ||
{ | ||
internal static void Usage() | ||
{ | ||
Console.WriteLine("\nBinaryFormatter"); | ||
Console.WriteLine("Version {0}", | ||
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(2)); | ||
Console.WriteLine("Copyright (c) 2009-2017 Solomon Rutzky. All rights reserved."); | ||
Console.WriteLine("https://SqlQuantumLeap.com/\n"); | ||
|
||
Console.WriteLine("Format binary file into hex string for SQL script."); | ||
Console.WriteLine("Output broken into multiple lines of \"ChunkSize\" bytes."); | ||
Console.WriteLine("If there are multiple lines, all lines except the final"); | ||
Console.WriteLine("line are appended with the line-continuation character of: \\"); | ||
|
||
Console.Write("\nUsage:"); | ||
Console.WriteLine("\tBinaryFormatter [ /? | /help ]"); | ||
Console.WriteLine("\n\tDisplay this help info"); | ||
|
||
Console.Write("\nUsage:"); | ||
Console.WriteLine("\tBinaryFormatter path\\to\\binary_file.ext [path\\to\\OutputFile.sql] [ChunkSize]"); | ||
Console.WriteLine("\t\t[ /Clipboard ] [ /Console ] [ /NoFile ]\n"); | ||
Console.WriteLine("\tChunkSize = the number of bytes per row. A byte is 2 characters: 00 - FF."); | ||
Console.WriteLine("\t/Clipboard = Copy output to clipboard (to then paste with Control-V)"); | ||
Console.WriteLine("\t/Console = Send output to console"); | ||
Console.WriteLine("\t/NoFile = Do not save to file, even if specified"); | ||
Console.WriteLine(""); | ||
|
||
Console.WriteLine("\tDefault ChunkSize = 10000"); | ||
Console.WriteLine("\tDefault OutputFile = {path\\to\\binary_file_name}.sql"); | ||
Console.WriteLine("\tMaximum line length = (ChunkSize * 2) + 1."); | ||
|
||
Console.WriteLine("\nVisit https://SqlQuantumLeap.com/ for other useful utilities and more."); | ||
|
||
return; | ||
} | ||
|
||
internal static void Error(string ErrorMessage) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine(ErrorMessage); | ||
Console.ResetColor(); | ||
|
||
return; | ||
} | ||
} | ||
} |
Oops, something went wrong.