private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            BatteryStatViewModel viewModel;

            if (SharedData.Default.BatteryPackContainer.TryGetValue(e.Node.Name, out viewModel))
            {
                var statUC = new BatteryStats(e.Node.Name, viewModel);
                this.flowLayoutPanel1.Controls.Add(statUC);
            }
        }
 private void HandleBatteriesLoad()
 {
     foreach (var item in SharedData.Default.BatteryPackContainer)
     {
         var addr      = item.Key;
         var viewModel = item.Value;
         var statUC    = new BatteryStats(addr, viewModel);
         this.flowLayoutPanel1.Controls.Add(statUC);
     }
 }
        private void addBatteryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var newBatteryView = new NewBatteryView();
            var dialogResult   = newBatteryView.ShowDialog(this);

            if (dialogResult == DialogResult.OK)
            {
                if (!SharedData.Default.BatteryPackContainer.ContainsKey(newBatteryView.Address.ToString()))
                {
                    var viewModel = new BatteryStatViewModel(WindowsFormsSynchronizationContext.Current)
                    {
                        IsPartOfCluster = newBatteryView.IsPartOfCluster
                    };
                    viewModel.Address = newBatteryView.Address.ToString();
                    SharedData.Default.BatteryPackContainer.TryAdd(
                        newBatteryView.Address.ToString(),
                        viewModel);

                    if (!viewModel.IsPartOfCluster)
                    {
                        var statUC = new BatteryStats(newBatteryView.Address.ToString(), viewModel);
                        this.flowLayoutPanel1.Controls.Add(statUC);
                    }

                    //toolStripLabel1.Text = string.Format("Battery added : {0}", viewModel.Address);
                }
                else
                {
                    if (!newBatteryView.IsPartOfCluster)
                    {
                        BatteryStatViewModel viewModel;
                        bool succeeded = SharedData.Default.BatteryPackContainer.TryGetValue(newBatteryView.Address.ToString(), out viewModel);
                        if (succeeded)
                        {
                            viewModel.IsPartOfCluster = newBatteryView.IsPartOfCluster;
                            var statUC = new BatteryStats(newBatteryView.Address.ToString(), viewModel);
                            this.flowLayoutPanel1.Controls.Add(statUC);
                        }
                    }
                }

                treeView1.Nodes.Add(newBatteryView.Address.ToString(), string.Format("Battery : {0}", newBatteryView.Address), 0);
                logger.Info(string.Format("Added Battery : {0}", newBatteryView.Address));
            }
        }
Exemple #4
0
        private void ShowBatteryStat(string name, bool shouldClear = false)
        {
            try
            {
                BatteryStatViewModel viewModel;
                if (SharedData.Default.BatteryPackContainer.TryGetValue(name, out viewModel))
                {
                    Control statUC;
                    if (viewModel.IsSeries)
                    {
                        statUC = new ClusterStatistics(viewModel);
                    }
                    else
                    {
                        statUC = new BatteryStats(name, viewModel);
                    }

                    this.flowLayoutPanel1.SuspendLayout();
                    if (shouldClear || viewModel.IsSeries)
                    {
                        this.flowLayoutPanel1.Controls.Clear();
                        this.batteryAddressCtrlMap.Clear();
                    }
                    if (!this.batteryAddressCtrlMap.ContainsKey(name))
                    {
                        this.flowLayoutPanel1.Controls.Add(statUC);
                        this.batteryAddressCtrlMap.Add(name, statUC);
                    }
                    this.flowLayoutPanel1.ResumeLayout(true);
                }
                else
                {
                    RemoveFromTreeView(name);
                }
            }
            catch (Exception e)
            {
                logger.Error(e, "Error adding battery statistics view");
            }
        }