Ejemplo n.º 1
0
        /// <summary>
        /// Posts this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <HttpResponseMessage> Post()
        {
            //check if the request does't have Zip file
            if (!HttpContentMultipartExtensions.IsMimeMultipartContent(this.Request.Content))
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Expected Zip folder for deployment"));
            }

            //Zip files in the request data will be put into current directory
            string requestBackupPath = Path.Combine(Environment.CurrentDirectory, "RequestZipFiles");

            Console.WriteLine(requestBackupPath);

            MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(requestBackupPath);

            await
            HttpContentMultipartExtensions.ReadAsMultipartAsync <MultipartFormDataStreamProvider>(
                this.Request.Content,
                streamProvider);

            var sourcePath =
                Enumerable.FirstOrDefault <string>(
                    Enumerable.Select((IEnumerable <MultipartFileData>)streamProvider.FileData,
                                      (p => p.LocalFileName)));

            try
            {
                //getting the deploy path
                var deployPath = streamProvider.FormData.Get("Directory");
                //const string deployPath = "C:\\Test"; //for testing locally using fiddler

                //creates the deploy path if it does not exists
                if (!Directory.Exists(deployPath))
                {
                    Directory.CreateDirectory(deployPath);
                }

                this.deploymentRequestHandler.Handle(new DeployRequestDto
                {
                    SourcePath = sourcePath,
                    DeployPath = deployPath
                });

                //to clear the stream provider folder
                this.ClearStreamProvider(requestBackupPath);
            }
            catch (AggregateException ex)
            {
                DeployLogger.LogMessage.Error(ex);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
            catch (Exception ex)
            {
                DeployLogger.LogMessage.Error(ex);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(this.Request.CreateErrorResponse(HttpStatusCode.OK,
                                                    "Deployment Completed"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Posts this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <HttpResponseMessage> Post()
        {
            //check if the request does't have Zip file
            if (!HttpContentMultipartExtensions.IsMimeMultipartContent(this.Request.Content))
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Expected Zip folder for deployment"));
            }

            //Zip files in the request data will be put into current directory
            string sqlBackUpPath = Path.Combine(Environment.CurrentDirectory, "RequestZipFiles");

            Console.WriteLine(sqlBackUpPath);

            var streamProvider = new MultipartFormDataStreamProvider(sqlBackUpPath);

            await
            HttpContentMultipartExtensions.ReadAsMultipartAsync <MultipartFormDataStreamProvider>(
                this.Request.Content,
                streamProvider);

            var sourcePath =
                Enumerable.FirstOrDefault <string>(
                    Enumerable.Select((IEnumerable <MultipartFileData>)streamProvider.FileData,
                                      (p => p.LocalFileName)));

            try
            {
                //getting the deploy path
                var deployPath    = streamProvider.FormData.Get("Directory");
                var tempDirectory = streamProvider.FormData.Get("TempDirectory");
                var webConfigPath = streamProvider.FormData.Get("WebConfigPath");

                //var deployPath = "C:\\Papillon\\DEVSQLScripts";
                //var tempDirectory = "C:\\SQLScripts";
                var deployRequest = new DeployRequestDto
                {
                    SourcePath            = sourcePath,
                    DeployPath            = deployPath,
                    IntermediateDirectory = tempDirectory,
                    WebConfigPath         = webConfigPath
                };

                //creates the temporary directory to store the sql files if it does not exists.
                if (!Directory.Exists(tempDirectory))
                {
                    Directory.CreateDirectory(tempDirectory);
                }

                // Store the SQL files in the temporary directory.
                this.sqlDeploymentRequestHandler.Handle(deployRequest);

                //Execute all the files available in intermediate directory.
                this.sqlScriptExecutor.Handle(deployRequest);

                //creates the deploy path if it does not exists
                if (!Directory.Exists(deployPath))
                {
                    Directory.CreateDirectory(deployPath);
                }

                // Store the SQL files in the destination.
                this.deploymentRequestHandler.Handle(deployRequest);

                //Deletes the sql scripts from the source server.
                this.clearSourceScriptsHelper.Handle(deployRequest);

                return(Request.CreateResponse(HttpStatusCode.OK, "SQL Scripts Deployed and Executed Successfully."));
            }
            catch (AggregateException ex)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
            catch (Exception ex)
            {
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }