/// <summary>
        /// Returns StiTestConnectionResult that is the information of whether the connection string specified in this class is correct.
        /// </summary>
        /// <returns>The result of testing the connection string.</returns>
        public override StiTestConnectionResult TestConnection()
        {
            try
            {
                //var client = new MongoClient(this.ConnectionString);
                var client = AssemblyHelper.CreateObject("MongoDB.Driver.MongoClient", this.ConnectionString);

                //var server = client.GetServer();
                var server = client.GetType().GetMethod("GetServer").Invoke(client, null);
                if (server == null)
                {
                    throw new NotSupportedException();
                }

                //server.Ping();
                server.GetType().GetMethod("Ping").Invoke(server, null);
            }
            catch (Exception exception)
            {
                if (exception.InnerException != null)
                {
                    return(StiTestConnectionResult.MakeWrong(exception.InnerException.Message));
                }
                else
                {
                    return(StiTestConnectionResult.MakeWrong(exception.Message));
                }
            }

            return(StiTestConnectionResult.MakeFine());
        }
        /// <summary>
        /// Returns StiTestConnectionResult that is the information of whether the connection string specified in this class is correct.
        /// </summary>
        /// <returns>The result of testing the connection string.</returns>
        public StiTestConnectionResult TestConnection()
        {
            try
            {
                using (var client = GetDefaultWebClient())
                {
                    client.DownloadString(Address);
                }
            }
            catch (Exception exception)
            {
                return(StiTestConnectionResult.MakeWrong(exception.Message));
            }

            return(StiTestConnectionResult.MakeFine());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns StiTestConnectionResult that is the information of whether the connection string specified in this class is correct.
        /// </summary>
        /// <returns>The result of testing the connection string.</returns>
        public virtual StiTestConnectionResult TestConnection()
        {
            try
            {
                using (var connection = CreateConnection())
                {
                    connection.Open();
                    connection.Close();
                }
            }
            catch (Exception exception)
            {
                return(StiTestConnectionResult.MakeWrong(exception.Message));
            }

            return(StiTestConnectionResult.MakeFine());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns StiTestConnectionResult that is the information of whether the connection string specified in this class is correct.
        /// </summary>
        /// <returns>The result of testing the connection string.</returns>
        public StiTestConnectionResult TestConnection(StiFileDataOptions options)
        {
            try
            {
                if (options == null || options.Content == null || options.Content.Length == 0)
                {
                    return(StiTestConnectionResult.MakeWrong(string.Format("{0} content is not found!", this.Name)));
                }

                var dataSet = GetDataSet(options);
                if (dataSet == null)
                {
                    return(StiTestConnectionResult.MakeWrong(string.Format("{0} content is not recognized!", this.Name)));
                }

                return(StiTestConnectionResult.MakeFine());
            }
            catch (Exception e)
            {
                return(StiTestConnectionResult.MakeWrong(e));
            }
        }