/// <summary>
        /// Gets the service host types.
        /// </summary>
        /// <returns></returns>
        public IList <ServiceHostType> GetServiceHostTypes()
        {
            var list = new List <ServiceHostType>();

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetAllServiceHostTypes();

                foreach (var result in results)
                {
                    var item = new ServiceHostType
                    {
                        ClassName    = result.ServiceHostTypeClassName,
                        FriendlyName = result.ServiceHostTypeFriendlyName,
                        Type_id      = result.ServiceHostType_id
                    };
                    list.Add(item);
                }

                conn.Close();
                conn.Dispose();
            }

            return(list);
        }
        /// <summary>
        /// Gets the service configuration.
        /// </summary>
        /// <param name="serviceName">Name of the service.</param>
        /// <param name="appCode">The app code.</param>
        /// <returns></returns>
        public ServiceConfiguration GetServiceConfiguration(string serviceName, string appCode)
        {
            var config = new ServiceConfiguration();

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetServiceConfiguration(serviceName, Environment.MachineName.ToLowerInvariant(), appCode);

                var en = results.GetResult <ServiceConfiguration>().GetEnumerator();
                try
                {
                    if (en.MoveNext())
                    {
                        config.ServiceBehaviorXML = en.Current.ServiceBehaviorXML;
                        config.ServiceHostType_id = en.Current.ServiceHostType_id;
                        config.HostXML            = en.Current.HostXML;
                    }
                    var endpoints = results.GetResult <EndpointConfiguration>();
                    config.Endpoints = new List <EndpointConfiguration>(endpoints);
                }
                catch (InvalidOperationException)
                {
                    throw new ConfigurationErrorsException("No endpoint could be found for specified service - " + serviceName);
                }
                conn.Close();
                conn.Dispose();
            }

            return(config);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the service deployment configuration.
        /// </summary>
        /// <param name="appCode">The app code.</param>
        /// <returns></returns>
        public IList <ServiceDeploymentConfiguration> GetServiceDeploymentConfiguration(string appCode)
        {
            var list = new List <ServiceDeploymentConfiguration>();

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetServiceDeploymentConfiguration(
                    Environment.MachineName.ToLowerInvariant(), appCode);

                foreach (var result in results)
                {
                    var serviceDeployment = new ServiceDeploymentConfiguration
                    {
                        ServiceName     = result.ServiceName,
                        HostXML         = result.HostXML,
                        EndpointAddress = result.EndpointAddress,
                        ListenUri       = result.ListenUri
                    };

                    list.Add(serviceDeployment);
                }

                conn.Close();
                conn.Dispose();
            }

            return(list);
        }
        /// <summary>
        /// Gets AppVariable value by given appVariableName and appCode.
        /// </summary>
        /// <param name="appVariableName">Name of the app variable.</param>
        /// <param name="appCode">The app code.</param>
        /// <returns></returns>
        public string GetAppVariable(string appVariableName, string appCode)
        {
            if (string.IsNullOrEmpty(appVariableName))
            {
                throw new ArgumentNullException("appVariableName");
            }

            string retValue = null;

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetAppVariable(appVariableName, appCode,
                                                        Environment.MachineName.ToLowerInvariant());

                foreach (var result in results)
                {
                    retValue = result.Value;
                    break;
                }

                conn.Close();
                conn.Dispose();
            }

            return(retValue);
        }
        /// <summary>
        /// Get connection string by given connectionStringName.
        /// </summary>
        /// <param name="connectionStringName">Name of the connection string.</param>
        /// <returns></returns>
        public ConnectionString GetConnectionString(string connectionStringName)
        {
            if (string.IsNullOrEmpty(connectionStringName))
            {
                throw new ArgumentNullException("connectionStringName");
            }

            ConnectionString connectionString = null;

            if (connectionStringName == Constants.ConfigurationDatabaseConnectionStringName)
            {
                connectionString = new ConnectionString
                {
                    ProviderName = "System.Data.SqlClient",
                    Value        = WcfServiceHelper.GetConfigurationConnectionString()
                };
                return(connectionString);
            }

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetConnectionString(connectionStringName,
                                                             Environment.MachineName.ToLowerInvariant());

                foreach (var result in results)
                {
                    connectionString = new ConnectionString {
                        Value = result.Value, ProviderName = result.ProviderName
                    };
                    break;
                }

                conn.Close();
                conn.Dispose();
            }

            if (connectionString == null)
            {
                throw new ConfigurationErrorsException("Specified connection string name '" + connectionStringName + "' doesn't exist for your server farm!");
            }

            return(connectionString);
        }
        /// <summary>
        /// Gets the client configuration.
        /// </summary>
        /// <param name="serviceContract">The service contract.</param>
        /// <returns></returns>
        public ClientConfiguration GetClientConfiguration(Type serviceContract)
        {
            var config = new ClientConfiguration();

            using (var conn = new SqlConnection(WcfServiceHelper.GetConfigurationConnectionString()))
            {
                conn.Open();

                var context = new StoredProceduresDataContext(conn);
                var results = context.sp_GetClientConfiguration(serviceContract.GetQualifiedTypeName(),
                                                                Environment.MachineName.ToLowerInvariant());

                foreach (var result in results)
                {
                    config.HostXML  = result.HostXML;
                    config.Endpoint = new EndpointConfiguration
                    {
                        BindingNamespace    = result.BindingNamespace,
                        EndpointAddress     = result.EndpointAddress,
                        FarmAddress         = result.FarmAddress,
                        ListenUri           = result.ListenUri,
                        EndpointBehaviorXML = result.EndpointBehaviorXML,
                        IdentityXML         = result.IdentityXML,
                        BindingType_id      = result.BindingType_id,
                        BindingXML          = result.BindingXML
                    };
                    if (result.ListenUriMode_id.HasValue)
                    {
                        config.Endpoint.ListenUriMode
                            = (EndpointListenUriMode)result.ListenUriMode_id.Value;
                    }

                    break;
                }

                conn.Close();
                conn.Dispose();
            }

            return(config);
        }