當前位置: 首頁>>代碼示例>>C#>>正文


C# AdoDataConnection.ServiceConnectionString方法代碼示例

本文整理匯總了C#中AdoDataConnection.ServiceConnectionString方法的典型用法代碼示例。如果您正苦於以下問題:C# AdoDataConnection.ServiceConnectionString方法的具體用法?C# AdoDataConnection.ServiceConnectionString怎麽用?C# AdoDataConnection.ServiceConnectionString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AdoDataConnection的用法示例。


在下文中一共展示了AdoDataConnection.ServiceConnectionString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ConnectWindowsServiceClient

        /// <summary>
        /// Connects to backend windows service.
        /// </summary>
        public static void ConnectWindowsServiceClient(bool overwrite = false)
        {
            TlsClient remotingClient;
            ISecurityProvider provider;
            UserData userData;

            if (overwrite)
            {
                DisconnectWindowsServiceClient();
                ServiceConnectionRefreshed(null, EventArgs.Empty);
            }
            else if (s_windowsServiceClient == null || s_windowsServiceClient.Helper.RemotingClient.CurrentState != ClientState.Connected)
            {
                if (s_windowsServiceClient != null)
                    DisconnectWindowsServiceClient();

                AdoDataConnection database = new AdoDataConnection(DefaultSettingsCategory);

                try
                {
                    string connectionString = database.ServiceConnectionString(true);

                    if (!string.IsNullOrWhiteSpace(connectionString))
                    {
                        s_windowsServiceClient = new WindowsServiceClient(connectionString);

                        if (SecurityProviderCache.TryGetCachedProvider(CurrentPrincipal.Identity.Name, out provider))
                        {
                            userData = provider.UserData;

                            if ((object)userData != null)
                            {
                                s_windowsServiceClient.Helper.Username = userData.LoginID;
                                s_windowsServiceClient.Helper.Password = SecurityProviderUtility.EncryptPassword(provider.Password);
                                remotingClient = s_windowsServiceClient.Helper.RemotingClient as TlsClient;

                                if ((object)remotingClient != null && (object)provider.SecurePassword != null && provider.SecurePassword.Length > 0)
                                    remotingClient.NetworkCredential = new NetworkCredential(userData.LoginID, provider.SecurePassword);
                            }
                        }

                        s_windowsServiceClient.Helper.RemotingClient.MaxConnectionAttempts = -1;
                        s_windowsServiceClient.Helper.RemotingClient.ConnectionEstablished += RemotingClient_ConnectionEstablished;
                        s_windowsServiceClient.Helper.RemotingClient.ConnectionException += RemotingClient_ConnectionException;

                        ConnectAsync();
                    }
                }
                finally
                {
                    database.Dispose();
                }
            }
        }
開發者ID:rmc00,項目名稱:gsf,代碼行數:57,代碼來源:CommonFunctions.cs


注:本文中的AdoDataConnection.ServiceConnectionString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。