Ejemplo n.º 1
0
 private bool Validate(UserState userState, byte[] input)
 {
     try {
         return (bool)userState.MethodValidate.Invoke(null, new object[] { input });
     } catch {
         return false;
     }
 }
Ejemplo n.º 2
0
 public UserDefinedTimestampState(UserState us)
     : base(us)
 {
 }
Ejemplo n.º 3
0
 public UserDefinedState(UserState us)
 {
     UserStateObj = us;
 }
Ejemplo n.º 4
0
 private DateTime GetDateTime(UserState userState, byte[] input)
 {
     try {
         return (DateTime)userState.MethodDatetime.Invoke(null, new object[] { input });
     } catch {
         // Timestamp that will be filtered out.
         return new DateTime(1800, 1, 1);
     }
 }
Ejemplo n.º 5
0
 private static UserState ParseStateMachine(XElement xState)
 {
     string name = RequiredAttribute(xState, "name");
     Viterbi.MachineList type = UserState.GetMachineType(RequiredAttribute(xState, "type"));
     string lib = RequiredAttribute(xState, "lib");
     string classname = RequiredAttribute(xState, "class");
     string format = RequiredAttribute(xState, "format");
     string validate = RequiredAttribute(xState, "validate");
     string datetime = null;
     if (type == Viterbi.MachineList.TimeStamp_User) {
         datetime = RequiredAttribute(xState, "datetime");
     }
     List<UserByte> bytes = new List<UserByte>();
     foreach (XElement xByte in xState.Elements("byte")) {
         UserByte ub = new UserByte();
         foreach (XElement xVal in xByte.Elements()) {
             ub.AddElement(xVal);
         }
         if (!ub.IsValid()) {
             throw new UserStatesException("Invalid byte in state machine");
         }
         bytes.Add(ub);
     }
     if (bytes.Count < 2) {
         throw new UserStatesException("State machine has last than two bytes defined");
     }
     UserState uState = new UserState(type, name, bytes, lib, classname, format, validate, datetime);
     uState.LoadMethods();
     return uState;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets the state machine for a user-defined timestamp.
 /// </summary>
 /// <param name="userState">Object representing the user-defined state machine.</param>
 /// <param name="weight"></param>
 /// <returns>The state machine.</returns>
 public static StateMachine GetTimestamp_UserDefined(UserState userState, int weight)
 {
     StateMachine timestamp = new StateMachine { Name = userState.MachineType, _weight = weight };
     State prevState = null;
     // Have a minimum of 2 bytes.
     for (int n = 0; n < userState.Bytes.Count - 1; n++)
     {
         string nm = String.Format("UserTimestampByte{0}", n);
         State state = new State { Name = nm, ParentStateMachine = timestamp };
         timestamp.AddState(state);
         if (n == 0)
         {
             timestamp.StartingStates.Add(state);
         }
         else
         {
             AddTransition(prevState, state, 1d);
         }
         prevState = state;
         UserDefinedByteProbabilities(state, userState.Bytes[n]);
     }
     UserDefinedTimestampState endState = new UserDefinedTimestampState(userState) { Name = "EndUserTimestampByte", ParentStateMachine = timestamp };
     timestamp.AddState(endState);
     UserDefinedByteProbabilities(endState, userState.Bytes[userState.Bytes.Count - 1]);
     AddTransition(prevState, endState, 1d);
     timestamp.EndingStates.Add(endState);
     return timestamp;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Called by the ExtractField() method of Viterbi class, to get a readable format of a Viterbi field
 /// whose corresponding bytes are passed through input. This metohd is used with user-defined states.
 /// </summary>
 /// <param name="machineName">The state's machine name.</param>
 /// <param name="input">The bytes to ne interpreted.</param>
 /// <param name="uState">The UserState object, which references the method for interpreting the input.</param>
 /// <returns>The string representation.</returns>
 public static string GetUserField(MachineList machineName, byte[] input, UserState uState)
 {
     try {
         if ((machineName == MachineList.PhoneNumber_User) || (machineName == MachineList.Text_User)) {
             return (string)uState.MethodFormat.Invoke(null, new object[] { input });
         } else {
             // For timestamps get the DateTime and format it, rather than use the user's
             // format method. This is for consistency.
             DateTime dt = (DateTime)uState.MethodDatetime.Invoke(null, new object[] { input });
             return dt.ToString();
         }
     } catch {
         return "???";
     }
 }