Ejemplo n.º 1
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");
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 6
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();
 }