Exemplo n.º 1
0
        /// <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);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            DirectoryInfo directory = new DirectoryInfo(request.IntermediateDirectory);

            var signalrHub = new SignalrHub();

            //for deleting all the files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }

                //for deleting all the directories
                foreach (var dir in directory.GetDirectories())
                {
                    dir.Delete(true);
                }
            }
            catch (AggregateException ex)
            {
                throw ex;
            }

            //Copy only if the direcory is empty
            if (!directory.GetDirectories().Any() && !directory.GetFiles().Any())
            {
                //unzipping and extracting data to the deploy path
                ZipFile.ExtractToDirectory(request.SourcePath, request.IntermediateDirectory);
            }

            signalrHub.Publish("SqlDeployment", "Sql Scripts deployed to intermediate folder successfully.");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            DirectoryInfo directory = new DirectoryInfo(request.IntermediateDirectory);

            var signalrHub = new SignalrHub();

            //for deleting all the files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }

                //for deleting all the directories
                foreach (var dir in directory.GetDirectories())
                {
                    dir.Delete(true);
                }

            }
            catch (AggregateException ex)
            {
                throw ex;
            }

            //Copy only if the direcory is empty
            if (!directory.GetDirectories().Any() && !directory.GetFiles().Any())
            {
                //unzipping and extracting data to the deploy path
                ZipFile.ExtractToDirectory(request.SourcePath, request.IntermediateDirectory);
            }

            signalrHub.Publish("SqlDeployment", "Sql Scripts deployed to intermediate folder successfully.");
        }
Exemplo n.º 4
0
 /// <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();
     }
 }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
 public void ExcecuteTask(DeployRequestDto request)
 {
     try
     {
         var serverStopTask  = new Task(() => new ServerStopHelper().Handle(request));
         var deploytask      = serverStopTask.ContinueWith((task => new DeployRequestHandler().Handle(request)));
         var cacheCleartask  = deploytask.ContinueWith(task => new ClearCacheHelper().Handle(request));
         var startServerTask = cacheCleartask.ContinueWith(task => new ServerStartHelper().Handle(request));
         serverStopTask.Start();
     }
     catch (AggregateException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
 public void ExcecuteTask(DeployRequestDto request)
 {
     try
     {
         var serverStopTask = new Task(() => new ServerStopHelper().Handle(request));
         var deploytask = serverStopTask.ContinueWith((task => new DeployRequestHandler().Handle(request)));
         var cacheCleartask = deploytask.ContinueWith(task => new ClearCacheHelper().Handle(request));
         var startServerTask = cacheCleartask.ContinueWith(task => new ServerStartHelper().Handle(request));
         serverStopTask.Start();
     }
         catch(AggregateException ex)
         {
             throw ex;
         }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            var directory = new DirectoryInfo(request.SourcePath);

            var signalrHub = new SignalrHub();

            //for deleting all the sql script files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }
            }
            catch (AggregateException ex)
            {
                throw ex;
            }

            signalrHub.Publish("SqlSourceClear", "Sql scripts cleared from the source location.");
        }
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            var directory = new DirectoryInfo(request.SourcePath);

            var signalrHub = new SignalrHub();

            //for deleting all the sql script files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }
            }
            catch (AggregateException ex)
            {
                throw ex;
            }

               signalrHub.Publish("SqlSourceClear", "Sql scripts cleared from the source location.");
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            DirectoryInfo directory = new DirectoryInfo(request.DeployPath);

            var signalrHub = new SignalrHub();

            //for deleting all the files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }

                //for deleting all the directories
                foreach (var dir in directory.GetDirectories())
                {
                    dir.Delete(true);
                }
                DeployLogger.LogMessage.InfoFormat("Deploy folder {0} has been cleared successfully", request.DeployPath);
            }
            catch (AggregateException ex)
            {
                throw ex;
            }

            //Copy only if the direcory is empty
            if (!directory.GetDirectories().Any() && !directory.GetFiles().Any())
            {
                //unzipping and extracting data to the deploy path
                ZipFile.ExtractToDirectory(request.SourcePath, request.DeployPath);
                DeployLogger.LogMessage.InfoFormat("Code has been deployed to {0} folder successfully", request.DeployPath);
            }

            signalrHub.Publish("Deployment", "Deployment completed successfully");
        }
Exemplo n.º 11
0
        /// <summary>
        /// Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        public void Handle(DeployRequestDto request)
        {
            DirectoryInfo directory = new DirectoryInfo(request.DeployPath);

            var signalrHub = new SignalrHub();

            //for deleting all the files
            try
            {
                foreach (FileInfo file in directory.GetFiles())
                {
                    file.Delete();
                }

                //for deleting all the directories
                foreach (var dir in directory.GetDirectories())
                {
                    dir.Delete(true);
                }
                DeployLogger.LogMessage.InfoFormat("Deploy folder {0} has been cleared successfully", request.DeployPath);
            }
            catch (AggregateException ex)
            {
                throw ex;
            }

            //Copy only if the direcory is empty
            if (!directory.GetDirectories().Any() && !directory.GetFiles().Any())
            {
                //unzipping and extracting data to the deploy path
                ZipFile.ExtractToDirectory(request.SourcePath, request.DeployPath);
                DeployLogger.LogMessage.InfoFormat("Code has been deployed to {0} folder successfully", request.DeployPath);
            }

            signalrHub.Publish("Deployment" , "Deployment completed successfully");
        }
Exemplo n.º 12
0
 /// <summary>
 /// Handles the specified request.
 /// </summary>
 /// <param name="request">The request.</param>
 public void Handle(DeployRequestDto request)
 {
     var client = new RedisClient();
     client.FlushAll();
 }
Exemplo n.º 13
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);
            }
        }