public static Double GetFloat(String data, int ts, int te) { int len = (int)(te - ts); if (len >= 0) { try { return(Double.Parse(data.Substring(ts, len))); } catch (Exception e) { TSK_Debug.Error(e.ToString()); } } return(-1.0); }
public static List <TSK_Param> AddParam(List <TSK_Param> @params, String name, String value) { TSK_Param param = null; if (@params == null || String.IsNullOrEmpty(name)) { TSK_Debug.Error("Invalid parameter"); return(@params); } if ((param = TSK_Param.GetByName(@params, name)) != null) { param.Value = value;/* Already exist ==> update the value. */ } else { @params.Add(TSK_Param.Create(name, value)); } return(@params); }
public Boolean ExecuteAction(Int32 action, Object condObj1, Object condObj2, params Object[] parameters) { Boolean found = false; Boolean terminates = false; Boolean ok = true; if (this.IsTerminated) { TSK_Debug.Warn("The FSM is in the final state."); return(false); } // lock mMutex.WaitOne(); foreach (Entry entry in mEntries) { if ((entry.StateFrom != TSK_StateMachine.STATE_ANY) && (entry.StateFrom != mCurrentSate)) { continue; } if ((entry.Action != TSK_StateMachine.ACTION_ANY) && (entry.Action != action)) { continue; } // check condition if (entry.Condition == null || entry.Condition(condObj1, condObj2)) { // For debug information if (mDebug) { TSK_Debug.Info("State machine: {0}", entry.Description); } if (entry.StateTo != TSK_StateMachine.STATE_ANY) { /* Stay at the current state if dest. state is Any */ mCurrentSate = entry.StateTo; } if (entry.Execute != null) { if (!(ok = entry.Execute(parameters))) { TSK_Debug.Info("State machine: Exec function failed. Moving to terminal state."); } else { } // Do nothing terminates = (!ok || (mCurrentSate == mTermState)); found = true; break; } } } mMutex.ReleaseMutex(); /* Only call the callback function after unlock. */ if (terminates) { mCurrentSate = mTermState; if (mOnTerminated != null) { mOnTerminated(); } } if (!found) { TSK_Debug.Warn("State machine: No matching state found."); } return(ok); }