public static IBatchable Create_Display(Input item, ev.Environment env) { IGetter <string> src; ISetter <string> dst; string hdr = null; Arg asrc, adst, ahdr; if (!item.TrySet(out asrc, 1)) { throw new ArgumentException("Первый аргумент, который должен быть переменной отсутствует"); } if (!item.TrySet(out adst, 2)) { throw new ArgumentException("Второй аргумент, который должен описывать способ отображения, отуствует"); } if (item.TrySet(out ahdr, 3, "header")) { hdr = item.GetGetter_STR(env, ref ahdr).Get(); } if (asrc.IsVariable) { src = env.GetGetter <string>(asrc.Value); } else if (asrc.Value == lg.KwAsk) { src = new GetterAskConsole(STR_ASKTEXT); } else { src = new GetterValue <string>() { Value = asrc.Value } }; if (adst.IsVariable) { dst = env[adst.Value].Value as ISetter <string>; } else { throw new ArgumentException("Второй аргумент должен быть переменной"); } if (dst == null) { throw new InvalidCastException("Неизвестный способ отображения"); } return(new CmdTransfer <string>(src, dst) { Text = hdr }); }
public override IBatchable Create(Input item) { string fil = null; bool onc = false, ask = false; if (!item.TrySet(ref fil, 1, "file")) { throw new ArgumentException("Codesource file not specified"); } if (string.IsNullOrEmpty(fil)) { return(null); } item.TrySet(ref onc, 2, "once"); ask = fil == Language.KwAsk; // we will ask the user for a command if he has input word ASK instead of a filename onc = onc && !ask; // we do not use once-mode when asking IGetter <string> gcmd = null; if (ask) { gcmd = new GetterAskConsole("Какой файл запустить:"); gcmd = new GetterTextFile(gcmd); } else { gcmd = new GetterTextFile(fil); } var itm = new bch_file(this, gcmd); if (onc) { itm.Filepath = fil; // this will make once-mode work } return(itm); }
static void Main(string[] args) { var cor = Program.Core; var dsp = cor.Display; var env = cor.Environment; Console.WriteLine(); cor.BusConsole = new mg.BusConsole(dsp); cor.BusMsg = new mg.BusMsgBox(dsp) { Header = "TEO-Application" }; dsp.Write("Program initialized", mg.TMessage.CommandResult); var prs = new APP.Commanding.Parser(env); var prc = new Processor(env) { Display = dsp }; var ask = new GetterAskConsole("app") { Display = dsp }; var earg = args.Where(x => x.Length > 1 && x.StartsWith("/")); var ecmd = args.Where(x => x.Length > 1 && x.StartsWith("-")); var efil = cor.GetMacros("ini"); #if DEBUG efil = efil.Concat(cor.GetMacros("debug")); #endif efil = efil.Concat(args.Except(earg).Except(ecmd)); earg = earg.Select(x => x.Substring(1)); ecmd = ecmd.Select(x => x.Substring(1)); cor.GetConfigurator(earg).Configure(); var enm = ecmd.GetEnumerator(); while (enm.MoveNext()) { process_cmd(enm.Current); } enm = efil.GetEnumerator(); while (enm.MoveNext()) { process_fil(enm.Current); } while (Program.Continue) { try { Console.WriteLine(); var cmd = prs.Parse(ask); prc.Execute(cmd); } catch (OperationCanceledException) { // dsp.Write("..", mg.TMessage.CommandHeader); } catch (ExceptionRuntime ex) { dsp.Write(ex, ex.IsCritical ? mg.TMessage.ExceptionWorkflow : mg.TMessage.Warning); } catch (Exception ex) { dsp.Write(ex, mg.TMessage.ExceptionCritical); } } void process_cmd(string arg) { throw new NotImplementedException("Processing command-arguments not yet implemented"); } void process_fil(string file) { dsp.Write(file, mg.TMessage.CommandHeader); IBatch bch = null; try { bch = prs.Parse(cor.GFileContent_TXT(file), description: file); } catch (Exception ex) { dsp.Write(ex, position: "Batch-parsing"); return; } prc.Execute(bch); } }