Ejemplo n.º 1
0
        public static ModelSettings FindOrCreateSettings()
        {
            ModelSettings modelSettings = new ModelSettings();
            var           filePath      = GetFilePath();

            JsonSerializer serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            if (File.Exists(filePath))
            {
                // read the file
                using (var sr = new StreamReader(filePath))
                {
                    using (var jsonReader = new JsonTextReader(sr))
                    {
                        modelSettings = serializer.Deserialize <ModelSettings>(jsonReader);
                    }
                }
            }
            else
            {
                // create the file
                using (var sw = new StreamWriter(filePath))
                {
                    using (var jsonWriter = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(jsonWriter, modelSettings);
                    }
                }
            }

            return(modelSettings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetches the current model settings file and sets the data in the form
        /// </summary>
        public void initModelSettings()
        {
            // Get the model settings file
            modelSettings = FetchSettings.FindOrCreateSettings();

            // Get the list of labels in the current model
            this.labelFiles = Labels.LabelHelper.GetLabelFiles();

            this.BindData();
        }
Ejemplo n.º 3
0
        public static void SaveSettings(ModelSettings modelSettings)
        {
            var filePath = GetFilePath();

            JsonSerializer serializer = new JsonSerializer();

            serializer.Converters.Add(new JavaScriptDateTimeConverter());
            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (var sw = new StreamWriter(filePath))
            {
                using (var jsonWriter = new JsonTextWriter(sw))
                {
                    serializer.Serialize(jsonWriter, modelSettings);
                }
            }
        }