예제 #1
0
        private void AddBatteries(IEnumerable <byte> addresses, bool isPartOfCluster)
        {
            foreach (var item in addresses)
            {
                if (!SharedData.Default.BatteryPackContainer.ContainsKey(item.ToString()))
                {
                    var viewModel = new BatteryStatViewModel(WindowsFormsSynchronizationContext.Current)
                    {
                        IsPartOfCluster = isPartOfCluster
                    };
                    viewModel.Address = item.ToString();

                    logic.AddBattery(viewModel);
                    //SharedData.Default.BatteryPackContainer.TryAdd(
                    //    newBatteryView.Address.ToString(),
                    //    viewModel);

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

                    //toolStripLabel1.Text = string.Format("Battery added : {0}", viewModel.Address);
                }
                else
                {
                    if (!isPartOfCluster)
                    {
                        BatteryStatViewModel viewModel;
                        bool succeeded = SharedData.Default.BatteryPackContainer.TryGetValue(item.ToString(), out viewModel);
                        if (succeeded)
                        {
                            viewModel.IsPartOfCluster = isPartOfCluster;

                            ShowBatteryStat(viewModel.Address);
                            //var statUC = new BatteryStats(newBatteryView.Address.ToString(), viewModel);
                            //this.flowLayoutPanel1.Controls.Add(statUC);
                        }
                    }
                }

                AddToTreeView(item.ToString(), string.Format("Battery : {0}", item), 0);

                logger.Info(string.Format("Added Battery : {0}", item));
            }
        }