예제 #1
0
        private void WindowClosed(object sender, EventArgs e)
        {
            Console.WriteLine("MainWindow Closed!");
            //关闭程序前,释放掉资源
            WatchDogManager tm = WatchDogManager.Instance;

            if (tm.Timer != null)
            {
                MessageBoxResult result = MessageBox.Show("看门狗正在运行是否终止看门狗?", "提示",
                                                          MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
                if (result == MessageBoxResult.Yes)
                {
                    tm.Timer.Stop();
                    if (tm.WatchDog.MinipcType.Equals("Q500"))
                    {
                        tm.WatchDog.StopWatchDog(0xf1, 0x40);
                    }
                    else
                    {
                        tm.WatchDog.StopWatchDog(0x72, 0x80);
                    }
                }
                tm.WatchDog.SysDispose();
            }
            SensorManager sm = SensorManager.Instance;

            if (sm.CpuCelsius != null)
            {
                Console.WriteLine("CpuCelsius Dispose!!!");
                sm.CpuCelsius.Dispose();
            }
        }
예제 #2
0
        /// <summary>
        /// Initialise Xibo
        /// </summary>
        private void InitializeXibo()
        {
            // Set the title
            Title = ApplicationSettings.GetProductNameFromAssembly();

            // Check the directories exist
            if (!Directory.Exists(ApplicationSettings.Default.LibraryPath + @"\backgrounds\"))
            {
                // Will handle the create of everything here
                Directory.CreateDirectory(ApplicationSettings.Default.LibraryPath + @"\backgrounds");
            }

            // Default the XmdsConnection
            ApplicationSettings.Default.XmdsLastConnection = DateTime.MinValue;

            // Bind to the resize event
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;

            // Show in taskbar
            ShowInTaskbar = ApplicationSettings.Default.ShowInTaskbar;

            // Events
            Loaded          += MainWindow_Loaded;
            Closing         += MainForm_FormClosing;
            ContentRendered += MainForm_Shown;

            // Trace listener for Client Info
            ClientInfoTraceListener clientInfoTraceListener = new ClientInfoTraceListener
            {
                Name = "ClientInfo TraceListener"
            };

            Trace.Listeners.Add(clientInfoTraceListener);

            // Log to disk?
            if (!string.IsNullOrEmpty(ApplicationSettings.Default.LogToDiskLocation))
            {
                TextWriterTraceListener listener = new TextWriterTraceListener(ApplicationSettings.Default.LogToDiskLocation);
                Trace.Listeners.Add(listener);
            }

#if !DEBUG
            // Initialise the watchdog
            if (!_screenSaver)
            {
                try
                {
                    // Update/write the status.json file
                    ClientInfo.Instance.UpdateStatusMarkerFile();

                    // Start watchdog
                    WatchDogManager.Start();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - InitializeXibo", "Cannot start watchdog. E = " + e.Message), LogType.Error.ToString());
                }
            }
#endif

            // An empty set of overlays
            _overlays = new Collection <Layout>();

            // Switch to TLS 2.1
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

            // Initialise the database
            StatManager.Instance.InitDatabase();

            Trace.WriteLine(new LogMessage("MainForm", "Player Initialised"), LogType.Info.ToString());
        }
예제 #3
0
        //设定喂狗时间
        private void Feed_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //WDT的可编程超时范围为1~65535秒/分
            ushort time = 60;

            try
            {
                time = Convert.ToUInt16(time_val.Text);
                if (time < 10 || time > 65535)
                {
                    MessageBox.Show("请输入10~65536之间的整数!");
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("请输入10~65536之间的整数!");
                return;
            }

            if (watchdog == null)
            {
                MessageBox.Show("未选择迷你电脑型号!");
                return;
            }
            interval.Text = "喂狗间隔:" + time + "s";
            feedTime      = time;
            wtimer        = Convert.ToUInt16(Math.Ceiling(time * 0.8));//定时器必须提前喂狗
            Console.WriteLine("feedTime:{0} wtimer:{1}", feedTime, wtimer);

            watchdog.InitSuperIO();
            watchdog.InitLogicDevice();//LDN 07

            if (watchdog.MinipcType.Equals("Q500"))
            {
                //SMI# Control Register 2 (Index=F1h, Default=00h)
                //bit 6:触发方式 0边沿触发/1电平触发
                //bit 2 SMI# WDT功能开关 1开/0关
                if (timeUint == 0)
                {
                    watchdog.EnableWatchDog(0xf1, 0x44);//0100 0100
                }
            }
            else
            {
                //Watch Dog Timer Configuration Register (Index=72h, Default=001s0000b)
                //bit 7:喂狗时间单位 1秒/0分
                //bit 4:WDT功能开关 1开/0关
                if (timeUint == 0)
                {
                    watchdog.EnableWatchDog(0x72, 0x90);//1001 0000
                }
            }
            watchdog.ExitSuperIo();

            //看门狗管理器
            //先清除已存在的看门狗,如果存在
            WatchDogManager tm = WatchDogManager.Instance;

            if (tm.Timer != null)
            {
                Console.WriteLine("关闭之前的定时器!");
                tm.Timer.Stop();
                tm.Timer    = null;
                tm.WatchDog = null;
            }

            //设定喂狗时间,即在设定时间内必须喂狗,否则会自动重启
            watchdog.FeedDog(feedTime);
            if (!wdttimer.IsEnabled)
            {
                wdttimer.Interval = TimeSpan.FromMilliseconds(wtimer * 1000);
                wdttimer.Start();
            }

            tm.Timer    = wdttimer;
            tm.WatchDog = watchdog;
        }
예제 #4
0
        public void Initialize()
        {
            //Thread.CurrentThread.Name = "UI Thread";

            // Check the directories exist
            if (!Directory.Exists(ApplicationSettings.Default.LibraryPath + @"\backgrounds\"))
            {
                // Will handle the create of everything here
                Directory.CreateDirectory(ApplicationSettings.Default.LibraryPath + @"\backgrounds");
            }

            // Default the XmdsConnection
            ApplicationSettings.Default.XmdsLastConnection = DateTime.MinValue;

            // Show in taskbar
            ShowInTaskbar = ApplicationSettings.Default.ShowInTaskbar;

            // Setup the proxy information
            OptionForm.SetGlobalProxy();

            _statLog = new StatLog();

            // Create the info form
            _clientInfoForm = new ClientInfo();
            _clientInfoForm.Hide();

            // Define the hotkey
            Keys key;

            try
            {
                key = (Keys)Enum.Parse(typeof(Keys), ApplicationSettings.Default.ClientInformationKeyCode.ToUpper());
            }
            catch
            {
                // Default back to I
                key = Keys.I;
            }

            KeyStore.Instance.AddKeyDefinition("ClientInfo", key, ((ApplicationSettings.Default.ClientInfomationCtrlKey) ? Keys.Control : Keys.None));

            // Register a handler for the key event
            KeyStore.Instance.KeyPress += Instance_KeyPress;

            // Trace listener for Client Info
            ClientInfoTraceListener clientInfoTraceListener = new ClientInfoTraceListener(_clientInfoForm);

            clientInfoTraceListener.Name = "ClientInfo TraceListener";
            Trace.Listeners.Add(clientInfoTraceListener);

            // Log to disk?
            if (!string.IsNullOrEmpty(ApplicationSettings.Default.LogToDiskLocation))
            {
                TextWriterTraceListener listener = new TextWriterTraceListener(ApplicationSettings.Default.LogToDiskLocation);
                Trace.Listeners.Add(listener);
            }

#if !DEBUG
            // Initialise the watchdog
            if (!_screenSaver)
            {
                try
                {
                    // Update/write the status.json file
                    File.WriteAllText(System.IO.Path.Combine(ApplicationSettings.Default.LibraryPath, "status.json"), "{\"lastActivity\":\"" + DateTime.Now.ToString() + "\"}");

                    // Start watchdog
                    WatchDogManager.Start();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - InitializeXibo", "Cannot start watchdog. E = " + e.Message), LogType.Error.ToString());
                }
            }
#endif
            // An empty set of overlay regions
            //_overlays = new Collection<Region>();


            Trace.WriteLine(new LogMessage("MainForm", "Client Initialised"), LogType.Info.ToString());
        }
예제 #5
0
        private void InitializeXibo()
        {
            Thread.CurrentThread.Name = "UI Thread";

            // Check the directories exist
            if (!Directory.Exists(ApplicationSettings.Default.LibraryPath) || !Directory.Exists(ApplicationSettings.Default.LibraryPath + @"\backgrounds\"))
            {
                // Will handle the create of everything here
                Directory.CreateDirectory(ApplicationSettings.Default.LibraryPath + @"\backgrounds");
            }

            // Default the XmdsConnection
            ApplicationSettings.Default.XmdsLastConnection = DateTime.MinValue;

            // Override the default size if necessary
            if (ApplicationSettings.Default.SizeX != 0)
            {
                _clientSize   = new Size((int)ApplicationSettings.Default.SizeX, (int)ApplicationSettings.Default.SizeY);
                Size          = _clientSize;
                WindowState   = FormWindowState.Normal;
                Location      = new Point((int)ApplicationSettings.Default.OffsetX, (int)ApplicationSettings.Default.OffsetY);
                StartPosition = FormStartPosition.Manual;
            }
            else
            {
                _clientSize = SystemInformation.PrimaryMonitorSize;
                ApplicationSettings.Default.SizeX = _clientSize.Width;
                ApplicationSettings.Default.SizeY = _clientSize.Height;
            }

            // Show in taskbar
            ShowInTaskbar = ApplicationSettings.Default.ShowInTaskbar;

            // Setup the proxy information
            OptionForm.SetGlobalProxy();

            _statLog = new StatLog();

            this.FormClosing += new FormClosingEventHandler(MainForm_FormClosing);
            this.Shown       += new EventHandler(MainForm_Shown);

            // Create the info form
            _clientInfoForm = new ClientInfo();
            _clientInfoForm.Hide();

            // Define the hotkey
            Keys key;

            try
            {
                key = (Keys)Enum.Parse(typeof(Keys), ApplicationSettings.Default.ClientInformationKeyCode.ToUpper());
            }
            catch
            {
                // Default back to I
                key = Keys.I;
            }

            KeyStore.Instance.AddKeyDefinition("ClientInfo", key, ((ApplicationSettings.Default.ClientInfomationCtrlKey) ? Keys.Control : Keys.None));

            // Register a handler for the key event
            KeyStore.Instance.KeyPress += Instance_KeyPress;

            // Trace listener for Client Info
            ClientInfoTraceListener clientInfoTraceListener = new ClientInfoTraceListener(_clientInfoForm);

            clientInfoTraceListener.Name = "ClientInfo TraceListener";
            Trace.Listeners.Add(clientInfoTraceListener);

            // Log to disk?
            if (!string.IsNullOrEmpty(ApplicationSettings.Default.LogToDiskLocation))
            {
                TextWriterTraceListener listener = new TextWriterTraceListener(ApplicationSettings.Default.LogToDiskLocation);
                Trace.Listeners.Add(listener);
            }

#if !DEBUG
            // Initialise the watchdog
            if (!_screenSaver)
            {
                try
                {
                    // Update/write the status.json file
                    File.WriteAllText(Path.Combine(ApplicationSettings.Default.LibraryPath, "status.json"), "{\"lastActivity\":\"" + DateTime.Now.ToString() + "\"}");

                    // Start watchdog
                    WatchDogManager.Start();
                }
                catch (Exception e)
                {
                    Trace.WriteLine(new LogMessage("MainForm - InitializeXibo", "Cannot start watchdog. E = " + e.Message), LogType.Error.ToString());
                }
            }
#endif

            Trace.WriteLine(new LogMessage("MainForm", "Client Initialised"), LogType.Info.ToString());
        }