示例#1
0
        public static void parseString(this IList <MyByteArray> returned, byte[] B)
        {
            returned.Clear();

            arrayType   type = arrayType.Text;
            List <byte> temp = new List <byte>();

            int Index = 0;

            for (int i = 0; i < B.Length; i++)
            {
                if (0x20 <= B[i] & B[i] < 0x80)
                {
                    temp.Add(B[i]);
                }
                else if (0x80 <= B[i] & B[i] < 0xF0)
                {
                    temp.Add(B[i]);
                    i = i + 1;
                    temp.Add(B[i]);
                }
                else
                {
                    if (0x00 <= B[i] & B[i] < 0x20)
                    {
                        if (temp.Count != 0)
                        {
                            returned.Add(new MyByteArray {
                                Index = Index, Type = type, Bytes = temp.ToArray()
                            });
                            Index++;
                            temp.Clear();
                        }

                        type = arrayType.System;
                        temp.Add(B[i]);

                        returned.Add(new MyByteArray {
                            Index = Index, Type = type, Bytes = temp.ToArray()
                        });
                        Index++;
                        type = arrayType.Text;
                        temp.Clear();
                    }
                    else
                    {
                        if (temp.Count != 0)
                        {
                            returned.Add(new MyByteArray {
                                Index = Index, Type = type, Bytes = temp.ToArray()
                            });
                            Index++;
                            type = arrayType.Text;
                            temp.Clear();
                        }


                        type = arrayType.System;
                        temp.Add(B[i]);
                        int count = (B[i] - 0xF0) * 2 - 1;
                        for (int k = 0; k < count; k++)
                        {
                            i++;
                            temp.Add(B[i]);
                        }

                        returned.Add(new MyByteArray {
                            Index = Index, Type = type, Bytes = temp.ToArray()
                        });
                        Index++;
                        type = arrayType.Text;
                        temp.Clear();
                    }
                }
            }

            if (temp.Count != 0)
            {
                returned.Add(new MyByteArray {
                    Index = Index, Type = type, Bytes = temp.ToArray()
                });
                temp.Clear();
            }
        }
示例#2
0
 new CoreTypeMappingParameters(
     arrayType,
     elementMapping.Converter is ValueConverter elementConverter
        // The rest of the SMSTest class consistes of helper methods for pretty-printing result data.
        // These methods serve to illustrate how the result data is formatted and how it may be processed.

        private object populateFields(object Obj)
        {
            try
            {
                Type     T           = Obj.GetType();
                String[] fieldArray  = fields.Split(delimiter);
                String   mStartsWith = ("set_");
                System.Collections.Hashtable objectTable = new System.Collections.Hashtable();

                foreach (String f in fieldArray)
                {
                    String   fvalue      = null;
                    String   fname       = null;
                    bool     setField    = false;
                    String[] fvalueArray = f.Split(new char[1] {
                        '='
                    });

                    if (fvalueArray.Length == 2)
                    {
                        // Check if we have an array object
                        if (isArrayField(fvalueArray[0]))
                        {
                            // Find array index
                            uint   idx = (uint)arrayIndex(fvalueArray[0]);
                            String fn  = arrayFieldname(fvalueArray[0]);
                            fvalue = fvalueArray[1];

                            // The arrayType defined in SMS consists of a 'value' and 'postion'
                            arrayType arrayElement = new arrayType();
                            arrayElement.Value    = fvalue;
                            arrayElement.position = idx;

                            // Check if we already have the field in the objectTable and add
                            if (objectTable.ContainsKey(fn))
                            {
                                arrayType[] afv           = (arrayType[])objectTable[fn];
                                int         currentLength = afv.Length;
                                // Resize the array to add new arrayElement
                                Array.Resize <arrayType>(ref afv, currentLength + 1);
                                afv[currentLength] = arrayElement;
                                objectTable[fn]    = afv;
                            }
                            else
                            {
                                arrayType[] new_afv = new arrayType[1];
                                new_afv[0] = arrayElement;
                                objectTable.Add(fn, new_afv);
                            }
                        }

                        else
                        {
                            fname    = fvalueArray[0];
                            fvalue   = fvalueArray[1];
                            setField = true;
                        }
                    }
                    else
                    {
                        fname    = fvalueArray[0];
                        fvalue   = "";
                        setField = true;
                    }

                    if (setField)
                    {
                        // Go ahead and set the field since its not an array
                        String     mName = (mStartsWith + fname);
                        MethodInfo mi    = T.GetMethod(mName);

                        // Try to set the vaule if the field exists
                        if (mi != null)
                        {
                            mi.Invoke(Obj, new String[1] {
                                fvalue
                            });
                            //System.Console.WriteLine(mName + " = \"" + fvalue + '"');
                        }
                    }
                }

                // Now set the object arrays
                if (objectTable.Count > 0)
                {
                    foreach (String key in objectTable.Keys)
                    {
                        String     mName = (mStartsWith + key);
                        MethodInfo mi    = T.GetMethod(mName);
                        // Try to set the vaule if the field exists
                        if (mi != null)
                        {
                            arrayType[] val = (arrayType[])objectTable[key];
                            mi.Invoke(Obj, new object[] { val });
                            //System.Console.WriteLine("Setting " + key + " Array -- Length of " + val.Length );
                        }
                        else
                        {
                            //System.Console.WriteLine(key + " Element Does Not Exist!");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Info("SMSService failed with an unexpected exception:");
                log.Info(e.Message);
                log.Info(e.StackTrace);
            }

            return(Obj);
        }