Beispiel #1
0
        /// <summary>
        /// Replaces the config file.
        /// </summary>
        /// <param name="serverDetails">The server details.</param>
        public void ReplaceConfigFile(ServerDetailsModel serverDetails)
        {
            var        dir         = new DirectoryInfo(serverDetails.DestinationFileLocation);
            FileInfo   fileDetails = dir.EnumerateFiles("*.zip", SearchOption.AllDirectories).First();
            ZipArchive archive     = ZipFile.Open(fileDetails.FullName, ZipArchiveMode.Update);
            //Gets the Web.config file for the server.
            IEnumerable <FileInfo> configFiles = dir.EnumerateFiles("*.config", SearchOption.AllDirectories);

            if (configFiles.Any())
            {
                FileInfo configFileDetails = dir.EnumerateFiles("*.config", SearchOption.AllDirectories).First();
                archive.Entries.First(p => p.Name == "Web.config").Delete();
                if (archive.Entries.Any(p => p.Name == "Web.Debug.config"))
                {
                    archive.Entries.First(p => p.Name == "Web.Debug.config").Delete();
                }
                if (archive.Entries.Any(p => p.Name == "Web.Release.config"))
                {
                    archive.Entries.First(p => p.Name == "Web.Release.config").Delete();
                }
                //Copies the web.config file to the zip file.
                archive.CreateEntryFromFile(configFileDetails.FullName, "Web.config");
            }
            archive.Dispose();
        }
Beispiel #2
0
        /// <summary>
        /// Processes the xcopy.
        /// </summary>
        /// <param name="serverDetails">The server details.</param>
        public void ProcessXcopy(ServerDetailsModel serverDetails)
        {
            // Use ProcessStartInfo class
            var startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow  = false;
            startInfo.UseShellExecute = false;
            //Give the name as Xcopy
            startInfo.FileName = "xcopy";
            //make the window Hidden
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            //Send the Source and destination as Arguments to the process
            startInfo.Arguments = "\"" + serverDetails.SourceFileName + "\"" + " " + "\"" + serverDetails.DestinationFileLocation + "\"" + @" /e /y /I";
            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                    exeProcess.Close();
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Puts the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public HttpResponseMessage Put(ServerDetailsModel input)
        {
            var configFileWriter = new ConfigFileWriter().UpdateConfigFile(input);

            return(configFileWriter
                ? Request.CreateResponse(HttpStatusCode.Created, "Updated successfully")
                : Request.CreateErrorResponse(HttpStatusCode.NotModified, "Config file not modified"));
        }
Beispiel #4
0
        /// <summary>
        /// Deletes the old file.
        /// </summary>
        /// <param name="serverDetails">The server details.</param>
        public void DeleteOldFile(ServerDetailsModel serverDetails)
        {
            var dir    = new DirectoryInfo(serverDetails.DestinationFileLocation);
            int fCount = Directory.GetFiles(serverDetails.DestinationFileLocation, "*.zip", SearchOption.AllDirectories).Length;

            if (fCount > serverDetails.FileLimit)
            {
                FileInfo oldFileName =
                    dir.EnumerateFiles("*.zip", SearchOption.AllDirectories).OrderBy(d => d.CreationTime).First();
                File.Delete(serverDetails.DestinationFileLocation + "\\" + oldFileName);
            }
        }
        /// <summary>
        /// Selects the source and destination.
        /// </summary>
        /// <param name="promoteCode">The promote code.</param>
        private static string SelectSourceAndDestination(PromoteCodeModel promoteCode)
        {
            var configFileReader = new ConfigFileReader();

            ServerDetailsModel serverDetails = configFileReader.ReadConfigFile(new ServerDetailsModel
            {
                Region = promoteCode.Region
            });

            var sourceFileName = serverDetails.SourceFileLocation + "\\" + promoteCode.FileName;

            return(sourceFileName);
        }
Beispiel #6
0
        /// <summary>
        /// Reads the config file.
        /// </summary>
        /// <param name="serverDetailsRequest">The server details request.</param>
        /// <returns></returns>
        public ServerDetailsModel ReadConfigFile(ServerDetailsModel serverDetailsRequest)
        {
            //string path = Path.Combine(Environment.CurrentDirectory, "Config.json");
            //for testing purpose only
            const string path = @"D:\\DeployNowClient\\Config.json";

            var configList = JsonConvert.DeserializeObject <List <ServerDetailsModel> >(File.ReadAllText(path));


            var serverDetailsResponse = configList.FirstOrDefault(p => p.Region == serverDetailsRequest.Region);

            return((ServerDetailsModel)serverDetailsResponse);
        }
        /// <summary>
        /// Updates the config file.
        /// </summary>
        /// <param name="serverModels">The server models.</param>
        /// <returns></returns>
        public bool UpdateConfigFile(ServerDetailsModel serverModels)
        {
            const string path = @"C:\\Shared\\Dev\\DeployNow\\DeployNowClient\\Config.json";

            var configList = JsonConvert.DeserializeObject <List <ServerDetailsModel> >(File.ReadAllText(path));

            foreach (var config in configList.Where(config => serverModels.Region != null && config.Region == serverModels.Region))
            {
                //mapping the previous values to modified value
                config.ServerList = serverModels.ServerList;
            }
            var output = Newtonsoft.Json.JsonConvert.SerializeObject(configList, Newtonsoft.Json.Formatting.Indented);

            File.WriteAllText(path, output);
            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// Excecutes the specified deploy entity.
        /// </summary>
        /// <param name="deployEntity">The deploy entity.</param>S
        public void Excecute(dynamic deployEntity)
        {
            var promoteCodeModel = (PromoteCodeModel)deployEntity;

            //initialize config file reader
            var configFileReader = new ConfigFileReader();

            //read config file based on region givenS
            ServerDetailsModel serverDetails = configFileReader.ReadConfigFile(new ServerDetailsModel
            {
                Region = promoteCodeModel.Region
            });

            //get the source file name by concatenating sourcelocation and filename
            serverDetails.SourceFileName = serverDetails.SourceFileLocation + "\\" + promoteCodeModel.FileName;

            //create the destination directory if uit does now exists
            if (!Directory.Exists(serverDetails.DestinationFileLocation))
            {
                Directory.CreateDirectory(serverDetails.DestinationFileLocation);
            }
        }