internal bool Match(InfoPlusEvent e) { // to compatible with old version without domain if (null == e.Step.Domain) { return(string.Equals(this.Workflow.Code, e.Step.WorkflowCode, StringComparison.CurrentCultureIgnoreCase)); } else { // match code var match = string.Equals(this.Workflow.Code, e.Step.WorkflowCode, StringComparison.CurrentCultureIgnoreCase) || this.Workflow.Code == "*"; if (!match) { return(false); } // match domain match = string.Equals(this.Workflow.Domain, e.Step.Domain, StringComparison.CurrentCultureIgnoreCase) || this.Workflow.Domain == "*"; if (!match) { return(false); } // match version return(e.Step.WorkflowVersion >= this.Workflow.MinVersion && e.Step.WorkflowVersion <= this.Workflow.MaxVersion); } }
public InfoPlusResponse OnActionClicking(InfoPlusEvent e) { string method = string.Format("OnStep{0}Action{1}Clicking", AbstractMessenger.ToFirstUpper(e.Step.StepCode), AbstractMessenger.ToFirstUpper(e.ActionCode)); return(this.CallEventMethodWrapper(method, e)); }
InfoPlusResponse CallEventMethodWrapper(string method, InfoPlusEvent e) { var response = this.Update(e); var r2 = this.CallEventMethod(method, e); if (null != r2) { response = r2; } else { System.Diagnostics.Trace.WriteLine("Method " + method + " not found."); } return(response); }
public InfoPlusResponse OnStepWithdrawn(InfoPlusEvent e) { if (string.IsNullOrEmpty(e.ActionCode)) { string method = string.Format("OnStep{0}Withdrawn", AbstractMessenger.ToFirstUpper(e.Step.StepCode)); return(this.CallEventMethodWrapper(method, e)); } else { string method = string.Format("OnStep{0}Action{1}Withdrawn", AbstractMessenger.ToFirstUpper(e.Step.StepCode), AbstractMessenger.ToFirstUpper(e.ActionCode)); return(this.CallEventMethodWrapper(method, e)); } }
/* * The following events are divided. * public virtual InfoPlusResponse OnActionDoing(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnActionDone(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnStepRendering(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnStepRendered(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnActionClicking(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnStepPrinting(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnStepExpiring(InfoPlusEvent e) { return this.Update(e); } * public virtual InfoPlusResponse OnStepExpired(InfoPlusEvent e) { return this.Update(e); } */ /// <summary> /// Suggesting is implemented for cache & pinyin by default. /// </summary> /// <param name="e"></param> /// <returns></returns> public virtual InfoPlusResponse OnFieldSuggesting(InfoPlusEvent e) { if (null == e.Suggestion) { return(this.Update(e)); } try { string code = e.Suggestion.Code; var cl = AbstractMessenger.cachedCodeLists; var ce = AbstractMessenger.cachedCodeExpires; if (e.Suggestion.Dirty || false == cl.ContainsKey(code) || ce[code] < UnixTime.ToInt64(DateTime.Now)) { lock (_code_lock) { if (e.Suggestion.Dirty || false == cl.ContainsKey(code) || ce[code] < UnixTime.ToInt64(DateTime.Now)) { CodeList list = this.OnQueryCodeTable(code); if (null == list || null == list.Items || 0 == list.Items.Count) { throw new Exception("CodeTable " + code + " invalid."); } foreach (var item in list.Items) { item.CalculateSpell(); } // add to cache AbstractMessenger.cachedCodeLists[code] = list; AbstractMessenger.cachedCodeExpires[code] = UnixTime.ToInt64(DateTime.Now.AddHours(1)); } } } CodeList l = this.Suggest(e.Suggestion); var response = new InfoPlusResponse(); response.Codes = new List <CodeList>(); response.Codes.Add(l); return(response); } catch (Exception ex) { return(new InfoPlusResponse(true, true, ex.Message)); } }
public InfoPlusResponse OnActionDone(InfoPlusEvent e) { var methods = new List <string>(); var stepCode = AbstractMessenger.ToFirstUpper(e.Step.StepCode); var actionCode = AbstractMessenger.ToFirstUpper(e.ActionCode); methods.Add(string.Format("OnStep{0}Action{1}Done", stepCode, actionCode)); if (null != e.NextSteps) { foreach (var step in e.NextSteps) { methods.Add(string.Format("ToStep{0}Done", AbstractMessenger.ToFirstUpper(step.StepCode))); } } if (null != e.EndStep) { methods.Add(string.Format("ToStep{0}Done", AbstractMessenger.ToFirstUpper(e.EndStep.StepCode))); } bool called = false; var response = this.Update(e); foreach (string method in methods) { var r2 = this.CallEventMethod(method, e); if (null != r2) { called = true; response += r2; } } if (false == called) { System.Diagnostics.Trace.WriteLine("All Methods in (" + string.Join(",", methods.ToArray()) + ") are not found."); } return(response); }
InfoPlusResponse CallEventMethod(string method, InfoPlusEvent e) { var type = this.GetType(); if (null == type.GetMethod(method)) { return(null); } var response = this.GetType().InvokeMember( method, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, this, new object[] { e } ); if (response is InfoPlusResponse) { return((InfoPlusResponse)response); } return(new InfoPlusResponse()); }
public virtual InfoPlusResponse OnInstanceCompleting(InfoPlusEvent e) { return(this.Update(e)); }
public virtual InfoPlusResponse OnInstanceStarted(InfoPlusEvent e) { return(this.Update(e)); }
/// <summary> /// Update Cache /// </summary> /// <param name="e"></param> /// <returns></returns> protected InfoPlusResponse Update(InfoPlusEvent e) { return(new InfoPlusResponse()); }
public InfoPlusResponse OnStepExpired(InfoPlusEvent e) { string method = string.Format("OnStep{0}Expired", AbstractMessenger.ToFirstUpper(e.Step.StepCode)); return(this.CallEventMethodWrapper(method, e)); }
public virtual InfoPlusResponse OnFieldChanging(InfoPlusEvent e) { return(this.Update(e)); }
public virtual InfoPlusResponse OnActionSaved(InfoPlusEvent e) { return(this.Update(e)); }
public string OnEvent(string verify, string version, string eventType, string eventData) { // Trace string s = string.Format("eventType:{0},eventData:{1}", eventType, eventData); System.Diagnostics.Trace.WriteLine(s); InfoPlusResponse r = new InfoPlusResponse(); try { // 1.Data type conversion. EventTypes eTypes = (EventTypes)Enum.Parse(typeof(EventTypes), eventType); // just return the default response when ECHO if (eTypes == EventTypes.ECHO) { return(JsonConvert.ExportToString(r)); } InfoPlusEvent e = JsonConvert.Import <InfoPlusEvent>(eventData); if (null == e) { return(JsonConvert.ExportToString(new InfoPlusResponse(true, true, "InfoPlusEvent malformed"))); } // 2.Retrieve messengers IList <AbstractMessenger> messengers = this.settings.Messengers; var targets = from m in messengers where m.Match(e) select m; // 3.Dispatch messages. // Devoted to Charles Petzold, the first Win32 program, Orz by marstone, 2011/06/29 // Changed switch(eventType) to Reflection. Devoted to Brian Cantwell Smith, 2011/07 bool verified = !targets.Any(); string detail = null; foreach (AbstractMessenger messenger in targets) { // 4.Check verify. verified = true; if (messenger.RequireVerification && ServiceType.Insecure != ApplicationSettings.ServiceType) { ResponseEntity re = this.CheckParameters(messenger, verify, version, version, eventType, eventData); if (false == re.Successful) { verified = false; detail = re.error; break; } } // Notice: the CurrentEvent is thread safe. by marstone, 2011/10/18 messenger.CurrentEvent = e; InfoPlusResponse response = null; try { var words = (from t in eTypes.ToString().Split(new char[] { '_' }) select t[0] + t.Substring(1).ToLower()); string method = "On" + string.Join("", words.ToArray()); string log = string.Format("Dispatching {0} to {1}->{2}", eTypes, messenger.GetType().Name, method); System.Diagnostics.Trace.WriteLine(log); response = (InfoPlusResponse)messenger.GetType().InvokeMember( method, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, messenger, new object[] { e } ); } catch (Exception mex) { System.Diagnostics.Trace.WriteLine(mex); String message = mex.Message + "\n" + mex.StackTrace; while (true) { if (mex.InnerException == null || mex.InnerException == mex) { break; } mex = mex.InnerException; message += "\n" + mex.Message + "\n" + mex.StackTrace; } response = new InfoPlusResponse(true, true, "发生未知的错误", message); } if (null != response) { r += response; // skip next messenger if said Break. if (response.Break) { break; } } } if (false == verified) { r = new InfoPlusResponse(true, true, "Verification Failed.", detail); } return(JsonConvert.ExportToString(r)); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); return(JsonConvert.ExportToString(new InfoPlusResponse(true, true, "发生未知的错误", ex.Message + ex.StackTrace))); } }