コード例 #1
0
        /// <summary>
        /// Register vendor extension assembly
        /// </summary>
        /// <param name="asm"></param>
        public static void LoadVendorExtensionAssembly(Assembly asm)
        {
            try
            {
                Type[] types = asm.GetTypes();
                vendorExtensionIDTypeHash   = new Hashtable();
                vendorExtensionNameTypeHash = new Hashtable();

                foreach (Type tp in types)
                {
                    if (tp.BaseType != typeof(PARAM_Custom))
                    {
                        continue;
                    }

                    string type_full_name = tp.Namespace + "." + tp.Name;

                    object       obj        = asm.CreateInstance(type_full_name);
                    PARAM_Custom temp_param = (PARAM_Custom)obj;
                    string       key        = temp_param.VendorID + "-" + temp_param.SubType;
                    if (!vendorExtensionIDTypeHash.ContainsKey(key))
                    {
                        vendorExtensionIDTypeHash.Add(key, tp);
                    }
                    if (!vendorExtensionNameTypeHash.ContainsKey(tp.Name))
                    {
                        vendorExtensionNameTypeHash.Add(tp.Name, tp);
                    }
                }
            }
            catch { }
        }
コード例 #2
0
        public static ICustom_Parameter DecodeXmlNodeToCustomParameter(XmlNode node)
        {
            string[] strArray = node.Name.Split(':');
            string   str      = "PARAM_" + strArray[strArray.Length - 1];

            if (str == "PARAM_Custom")
            {
                return((ICustom_Parameter)PARAM_Custom.FromXmlNode(node));
            }
            if (CustomParamDecodeFactory.vendorExtensionNameTypeHash != null)
            {
                try
                {
                    Type type = (Type)CustomParamDecodeFactory.vendorExtensionNameTypeHash[(object)str];
                    if (type != null)
                    {
                        MethodInfo method = type.GetMethod("FromXmlNode");
                        if (method == null)
                        {
                            return((ICustom_Parameter)null);
                        }
                        object[] parameters = new object[1]
                        {
                            (object)node
                        };
                        return((ICustom_Parameter)method.Invoke((object)null, parameters));
                    }
                }
                catch
                {
                }
            }
            return((ICustom_Parameter)null);
        }
コード例 #3
0
        /// <summary>
        /// Decode a general Xml node to vendor extended parameters.
        /// </summary>
        /// <param name="node">Xml node to be decoded.</param>
        /// <returns>Custom Parameter</returns>
        public static ICustom_Parameter DecodeXmlNodeToCustomParameter(XmlNode node)
        {
            // Our hash is not namespace aware.
            string[] temp      = node.Name.Split(new char[] { ':' });
            string   type_name = "PARAM_" + temp[temp.Length - 1];

            if (type_name == "PARAM_Custom")
            {
                return((ICustom_Parameter)PARAM_Custom.FromXmlNode(node));
            }
            else if (null != vendorExtensionNameTypeHash)
            {
                try
                {
                    Type tp = (Type)vendorExtensionNameTypeHash[type_name];
                    if (tp != null)
                    {
                        MethodInfo mis = tp.GetMethod("FromXmlNode");
                        if (mis == null)
                        {
                            return(null);
                        }

                        object[] parameters = new object[] { node };
                        object   obj        = mis.Invoke(null, parameters);

                        return((ICustom_Parameter)obj);
                    }
                }
                catch { }
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Register vendor extension assembly
        /// </summary>
        /// <param name="asm"></param>
        public static void LoadVendorExtensionAssembly(Assembly asm)
        {
            if (null == vendorExtensionIDTypeHash)
            {
                vendorExtensionIDTypeHash = new Hashtable();
            }

            if (null == vendorExtensionNameTypeHash)
            {
                vendorExtensionNameTypeHash = new Hashtable();
            }

            if (null == vendorExtensionAssemblyHash)
            {
                vendorExtensionAssemblyHash = new Hashtable();
            }

            // Prevent double registration, and recursion
            string assembly_name = asm.GetName().Name;

            if (!vendorExtensionAssemblyHash.ContainsKey(assembly_name))
            {
                vendorExtensionAssemblyHash.Add(assembly_name, asm);
            }
            else
            {
                return;
            }

            try
            {
                Type[] types = asm.GetTypes();

                foreach (Type tp in types)
                {
                    if (tp.BaseType != typeof(PARAM_Custom))
                    {
                        continue;
                    }

                    string type_full_name = tp.Namespace + "." + tp.Name;
                    object obj            = asm.CreateInstance(type_full_name);

                    PARAM_Custom temp_param = (PARAM_Custom)obj;
                    string       key        = temp_param.VendorID + "-" + temp_param.SubType;
                    if (!vendorExtensionIDTypeHash.ContainsKey(key))
                    {
                        vendorExtensionIDTypeHash.Add(key, tp);
                    }
                    if (!vendorExtensionNameTypeHash.ContainsKey(tp.Name))
                    {
                        vendorExtensionNameTypeHash.Add(tp.Name, tp);
                    }
                }
            }
            catch
            {
                Console.WriteLine("LVEA failed", asm);
            }
        }
コード例 #5
0
        /// <summary>
        /// Decode a BitArray to Custom Parameter
        /// </summary>
        /// <param name="bit_array">BitArray to be decoded.</param>
        /// <param name="cursor">Current bit position to be processed.</param>
        /// <param name="length">Total length of the BitArray.</param>
        /// <returns></returns>
        public new static PARAM_Custom FromBitArray(ref BitArray bit_array, ref int cursor, int length)
        {
            if (cursor >= length)
            {
                return(null);
            }

            PARAM_Custom obj = new PARAM_Custom();
            object       obj_val;
            int          orig_cursor = cursor;
            int          param_type  = 0;

            cursor    += 6;
            param_type = (int)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 10);
            if (param_type != obj.TypeID)
            {
                cursor = orig_cursor;
                return(null);
            }

            obj.length = (UInt16)(int)Util.DetermineFieldLength(ref bit_array, ref cursor);

            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt32), 32);
            obj.VendorIdentifier = (UInt32)obj_val;

            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt32), 32);
            obj.ParameterSubtype = (UInt32)obj_val;

            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            int field_len = (obj.length * 8 - (cursor - orig_cursor)) / 8;

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(ByteArray), field_len);
            obj.Data = (ByteArray)obj_val;

            return(obj);
        }
コード例 #6
0
        /// <summary>
        /// Create vendor extended paramters from BitArray
        /// </summary>
        /// <param name="bit_array">BitArray. Input</param>
        /// <param name="cursor">The current bit position to be processed.</param>
        /// <param name="length">Total length of the array</param>
        /// <returns></returns>
        public static ICustom_Parameter DecodeCustomParameter(ref BitArray bit_array, ref int cursor, int length)
        {
            if (cursor >= length)
            {
                return(null);
            }

            int          old_cursor = cursor;
            PARAM_Custom param      = PARAM_Custom.FromBitArray(ref bit_array, ref cursor, length);

            if (param != null)
            {
                string key = param.VendorID + "-" + param.SubType;
                if (vendorExtensionIDTypeHash != null)
                {
                    try
                    {
                        Type       tp  = (Type)vendorExtensionIDTypeHash[key];
                        MethodInfo mis = tp.GetMethod("FromBitArray");

                        if (mis == null)
                        {
                            return(null);
                        }

                        cursor = old_cursor;
                        object[] parameters = new object[] { bit_array, cursor, length };

                        object obj = mis.Invoke(null, parameters);
                        cursor = (int)parameters[1];

                        return((ICustom_Parameter)obj);
                    }
                    catch
                    {
                        return(param);
                    }
                }
                else
                {
                    return(param);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #7
0
        public static ICustom_Parameter DecodeCustomParameter(
            ref BitArray bit_array,
            ref int cursor,
            int length)
        {
            if (cursor >= length)
            {
                return((ICustom_Parameter)null);
            }
            int          num1        = cursor;
            PARAM_Custom paramCustom = PARAM_Custom.FromBitArray(ref bit_array, ref cursor, length);

            if (paramCustom == null)
            {
                return((ICustom_Parameter)null);
            }
            string str = paramCustom.VendorID.ToString() + "-" + (object)paramCustom.SubType;

            if (CustomParamDecodeFactory.vendorExtensionIDTypeHash != null)
            {
                int num2 = cursor;
                try
                {
                    MethodInfo method = ((Type)CustomParamDecodeFactory.vendorExtensionIDTypeHash[(object)str]).GetMethod("FromBitArray");
                    if (method == null)
                    {
                        return((ICustom_Parameter)null);
                    }
                    cursor = num1;
                    object[] parameters = new object[3]
                    {
                        (object)bit_array,
                        (object)cursor,
                        (object)length
                    };
                    object obj = method.Invoke((object)null, parameters);
                    cursor = (int)parameters[1];
                    return((ICustom_Parameter)obj);
                }
                catch
                {
                    cursor = num2;
                }
            }
            return((ICustom_Parameter)paramCustom);
        }
コード例 #8
0
        public static void LoadVendorExtensionAssembly(Assembly asm)
        {
            if (CustomParamDecodeFactory.vendorExtensionIDTypeHash == null)
            {
                CustomParamDecodeFactory.vendorExtensionIDTypeHash = new Hashtable();
            }
            if (CustomParamDecodeFactory.vendorExtensionNameTypeHash == null)
            {
                CustomParamDecodeFactory.vendorExtensionNameTypeHash = new Hashtable();
            }
            if (CustomParamDecodeFactory.vendorExtensionAssemblyHash == null)
            {
                CustomParamDecodeFactory.vendorExtensionAssemblyHash = new Hashtable();
            }
            string name = asm.GetName().Name;

            if (CustomParamDecodeFactory.vendorExtensionAssemblyHash.ContainsKey((object)name))
            {
                return;
            }
            CustomParamDecodeFactory.vendorExtensionAssemblyHash.Add((object)name, (object)asm);
            try
            {
                foreach (Type type in asm.GetTypes())
                {
                    if (type.BaseType == typeof(PARAM_Custom))
                    {
                        string       typeName = type.Namespace + "." + type.Name;
                        PARAM_Custom instance = (PARAM_Custom)asm.CreateInstance(typeName);
                        string       str      = instance.VendorID.ToString() + "-" + (object)instance.SubType;
                        if (!CustomParamDecodeFactory.vendorExtensionIDTypeHash.ContainsKey((object)str))
                        {
                            CustomParamDecodeFactory.vendorExtensionIDTypeHash.Add((object)str, (object)type);
                        }
                        if (!CustomParamDecodeFactory.vendorExtensionNameTypeHash.ContainsKey((object)type.Name))
                        {
                            CustomParamDecodeFactory.vendorExtensionNameTypeHash.Add((object)type.Name, (object)type);
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("LVEA failed", (object)asm);
            }
        }
コード例 #9
0
        /// <summary>
        /// Deserialize a XmlNode to custom parameter
        /// </summary>
        /// <param name="node">Xml node to be deserialized</param>
        /// <returns>Custom Parameter</returns>
        public static PARAM_Custom FromXmlNode(XmlNode node)
        {
            string       val;
            PARAM_Custom param = new PARAM_Custom();


            val = XmlUtil.GetNodeValue(node, "VendorIdentifier");

            param.VendorIdentifier = Convert.ToUInt32(val);

            val = XmlUtil.GetNodeValue(node, "ParameterSubtype");

            param.ParameterSubtype = Convert.ToUInt32(val);

            val = XmlUtil.GetNodeValue(node, "Data");

            param.Data = ByteArray.FromString(val);

            return(param);
        }
コード例 #10
0
        /// <summary>
        /// Decode a general Xml node to vendor extended parameters.
        /// </summary>
        /// <param name="node">Xml node to be decoded.</param>
        /// <returns>Custom Parameter</returns>
        public static ICustom_Parameter DecodeXmlNodeToCustomParameter(XmlNode node)
        {
            if (vendorExtensionIDTypeHash == null || vendorExtensionNameTypeHash == null)
            {
                vendorExtensionIDTypeHash   = new Hashtable();
                vendorExtensionNameTypeHash = new Hashtable();

                Assembly asm = Assembly.GetCallingAssembly();

                string fullName = asm.ManifestModule.FullyQualifiedName;
                string path     = fullName.Substring(0, fullName.LastIndexOf("\\"));

                DirectoryInfo di      = new DirectoryInfo(path);
                FileInfo[]    f_infos = di.GetFiles("LLRP.*.dll");

                foreach (FileInfo fi in f_infos)
                {
                    asm = Assembly.LoadFile(fi.FullName);
                    Type[] types = asm.GetTypes();
                    foreach (Type tp in types)
                    {
                        if (tp.BaseType != typeof(PARAM_Custom))
                        {
                            continue;
                        }

                        string type_full_name = tp.Namespace + "." + tp.Name;

                        object       obj        = asm.CreateInstance(type_full_name);
                        PARAM_Custom temp_param = (PARAM_Custom)obj;
                        string       key        = temp_param.VendorID + "-" + temp_param.SubType;
                        vendorExtensionIDTypeHash.Add(key, tp);
                        vendorExtensionNameTypeHash.Add(tp.Name, tp);
                    }
                }
            }

            ///This part is arbitrary and lack of flexibility
            string[] temp     = node.Name.Split(new char[] { ':' });
            string   typeName = string.Empty;

            if (temp.Length == 2)
            {
                typeName = temp[1];
            }
            else
            {
                typeName = temp[0];
            }

            //
            string type_name = "PARAM_" + typeName;
            Type   custom_tp = (Type)vendorExtensionNameTypeHash[type_name];

            if (custom_tp != null)
            {
                object[]   parameters = new object[] { node };
                MethodInfo mis        = custom_tp.GetMethod("FromXmlNode");

                if (mis == null)
                {
                    return(null);
                }
                object obj = mis.Invoke(null, parameters);

                return((ICustom_Parameter)obj);
            }
            else
            {
                return(null);
            }
        }
コード例 #11
0
        /// <summary>
        /// Decode a BitArray to Custom Parameter
        /// </summary>
        /// <param name="bit_array">BitArray to be decoded.</param>
        /// <param name="cursor">Current bit position to be processed.</param>
        /// <param name="length">Total length of the BitArray.</param>
        /// <returns></returns>
        public new static PARAM_Custom FromBitArray(ref BitArray bit_array, ref int cursor, int length)
        {
            if (cursor >= length)
            {
                return(null);
            }

            int       field_len = 0;
            object    obj_val;
            ArrayList param_list = new ArrayList();

            PARAM_Custom obj = new PARAM_Custom();

            int param_type = 0;

            if (bit_array[cursor])
            {
                obj.tvCoding = true;
            }
            if (obj.tvCoding)
            {
                cursor++;
                param_type = (int)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 7);

                if (param_type != obj.TypeID)
                {
                    cursor -= 8;
                    return(null);
                }
            }
            else
            {
                cursor    += 6;
                param_type = (int)(UInt64)Util.CalculateVal(ref bit_array, ref cursor, 10);

                if (param_type != obj.TypeID)
                {
                    cursor -= 16;
                    return(null);
                }
                obj.length = (UInt16)(int)Util.DetermineFieldLength(ref bit_array, ref cursor);
            }


            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            field_len = 32;

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt32), field_len);
            obj.VendorIdentifier = (UInt32)obj_val;

            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            field_len = 32;

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(UInt32), field_len);
            obj.ParameterSubtype = (UInt32)obj_val;

            if (cursor > length)
            {
                throw new Exception("Input data is not complete message");
            }

            field_len = (bit_array.Length - cursor) / 8;

            Util.ConvertBitArrayToObj(ref bit_array, ref cursor, out obj_val, typeof(ByteArray), field_len);
            obj.Data = (ByteArray)obj_val;

            return(obj);
        }