private void ExecuteIntervalMethods() { // If this application is in the system... ApplicationInfo app = this.CurrentApp.Key; List <ApplicationMethod> methods = app.Methods.Where(m => m.IsIntervalMethod && (DateTime.Now - m.LastCallTime).TotalMilliseconds >= m.Interval).ToList(); app.Methods.ForEach(m => { }); methods.ForEach(method => { if (method != null) { object instance; if (!this.AppInstances.TryGetValue(app, out instance)) { instance = app.Asm.CreateInstance(app.AppType.ToString()); this.AppInstances.Add(app, instance); } ((ApplicationBase)instance).AppInfo = app; if (method.FireEvents) { //Fire BeforeCommand Event BeforeCommandEventArgs bcArgs = new BeforeCommandEventArgs() { Continue = true }; ((ApplicationBase)instance).OnBeforeCommand(bcArgs); if (bcArgs.Continue) { object result = method.Method.Invoke(instance, null); if (result != null && result.ToString() != "") { SendReply(result.ToString()); } this.ClearParameters(); } } else { object result = method.Method.Invoke(instance, null); if (result != null && result.ToString() != "") { SendReply(result.ToString()); } this.ClearParameters(); } if (method.FireEvents) { //Fire AfterCommand Event AfterCommandEventArgs acArgs = new AfterCommandEventArgs(); ((ApplicationBase)instance).OnAfterCommand(acArgs); } method.LastCallTime = DateTime.Now; } }); }
private bool ExecuteMethod(string input) { // If this application is in the system... ApplicationInfo app = this.CurrentApp.Key; object[] parameters = null; var args = input.ToArgs(); ApplicationMethod method = app.Methods.FirstOrDefault(m => !m.IsIntervalMethod && !m.HasParamArray && m.Names.Where(name => args.Length == m.ParameterCount + name.NameWordCount && Regex.IsMatch(input, name.RegEx, RegexOptions.IgnoreCase) && (parameters = this.ParseArgs(args.ToList(), m, name)) != null).FirstOrDefault() != null); if (method == null) //try looking for a parameter method { method = app.Methods.FirstOrDefault(m => !m.IsIntervalMethod && m.HasParamArray && m.Names.Where(name => args.Length >= m.ParameterCount + name.NameWordCount && Regex.IsMatch(input, name.RegEx, RegexOptions.IgnoreCase) && (parameters = this.ParseArgs(args.ToList(), m, name)) != null).FirstOrDefault() != null); } if (method != null) { // Match the number of params object instance; if (!this.AppInstances.TryGetValue(app, out instance)) { instance = app.Asm.CreateInstance(app.AppType.ToString()); this.AppInstances.Add(app, instance); } ((ApplicationBase)instance).AppInfo = app; //Fire BeforeCommand Event BeforeCommandEventArgs bcArgs = new BeforeCommandEventArgs() { Continue = true }; ((ApplicationBase)instance).OnBeforeCommand(bcArgs); if (bcArgs.Continue) { object result = null; try { result = method.Method.Invoke(instance, parameters); } catch (Exception ex) { EventLog.WriteEntry("Ostrich ApplicationUser class", ex.Message); } if (result != null && result.ToString() != "") { SendReply(result.ToString()); } this.ClearParameters(); } //Fire AfterCommand Event AfterCommandEventArgs acArgs = new AfterCommandEventArgs(); ((ApplicationBase)instance).OnAfterCommand(acArgs); return(true); } return(false); }