Exemplo n.º 1
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;
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Defines the value probabilities for a user defined byte.
 /// </summary>
 /// <param name="state">State machine.</param>
 /// <param name="userByte">UserByte object representing the byte.</param>
 public static void UserDefinedByteProbabilities(State state, UserByte userByte)
 {
     if (userByte.All)
     {
         state.IsBinary = true;
     }
     else
     {
         foreach (byte b in userByte.Values)
         {
             state.PossibleValueProbabilities[b] = 1d;
         }
         state.NormalizeProbabilities();
     }
 }