/[NexusPowerControl]/trunk/NexusPowerCommand/Program.cs
ViewVC logotype

Contents of /trunk/NexusPowerCommand/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations) (download)
Tue Oct 25 07:39:27 2011 UTC (7 years, 9 months ago) by william
File size: 3100 byte(s)
use #define USE_TESTING_CODE, for testing application before actually implementing the power state commands

1 #define USE_TESTING_CODE // when defined, no actuall power command will be processed, it will just ouput a message to the console
2 using System;
3 using System.Collections.Generic;
4 using System.Linq;
5 using System.Text;
6 using System.Reflection;
7
8 namespace NexusPowerCommand
9 {
10
11 public class PowerCommands
12 {
13 public const string shutdown = "/shutdown";
14 public const string restart = "/restart";
15 public const string logoff = "/logoff";
16 public const string lockscreen = "/lock";
17 public const string sleep = "/sleep";
18 }
19
20 class Program
21 {
22 static void Main(string[] args)
23 {
24 if (args.Length == 0 || args.Length > 1) { ShowUsage(); return; }
25
26 switch (args[0].ToLower())
27 {
28 case PowerCommands.shutdown: Shutdown(); return;
29 case PowerCommands.restart: Restart(); return;
30 case PowerCommands.logoff: Logoff(); return;
31 case PowerCommands.lockscreen: Lock(); return;
32 case PowerCommands.sleep: Sleep(); return;
33 default: ShowUsage(); return;
34 }
35 }
36
37
38 private static void ShowUsage()
39 {
40 Console.WriteLine();
41 Console.WriteLine(string.Format("USAGE: {0}.exe <option>", Assembly.GetExecutingAssembly().GetName().Name));
42 Console.WriteLine();
43 Console.WriteLine("Where <option> is one of: ");
44 Console.WriteLine();
45 Console.WriteLine(string.Format("\t{0} = {1}","/shutdown","Shuts down the computer."));
46 Console.WriteLine(string.Format("\t{0} = {1}", "/restart", "Restarts the computer."));
47 Console.WriteLine(string.Format("\t{0} = {1}", "/logoff", "Logs off the current user."));
48 Console.WriteLine(string.Format("\t{0} = {1}", "/lock", "Locks the current user's session."));
49 Console.WriteLine(string.Format("\t{0} = {1}", "/sleep", "Puts the computer to sleep."));
50 }
51 private static void Shutdown()
52 {
53 #if USE_TESTING_CODE
54 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.shutdown));
55 return;
56 #endif
57 }
58 private static void Restart()
59 {
60 #if USE_TESTING_CODE
61 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.restart));
62 return;
63 #endif
64 }
65 private static void Logoff()
66 {
67 #if USE_TESTING_CODE
68 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.logoff));
69 return;
70 #endif
71 }
72 private static void Lock()
73 {
74 #if USE_TESTING_CODE
75 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.lockscreen));
76 return;
77 #endif
78 }
79 private static void Sleep()
80 {
81 #if USE_TESTING_CODE
82 Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.sleep));
83 return;
84 #endif
85 }
86 }
87 }

  ViewVC Help
Powered by ViewVC 1.1.22