Esempio n. 1
0
        /// <summary>
        /// si wapiConfigPath = "" intenta buscarlo en AppSettings si no lo encuntra configurado lo buscara en el root de la aplicacion
        /// </summary>
        /// <param name="wapiConfigPath"></param>
        /// <returns></returns>
        public static apiConfig CreateNew(string wapiConfigPath)
        {
            apiConfig apiConfig = null;

            if (string.IsNullOrEmpty(wapiConfigPath))
            {
                //wapiConfigPath = System.Configuration.ConfigurationManager.AppSettings.Get("wapiConfig");

                if (String.IsNullOrEmpty(wapiConfigPath))
                {
                    throw new TechnicalException("No se encuentra configurada la ruta del archivo  el wapiConfig.json en web.config settings");
                }
            }

            if (System.IO.File.Exists(wapiConfigPath) == false)
            {
                throw new TechnicalException("No existe el archivo  " + wapiConfigPath);
            }


            string apiConfigJson = FileFunctions.OpenTextFile(wapiConfigPath);

            apiConfig = (apiConfig)SerializationFunctions.DeSerializeObjectFromJson(typeof(apiConfig), apiConfigJson);



            return(apiConfig);
        }
Esempio n. 2
0
        /// <summary>
        /// update and set current apiConfig
        /// </summary>
        /// <param name="config"></param>
        public static void updateConfig(apiConfig config)
        {
            try
            {
                //TODO : ver updateConfig
                var settingName = "";//System.Configuration.ConfigurationManager.AppSettings.Get("wapiConfig");
                if (!String.IsNullOrEmpty(settingName))
                {
                    //if (System.IO.File.Exists(settingName) == false)
                    //{
                    //    throw new Fwk.Exceptions.TechnicalException("No existe el archivo de config " + settingName);
                    //}


                    var apiConfigString = Newtonsoft.Json.JsonConvert.SerializeObject(config, Formatting.Indented, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                    });

                    FileFunctions.SaveTextFile(settingName, apiConfigString, false);
                    apiConfig = config;

                    //apiConfig.logsFolder = @"c:\wapi_logs";
                    if (!System.IO.Directory.Exists(config.logsFolder))
                    {
                        System.IO.Directory.CreateDirectory(config.logsFolder);
                    }

                    //setProxy();
                }
            }
            catch (Exception ex)
            {
                //Log_FileSystem(ex);
                throw ex;
            }
        }