Ejemplo n.º 1
0
        public void Update(ToscaConfigFilesModel config)
        {
            IEnumerable <string> appsettingsList = Directory.GetFiles(AppPath, "appsettings.json");

            foreach (var appsetting in appsettingsList)
            {
                try
                {
                    Trace.WriteLine("Updating files in AO service");
                    string  json    = File.ReadAllText(appsetting);
                    JObject jsonObj = JObject.Parse(json);
                    Trace.WriteLine("---ServiceDiscovery.");
                    UpdateJSONFields.UpdateServiceDiscovery(jsonObj, config, appsetting);
                    Trace.WriteLine("---Scheme.");
                    UpdateJSONFields.UpdateScheme(jsonObj, appsetting);
                    Trace.WriteLine("---HTTPS Thumbprint.");
                    UpdateJSONFields.UpdateCertificate(jsonObj, config, appsetting);
                    Trace.WriteLine("---DexBaseUrl");
                    UpdateDexBaseUrl(jsonObj, config, appsetting);
                    string output = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
                    File.WriteAllText(appsetting, output);
                    UpdatedFilesCount++;
                    Updated = true;
                }
                catch (Exception)
                {
                    Trace.WriteLine("Failed to updated file at " + AppPath);
                }
            }
        }
Ejemplo n.º 2
0
        public void Update(ToscaConfigFilesModel config)
        {
            try
            {
                IEnumerable <string> appsettingsList = Directory.GetFiles(AppPath, "appsettings.json");

                foreach (var appsetting in appsettingsList)
                {
                    Trace.WriteLine($"Updating files in {appsetting}");
                    string  json    = File.ReadAllText(appsetting);
                    JObject jsonObj = JObject.Parse(json);
                    Trace.WriteLine("---ServiceDiscovery.");
                    UpdateJSONFields.UpdateServiceDiscovery(jsonObj, config, appsetting);
                    string output = JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
                    File.WriteAllText(appsetting, output);
                    UpdatedFilesCount++;
                }
            }
            catch (Exception)
            {
                Trace.WriteLine("Failed to updated file at " + AppPath);
            }

            //update web.config
            var         webconfig = AppPath + @"\web.config";
            XmlDocument doc       = new XmlDocument();

            try
            {
                doc.Load(AppPath + @"\web.config");
                Trace.WriteLine("---CORS.");
                UpdateXMLFields.UpdateCORS(ref doc, config, webconfig);

                using (FileStream fs = File.Open(AppPath + @"\Web.config", FileMode.Create, FileAccess.Write))
                {
                    doc.Save(fs);
                    UpdatedFilesCount++;
                    Updated = true;
                }
            }
            catch (Exception)
            {
                Trace.WriteLine("Unable to update file at " + AppPath + @"\Web.config");
            }
        }