public static InstanceVersion GetMinVersion(string version)
		{
			version = version.Trim();

			if(version == "*")
			{
				return new InstanceVersion() { Major = int.MinValue};
			}

			var result = new InstanceVersion();
			var split  = version.Split(' ')[0].Split('.');

			if(split.Length > 0)
			{
				result.Major = (split[0] ?? "0") == "*" ? int.MinValue : int.Parse(split[0] ?? "0");
			}

			if(split.Length > 1)
			{
				result.Minor = (split[1] ?? "0") == "*" ? int.MinValue : int.Parse(split[1] ?? "0");
			}

			if(split.Length > 2)
			{
				result.Build = (split[2] ?? "0") == "*" ? int.MinValue : int.Parse(split[2] ?? "0");
			}

			return result;
		}
Beispiel #2
0
        public static InstanceVersion GetMaxVersion(string version)
        {
            version = version.Trim();

            if (version == "*")
            {
                return(new InstanceVersion()
                {
                    Major = int.MaxValue
                });
            }

            var result = new InstanceVersion();
            var split  = version.Split(' ')[0].Split('.');

            if (split.Length > 0)
            {
                result.Major = (split[0] ?? "0") == "*" ? int.MaxValue : int.Parse(split[0] ?? "0");
            }

            if (split.Length > 1)
            {
                result.Minor = (split[1] ?? "0") == "*" ? int.MaxValue : int.Parse(split[1] ?? "0");
            }

            if (split.Length > 2)
            {
                result.Build = (split[2] ?? "0") == "*" ? int.MaxValue : int.Parse(split[2] ?? "0");
            }

            return(result);
        }
Beispiel #3
0
 public ServerProperties(
     InstanceVersion version,
     string name,
     DateTime date
     )
 {
     this.Version = version;
     this.Name    = name;
     this.Date    = date;
 }
		public ServerProperties(
			InstanceVersion version,
			string          name,
			DateTime        date
		)
		{
			this.Version = version;
			this.Name    = name;
			this.Date    = date;
		}
Beispiel #5
0
        public override bool Equals(object obj)
        {
            InstanceVersion version = obj as InstanceVersion;

            if (version == null)
            {
                return(false);
            }

            return(version.CompareTo(this) == 0);
        }
Beispiel #6
0
        private static ServerProperties QueryMssql(
            InstanceInfo instance,
            int timeout = 0
            )
        {
            string   sqlString  = string.Empty;
            string   serverName = string.Empty;
            DateTime serverDate = DateTime.MaxValue;

            using (DbConnection dbConnection = CreateMssqlConnection(instance))
            {
                dbConnection.Open();

                InstanceVersion version = new InstanceVersion(dbConnection.ServerVersion);

                bool isNewServer = version.Major >= 8;                  // MS SQL Server 2000

                if (isNewServer)
                {
                    sqlString = "SELECT SERVERPROPERTY(N'ServerName') AS [ServerName], " +
                                "SERVERPROPERTY(N'InstanceName') AS [InstanceName], " +
                                "GetDate() AS [InstanceDate];";
                }
                else
                {
                    sqlString = "SELECT GetDate() AS [InstanceDate];";
                }

                using (DbCommand command = dbConnection.CreateCommand())
                {
                    command.CommandText = sqlString;

                    if (timeout != 0)
                    {
                        command.CommandTimeout = timeout;
                    }

                    using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (reader.Read())
                        {
                            serverName = isNewServer
                                                                ? reader["ServerName"].ToString()
                                                                : dbConnection.DataSource;

                            serverDate = DateTime.Parse(reader["InstanceDate"].ToString());
                        }
                    }
                }

                return(new ServerProperties(version, serverName, serverDate));
            }
        }
		private static ServerProperties QueryMssql(
			InstanceInfo instance,
			int          timeout = 0
		)
		{
			string   sqlString  = string.Empty;
			string   serverName = string.Empty;
			DateTime serverDate = DateTime.MaxValue;

			using (DbConnection dbConnection = CreateMssqlConnection(instance))
			{
				dbConnection.Open();

				InstanceVersion version = new InstanceVersion(dbConnection.ServerVersion);

				bool isNewServer = version.Major >= 8;  // MS SQL Server 2000

				if (isNewServer)
				{
					sqlString = "SELECT SERVERPROPERTY(N'ServerName') AS [ServerName], " +
					            "SERVERPROPERTY(N'InstanceName') AS [InstanceName], " +
					            "GetDate() AS [InstanceDate];";
				}
				else
				{
					sqlString = "SELECT GetDate() AS [InstanceDate];";
				}

				using (DbCommand command = dbConnection.CreateCommand())
				{
					command.CommandText = sqlString;

					if (timeout != 0)
					{
						command.CommandTimeout = timeout;
					}

					using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
					{
						if (reader.Read())
						{
							serverName = isNewServer
								? reader["ServerName"].ToString()
								: dbConnection.DataSource;

							serverDate = DateTime.Parse(reader["InstanceDate"].ToString());
						}
					}
				}

				return new ServerProperties(version, serverName, serverDate);
			}
		}
Beispiel #8
0
        /// <summary>
        /// Determines is query item applicable for server version
        /// </summary>
        /// <param name="version">Server version</param>
        /// <returns>Is it match</returns>
        public bool IsApplicableVersion(InstanceVersion version)
        {
            if (ParentQuery.Source == QuerySource.SQLite)
            {
                return(true);
            }

            var minVersion = InstanceVersion.GetMinVersion(MinVersion);
            var maxVersion = InstanceVersion.GetMaxVersion(MaxVersion);

            return(version.CompareTo(minVersion) >= 0 && version.CompareTo(maxVersion) <= 0);
        }
Beispiel #9
0
        private static ServerProperties QueryTeradata(
            InstanceInfo instance,
            int timeout = 0
            )
        {
            using (DbConnection dbConnection = CreateTeradataConnection(instance))
            {
                dbConnection.Open();

                InstanceVersion version    = new InstanceVersion(dbConnection.ServerVersion);
                DateTime        serverDate = DateTime.MaxValue;

                using (DbCommand command = dbConnection.CreateCommand())
                {
                    command.CommandText = "SELECT CURRENT_DATE AS InstanceDate";

                    if (timeout != 0)
                    {
                        command.CommandTimeout = timeout;
                    }

                    using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (reader.Read())
                        {
                            serverDate = DateTime.Parse(reader["InstanceDate"].ToString());
                        }
                    }
                }

                return(new ServerProperties(
                           version,
                           dbConnection.DataSource,
                           serverDate));
            }
        }
		private static ServerProperties QueryTeradata(
			InstanceInfo instance,
			int          timeout = 0
		)
		{
			using (DbConnection dbConnection = CreateTeradataConnection(instance))
			{
				dbConnection.Open();

				InstanceVersion version = new InstanceVersion(dbConnection.ServerVersion);
				DateTime  serverDate    = DateTime.MaxValue;

				using (DbCommand command = dbConnection.CreateCommand())
				{
					command.CommandText = "SELECT CURRENT_DATE AS InstanceDate";

					if (timeout != 0)
					{
						command.CommandTimeout = timeout;
					}

					using (DbDataReader reader = command.ExecuteReader(CommandBehavior.SingleRow))
					{
						if (reader.Read())
						{
							serverDate = DateTime.Parse(reader["InstanceDate"].ToString());
						}
					}
				}

				return new ServerProperties(
					version,
					dbConnection.DataSource,
					serverDate);
			}
		}
Beispiel #11
0
		/// <summary>
		/// Determines is query item applicable for server version
		/// </summary>
		/// <param name="version">Server version</param>
		/// <returns>Is it match</returns>
		public bool IsApplicableVersion(InstanceVersion version)
		{
			if (ParentQuery.Source == QuerySource.SQLite)
			{
				return true;
			}

			var minVersion = InstanceVersion.GetMinVersion(MinVersion);
			var maxVersion = InstanceVersion.GetMaxVersion(MaxVersion);

			return version.CompareTo(minVersion) >= 0 && version.CompareTo(maxVersion) <= 0;
		}
		private List<InstanceInfo> ExecuteSelectInstancesCommand(SQLiteConnection connection, string sql)
		{
			List<InstanceInfo> result = new List<InstanceInfo>();

			new SqlSelectCommand(
				connection,
				sql,
				reader =>
				{
					InstanceVersion version = new InstanceVersion(reader[ServerInstanceDirectory.ServerInstanceVersionFn].ToString());

					ServerProperties props  = new ServerProperties(
						version,
						reader[ServerInstanceDirectory.ServerInstanceNameFn].ToString(),
						DateTime.Now
					);

					AuthenticationInfo auth = new AuthenticationInfo
					{
						IsWindows = (bool) reader[LoginDirectory.IsWinAuthFn],
						Username  = reader[LoginDirectory.LoginFn].ToString(),
						Password  = this._cryptoService.Decrypt(reader[LoginDirectory.PasswordFn].ToString())
					};

					result.Add(
						new InstanceInfo(props)
						{
							Authentication = auth,
							Instance       = reader[ServerInstanceDirectory.ConnectionNameFn].ToString(),
							IsEnabled      = true,
							Name           = reader[ServerInstanceDirectory.ConnectionNameFn].ToString(),
							DbType         = reader[ServerInstanceDirectory.DbTypeFn].ToString(),
							IsODBC         = (bool) reader[ServerInstanceDirectory.IsOdbcFn]
						}
					);
				}
			).Execute(100);

			return result;
		}
 /// <summary>
 /// Get item query for this version.
 /// </summary>
 /// <param name="list">List item query.</param>
 /// <param name="version">Version.</param>
 /// <returns>
 /// Item for your version.
 /// </returns>
 public static QueryItemInfo GetQueryItemForVersion(this IEnumerable<QueryItemInfo> list, InstanceVersion version)
 {
     return (from itemInfo in list where itemInfo.IsApplicableVersion(version) select itemInfo).FirstOrDefault();
 }