Ejemplo n.º 1
0
        private void ReadSettings()
        {
            UserPreference = JsonConvert.DeserializeObject <UserPreference>(Properties.Settings.Default["preference"].ToString());
            List <IController> ctrls = new List <IController>();

            if (UserPreference != null)
            {
                Type   t  = typeof(Helper);
                string ns = t.Namespace;
                foreach (string vendor in UserPreference.Vendors)
                {
                    AccountOption accOpt = (dynamic)UserPreference.GetType().GetProperty(vendor + "Account").GetValue(UserPreference);
                    foreach (var acc in accOpt.Accounts)
                    {
                        if (acc.IsActivate)
                        {
                            string      clsName = ns + "." + vendor + "Controller";
                            Type        type    = Type.GetType(clsName);
                            IController ctrl    = Activator.CreateInstance(type, this) as IController;
                            ctrl.ConnParam = acc;
                            // if some connection is connected, then remain unchanged
                            IController ic = Controllers.FirstOrDefault(x => x.DisplayName == ctrl.DisplayName);
                            if (ic != null && ic.IsConnected)
                            {
                                ctrls.Add(ic);
                            }
                            else
                            {
                                ctrls.Add(ctrl);
                            }
                        }
                    }
                    Controllers.Clear();
                    foreach (var item in ctrls)
                    {
                        Controllers.Add(item);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Setting(List <IController> ctrls)
        {
            InitializeComponent();
            // set Window Icon

            /*
             * string resourceName = "AmiBroker.Controllers.images.setting.png";
             * Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
             * this.Icon = BitmapFrame.Create(s);*/
            Uri         uri = new Uri("pack://application:,,,/OrderManager;component/Controllers/images/setting.png");
            BitmapImage bi  = new BitmapImage(uri);

            this.Icon = bi;

            // read preference from setting
            string up = Properties.Settings.Default["preference"].ToString();

            if (up != string.Empty)
            {
                settings = JsonConvert.DeserializeObject <UserPreference>(up);
            }
            else
            {
                settings = new UserPreference();
            }
            this.DataContext = settings;

            // set CheckBox (exclusive) click event
            chk_ft_ex.Click += (sender, EventArgs) => { CheckBox_Checked(sender, EventArgs, settings.FTAccount); };
            chk_ib_ex.Click += (sender, EventArgs) => { CheckBox_Checked(sender, EventArgs, settings.IBAccount); };

            // set ReadOnly = true if the connection is being connected, so that item will be non-editable
            foreach (string vendor in settings.Vendors)
            {
                AccountOption accOpt = (dynamic)settings.GetType().GetProperty(vendor + "Account").GetValue(settings);
                foreach (var item in accOpt.Accounts)
                {
                    var ctrl = ctrls.FirstOrDefault(x => x.DisplayName == vendor + "(" + item.AccName + ")");
                    if (ctrl != null)
                    {
                        item.ReadOnly = ctrl.IsConnected;
                    }
                }
            }
        }