Example #1
0
        //public static List<string> LoadSAPClientSettings()
        //{
        //    List<String> ClientList = new List<string>();
        //    try
        //    {
        //        ConfigurationSectionGroup sectionGroup = getSapSectionGroup();
        //        RfcGeneralConfiguration configuration2 = getSAPGeneralConfiguration(sectionGroup);
        //        RfcDestinationCollection clientsSetting = getClientSettings(sectionGroup);

        //        IEnumerator enumerator = clientsSetting.GetEnumerator();

        //        while (enumerator.MoveNext())
        //        {
        //            RfcDestinationParameters current = (RfcDestinationParameters)enumerator.Current;
        //            ClientList.Add(current.Name);

        //        }
        //        // RfcDestinationManager.RegisterDefaultConfiguration(new DefaultDestinationConfiguration(clientsSetting));
        //    }
        //    catch (Exception)
        //    {

        //        throw;
        //    }
        //    return ClientList;
        //}
        public static bool LoadSAPClientConfig()
        {
            try
            {
                if (_clientStarted == false)
                {
                    RfcDestinationCollection clientsSetting = ConfigFileTool.SAPClientServerSetting.getClientSettings();
                    if (clientsSetting != null)
                    {
                        RfcDestinationManager.RegisterDestinationConfiguration(new DefaultDestinationConfiguration(clientsSetting));
                    }

                    //RfcServerCollection severSetting = ConfigFileTool.SAPClientServerSetting.getServerSettings();
                    //if (severSetting != null)
                    //{
                    //    RfcServerManager.RegisterServerConfiguration(new DefaultServerConfiguration(severSetting));
                    //}

                    // RfcServerManager.loadedFromParameterFile = true;
                    _clientStarted = true;
                }
                return(true);
            }
            catch (Exception exception)
            {
                throw new SAPException(exception.Message +   "无法从配置文件加载");
            }
        }
        // Methods
        public DefaultDestinationConfiguration(RfcDestinationCollection destCollection)
        {
            try
            {
                IEnumerator enumerator = destCollection.GetEnumerator();
                this.destinations = new Dictionary <string, RfcConfigParameters>();
                while (enumerator.MoveNext())
                {
                    RfcDestinationParameters current     = (RfcDestinationParameters)enumerator.Current;
                    RfcConfigParameters      parameters2 = new RfcConfigParameters(0x20);

                    //RfcConfigParameters parameters2 = new RfcConfigParameters();
                    // Assembly a = Assembly.LoadFrom("sapnco.dll");
                    // String ConfigFileToolpath = System.AppDomain.CurrentDomain.BaseDirectory + "ConfigFileTool.dll";
                    // PropertyInfo[] properties = Assembly.LoadFrom(ConfigFileToolpath).GetType("ConfigFileTool.SapConfig.RfcDestinationParameters").GetProperties();
                    PropertyInfo[] properties = current.GetType().GetProperties();
                    //  PropertyInfo[] properties = Assembly.LoadFrom("ConfigFileTool.dll").GetType("ConfigFileTool.SapConfig.RfcDestinationParameters").GetProperties();

                    // String sapncoPath = System.AppDomain.CurrentDomain.BaseDirectory + "sapnco.dll";
                    //  Type type = Assembly.LoadFrom(sapncoPath).GetType("SAP.Middleware.Connector.RfcConfigParameters");
                    //  Type type = Assembly.LoadFrom("sapnco.dll").GetType("SAP.Middleware.Connector.RfcConfigParameters");
                    Type type = parameters2.GetType();
                    for (int i = 0; i < properties.Length; i++)
                    {
                        string str = properties[i].GetValue(current, null) as string;
                        if ((str != null) && (str.Length > 0))
                        {
                            parameters2[(string)type.GetField(properties[i].Name).GetValue(null)] = str;
                        }
                    }
                    this.destinations[current.Name] = parameters2;
                    SAPLogonConfigList.SystemNameList.Add(current.Name);
                }
            }
            catch (Exception exception)
            {
                throw new SAPException(exception.Message + "无法加载程序集ConfigFileTool.exe,或sapnco.dll");
            }
        }
        /// <summary>
        /// 从配置文件中加载客户端设置的名列表。
        /// </summary>
        /// <returns></returns>
        public static List <string> LoadSAPClientNameList()
        {
            List <String> ClientList = new List <string>();

            try
            {
                RfcGeneralConfiguration  configuration2 = getSAPGeneralConfiguration();
                RfcDestinationCollection clientsSetting = getClientSettings();

                IEnumerator enumerator = clientsSetting.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    RfcDestinationParameters current = (RfcDestinationParameters)enumerator.Current;
                    ClientList.Add(current.Name);
                }
                // RfcDestinationManager.RegisterDefaultConfiguration(new DefaultDestinationConfiguration(clientsSetting));
            }
            catch (Exception)
            {
                throw;
            }
            return(ClientList);
        }