Esempio n. 1
0
        public static AuxConfig Load(String configFilePath)
        {
            AuxConfig config = null;

            if (String.IsNullOrEmpty(configFilePath))
            {
                throw new ArgumentNullException(nameof(configFilePath));
            }
            if (!File.Exists(configFilePath))
            {
                String configDirPath = Path.GetDirectoryName(configFilePath);
                if (!Directory.Exists(configDirPath))
                {
                    Directory.CreateDirectory(configDirPath);
                }

                using (StreamWriter stream = File.CreateText(configFilePath))
                {
                    config = AuxConfig.GetDefault();
                    JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()
                    {
                        Formatting        = Formatting.Indented,
                        NullValueHandling = NullValueHandling.Ignore
                    });
                    serializer.Serialize(stream, config);
                }
            }
            using (StreamReader file = File.OpenText(configFilePath))
            {
                JsonSerializer serializer = new JsonSerializer();
                config = (AuxConfig)serializer.Deserialize(file, typeof(AuxConfig));
            }
            return(config);
        }
 internal void OnDeserialized(StreamingContext context)
 {
     AuxConfig = AuxConfig.Load(AuxConfigFilePath);
 }