Exemplo n.º 1
0
        static void SetDefault()
        {
            _ThresholdConfigs = new ThresholdConfigs();

            _ThresholdConfigs.AppName  = "Breast";
            _ThresholdConfigs.Elements = new List <ThresholdElement>();


            ThresholdElement Element1 = new ThresholdElement {
                ID = 1, ThresholdName = new string[] { "Free", "Free", "Free" }, ThresholdValue = new double[] { 80, 80, 80 }, Color = Color.Green
            };
            ThresholdElement Element2 = new ThresholdElement {
                ID = 2, ThresholdName = new string[] { "First Warning", "First Warning", "First Warning" }, ThresholdValue = new double[] { 110, 110, 110 }, Color = Color.GreenYellow
            };
            ThresholdElement Element3 = new ThresholdElement {
                ID = 3, ThresholdName = new string[] { "Second Warning", "Second Warning", "Second Warning" }, ThresholdValue = new double[] { 130, 130, 130 }, Color = Color.Yellow
            };
            ThresholdElement Element4 = new ThresholdElement {
                ID = 4, ThresholdName = new string[] { "First Danger", "First Danger", "First Danger" }, ThresholdValue = new double[] { 160, 160, 160 }, Color = Color.OrangeRed
            };
            ThresholdElement Element5 = new ThresholdElement {
                ID = 5, ThresholdName = new string[] { "Second Danger", "Second Danger", "Second Danger" }, ThresholdValue = new double[] { 300, 300, 300 }, Color = Color.Red
            };


            _ThresholdConfigs.Elements.Add(Element1);
            _ThresholdConfigs.Elements.Add(Element2);
            _ThresholdConfigs.Elements.Add(Element3);
            _ThresholdConfigs.Elements.Add(Element4);
            _ThresholdConfigs.Elements.Add(Element5);
        }
Exemplo n.º 2
0
        public static ThresholdConfigs GetInstance()
        {
            if (_ThresholdConfigs == null)
            {
                string contents = "";
                try
                {
                    contents = File.ReadAllText(@"ThresholdConfig.json");
                }
                catch (Exception ex)
                {
                    SetDefault();
                    return(_ThresholdConfigs);
                }


                if (string.IsNullOrEmpty(contents))
                {
                    SetDefault();
                    return(_ThresholdConfigs);
                }

                try
                {
                    _ThresholdConfigs = JsonConvert.DeserializeObject <ThresholdConfigs>(contents);
                }
                catch (Exception ex)
                {
                    SetDefault();
                    return(_ThresholdConfigs);
                }
            }
            return(_ThresholdConfigs);
        }