Skip to content

Instantly share code, notes, and snippets.

@duangsuse
Created August 21, 2017 20:25
Show Gist options
  • Save duangsuse/ec86e7302dfe36261f3cf207cdb27434 to your computer and use it in GitHub Desktop.
Save duangsuse/ec86e7302dfe36261f3cf207cdb27434 to your computer and use it in GitHub Desktop.
GUIDAuto low B Source Code
using System;
using static System.IO.File;
using System.Text.RegularExpressions;
namespace guid_auto {
class MainClass {
const string DB_FILENAME = "database.xml";
const string REPLACE_TEXT = "{}";
public static void Main(string[] args) {
if (args.Length >= 1) {
println("警告: 程序不会解析命令行参数!");
}
if (System.IO.File.Exists(DB_FILENAME)) {
println("找到库文件, 开始读取...");
string file_content = System.IO.File.ReadAllText(DB_FILENAME);
println("完成读取, 正在处理...(替换'{}' 为随机生成的GUID)");
string content_processed = Regex.
Replace(file_content, REPLACE_TEXT, gen_guid_str);
println("处理完成, 写入文件...");
System.IO.File.WriteAllText(DB_FILENAME, content_processed);
} else {
println("请把此程序放在" + DB_FILENAME + "的同级目录下.");
}
}
static string gen_guid_str(Match match) {
Guid guid = Guid.NewGuid();
println("正在生成GUID " + guid + " ...");
return guid.ToString();
}
static void println(string msg) {
Console.WriteLine(msg);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment