示例#1
0
文件: Config.cs 项目: arjenst/NetJS
        public Config(Watch watch, Scope scope, Settings settings)
        {
            var file = settings.Root + settings.Config;

            Load(file, scope);
            watch.Add(file, () => {
                Load(file, scope);
            });
        }
 // ----------------------------------------------------------------------------------------
 /// <!-- Measuring -->
 /// <summary>
 ///      Run before Measured with the same parameter
 /// </summary>
 /// <param name="method"></param>
 /// <remarks>ABCDEFGHIJKLMNOP</remarks>
 public static void Measuring(string method)
 {
     try
     {
         if (Watch == null)
         {
             Watch = new Dictionary <string, Stopwatch>();
         }
         if (Watch.ContainsKey(method))
         {
             Watch[method].Reset();
             Watch[method].Start();
         }
         else
         {
             Watch.Add(method, new Stopwatch());
             Watch[method].Start();
         }
     }
     catch (Exception ex)
     {
         string err = ex.Message;
     }
 }
示例#3
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();
            });
        }
示例#4
0
        private void ModelChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "Rigs": {
                Rigs      = new ObservableCollection <Settings.Rig>(_model.Rigs);
                RigsNames = from r in Rigs orderby r.Index select r.Name;
                for (int i = 0; i < RigsNames.Count(); i++)
                {
                    Indicators.Add(RigStatus.offline);
                    Watch.Add(Rigs[i].Waching);
                    {
                        if (Rigs[i].Waching)
                        {
                            AddRigPanel(i);
                        }
                        else
                        {
                            RemoveRigPanel(i);
                        }
                    }
                }
            } break;

            case "PoolsSets":
            {
                for (int i = 0; i < _model.PoolsSets.Count; i++)
                {
                    Selection.Add(false);
                    PoolsSets.Add(_model.PoolsSets[i]);
                    if (_model.PoolsSets[i].Wach)
                    {
                        WachPoolStart(i);
                    }
                }
            } break;

            case "GenSettings": {
                GenSettings = _model.GenSettings;

                StartOfRange  = GenSettings.TotalMinTemp;
                StartOfRangeD = GenSettings.TotalMinTemp;
                EndOfRange    = GenSettings.TotalMaxTemp;
                EndOfRangeD   = GenSettings.TotalMaxTemp;

                eWeLogin        = GenSettings.eWeLogin;
                eWePasswordSend = GenSettings.eWePassword;
                if (!String.IsNullOrEmpty(eWeLogin) && !String.IsNullOrEmpty(eWePasswordSend))
                {
                    Task.Run(() => eWeConnect());
                }

                Task.Run(() =>
                    {
                        if (!string.IsNullOrEmpty(GenSettings.HiveLogin) && !string.IsNullOrEmpty(GenSettings.HivePassword))
                        {
                            AuthenticationStatus st = HiveClient.HiveAuthentication(
                                GenSettings.HiveLogin, GenSettings.HivePassword);
                            if (st.Status)
                            {
                                HiveLogin           = GenSettings.HiveLogin;
                                HivePasswordSend    = GenSettings.HivePassword;
                                HiveConnection      = true;
                                App.HiveConnection  = true;
                                HiveAccountState    = "Подключение к Hive установлено";
                                HiveConnectionState = "Подключение к Hive установлено";

                                HiveWorkers = HiveClient.GetWorkers();

                                if (HiveWorkers != null)
                                {
                                    List <string> LST = (from w in HiveWorkers select w.name).ToList();
                                    LST.Insert(0, "---");
                                    HiveWorkersNames = LST;
                                }
                            }
                            else
                            {
                                HiveAccountState = st.Message;
                            }
                        }
                        else
                        {
                            HiveAccountState    = "Подключение к Hive отсутствует";
                            HiveConnectionState = "Подключение к Hive отсутствует";
                        }
                    });

                VKuserID = GenSettings.VKuserID;
            } break;
            }
        }