예제 #1
0
        public void Start()
        {
            m_accountInfo = MainAccountInfo.LoadAccount(m_mainFile);
            if (!File.Exists(m_mainFile))
            {
                m_accountInfo.Save();
            }

            m_mainEntity = new MainEntity(m_accountInfo);
            MainTaskMgr.Instance.InitEntityTasks(m_mainEntity);
            m_mainEntity.DescriptionChanged += MainEntityOnDescriptionChanged;
            m_mainEntity.Start();

            foreach (var t in WxHelper.GetEnumValues <WlySwitchType>())
            {
                var info    = m_accountInfo.GetSwitchInfo(t);
                var wrapper = new WlyTaskSwitchWrapper(info);
                wrapper.Changed += WrapperOnChanged;
                Switches.Add(wrapper);
            }

            // 主账号监测
            m_cancellationTokenSource = new CancellationTokenSource();
            var token = m_cancellationTokenSource.Token;

            Task.Run(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    try
                    {
                        Thread.Sleep(TimeSpan.FromMinutes(1));
                        if (!m_mainEntity.Run)
                        {
                            WxLog.Debug($"WlyAutoVM.Start 对主账号进行重置 <{DateTime.Now}>");
                            m_mainEntity.Stop();
                            m_mainEntity.DescriptionChanged -= MainEntityOnDescriptionChanged;
                            MainEntity = new MainEntity(m_accountInfo);
                            MainTaskMgr.Instance.InitEntityTasks(m_mainEntity);
                            m_mainEntity.DescriptionChanged += MainEntityOnDescriptionChanged;
                            m_mainEntity.Start();
                        }
                    }
                    catch (Exception ex)
                    {
                        WxLog.Error($"WlyAutoVM.Start Error <{ex}>");
                    }
                }

                WxLog.Debug($"WlyAutoVM.Start Stop On <{ResetTime}>");
            }, token);

            //StartSubCmdExecute(this);
        }
예제 #2
0
 /// <summary>
 /// 保存账号信息
 /// </summary>
 private void Save()
 {
     m_accountInfo.Save();
 }
예제 #3
0
 private void WrapperOnChanged(object sender, EventArgs eventArgs)
 {
     m_accountInfo.Save();
 }