Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 574eb9653b | |||
| 57934673df |
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 15
|
# Visual Studio 15
|
||||||
VisualStudioVersion = 15.0.27004.2005
|
VisualStudioVersion = 15.0.27130.2027
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimedShutdown", "TimedShutdown\TimedShutdown.csproj", "{C1158C45-7666-4586-A6DA-CCC1EE95D457}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimedShutdown", "TimedShutdown\TimedShutdown.csproj", "{C1158C45-7666-4586-A6DA-CCC1EE95D457}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||||
</startup>
|
</startup>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using System.Windows;
|
|
||||||
|
|
||||||
namespace TimedShutdown
|
|
||||||
{
|
|
||||||
public class Messaging
|
|
||||||
{
|
|
||||||
public enum Message
|
|
||||||
{
|
|
||||||
RemoteShutdown
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Show(Message message, string info)
|
|
||||||
{
|
|
||||||
switch (message)
|
|
||||||
{
|
|
||||||
case Message.RemoteShutdown:
|
|
||||||
MessageBox.Show(
|
|
||||||
$"The following remote machine has been sent a shutdown/reboot signal:\n\n{info}",
|
|
||||||
"Timed Shutdown",
|
|
||||||
MessageBoxButton.OK,
|
|
||||||
MessageBoxImage.Information);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace TimedShutdown
|
|
||||||
{
|
|
||||||
public class PingWidget
|
|
||||||
{
|
|
||||||
private string RemoteAddress { get; set; }
|
|
||||||
public bool WidgetHasInitialized { get; private set; } = false;
|
|
||||||
|
|
||||||
BackgroundWorker contPingBackgroundWorker = new BackgroundWorker();
|
|
||||||
|
|
||||||
public void InitatePingRequest(string _remoteAddress)
|
|
||||||
{
|
|
||||||
RemoteAddress = _remoteAddress;
|
|
||||||
|
|
||||||
contPingBackgroundWorker.WorkerSupportsCancellation = true;
|
|
||||||
contPingBackgroundWorker.DoWork += ContPingBackgroundWorkerDoWork;
|
|
||||||
|
|
||||||
if (contPingBackgroundWorker.IsBusy == false)
|
|
||||||
{
|
|
||||||
contPingBackgroundWorker.RunWorkerAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
WidgetHasInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StopCurrentPingRequest()
|
|
||||||
{
|
|
||||||
contPingBackgroundWorker.CancelAsync();
|
|
||||||
Debug.WriteLine("Stopped ping request");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Will continuously ping the input IP address every 5 seconds,
|
|
||||||
/// will stop if a cancellation request is made.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="sender"></param>
|
|
||||||
/// <param name="e"></param>
|
|
||||||
private void ContPingBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
while (contPingBackgroundWorker.CancellationPending == false)
|
|
||||||
{
|
|
||||||
Ping pingSender = new Ping();
|
|
||||||
IPAddress address = IPAddressConverter(RemoteAddress);
|
|
||||||
PingReply reply = pingSender.Send(address);
|
|
||||||
|
|
||||||
if (reply.Status == IPStatus.Success)
|
|
||||||
{
|
|
||||||
Debug.WriteLine("Ping Success!");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Debug.WriteLine(reply.Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.Sleep(3000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IPAddress IPAddressConverter (string remoteAddress)
|
|
||||||
{
|
|
||||||
IPAddress ip;
|
|
||||||
if (IPAddress.TryParse(remoteAddress, out ip))
|
|
||||||
return ip;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IPHostEntry iphost = Dns.GetHostEntry(remoteAddress);
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -51,5 +51,5 @@ using System.Windows;
|
|||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.1.0.0")]
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ namespace TimedShutdown.Properties {
|
|||||||
// class via a tool like ResGen or Visual Studio.
|
// class via a tool like ResGen or Visual Studio.
|
||||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||||
// with the /str option, or rebuild your VS project.
|
// with the /str option, or rebuild your VS project.
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
public class Resources {
|
public class Resources {
|
||||||
|
|||||||
+9
-5
@@ -8,17 +8,21 @@
|
|||||||
// </auto-generated>
|
// </auto-generated>
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace TimedShutdown.Properties {
|
namespace TimedShutdown.Properties
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.2.0.0")]
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||||
|
{
|
||||||
|
|
||||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
public static Settings Default {
|
public static Settings Default
|
||||||
get {
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
|
|
||||||
namespace TimedShutdown
|
namespace TimedShutdown
|
||||||
{
|
{
|
||||||
public class ShutdownManager
|
public class ShutdownManager
|
||||||
{
|
{
|
||||||
private readonly Func<bool, string> _funcForceShutdown = ForceShutdown;
|
|
||||||
private readonly Func<Operation, string> _funcShutdownOperation = ShutdownOperation;
|
|
||||||
private readonly Func<string, string> _funcRemoteShutdown = RemoteShutdown;
|
|
||||||
|
|
||||||
public enum Operation
|
public enum Operation
|
||||||
{
|
{
|
||||||
Shutdown,
|
Shutdown,
|
||||||
@@ -23,16 +17,18 @@ namespace TimedShutdown
|
|||||||
/// <param name="shutdownoperation"></param>
|
/// <param name="shutdownoperation"></param>
|
||||||
/// <param name="shutdownSeconds"></param>
|
/// <param name="shutdownSeconds"></param>
|
||||||
/// <param name="forceShutdownState"></param>
|
/// <param name="forceShutdownState"></param>
|
||||||
public void ExecuteOperation(Operation shutdownoperation, int shutdownSeconds, bool forceShutdownState, string remoteShutdown)
|
public void ExecuteOperation(Operation shutdownoperation, int shutdownSeconds, bool forceShutdownState)
|
||||||
{
|
{
|
||||||
|
Func<bool,string> forceShutdown = ForceShutdown;
|
||||||
|
Func<Operation, string> shutdownOperation = ShutdownOperation;
|
||||||
|
|
||||||
ProcessStartInfo info = new ProcessStartInfo();
|
ProcessStartInfo info = new ProcessStartInfo();
|
||||||
Process proc = new Process();
|
Process proc = new Process();
|
||||||
|
|
||||||
info.FileName = "cmd.exe";
|
info.FileName = "cmd.exe";
|
||||||
info.Arguments = $"/c shutdown {_funcShutdownOperation(shutdownoperation)} -t" +
|
info.Arguments = $"/c shutdown {ShutdownOperation(shutdownoperation)} -t" +
|
||||||
$" {shutdownSeconds}" +
|
$" {shutdownSeconds}" +
|
||||||
$" {_funcForceShutdown(forceShutdownState)}" +
|
$" {ForceShutdown(forceShutdownState)}";
|
||||||
$" {_funcRemoteShutdown(remoteShutdown)}";
|
|
||||||
info.WindowStyle = ProcessWindowStyle.Hidden;
|
info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
info.CreateNoWindow = true;
|
info.CreateNoWindow = true;
|
||||||
|
|
||||||
@@ -40,23 +36,22 @@ namespace TimedShutdown
|
|||||||
proc.Start();
|
proc.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AbortOperation(string remoteShutdown)
|
public void AbortOperation()
|
||||||
{
|
{
|
||||||
ProcessStartInfo info = new ProcessStartInfo();
|
ProcessStartInfo info = new ProcessStartInfo();
|
||||||
Process proc = new Process();
|
Process proc = new Process();
|
||||||
|
|
||||||
info.FileName = "cmd.exe";
|
info.FileName = "cmd.exe";
|
||||||
info.Arguments = $"/c shutdown -a {_funcRemoteShutdown(remoteShutdown)}";
|
info.Arguments = $"/c shutdown -a";
|
||||||
info.CreateNoWindow = true;
|
info.CreateNoWindow = true;
|
||||||
info.WindowStyle = ProcessWindowStyle.Hidden;
|
info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
|
|
||||||
proc.StartInfo = info;
|
proc.StartInfo = info;
|
||||||
proc.Start();
|
proc.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Functions
|
#region Functions
|
||||||
|
|
||||||
private static string ShutdownOperation(Operation arg)
|
private string ShutdownOperation(Operation arg)
|
||||||
{
|
{
|
||||||
switch (arg)
|
switch (arg)
|
||||||
{
|
{
|
||||||
@@ -69,24 +64,11 @@ namespace TimedShutdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ForceShutdown(bool arg)
|
private string ForceShutdown(bool arg)
|
||||||
{
|
{
|
||||||
return "-f";
|
return "-f";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string RemoteShutdown(string arg)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(arg)) return string.Empty;
|
|
||||||
|
|
||||||
if (IPAddress.TryParse(arg, out IPAddress address) == false) { throw new FormatException(); }
|
|
||||||
|
|
||||||
if (arg.StartsWith(@"\\"))
|
|
||||||
{
|
|
||||||
return $"-m {arg}";
|
|
||||||
}
|
|
||||||
return $@"-m \\{arg}";
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,11 @@
|
|||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>TimedShutdown</RootNamespace>
|
<RootNamespace>TimedShutdown</RootNamespace>
|
||||||
<AssemblyName>TimedShutdown</AssemblyName>
|
<AssemblyName>TimedShutdown</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<TargetFrameworkProfile />
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
@@ -71,8 +70,6 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
<Compile Include="Messaging.cs" />
|
|
||||||
<Compile Include="PingWidget.cs" />
|
|
||||||
<Compile Include="ShutdownManager.cs" />
|
<Compile Include="ShutdownManager.cs" />
|
||||||
<Compile Include="ViewModels\ShellRootViewModel.cs" />
|
<Compile Include="ViewModels\ShellRootViewModel.cs" />
|
||||||
<Compile Include="Views\ShellRootView.xaml.cs">
|
<Compile Include="Views\ShellRootView.xaml.cs">
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Net;
|
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using Caliburn.Micro;
|
using Caliburn.Micro;
|
||||||
|
|
||||||
@@ -8,8 +6,29 @@ namespace TimedShutdown.ViewModels
|
|||||||
{
|
{
|
||||||
public class ShellRootViewModel : Screen
|
public class ShellRootViewModel : Screen
|
||||||
{
|
{
|
||||||
private readonly ShutdownManager _shutdownManager = new ShutdownManager();
|
readonly ShutdownManager shutdownManager = new ShutdownManager();
|
||||||
private readonly PingWidget pingWidget = new PingWidget();
|
|
||||||
|
#region Labels
|
||||||
|
|
||||||
|
public string LabelWindowTitle { get; } = "Timed Shutdown";
|
||||||
|
|
||||||
|
public string LabelHoursLabel { get; } = "Hours:";
|
||||||
|
|
||||||
|
public string LabelMinutesLabel { get; } = "Minutes:";
|
||||||
|
|
||||||
|
public string LabelShutdownOptions { get; } = "Options:";
|
||||||
|
|
||||||
|
public string LabelShutdownOptionsForce { get; } = "Force Operation";
|
||||||
|
|
||||||
|
public string LabelShutdownTime { get; set; } = "Shutdown Time:";
|
||||||
|
|
||||||
|
public string LabelShutdown { get; } = "Shutdown";
|
||||||
|
|
||||||
|
public string LabelReboot { get; } = "Reboot";
|
||||||
|
|
||||||
|
public string LabelAbortShutdown { get; } = "Abort Shutdown";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Values
|
#region Values
|
||||||
|
|
||||||
@@ -63,79 +82,19 @@ namespace TimedShutdown.ViewModels
|
|||||||
|
|
||||||
public bool ShutdownOptionsForce { get; set; }
|
public bool ShutdownOptionsForce { get; set; }
|
||||||
|
|
||||||
private string _IPRemoteShutdown;
|
|
||||||
public string IPRemoteShutdown
|
|
||||||
{
|
|
||||||
get { return _IPRemoteShutdown; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (IPAddress.TryParse(value, out IPAddress address) == false) { value = string.Empty; } // Temporary validation.
|
|
||||||
_IPRemoteShutdown = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _pingRemoteHost;
|
|
||||||
public bool PingRemoteHost
|
|
||||||
{
|
|
||||||
get { return _pingRemoteHost; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_pingRemoteHost = value;
|
|
||||||
|
|
||||||
if (value == true)
|
|
||||||
{
|
|
||||||
|
|
||||||
pingWidget.InitatePingRequest(IPRemoteShutdown);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (pingWidget.WidgetHasInitialized == true)
|
|
||||||
{
|
|
||||||
pingWidget.StopCurrentPingRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string PingRemoteHostStatus { get; set; }
|
|
||||||
|
|
||||||
#region Remote Expander
|
|
||||||
|
|
||||||
public int WindowHeight { get; set; } = 335; // Default 335
|
|
||||||
|
|
||||||
private bool _remoteExpander;
|
|
||||||
public bool RemoteExpander
|
|
||||||
{
|
|
||||||
get { return _remoteExpander; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
WindowHeight = value ? 460 : 335;
|
|
||||||
NotifyOfPropertyChange(() => WindowHeight);
|
|
||||||
|
|
||||||
_remoteExpander = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#region Buttons
|
||||||
|
|
||||||
#region Controls
|
|
||||||
|
|
||||||
public bool CanShutdown { get; set; } = true;
|
public bool CanShutdown { get; set; } = true;
|
||||||
public void Shutdown()
|
public void Shutdown()
|
||||||
{
|
{
|
||||||
_shutdownManager.ExecuteOperation(
|
shutdownManager.ExecuteOperation(ShutdownManager.Operation.Shutdown, ShutdownTime, false);
|
||||||
ShutdownManager.Operation.Shutdown,
|
CanAbortShutdown = true;
|
||||||
ShutdownTime,
|
|
||||||
ShutdownOptionsForce,
|
|
||||||
IPRemoteShutdown);
|
|
||||||
|
|
||||||
ProcessRemoteShutdownAlert();
|
|
||||||
|
|
||||||
CanReboot = false;
|
CanReboot = false;
|
||||||
CanShutdown = false;
|
CanShutdown = false;
|
||||||
|
|
||||||
|
NotifyOfPropertyChange(() => CanAbortShutdown);
|
||||||
NotifyOfPropertyChange(() => CanReboot);
|
NotifyOfPropertyChange(() => CanReboot);
|
||||||
NotifyOfPropertyChange(() => CanShutdown);
|
NotifyOfPropertyChange(() => CanShutdown);
|
||||||
}
|
}
|
||||||
@@ -143,96 +102,31 @@ namespace TimedShutdown.ViewModels
|
|||||||
public bool CanReboot { get; set; } = true;
|
public bool CanReboot { get; set; } = true;
|
||||||
public void Reboot()
|
public void Reboot()
|
||||||
{
|
{
|
||||||
_shutdownManager.ExecuteOperation(
|
shutdownManager.ExecuteOperation(ShutdownManager.Operation.Reboot, ShutdownTime, false);
|
||||||
ShutdownManager.Operation.Reboot,
|
CanAbortShutdown = true;
|
||||||
ShutdownTime,
|
|
||||||
ShutdownOptionsForce,
|
|
||||||
IPRemoteShutdown);
|
|
||||||
|
|
||||||
ProcessRemoteShutdownAlert();
|
|
||||||
|
|
||||||
CanReboot = false;
|
CanReboot = false;
|
||||||
CanShutdown = false;
|
CanShutdown = false;
|
||||||
|
|
||||||
|
NotifyOfPropertyChange(() => CanAbortShutdown);
|
||||||
NotifyOfPropertyChange(() => CanReboot);
|
NotifyOfPropertyChange(() => CanReboot);
|
||||||
NotifyOfPropertyChange(() => CanShutdown);
|
NotifyOfPropertyChange(() => CanShutdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CanAbortShutdown { get; set; } = true;
|
||||||
public void AbortShutdown()
|
public void AbortShutdown()
|
||||||
{
|
{
|
||||||
// Reset values to defaults.
|
// Reset values to defaults.
|
||||||
Minutes = 0;
|
Minutes = 0;
|
||||||
Hours = 0;
|
Hours = 0;
|
||||||
|
|
||||||
_shutdownManager.AbortOperation(IPRemoteShutdown);
|
shutdownManager.AbortOperation();
|
||||||
|
CanAbortShutdown = false;
|
||||||
CanReboot = true;
|
CanReboot = true;
|
||||||
CanShutdown = true;
|
CanShutdown = true;
|
||||||
|
|
||||||
|
NotifyOfPropertyChange(() => CanAbortShutdown);
|
||||||
NotifyOfPropertyChange(() => CanReboot);
|
NotifyOfPropertyChange(() => CanReboot);
|
||||||
NotifyOfPropertyChange(() => CanShutdown);
|
NotifyOfPropertyChange(() => CanShutdown);
|
||||||
NotifyOfPropertyChange(() => IPRemoteShutdown);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _contextRemoteShutdown;
|
|
||||||
public bool ContextRemoteShutdown
|
|
||||||
{
|
|
||||||
get { return _contextRemoteShutdown; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_contextRemoteShutdown = value;
|
|
||||||
|
|
||||||
if (value == true)
|
|
||||||
{
|
|
||||||
IPRemoteShutdownEnabled = true;
|
|
||||||
PingRemoteHostEnabled = true;
|
|
||||||
|
|
||||||
NotifyOfPropertyChange(() => IPRemoteShutdownEnabled);
|
|
||||||
NotifyOfPropertyChange(() => PingRemoteHostEnabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _contextLocalShutdown = true;
|
|
||||||
public bool ContextLocalShutdown
|
|
||||||
{
|
|
||||||
get { return _contextLocalShutdown; }
|
|
||||||
set
|
|
||||||
{
|
|
||||||
|
|
||||||
_contextLocalShutdown = value;
|
|
||||||
|
|
||||||
if (value == true)
|
|
||||||
{
|
|
||||||
IPRemoteShutdownEnabled = false;
|
|
||||||
PingRemoteHostEnabled = false;
|
|
||||||
IPRemoteShutdown = string.Empty;
|
|
||||||
|
|
||||||
NotifyOfPropertyChange(() => IPRemoteShutdown);
|
|
||||||
NotifyOfPropertyChange(() => IPRemoteShutdownEnabled);
|
|
||||||
NotifyOfPropertyChange(() => PingRemoteHostEnabled);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IPRemoteShutdownEnabled { get; set; }
|
|
||||||
|
|
||||||
public bool PingRemoteHostEnabled { get; set; }
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Alerts
|
|
||||||
|
|
||||||
private void ProcessRemoteShutdownAlert()
|
|
||||||
{
|
|
||||||
// Show remote shutdown alert upon checking for a non-loopback
|
|
||||||
// address.
|
|
||||||
if (!string.IsNullOrEmpty(IPRemoteShutdown)
|
|
||||||
&& IPRemoteShutdown != "localhost"
|
|
||||||
&& IPRemoteShutdown != "127.0.0.1")
|
|
||||||
{
|
|
||||||
Messaging alert = new Messaging();
|
|
||||||
alert.Show(Messaging.Message.RemoteShutdown, IPRemoteShutdown);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Timed Shutdown" Height="{Binding WindowHeight, Mode=TwoWay}" Width="400" WindowStartupLocation="CenterScreen"
|
Title="{Binding LabelWindowTitle}" Height="300" Width="400" WindowStartupLocation="CenterScreen"
|
||||||
ResizeMode="NoResize">
|
ResizeMode="NoResize">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Grid x:Name="ShutdownIcon" Margin="15">
|
<Grid x:Name="ShutdownIcon" Margin="15">
|
||||||
@@ -21,34 +21,33 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<!-- Icon -->
|
<!-- Icon -->
|
||||||
<Image Source="/TimedShutdown;component/Resources/ShutdownIcon.png" Grid.Column="0" Grid.Row="0"
|
<Image Source="/TimedShutdown;component/Resources/ShutdownIcon.png" Grid.Column="0" Grid.Row="0"
|
||||||
Margin="0,0,5,0" Grid.RowSpan="5" RenderOptions.BitmapScalingMode="Fant"/>
|
Margin="0,0,5,0" Grid.RowSpan="3" RenderOptions.BitmapScalingMode="Fant"/>
|
||||||
|
|
||||||
<!-- Row 1: Hours -->
|
<!-- Row 1: Hours -->
|
||||||
<Label Content="Hours:" Grid.Row="0" Grid.Column="1" />
|
<Label x:Name="LabelHoursLabel" Grid.Row="0" Grid.Column="1" />
|
||||||
<Slider Value="{Binding Hours, Mode=TwoWay}" Grid.Row="0" Grid.Column="2"
|
<Slider Value="{Binding Hours, Mode=TwoWay}" Grid.Row="0" Grid.Column="2"
|
||||||
Margin="10,0,10,0" Maximum="23" TickPlacement="BottomRight"/>
|
Margin="10,0,10,0" Maximum="23" TickPlacement="BottomRight"/>
|
||||||
<TextBox Text="{Binding Hours, Mode=TwoWay}" Grid.Row="0" Grid.Column="3"
|
<TextBox Text="{Binding Hours, Mode=TwoWay}" Grid.Row="0" Grid.Column="3"
|
||||||
Margin="0,2.5" Padding="5" />
|
Margin="0,2.5" Padding="5" />
|
||||||
|
|
||||||
<!-- Row 2: Minutes -->
|
<!-- Row 2: Minutes -->
|
||||||
<Label Content="Minutes:" Grid.Row="1" Grid.Column="1" />
|
<Label x:Name="LabelMinutesLabel" Grid.Row="1" Grid.Column="1" />
|
||||||
<Slider Value="{Binding Minutes, Mode=TwoWay}" Grid.Row="1" Grid.Column="2"
|
<Slider Value="{Binding Minutes, Mode=TwoWay}" Grid.Row="1" Grid.Column="2"
|
||||||
Margin="10,0,10,0" Maximum="59" TickPlacement="BottomRight"/>
|
Margin="10,0,10,0" Maximum="59" TickPlacement="BottomRight"/>
|
||||||
<TextBox Text="{Binding Minutes, Mode=TwoWay}" Grid.Row="1" Grid.Column="3"
|
<TextBox Text="{Binding Minutes, Mode=TwoWay}" Grid.Row="1" Grid.Column="3"
|
||||||
Margin="0,2.5" Padding="5"/>
|
Margin="0,2.5" Padding="5"/>
|
||||||
|
|
||||||
<!-- Row 3: Options -->
|
<!-- Row 3: Options -->
|
||||||
<Label Content="Options:" Grid.Row="2" Grid.Column="1" />
|
<Label x:Name="LabelShutdownOptions" Grid.Row="2" Grid.Column="1" />
|
||||||
<CheckBox x:Name="ShutdownOptionsForce" Content="Force Operation" Grid.Row="2" Grid.Column="2"
|
<CheckBox x:Name="ShutdownOptionsForce" Content="{Binding LabelShutdownOptionsForce}" Grid.Row="2" Grid.Column="2"
|
||||||
Margin="10,6,0,0" ToolTip="Forces a system shutdown/restart by ignoring programs preventing a shutdown."/>
|
Margin="10,6,0,0" />
|
||||||
|
|
||||||
<!-- Row 4: Shutdown Time -->
|
<!-- Row 4: Shutdown Time -->
|
||||||
<Label Content="Shutdown Time:" Grid.Row="4" Grid.Column="1" Margin="0,5,0,0"/>
|
<Label x:Name="LabelShutdownTime" Grid.Row="4" Grid.Column="1" Margin="0,5,0,0"/>
|
||||||
<TextBox Text="{Binding ShutdownTimeSpan, Mode=OneWay}" Grid.Row="4" Grid.Column="2"
|
<TextBox Text="{Binding ShutdownTimeSpan, Mode=OneWay}" Grid.Row="4" Grid.Column="2"
|
||||||
Grid.ColumnSpan="2" Padding="5" Margin="10,5,0,0" IsEnabled="False"/>
|
Grid.ColumnSpan="2" Padding="5" Margin="10,5,0,0" IsEnabled="False"/>
|
||||||
|
|
||||||
@@ -65,61 +64,15 @@
|
|||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Button x:Name="Shutdown" Content="Shutdown" Grid.Row="0" Grid.Column="0"
|
<Button x:Name="Shutdown" Content="{Binding LabelShutdown}" Grid.Row="0" Grid.Column="0"
|
||||||
Padding="5" Margin="0,5,2.5,0"/>
|
Padding="5" Margin="0,5,2.5,0"/>
|
||||||
<Button x:Name="Reboot" Content="Reboot" Grid.Row="0" Grid.Column="1"
|
<Button x:Name="Reboot" Content="{Binding LabelReboot}" Grid.Row="0" Grid.Column="1"
|
||||||
Padding="5" Margin="2.5,5,0,0"/>
|
Padding="5" Margin="2.5,5,0,0"/>
|
||||||
<Button x:Name="AbortShutdown" Content="Abort Shutdown" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
|
<Button x:Name="AbortShutdown" Content="{Binding LabelAbortShutdown}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"
|
||||||
Padding="5" Margin="0,5,0,0"/>
|
Padding="5" Margin="0,5,0,0"/>
|
||||||
|
|
||||||
<!-- Remote Shutdown Options -->
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<Separator/>
|
|
||||||
<Expander IsExpanded="{Binding RemoteExpander}" x:Name="remoteExpander" Header="Remote Shutdown Options" Height="172" Padding="5">
|
|
||||||
|
|
||||||
<Grid>
|
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
<ColumnDefinition Width="1*"/>
|
|
||||||
<ColumnDefinition Width="1*"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<!-- Row 6: Shutdown Type -->
|
|
||||||
<Label Content="Shutdown Type:" Grid.Row="0" Grid.Column="0" />
|
|
||||||
<RadioButton IsChecked="{Binding ContextLocalShutdown}" Content="Local" Grid.Row="0" Grid.Column="1"
|
|
||||||
Margin="10,5,0,0"/>
|
|
||||||
<RadioButton IsChecked="{Binding ContextRemoteShutdown}" Content="Remote" Grid.Row="0" Grid.Column="2"
|
|
||||||
Margin="10,5,0,0"/>
|
|
||||||
|
|
||||||
<!-- Row 7: Hostname/IP -->
|
|
||||||
<Label Content="Hostname/IP Address:" Grid.Row="1" Grid.Column="0" Margin="0,5,0,0"/>
|
|
||||||
<TextBox Text="{Binding IPRemoteShutdown, Mode=TwoWay}" Grid.Row="1" Grid.Column="1"
|
|
||||||
IsEnabled="{Binding IPRemoteShutdownEnabled, Mode=TwoWay}"
|
|
||||||
Padding="5" Margin="10,5,5,0" Grid.ColumnSpan="2"
|
|
||||||
ToolTip="Enter the machine name or IP address to remotely shutdown. NOTE: This will only work on machines part of the same Windows Domain."/>
|
|
||||||
|
|
||||||
<!-- Row 8: Ping remote host -->
|
|
||||||
<Label Content="Options:" Grid.Row="2" Grid.Column="0"/>
|
|
||||||
<CheckBox IsChecked="{Binding PingRemoteHost, Mode=OneWayToSource}" Content="Ping remote host"
|
|
||||||
IsEnabled="{Binding PingRemoteHostEnabled, Mode=TwoWay}"
|
|
||||||
Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Margin="10,5,0,0"/>
|
|
||||||
|
|
||||||
<!-- Row 9: Ping status -->
|
|
||||||
<Label Content="Status:" Grid.Row="3" Grid.Column="0"/>
|
|
||||||
<Label Content="{Binding PingRemoteHostStatus}" Grid.Row="3" Grid.Column="1"/>
|
|
||||||
</Grid>
|
|
||||||
</Expander>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user