/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> public void Handle(DeployRequestDto request) { //Get the connection string var sqlInputs = GetConnectionString(request); //get the scripts folder var directory = request.IntermediateDirectory; //get the files in the folder string[] fileEntries = Directory.GetFiles(directory); foreach (string fileName in fileEntries) { try { string content = string.Format(File.ReadAllText(fileName)); using (var oracleConnection = new OracleConnection(sqlInputs.ConnectionString)) { oracleConnection.Open(); var command = new OracleCommand(); var script = content.Replace("\t", " "); script = script.Replace("\n", Environment.NewLine); command.Connection = oracleConnection; command.CommandText = script; var result = command.ExecuteNonQuery(); Debug.Write(result); } } catch (Exception ex) { Debug.Write("Exception message: " + ex.Message); } } }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> public void Handle(DeployRequestDto request) { var processInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = "iisreset" }; using (var process = new Process()) { process.StartInfo = processInfo; process.Start(); process.WaitForExit(); } }
/// <summary> /// Gets the connection string. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> private SqlExecutionConfigModel GetConnectionString(DeployRequestDto request) { var sqlInput = new SqlExecutionConfigModel(); var webConfig = new XmlDocument(); //string webConfigPath = "C:\\Papillon\\Web.config"; string webConfigPath = request.WebConfigPath; webConfig.Load(webConfigPath); var connectionString = webConfig.SelectSingleNode("//connectionStrings"); if (connectionString != null) { var sqlConnectionString = connectionString.ChildNodes[0].Attributes[1].Value; var index = IndexOfNth(sqlConnectionString, 3); sqlInput.ConnectionString = sqlConnectionString.Substring(0, index); } return(sqlInput); }
/// <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)); } }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> public void Handle(DeployRequestDto request) { var client = new RedisClient(); client.FlushAll(); }