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

Diff of /trunk/NexusPowerCommand/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/NexusPowerCommand/Program.cs	2011/10/25 07:22:44	22
+++ trunk/NexusPowerCommand/Program.cs	2011/10/25 07:39:27	23
@@ -1,14 +1,87 @@
-´╗┐using System;
+´╗┐#define USE_TESTING_CODE // when defined, no actuall power command will be processed, it will just ouput a message to the console
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Reflection;
 
 namespace NexusPowerCommand
 {
+
+    public class PowerCommands
+    {
+        public const string shutdown = "/shutdown";
+        public const string restart = "/restart";
+        public const string logoff = "/logoff";
+        public const string lockscreen = "/lock";
+        public const string sleep = "/sleep";
+    }
+
     class Program
     {
         static void Main(string[] args)
         {
+            if (args.Length == 0 || args.Length > 1) { ShowUsage(); return; }
+
+            switch (args[0].ToLower())
+            {
+                case PowerCommands.shutdown: Shutdown(); return;
+                case PowerCommands.restart: Restart(); return;
+                case PowerCommands.logoff: Logoff(); return;
+                case PowerCommands.lockscreen: Lock(); return;
+                case PowerCommands.sleep: Sleep(); return;
+                default: ShowUsage(); return;
+            }
+        }
+        
+
+        private static void ShowUsage()
+        {
+            Console.WriteLine();
+            Console.WriteLine(string.Format("USAGE: {0}.exe <option>", Assembly.GetExecutingAssembly().GetName().Name));
+            Console.WriteLine();
+            Console.WriteLine("Where <option> is one of: ");
+            Console.WriteLine();
+            Console.WriteLine(string.Format("\t{0} = {1}","/shutdown","Shuts down the computer."));
+            Console.WriteLine(string.Format("\t{0} = {1}", "/restart", "Restarts the computer."));
+            Console.WriteLine(string.Format("\t{0} = {1}", "/logoff", "Logs off the current user."));
+            Console.WriteLine(string.Format("\t{0} = {1}", "/lock", "Locks the current user's session."));
+            Console.WriteLine(string.Format("\t{0} = {1}", "/sleep", "Puts the computer to sleep."));
+        }
+        private static void Shutdown()
+        {
+#if USE_TESTING_CODE
+            Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.shutdown));
+            return;
+#endif
+        }
+        private static void Restart()
+        {
+#if USE_TESTING_CODE
+            Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.restart));
+            return;
+#endif
+        }
+        private static void Logoff()
+        {
+#if USE_TESTING_CODE
+            Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.logoff));
+            return;
+#endif
+        }
+        private static void Lock()
+        {
+#if USE_TESTING_CODE
+            Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.lockscreen));
+            return;
+#endif
+        }
+        private static void Sleep()
+        {
+#if USE_TESTING_CODE
+            Console.WriteLine(string.Format("Detected use of: {0}", PowerCommands.sleep));
+            return;
+#endif
         }
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22