示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        public void Register(string path)
        {
            try
            {
                AssemblyName assemblyName = new AssemblyName();
                assemblyName.Name     = Path.GetFileNameWithoutExtension(path);
                assemblyName.CodeBase = path;
                Assembly assembly = Assembly.Load(assemblyName);
                log.Debug("Loaded " + Path.GetFileName(path));

                foreach (Type type in assembly.GetExportedTypes())
                {
                    if (type.IsClass && typeof(ICRCer).IsAssignableFrom(type))
                    {
                        ICRCer crc = (ICRCer)Activator.CreateInstance(type);
                        this._CRCers.Add(crc);
                        //log.Error("Addin {0} was already registered", addin.Name);
                        //else
                        //{
                        //    addinRegistry.Register(addin);
                        log.Debug("Registered addin: {0}", crc.GetType());
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                // NOTE: Since the gui isn't loaded at this point,
                // the trace output will only show up in Visual Studio
                log.Error("Failed to load" + path, ex);

                throw ex;
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        static private ReceivePart CreateReceivePart(XmlNode recievepartnode)
        {
            XmlElement e        = recievepartnode as XmlElement;
            string     str      = GetAttribute(e, DeviceDefineNodeNames.ReceivePartDataLength);
            int        rpLength = int.Parse(str);

            string name = GetAttribute(e, DeviceDefineNodeNames.ReceivePartName, true);

            ReceivePart rp = new ReceivePart(name, rpLength);

            foreach (XmlNode node in recievepartnode.ChildNodes)
            {
                switch (node.Name)
                {
                case DeviceDefineNodeNames.DataField:
                    DataField df = CreateDataField(node);
                    df.IsBytesVolatile = true;
                    rp.Add(df);
                    break;
                }
            }
            ICRCer crcer = GetCRCer(recievepartnode);

            rp.DataFieldManager.CRCer = crcer;

            if (rp.DataFieldManager.CRCer == null &&
                rp.DataFieldManager.GetCRCDataField() != null)
            {
                throw new ConfigException("not exist CRCer");
            }
            return(rp);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sendpartnode"></param>
        /// <returns></returns>
        static private SendPart CreateSendPart(XmlNode sendpartnode)
        {
            SendPart sp = new SendPart();

            sp.DataFieldManager.CRCBegin = GetCRCBegin((XmlElement)sendpartnode);

            DataField df = null;

            foreach (XmlNode node in sendpartnode.ChildNodes)
            {
                switch (node.Name)
                {
                case DeviceDefineNodeNames.DataField:
                    df = CreateDataField(node);
                    df.IsValueVolatile = true;
                    sp.Add(df);
                    break;
                }
            }

            ICRCer crcer = GetCRCer(sendpartnode);

            sp.DataFieldManager.CRCer = crcer;
            return(sp);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="this1"></param>
        /// <returns></returns>
        private ListViewItem CreateListViewItem(ICRCer item)
        {
            string assemblyInfo = GetAssemblyInfo(item);

            //string[] items = new string[] { this1.GetType ().Name , "-", assemblyInfo };
            string[]     items = new string[] { item.GetType().FullName };
            ListViewItem lvi   = new ListViewItem(items);

            return(lvi);
        }
示例#5
0
        /// <summary>
        /// 获取sendpart或receivepart的crcer,如不存在返回null
        /// </summary>
        /// <param name="node">sendpart xmlnode or receivepart xmlnode</param>
        /// <returns></returns>
        static private ICRCer GetCRCer(XmlNode node)
        {
            XmlNode crcerNode = node.SelectSingleNode(DeviceDefineNodeNames.CRCer);

            if (crcerNode != null)
            {
                string name  = crcerNode.Attributes["name"].Value;
                ICRCer crcer = CommuniSoft.Default.CRCerManager.GetCRCer(name);
                if (crcer == null)
                {
                    throw new ConfigException("not find CRCer: " + name);
                }
                return(crcer);
            }
            return(null);
        }
示例#6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="this1"></param>
 /// <returns></returns>
 private string GetAssemblyInfo(ICRCer item)
 {
     return(item.GetType().Assembly.FullName);
 }