Exemplo n.º 1
0
        /// <summary>
        /// Handles a create database request
        /// </summary>
        internal static async Task HandleCreateDatabaseRequest(
            CreateDatabaseParams databaseParams,
            RequestContext <CreateDatabaseResponse> requestContext)
        {
            var            response = new DefaultDatabaseInfoResponse();
            ConnectionInfo connInfo;

            AdminService.ConnectionServiceInstance.TryFindConnection(
                databaseParams.OwnerUri,
                out connInfo);

            if (taskHelper == null)
            {
                taskHelper = CreateDatabaseTaskHelper(connInfo);
            }

            DatabasePrototype prototype = taskHelper.Prototype;

            DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype);

            Database db = prototype.ApplyChanges();

            if (db != null)
            {
                taskHelper = null;
            }

            await requestContext.SendResult(new CreateDatabaseResponse()
            {
                Result = true,
                TaskId = 0
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create database task helper
        /// </summary>
        /// <param name="connInfo">connection info</param>
        /// <param name="databaseExists">flag indicating whether to create taskhelper for existing database or not</param>
        /// <returns></returns>
        internal static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo, bool databaseExists = false)
        {
            var dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists);
            var taskHelper    = new DatabaseTaskHelper(dataContainer);

            return(taskHelper);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Return database info for a specific database
 /// </summary>
 /// <param name="connInfo"></param>
 /// <returns></returns>
 internal static DatabaseInfo GetDatabaseInfo(ConnectionInfo connInfo)
 {
     using (DatabaseTaskHelper taskHelper = CreateDatabaseTaskHelper(connInfo, true))
     {
         return(DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Handles a create database request
        /// </summary>
        internal static async Task HandleCreateDatabaseRequest(
            CreateDatabaseParams databaseParams,
            RequestContext <CreateDatabaseResponse> requestContext)
        {
            try
            {
                var            response = new DefaultDatabaseInfoResponse();
                ConnectionInfo connInfo;
                AdminService.ConnectionServiceInstance.TryFindConnection(
                    databaseParams.OwnerUri,
                    out connInfo);

                using (var taskHelper = CreateDatabaseTaskHelper(connInfo))
                {
                    DatabasePrototype prototype = taskHelper.Prototype;
                    DatabaseTaskHelper.ApplyToPrototype(databaseParams.DatabaseInfo, taskHelper.Prototype);

                    Database db = prototype.ApplyChanges();

                    await requestContext.SendResult(new CreateDatabaseResponse()
                    {
                        Result = true,
                        TaskId = 0
                    });
                }
            }
            catch (Exception ex)
            {
                await requestContext.SendError(ex.ToString());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handle a request for the default database prototype info
        /// </summary>
        public static async Task HandleDefaultDatabaseInfoRequest(
            DefaultDatabaseInfoParams optionsParams,
            RequestContext <DefaultDatabaseInfoResponse> requestContext)
        {
            var            response = new DefaultDatabaseInfoResponse();
            ConnectionInfo connInfo;

            AdminService.ConnectionServiceInstance.TryFindConnection(
                optionsParams.OwnerUri,
                out connInfo);

            if (taskHelper == null)
            {
                taskHelper = CreateDatabaseTaskHelper(connInfo);
            }

            response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
            await requestContext.SendResult(response);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create database task helper
        /// </summary>
        /// <param name="connInfo">connection info</param>
        /// <param name="databaseExists">flag indicating whether to create taskhelper for existing database or not</param>
        /// <returns></returns>
        internal static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo, bool databaseExists = false)
        {
            XmlDocument    xmlDoc = CreateDataContainerDocument(connInfo, databaseExists);
            CDataContainer dataContainer;

            // add alternate port to server name property if provided
            var    connectionDetails = connInfo.ConnectionDetails;
            string serverName        = !connectionDetails.Port.HasValue
                ? connectionDetails.ServerName
                : string.Format("{0},{1}", connectionDetails.ServerName, connectionDetails.Port.Value);

            // check if the connection is using SQL Auth or Integrated Auth
            //TODO: ConnectionQueue try to get an existing connection (ConnectionQueue)
            if (string.Equals(connectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
            {
                var passwordSecureString = BuildSecureStringFromPassword(connectionDetails.Password);
                dataContainer = new CDataContainer(
                    CDataContainer.ServerType.SQL,
                    serverName,
                    false,
                    connectionDetails.UserName,
                    passwordSecureString,
                    xmlDoc.InnerXml);
            }
            else
            {
                dataContainer = new CDataContainer(
                    CDataContainer.ServerType.SQL,
                    serverName,
                    true,
                    null,
                    null,
                    xmlDoc.InnerXml);
            }

            var taskHelper = new DatabaseTaskHelper(dataContainer);

            return(taskHelper);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Handle a request for the default database prototype info
        /// </summary>
        public static async Task HandleDefaultDatabaseInfoRequest(
            DefaultDatabaseInfoParams optionsParams,
            RequestContext <DefaultDatabaseInfoResponse> requestContext)
        {
            try
            {
                var            response = new DefaultDatabaseInfoResponse();
                ConnectionInfo connInfo;
                AdminService.ConnectionServiceInstance.TryFindConnection(
                    optionsParams.OwnerUri,
                    out connInfo);

                using (var taskHelper = CreateDatabaseTaskHelper(connInfo))
                {
                    response.DefaultDatabaseInfo = DatabaseTaskHelper.DatabasePrototypeToDatabaseInfo(taskHelper.Prototype);
                    await requestContext.SendResult(response);
                }
            }
            catch (Exception ex)
            {
                await requestContext.SendError(ex.ToString());
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create database task helper
        /// </summary>
        /// <param name="connInfo">connection info</param>
        /// <param name="databaseExists">flag indicating whether to create taskhelper for existing database or not</param>
        /// <returns></returns>
        internal static DatabaseTaskHelper CreateDatabaseTaskHelper(ConnectionInfo connInfo, bool databaseExists = false)
        {
            XmlDocument    xmlDoc = CreateDataContainerDocument(connInfo, databaseExists);
            CDataContainer dataContainer;

            // check if the connection is using SQL Auth or Integrated Auth
            if (string.Equals(connInfo.ConnectionDetails.AuthenticationType, "SqlLogin", StringComparison.OrdinalIgnoreCase))
            {
                var passwordSecureString = new System.Security.SecureString();
                foreach (char c in connInfo.ConnectionDetails.Password)
                {
                    passwordSecureString.AppendChar(c);
                }
                dataContainer = new CDataContainer(
                    CDataContainer.ServerType.SQL,
                    connInfo.ConnectionDetails.ServerName,
                    false,
                    connInfo.ConnectionDetails.UserName,
                    passwordSecureString,
                    xmlDoc.InnerXml);
            }
            else
            {
                dataContainer = new CDataContainer(
                    CDataContainer.ServerType.SQL,
                    connInfo.ConnectionDetails.ServerName,
                    true,
                    null,
                    null,
                    xmlDoc.InnerXml);
            }

            var taskHelper = new DatabaseTaskHelper(dataContainer);

            return(taskHelper);
        }