Ejemplo n.º 1
0
        private List <string> GetProtocolNamesByType(EDllType4Xml dtype, string type = "channel")
        {
            var result = new List <string>();

            foreach (var item in this.m_dllInfo.Infos)
            {
                if (!item.Enabled)
                {
                    continue;
                }
                if (item.Type != type)
                {
                    continue;
                }
                if (item.DllType != dtype)
                {
                    continue;
                }
                result.Add(item.Name);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool AssertChannelProtocolDllValid(string path, string tag,
                                                         out string className,
                                                         out string interfaceName,
                                                         out string dllInfoTag,
                                                         out EDllType4Xml dllType)
        {
            className     = string.Empty;
            interfaceName = string.Empty;
            dllInfoTag    = string.Empty;
            dllType       = EDllType4Xml.none;
            try
            {
                if (!File.Exists(path))
                {
                    return(false);
                }
                if (string.IsNullOrEmpty(tag))
                {
                    return(false);
                }

                if (CS_DEFINE.I_CHANNEL_BEIDOU_500.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_BEIDOU_500;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_BEIDOU_500;
                    dllType       = EDllType4Xml.beidou_500;
                }
                else if (CS_DEFINE.I_CHANNEL_BEIDOU_NORMAL.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_BEIDOU_NORMAL;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_BEIDOU_NORMAL;
                    dllType       = EDllType4Xml.beidou_normal;
                }
                else if (CS_DEFINE.I_CHANNEL_CABLE.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_CABLE;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_CABLE;
                    dllType       = EDllType4Xml.cable;
                }
                else if (CS_DEFINE.I_CHANNEL_GPRS.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_GPRS;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_GPRS;
                    dllType       = EDllType4Xml.gprs;
                }
                else if (CS_DEFINE.I_CHANNEL_HDGPRS.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_HDGPRS;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_HDGPRS;
                    dllType       = EDllType4Xml.gprs;
                }
                else if (CS_DEFINE.I_CHANNEL_GSM.Contains(tag))
                {
                    interfaceName = CS_DEFINE.I_CHANNEL_GSM;
                    dllInfoTag    = CS_DEFINE.TAG_CHANNEL_GSM;
                    dllType       = EDllType4Xml.gsm;
                }
                else
                {
                    return(false);
                }

                Assembly asm   = Assembly.LoadFrom(path);
                var      types = new List <Type>(asm.GetTypes());
                foreach (var type in types)
                {
                    var iType = new List <Type>(type.GetInterfaces());
                    foreach (var t in iType)
                    {
                        if (t.FullName == interfaceName)
                        {
                            className = type.FullName;
                            return(true);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
            }
            return(false);
        }
Ejemplo n.º 3
0
        private void btnChannelSaveAddNew_Click(object sender, EventArgs e)
        {
            string protocolName = this.txt_ChannelProtocolName.Text.Trim();

            if (String.IsNullOrEmpty(protocolName))
            {
                MessageBox.Show("协议名不能为空!");
                return;
            }
            //  string stringThePath1 = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            // string baseDir = stringEXEPath;
            // string baseDir = this.txt_ChannelDllFileName.Text.Trim();
            string baseDir  = this.txt_ChannelDllPath.Text.Trim();
            string fileName = this.txt_ChannelDllFileName.Text.Trim();

            if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(baseDir))
            {
                MessageBox.Show("请选择DLL!");
                return;
            }
            string tag = this.cmb_ChannelInterfaceNames.Text.Trim();

            string path = string.Format(@"{0}\{1}", baseDir, fileName);

            string       className     = string.Empty;
            string       interfaceName = string.Empty;
            string       dllInfoTag    = string.Empty;
            EDllType4Xml dllInfoType   = EDllType4Xml.none;

            if (!ProtocolManager.AssertChannelProtocolDllValid(path,
                                                               tag,
                                                               out className,
                                                               out interfaceName,
                                                               out dllInfoTag,
                                                               out dllInfoType))
            {
                MessageBox.Show("不是合法的DLL!请重新添加!");
                this.txt_ChannelDllPath.Text     = string.Empty;
                this.txt_ChannelDllFileName.Text = string.Empty;
                return;
            }
            this.txt_ChannelClassName.Text = className;

            XmlMemberInfos members = new XmlMemberInfos();

            members.Add(new XmlMember()
            {
                ClassName     = className,
                Tag           = dllInfoTag,
                InterfaceName = interfaceName
            });
            // baseDir = "..";
            XmlDllInfo info = new XmlDllInfo()
            {
                BaseDir  = baseDir,
                FileName = fileName,
                Enabled  = true,
                DllType  = dllInfoType,
                Name     = protocolName,
                Type     = "channel",
                Members  = members,
                Coms     = new List <int>(),
                Ports    = new List <CXMLPort>()
            };

            if (m_mapChannelInfo.ContainsKey(protocolName))
            {
                MessageBox.Show(string.Format("通讯方式{0}已存在,不能重复添加!", protocolName));
                return;
            }
            if (MessageBox.Show("确定添加通讯方式?", "添加", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                m_dllCollections.Infos.Add(info);
                ResetChannelPanel();
            }
        }
Ejemplo n.º 4
0
        private void btn_ChannelBrowse_Click(object sender, EventArgs e)
        {
            // 浏览本地dll文件
            //m_openFileDialog.InitialDirectory = Directory.GetCurrentDirectory();// 设置起始目录
            if (!txt_ChannelDllPath.Text.Equals(""))
            {
                m_openFileDialog.InitialDirectory = txt_ChannelDllPath.Text;
            }

            //m_openFileDialog.InitialDirectory = @"E:\陈乐宁相关\水文监测\HelloWorld.1228\MDITest\bin\Debug";

            m_openFileDialog.FileName = txt_ChannelDllFileName.Text;
            //  m_openFileDialog.InitialDirectory = Application.StartupPath;
            string       stringThePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
            DialogResult result        = m_openFileDialog.ShowDialog();

            if (result == DialogResult.OK && (!m_openFileDialog.FileName.ToString().Equals("")))
            {
                // 显示路径
                this.txt_ChannelDllFileName.Text = Path.GetFileName(m_openFileDialog.FileName);
                this.txt_ChannelDllPath.Text     = Path.GetDirectoryName(m_openFileDialog.FileName);
                //  this.txt_ChannelDllPath.Text = "..";

                //  更新接口实现类型
                string tag = this.cmb_ChannelInterfaceNames.Text;
                // string baseDir = this.txt_ChannelDllPath.Text.Trim();
                string baseDir  = stringThePath;
                string fileName = this.txt_ChannelDllFileName.Text.Trim();
                string path     = string.Format(@"{0}\{1}", baseDir, fileName);

                string       className     = string.Empty;
                string       interfaceName = string.Empty;
                string       dllInfoTag    = string.Empty;
                EDllType4Xml dllInfoType   = EDllType4Xml.none;
                if (!ProtocolManager.AssertChannelProtocolDllValid(path,
                                                                   tag,
                                                                   out className,
                                                                   out interfaceName,
                                                                   out dllInfoTag,
                                                                   out dllInfoType))
                {
                    MessageBox.Show("不是合法的DLL!请重新添加!");
                    this.txt_ChannelDllPath.Text     = string.Empty;
                    this.txt_ChannelDllFileName.Text = string.Empty;
                    return;
                }
                this.txt_ChannelClassName.Text = className;
                // this.txt_ChannelProtocolName.Text = this.txt_ChannelDllFileName.Text.Replace(".dll", "");
                if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Gprs.dll")
                {
                    this.txt_ChannelProtocolName.Text = "SX-GPRS";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.HDGprs.dll")
                {
                    this.txt_ChannelProtocolName.Text = "HD-GPRS";
                }

                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Gsm.dll")
                {
                    this.txt_ChannelProtocolName.Text = "GSM";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Beidou.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Beidou-Normal";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Beidou500.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Beidou-500";
                }
                else if (this.txt_ChannelDllFileName.Text == "Protocol.Channel.Transparen.dll")
                {
                    this.txt_ChannelProtocolName.Text = "Transparen";
                }


                else
                {
                    MessageBox.Show("不是合法的DLL!请重新添加!");
                    this.txt_ChannelDllPath.Text     = string.Empty;
                    this.txt_ChannelDllFileName.Text = string.Empty;
                    return;
                }
            }
        }