Exemplo n.º 1
0
        private void InitializeRigsControlCommands()
        {
            SelectRig = new RelayCommand(obj =>
            {
                if (SelectedRigIndex > -1)
                {
                    RigName = Rigs[SelectedRigIndex].Name;
                    RigIP   = Rigs[SelectedRigIndex].IP;

                    if (Rigs[SelectedRigIndex].Type != null)
                    {
                        SelectedRigTypeString = Rigs[SelectedRigIndex].Type;
                    }
                    else
                    {
                        SelectedRigTypeIndex = -1;
                    }

                    OmgConnectButtonVisibility   = SelectedRigTypeString == "OMineGuard" ? true : false;
                    HiveWorkerSettingsVisibility = SelectedRigTypeString == "HiveOS" ? true : false;
                    if (HiveWorkerSettingsVisibility)
                    {
                        if (Rigs[SelectedRigIndex].HiveFarmID != null &&
                            Rigs[SelectedRigIndex].HiveWorkerID != null)
                        {
                            HiveFarmID   = Rigs[SelectedRigIndex].HiveFarmID;
                            HiveWorkerID = Rigs[SelectedRigIndex].HiveWorkerID;

                            for (int i = 0; i < HiveWorkers.Count; i++)
                            {
                                if (HiveWorkers[i].farm_id == HiveFarmID && HiveWorkers[i].id == HiveWorkerID)
                                {
                                    SelectedHiveWorkerIndex = i + 1;;
                                    break;
                                }
                            }

                            HiveWorkerActive = true;
                        }
                        else
                        {
                            HiveWorkerActive        = null;
                            SelectedHiveWorkerIndex = -1;
                        }
                    }

                    if (Rigs[SelectedRigIndex].eWeDevice != null)
                    {
                        SelectedeWeDevice = Rigs[SelectedRigIndex].eWeDevice;
                        eWeDeviceActive   = true;
                    }
                    else
                    {
                        SelectedeWeDeviceIndex = -1;
                    }

                    CurrentStartOfRange = Rigs[SelectedRigIndex].MinTemp;
                    CurrentEndOfRange   = Rigs[SelectedRigIndex].MaxTemp;
                    WachdogMinHashrate  = Rigs[SelectedRigIndex].WachdogMinHashrate;
                    WachdogMaxTemp      = Rigs[SelectedRigIndex].WachdogMaxTemp;
                    eWeDelayTimeout     = Rigs[SelectedRigIndex].eWeDelayTimeout;

                    // wol
                }
                else
                {
                    RigName = null;
                    RigIP   = null;
                    SelectedRigTypeString = null;
                }
                SetButtonsEnable();
            });
            RigMinus = new RelayCommand(obj =>
            {
                Rigs[SelectedRigIndex].InformReceivedClear();
                RemoveRigPanel(Rigs[SelectedRigIndex].Index);
                /////////////
                Rigs.RemoveAt(SelectedRigIndex);
                for (int i = SelectedRigIndex; i < RigsNames.Count(); i++)
                {
                    Rigs[i].Index--;
                }
                RigsNames = from r in Rigs orderby r.Index select r.Name;
                _model.cmd_SaveRigs(Rigs.ToList());
                SetButtonsEnable();

                Watch.RemoveAt(Watch.Count - 1);
            });
            RigPlus = new RelayCommand(obj =>
            {
                Rigs.Add(new Settings.Rig(RigsNames.Count()));
                RigsNames        = from r in Rigs orderby r.Index select r.Name;
                SelectedRigIndex = Rigs.Count - 1;
                _model.cmd_SaveRigs(Rigs.ToList());
                SetButtonsEnable();

                Watch.Add(false);
            });
            RigUp = new RelayCommand(obj =>
            {
                int i = SelectedRigIndex;

                FreezeWatch = true;
                {
                    var t = Watch[i];
                    Watch.RemoveAt(i);
                    Watch.Insert(i - 1, t);
                }
                FreezeWatch = false;

                {
                    int n1 = 0;
                    int n2 = 0;
                    for (int n = 0; n < RVMs.Count; n++)
                    {
                        if (RVMs[n].Index == Rigs[i].Index)
                        {
                            n1 = n; break;
                        }
                    }
                    for (int n = 0; n < RVMs.Count; n++)
                    {
                        if (RVMs[n].Index == Rigs[i - 1].Index)
                        {
                            n2 = n; break;
                        }
                    }
                    RVs[n1].Index--;
                    RVMs[n1].Index--;
                    Rigs[i].Index--;
                    RVs[n2].Index++;
                    RVMs[n2].Index++;
                    Rigs[i - 1].Index++;
                }

                RVs  = RVs.OrderBy(r => r.Index).ToList();
                RVMs = RVMs.OrderBy(r => r.Index).ToList();

                Rigs             = new ObservableCollection <Settings.Rig>(Rigs.OrderBy(r => r.Index));
                RigsNames        = from r in Rigs orderby r.Index select r.Name;
                SelectedRigIndex = i - 1;
                _model.cmd_SaveRigs(Rigs.ToList());
                SetButtonsEnable();
            });
            RigDown = new RelayCommand(obj =>
            {
                int i = SelectedRigIndex;

                FreezeWatch = true;
                {
                    var t = Watch[i];
                    Watch.RemoveAt(i);
                    Watch.Insert(i + 1, t);
                }
                FreezeWatch = false;

                {
                    int n1 = 0;
                    int n2 = 0;
                    for (int n = 0; n < RVMs.Count; n++)
                    {
                        if (RVMs[n].Index == Rigs[i].Index)
                        {
                            n1 = n; break;
                        }
                    }
                    for (int n = 0; n < RVMs.Count; n++)
                    {
                        if (RVMs[n].Index == Rigs[i + 1].Index)
                        {
                            n2 = n; break;
                        }
                    }
                    RVs[n1].Index++;
                    RVMs[n1].Index++;
                    Rigs[i].Index++;
                    RVs[n2].Index--;
                    RVMs[n2].Index--;
                    Rigs[i + 1].Index--;
                }

                RVs  = RVs.OrderBy(r => r.Index).ToList();
                RVMs = RVMs.OrderBy(r => r.Index).ToList();

                Rigs             = new ObservableCollection <Settings.Rig>(Rigs.OrderBy(r => r.Index));
                RigsNames        = from r in Rigs orderby r.Index select r.Name;
                SelectedRigIndex = i + 1;
                _model.cmd_SaveRigs(Rigs.ToList());
                SetButtonsEnable();
            });
            RigSave = new RelayCommand(obj =>
            {
                List <Settings.Rig> rigs = Rigs.ToList();

                int i        = SelectedRigIndex;
                rigs[i].Name = RigName;
                rigs[i].IP   = RigIP;
                if (SelectedRigTypeIndex > 0)
                {
                    rigs[i].Type = SelectedRigTypeString;
                }
                else
                {
                    rigs[i].Type = null;
                }
                RigsNames        = from r in rigs orderby r.Index select r.Name;
                SelectedRigIndex = i;
                _model.cmd_SaveRigs(rigs.ToList());

                Rigs = new ObservableCollection <Settings.Rig>(rigs);

                SetButtonsEnable();
            });
        }