public void SetTimer(int?secondsToShutdown, Controls.ProgressBarWithText progressBar, ShutdownTimerPicker.ShutdownTimerAction action, PersistentSettings.StartObjects.StartObjectsManager startObjects) { if (!secondsToShutdown.HasValue) { shutdownTimer?.Cancel(); return; } shutdownTimer = new ShutdownTimer(secondsToShutdown.Value, progressBar, this, action, startObjects); }
private void Window_Loaded(object sender, RoutedEventArgs e) { Title.Text = AppResource.ApplicationName + AppResource.Version; Txt_UpdateInstruction.Text = AppResource.UpdateInstruction; Txt_UpdateInstruction.IsReadOnly = true; S_ShareState.Text = AppResource.Unshared; S_ShutdownTime.Text = AppResource.ShutdownTimerState; B_WifiSetup.Content = AppResource.ShareWifi; B_ShutdownSetup.Content = AppResource.SetShutdown; if (Settings.Default.FirstLaunch) { Settings.Default.FirstLaunch = false; Settings.Default.Save(); } //用户密码读取 Txt_Ssid.Text = Settings.Default.SSID; PswBox.Password = Settings.Default.Password; shutdownTimer = new ShutdownTimer(); Txt_ShutDownHours.Text = Settings.Default.ShutdownTimeSpan.Hours.ToString(); Txt_ShutDownMinutes.Text = Settings.Default.ShutdownTimeSpan.Minutes.ToString(); wifiHost = new WifiHost(); sharingConnections = wifiHost.GetSharingConnections(); RefreshShareConnection(); foreach (SharingConnection connection in Cb_ShareConnections.Items) { if (connection.Name == Settings.Default.ShareConnection) { Cb_ShareConnections.SelectedItem = connection; break; } } InitialTray(); //软件开启时自动设定 if (Settings.Default.AutoSet) { SetWifi(); SetShutdownTimer(); this.WindowState = WindowState.Minimized; } }
private void ShutdownTimer_Tick(object sender, EventArgs e) { if (remainTime > 0) { remainTime -= 1; remainLabel.Text = Convert.ToString(remainTime) + " 초"; } else if (remainTime == 0) { ShutdownTimer.Stop(); System.Diagnostics.Process.Start("shutdown", "/s /f /t 1"); //MessageBox.Show("종료되었습니다.", "Debug"); } }
public void CancelShutdown(Authentication authentication) { this.DebugMethod(authentication, this, nameof(CancelShutdown), this); if (authentication.Types.HasFlag(AuthenticationType.Administrator) == false) { throw new PermissionDeniedException(); } if (this.shutdownTimer != null) { this.shutdownTimer.Elapsed -= ShutdownTimer_Elapsed; this.shutdownTimer.Stop(); this.shutdownTimer.Dispose(); this.shutdownTimer = null; this.Info($"[{authentication}] Shutdown cancelled."); } }
private void Shutdown(ShutdownType shutdownType) { if (this.shutdownTimer != null) { this.shutdownTimer.Elapsed -= ShutdownTimer_Elapsed; this.shutdownTimer.Stop(); this.shutdownTimer.Dispose(); this.shutdownTimer = null; } var isRestart = shutdownType.HasFlag(ShutdownType.Restart); this.Close(isRestart ? CloseReason.Restart : CloseReason.Shutdown, string.Empty); if (isRestart == true) { this.settings.NoCache = shutdownType.HasFlag(ShutdownType.NoCache); this.Open(); } }
/// <summary> /// Browse the folder /// </summary> /// <param name="startIndex">start index</param> /// <param name="requestedCount">requested count</param> /// <param name="userAgent">user agent</param> /// <returns>the browse result</returns> public override BrowseResult Browse(uint startIndex, uint requestedCount, UserAgent userAgent) { if (Path == null) { BrowseResult browseResult = new BrowseResult(); AddFolder(browseResult, startIndex, requestedCount, Resources.Cancel, "ShutdownCancel"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 30), "Shutdown30"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 60), "Shutdown60"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 90), "Shutdown90"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 120), "Shutdown120"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 180), "Shutdown180"); AddFolder(browseResult, startIndex, requestedCount, String.Format(Resources.InXMinutes, 240), "Shutdown240"); AddFolder(browseResult, startIndex, requestedCount, Resources.ShutdownImmediatly, "Shutdown"); AddFolder(browseResult, startIndex, requestedCount, Resources.Restart, "Restart"); return(browseResult); } ShutdownTimer.Stop(); TickCount = null; switch (Path) { case "ShutdownCancel": break; case "Shutdown": OnShutdown(); break; case "Restart": OnShutdown(true); break; default: ShutdownTimer.Interval = Int32.Parse(Path.Substring(8)) * 60000; TickCount = Environment.TickCount; ShutdownTimer.Start(); break; } return(null); }
public void Shutdown(Authentication authentication, int milliseconds, ShutdownType shutdownType, string message) { this.DebugMethod(authentication, this, nameof(Shutdown), this, milliseconds, shutdownType, message); if (authentication.Types.HasFlag(AuthenticationType.Administrator) == false) { throw new PermissionDeniedException(); } if (milliseconds < 0) { throw new ArgumentOutOfRangeException(nameof(milliseconds), "invalid milliseconds value"); } if (string.IsNullOrEmpty(message) == false) { this.userContext.Dispatcher.InvokeAsync(() => this.userContext.NotifyMessage(Authentication.System, message)); } if (this.shutdownTimer == null) { this.shutdownTimer = new ShutdownTimer() { Interval = 1000, }; this.shutdownTimer.Elapsed += ShutdownTimer_Elapsed; } var dateTime = DateTime.Now.AddMilliseconds(milliseconds); this.shutdownTimer.DateTime = dateTime; this.shutdownTimer.ShutdownType = shutdownType; this.shutdownTimer.Start(); if (milliseconds >= 1000) { this.SendShutdownMessage((dateTime - DateTime.Now) + new TimeSpan(0, 0, 0, 0, 500), true); } }
/// <summary> /// ShutdownTimer设定与取消逻辑控制 /// </summary> private void SetShutdownTimer() { if (shutdownTimer.enable == false) { try { shutdownTimeSpan = ShutdownTimer.TimeParse(Txt_ShutDownHours.Text, Txt_ShutDownMinutes.Text); shutdownTime = DateTime.Now.Add(shutdownTimeSpan); shutdownTimer.Start(shutdownTimeSpan); Txt_ShutDownHours.IsEnabled = false; Txt_ShutDownMinutes.IsEnabled = false; B_ShutdownSetup.Content = AppResource.CancelShutdown; notifyBalloonTip(AppResource.ShutdownInfo + shutdownTime.ToString()); //状态栏的倒计时监控线程 stateRefreshThread = new Thread(new ThreadStart(StartRefresh)); stateRefreshThread.IsBackground = true; srh = StartRefreshDelegate; stateRefreshThread.Start(); } catch (Exception ex) { notifyBalloonTip(ex.ToString()); } } else { shutdownTimer.Stop(); stateRefreshThread.Abort(); Txt_ShutDownHours.IsEnabled = true; Txt_ShutDownMinutes.IsEnabled = true; B_ShutdownSetup.Content = AppResource.SetShutdown; S_ShutdownTime.Text = AppResource.ShutdownTimerState; notifyBalloonTip(AppResource.ShutdownCancelInfo); } }
private void Cancel_Click(object sender, EventArgs e) { ShutdownTimer.Stop(); this.Close(); }
private void ShutdownForm_Load(object sender, EventArgs e) { ShutdownTimer.Start(); }