Esempio n. 1
0
        public void LoadSetting(string filename)
        {
            try
            {
                using (BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open, FileAccess.Read)))
                {
                    int len = 0;    //待读取的文件长度
                    byte[] value = null;    //缓冲数据
                    string assemblyName = string.Empty;
                    List<string> files = new List<string>();
                    len = br.ReadInt32(); //读取反射类全名类型
                    value = br.ReadBytes(len);
                    assemblyName = Encoding.UTF8.GetString(value);

                    if (_ilsc == null)
                    {
                        if (LinkManagementClass.Default.Items.ContainsKey(assemblyName) && File.Exists (LinkManagementClass.Default.Items[assemblyName].AssemblyFileName))
                        {
                                Assembly a = Assembly.LoadFile(LinkManagementClass.Default.Items[assemblyName].AssemblyFileName);
                                _ilsc = (ILinkStringCreate)a.CreateInstance(assemblyName);
                                _ilsc.SetItemData += new SetItemDataHandler(_ilsc_SetItemData);
                        }
                        else
                        {
                            return;
                        }
                    }

                    len = br.ReadInt32();
                    _ilsc.Load(br.BaseStream,len);
                    ReloadItemValue();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 加载数据库配置信息
        /// </summary>
        /// <param name="setfilename">配置文件名</param>
        /// <returns></returns>
        public bool Load_ILinkStringCreate(string setfilename)
        {
            if (!File.Exists(setfilename))
            {
                return false;
            }

            string filenamea = string.Empty, filenameb = string.Empty;
            Assembly a = null;
            Type tc = null;
            #if(INTERFACE_ON ==false )
            MethodInfo mi_sub_invoke = null;
            object ma = null;
            bool result = false;    //发射执行的结果
            #endif
            try
            {
                FileInfo fi = new FileInfo(setfilename);
                using (BinaryReader br = new BinaryReader(new FileStream(setfilename, FileMode.Open, FileAccess.Read)))
                {
                    int len = 0;    //待读取的文件长度
                    byte[] value = null;    //缓冲数据

                    long index = 0;
                    string nameSpacestr = null; //等待处理的命名空间名.类名

                    //读取数据库库设置类库文件名
                    //读取反射类全名类型
                    len = br.ReadInt32();
                    value = br.ReadBytes(len);
                    nameSpacestr = Encoding.UTF8.GetString(value);
                    if (LinkManagementClass.Default.Items.ContainsKey(nameSpacestr) && File.Exists(LinkManagementClass.Default.Items[nameSpacestr].AssemblyFileName))
                    {
                        a = Assembly.LoadFile(LinkManagementClass.Default.Items[nameSpacestr].AssemblyFileName);
                    }
                    else
                    {
                        return false;
                    }

                    len = br.ReadInt32();// 读取配置存储信息长度
                    index = br.BaseStream.Position; //记录当前读取位置,

                    //实施反射实例创建
                    tc = a.GetType(nameSpacestr);
            #if(INTERFACE_ON )
                    _ilsc = a.CreateInstance(nameSpacestr) as ILinkStringCreate;

                    if (!_ilsc.Load(br.BaseStream, len))
                    {
                        return false;
                    }

                    if (!_ilsc.Checked())
                    {
                        return false;
                    }

                    //取得数据连接实例
                    this._Idbcon = _ilsc.GetDbConnection();
                    //取得DBCommand实例
                    this._Idbcmd = _ilsc.GetDbCommand();

                    this._DA = _ilsc.GetDbDataAdapter(); ;
                    this._DA.SelectCommand = this._Idbcmd;

                    this._linksummary = _ilsc.LinkSummary;
                    return true;
            #else
                   ma = a.CreateInstance(nameSpacestr);
                    _ilsc =(ILinkStringCreate ) ma;
                    //建立配置读取反射
                    mi_sub_invoke = tc.GetMethod("Load");
                    //执行,取得读取结果
                    result = (bool)mi_sub_invoke.Invoke(ma, new object[] { br.BaseStream, len });
                    if (!result)
                        return false;//信息读取失败

                    mi_sub_invoke = tc.GetMethod("Checked");
                    result = (bool)mi_sub_invoke.Invoke(ma, new object[] { });

                    if (!result)
                        return false;

                    //取得数据连接实例
                    mi_sub_invoke = tc.GetMethod("GetDbConnection");
                    this._Idbcon = (DbConnection)mi_sub_invoke.Invoke(ma, new object[] { });
                    //取得DBCommand实例
                    mi_sub_invoke = tc.GetMethod("GetDbCommand");
                    this._Idbcmd = (DbCommand)mi_sub_invoke.Invoke(ma, new object[] { });

                    mi_sub_invoke = tc.GetMethod("GetDbDataAdapter");
                    this._DA = (DbDataAdapter)mi_sub_invoke.Invoke(ma, new object[] { });
                    this._DA.SelectCommand = _Idbcmd;

                    mi_sub_invoke = tc.GetMethod("GetDbCommandBuilder");
                    this._ldbcbuid  = (DbCommandBuilder )mi_sub_invoke.Invoke(ma, new object[] { });

                    mi_sub_invoke = tc.GetMethod("get_LinkSummary");
                    this._linksummary = (string)mi_sub_invoke.Invoke(ma, new object[] { });
                    return result;
            #endif
                }//end binaryreader
            }
            catch
            {
                this._DA = null;
                this._Idbcmd = null;
                this._Idbcon = null;
            }
            finally
            {
                a = null;
            #if (INTERFACE_ON ==false)
                mi_sub_invoke = null;
                ma = null;
            #endif
                tc = null;
            }
            return false;
        }