本文整理汇总了C#中StringScanner.Scan方法的典型用法代码示例。如果您正苦于以下问题:C# StringScanner.Scan方法的具体用法?C# StringScanner.Scan怎么用?C# StringScanner.Scan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringScanner
的用法示例。
在下文中一共展示了StringScanner.Scan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(ref IShellEngine engine, StringScanner s, Display display, InputCommand input)
{
if (engine == null) throw ShellExpcetion.NoDatabase();
var direction = s.Scan(@"[><]\s*").Trim();
var filename = s.Scan(@".+").Trim();
//dump import
if(direction == "<")
{
using (var reader = new StreamReader(filename, Encoding.UTF8))
{
string line;
while ((line = reader.ReadLine()) != null)
{
engine.Run(line, new Display()); // no output
}
}
}
// dump export
else
{
using (var writer = new StreamWriter(filename, false, Encoding.UTF8, 65536))
{
writer.AutoFlush = true;
writer.WriteLine("-- LiteDB v{0}.{1}.{2} dump file @ {3}",
engine.Version.Major, engine.Version.Minor, engine.Version.Build,
DateTime.Now);
engine.Dump(writer);
writer.Flush();
}
}
}
示例2: GetCode
public static Action<object, BsonDocument, LiteCollection<BsonDocument>, LiteDatabase> GetCode(StringScanner s)
{
var str = s.Scan(@"[\s\S]*");
var code = CODE_TEMPLATE.Replace("[code]", str);
var provider = new CSharpCodeProvider();
var parameters = new CompilerParameters();
parameters.ReferencedAssemblies.Add("LiteDB.dll");
parameters.GenerateInMemory = true;
parameters.GenerateExecutable = false;
var results = provider.CompileAssemblyFromSource(parameters, code);
if (results.Errors.HasErrors)
{
var err = new StringBuilder();
foreach (CompilerError error in results.Errors)
{
err.AppendLine(String.Format("Error ({0}): {1}", error.ErrorNumber, error.ErrorText));
}
throw new InvalidOperationException(err.ToString().Trim());
}
var assembly = results.CompiledAssembly;
var program = assembly.GetType("Program");
var method = program.GetMethod("DoWork");
return new Action<object, BsonDocument, LiteCollection<BsonDocument>, LiteDatabase>((id, doc, col, db) =>
{
method.Invoke(null, new object[] { id, doc, col, db });
});
}
示例3: Execute
public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
{
var col = this.ReadCollection(engine, s);
var index = s.Scan(this.FieldPattern).Trim();
display.WriteResult(engine.Max(col, index.Length == 0 ? "_id" : index));
}
示例4: Execute
public BsonValue Execute(DbEngine engine, StringScanner s)
{
var col = this.ReadCollection(engine, s);
var newName = s.Scan(@"[\w-]+").ThrowIfEmpty("Invalid new collection name");
return engine.RenameCollection(col, newName);
}
示例5: Execute
public BsonValue Execute(DbEngine engine, StringScanner s)
{
var col = this.ReadCollection(engine, s);
var index = s.Scan(this.FieldPattern).Trim();
return engine.Min(col, index.Length == 0 ? "_id" : index);
}
示例6: Execute
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
if(s.Scan("false|off").Length > 0 && _writer != null)
{
display.TextWriters.Remove(_writer);
input.OnWrite = null;
_writer.Flush();
_writer.Dispose();
_writer = null;
}
else if(_writer == null)
{
if (shell.Database == null) throw LiteException.NoDatabase();
var dbfilename = shell.Database.ConnectionString.Filename;
var path = Path.Combine(Path.GetDirectoryName(dbfilename),
string.Format("{0}-spool-{1:yyyy-MM-dd-HH-mm}.txt", Path.GetFileNameWithoutExtension(dbfilename), DateTime.Now));
_writer = File.CreateText(path);
display.TextWriters.Add(_writer);
input.OnWrite = (t) => _writer.Write(t);
}
}
示例7: Execute
public BsonValue Execute(LiteDatabase db, StringScanner s)
{
var col = this.ReadCollection(db, s);
var index = s.Scan(this.FieldPattern).Trim();
return col.Max(index.Length == 0 ? "_id" : index);
}
示例8: Execute
public void Execute(LiteEngine engine, StringScanner s, Display display, InputCommand input, Env env)
{
var col = this.ReadCollection(engine, s);
var newName = s.Scan(@"[\w-]+").ThrowIfEmpty("Invalid new collection name");
display.WriteResult(engine.RenameCollection(col, newName));
}
示例9: Execute
public BsonValue Execute(LiteDatabase db, StringScanner s)
{
var col = this.ReadCollection(db, s);
var newName = s.Scan(@"[\w-]+");
return db.RenameCollection(col.Name, newName);
}
示例10: Execute
public void Execute(LiteEngine engine, StringScanner s, Display d, InputCommand input, Env env)
{
var sb = new StringBuilder();
var enabled = !(s.Scan(@"off\s*").Length > 0);
env.Log.Level = enabled ? Logger.FULL : Logger.NONE;
}
示例11: Execute
public override void Execute(ref LiteDatabase db, StringScanner s, Display d, InputCommand input)
{
var sb = new StringBuilder();
var enabled = !(s.Scan(@"off\s*").Length > 0);
db.Log.Level = enabled ? Logger.FULL : Logger.NONE;
}
示例12: Execute
public override void Execute(ref IShellEngine engine, StringScanner s, Display d, InputCommand input)
{
var sb = new StringBuilder();
var enabled = !(s.Scan(@"off\s*").Length > 0);
if(engine == null) throw ShellExpcetion.NoDatabase();
engine.Debug(enabled);
}
示例13: Execute
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
var filename = s.Scan(@".+").Trim();
foreach (var line in File.ReadAllLines(filename))
{
input.Queue.Enqueue(line);
}
}
示例14: Execute
public override void Execute(LiteShell shell, StringScanner s, Display display, InputCommand input)
{
var filename = s.Scan(@".+");
if (shell.Database != null)
{
shell.Database.Dispose();
}
shell.Database = new LiteDatabase(filename);
}
示例15: Execute
public override void Execute(ref LiteDatabase db, StringScanner s, Display display, InputCommand input)
{
var filename = s.Scan(@".+");
if (db != null)
{
db.Dispose();
}
db = new LiteDatabase(filename);
}