//Command Handler public void ExecuteCommand(CommandConsole c, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed) { ArgClass existRef = null; if (this._argName != "") { // existRef = (from ArgClass r in c._argRefs // where (r is Reference) && r.FullName == this.FullName // select r).ToList<ArgClass>(); existRef = c.GetReference(this); } var existClass = (from ArgClass r in c._argRefs where !(r is Reference) && r.FullName == "" + this.Prefix select r).FirstOrDefault(); bool hasParenths = this._suffix != null && this._suffix[this._suffix.Length - 1] == ')', stdOut = false, stdEx = false; bool hasFunction = false; if (this.ArgName != null) hasFunction = this.Parent._funcs.ContainsKey(this.ArgName); List<ArgClass> refChain = new List<ArgClass> { this }; if (this._dotHierarchy.Length > 1) refChain = existClass.GetReferenceChain(this._dotHierarchy, this._dotHierarchy[this._dotHierarchy.Length - 1]); //ArgClass rf, fnc; //this.GetObjectFunction(this, refChain, out rf, out fnc); //if (hasFunction && (rf == null || fnc == null)) // return; Reference er = null; if (existRef != null && existRef is Reference) er = (Reference)existRef; if (hasParenths) { //////////////////// if (existRef == null && !hasFunction) { bool? cnstrct = this.AttemptConstruct(c, er, retArgs, swtchs, outputFeed); if (cnstrct.HasValue && cnstrct.Value) { if (existRef == null) { c.AddReference(this); outputFeed.Add("'" + this.FullName + "' was constructed."); return; } } else { //if (!cnstrct.HasValue) outputFeed.Add("'" + this.FullName + "' was unable to be constructed."); return; } } ////////////////////////// bool? b = null; if (!hasFunction) b = this.ExecuteCall(c, er, retArgs, swtchs, outputFeed); else b = this._parRef._funcs[this._argName](c, this, retArgs, swtchs, outputFeed); stdEx = b.HasValue && b.Value; if (!stdEx) return; } //Handle no class if (existClass == null) return; if (!stdEx && this._argName == null) { outputFeed.Add("'" + this.FullName + "' is a type."); return; } //Handleno reference if (!stdEx && (existClass == null || existRef == null)) { if (!hasFunction) outputFeed.Add("'" + this.FullName + "' is null."); else outputFeed.Add("'" + this.FullName + "' must be called with ()."); return; } else if (!stdEx) stdOut = true; //Standard output from object if (stdOut || stdEx) { if (stdOut) { var o = this.StandardOutput; if (o != null && o != "") outputFeed.Add(o); else outputFeed.Add("'" + this.FullName + "' is instantiated."); } if (stdEx) outputFeed.Add("'" + this.FullName + "' was called."); return; } return; }
//Functions public override bool? ExecuteCall(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed) { return false; }
public virtual bool? AttemptConstruct(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] sws, List<string> outputFeed) { return false; }
public Reference HandleCommand(CommandConsole c, ReturnArgs args, string req, List<string> outputFeed) { if (req == null || c == null || req.Length == 0) return null; //Vars string[] dotArgs; string argName = null, suffix = null, dblprfx = null; int sindent = 0, pindent = 0; //Get Prefix //var prfxArg = (from LineArgumentHandler la in c._argTypes // where la.Prefix == req[0] // select la).FirstOrDefault(); if (this._prefix.HasValue && this._prefix.Value != req[0]) return null; if (this._prefix.HasValue) pindent++; //Get Double prefix if (req.Length > 2) { dblprfx = ArgClass.GetDoublePrefix(req.Substring(pindent, 2)); if (dblprfx != null) pindent += 2; } //Suffix if (req.Length >= pindent + 2) { int ind1 = req.IndexOf(@"("); if (ind1 != -1) { int ind2 = req.IndexOf(@")", ind1); if (ind1 != -1 && ind2 != -1) suffix = ArgClass.GetSuffix(req.Substring(ind1, (ind2 - ind1) + 1)); } } if (suffix != null) sindent += suffix.Length; //Get next invalid char, if same as indented, then int invChar = ArgClass.GetInvalidCharIndex(pindent, req, ".", true); if (invChar == pindent && invChar < req.Length - sindent) return null; //Get Dot Hiearchy and final argument string ss = req.Substring(pindent, req.Length - sindent - pindent), ss2 = null; if (this._prefix.HasValue) ss2 = this._prefix.Value + "." + ss; dotArgs = ss2.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (dotArgs.Length > 1) argName = dotArgs[dotArgs.Length - 1]; if (argName != null) { int i = ArgClass.GetInvalidCharIndex(argName); if (i != -1) { outputFeed.Add("'" + argName[i] + "' is an invalid character."); return null; } } ArgClass par = this; if (argName != null && argName != "") { var ch1 = this.GetReferenceChain(dotArgs, dotArgs[dotArgs.Length - 2]); if (ch1 == null) { outputFeed.Add("'" + ss + "' is null or invalid."); return null; } var ch2 = ch1[ch1.Count - 1]; par = ch2; } //Get boolean states //bool refsObj = return this.CreateNewReference(par, dotArgs, argName, dblprfx, suffix); }
//Functions public virtual bool? ExecuteCall(CommandConsole c, Reference existRef, ReturnArgs retArgs, string[] swtchs, List<string> outputFeed) { outputFeed.Add("'" + this.FullName + "' was called."); return false; }
//Functions protected override List<string> _HandleCustomCommand(string req) { var reqs = req.Split(' '); var refStack = new List<ArgClass>(); var r = new List<string>(); for (int i = 0; i < reqs.Length; i++) reqs[i].Trim(); var retArgs = new ReturnArgs(); for (int i = 0; i < reqs.Length; i++) { var s = reqs[i]; if (s == "") continue; //Get Switches var sws = new List<string>(); for (int j = i + 1; j < reqs.Length; j++) if (reqs[j].Length > 0 && reqs[j][0] == '/') { i++; sws.Add(reqs[j].Substring(1, reqs[j].Length - 1)); } else break; CommandConsole.ArgClass.Reference comRef = null; for (int j = 0; j < this._argRefs.Count; j++) { comRef = this._argRefs[j].HandleCommand(this, retArgs, s, r); if (comRef == null) continue; break; } //If no command, run event if (comRef == null) { var rs = ""; for (int j = i; j < reqs.Length; j++) { if (reqs[j] == "") continue; rs += reqs[j]; if (j < reqs.Length - 1) rs += " "; } if (this.OnCommand != null) this.OnCommand(this, rs, sws.ToArray<string>(), r); break; } //Attempt to execulte comref comRef.ExecuteCommand(this, retArgs, sws.ToArray<string>(), r); continue; } if (r.Count == 0) return null; else return r; }