예제 #1
0
        private static void PrintUPSClients(UPS ups)
        {
            UPSDClient client = new UPSDClient(ups.Host);

            try
            {
                client.Connect();
                List <string> clients = client.ListUPSClient(ups.Name);
                foreach (string upsClient in clients)
                {
                    Console.WriteLine(upsClient);
                }
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
예제 #2
0
        private static void PrintUPSList(string upsdServer, bool displayDesc)
        {
            UPSDClient client = new UPSDClient(upsdServer);

            try
            {
                client.Connect();
                List <UPS> upsList = client.ListUPS();
                foreach (UPS ups in upsList)
                {
                    Console.Write(ups.Name);
                    if (displayDesc)
                    {
                        Console.Write(": " + ups.Description);
                    }
                    Console.WriteLine();
                }
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
예제 #3
0
        private static void PrintUPSVarList(UPS ups)
        {
            UPSDClient client = new UPSDClient(ups.Host);

            try
            {
                client.Connect();
                Dictionary <string, string> vars = client.ListUPSVar(ups.Name);
                foreach (KeyValuePair <string, string> item in vars)
                {
                    Console.WriteLine(item.Key + ": " + item.Value);
                }
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: sschocke/netNUT
 private static void ExecuteCommand(UPS target, UPSDClient client)
 {
     if (client.InstantCommand(target.Name, command, addParam) == false)
     {
         Console.WriteLine("UNKNOWN ERROR");
         return;
     }
     Console.WriteLine("OK");
 }
예제 #5
0
파일: Program.cs 프로젝트: sschocke/netNUT
        static void Main(string[] args)
        {
            if ((args.Length == 0) || (args[0] == "-h") || (args[0] == "-?") || (args[0] == "--help"))
            {
                HelpText();
                return;
            }

            if (AnalyzeCommandLineParams(args) == false)
            {
                return;
            }

            UPS        target = new UPS(ups);
            UPSDClient client = new UPSDClient(target.Host);

            try
            {
                client.Connect();
                if (String.IsNullOrEmpty(authUser) == false)
                {
                    if (client.SetUsername(authUser) == false)
                    {
                        Console.WriteLine("Error: Could not set username for authentication");
                        return;
                    }
                }
                if (String.IsNullOrEmpty(authPass) == false)
                {
                    if (client.SetPassword(authPass) == false)
                    {
                        Console.WriteLine("Error: Could not set password for authentication");
                        return;
                    }
                }
                if (String.IsNullOrEmpty(variable))
                {
                    ListVariables(target, client);
                    return;
                }

                SetVariable(target, client);
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: sschocke/netNUT
        private static void ListCommands(UPS target, UPSDClient client)
        {
            Dictionary <string, string> commands = client.ListUPSCommands(target.Name);

            Console.WriteLine("Instant commands supported on UPS [{0}]:", target.Name);
            Console.WriteLine();
            foreach (KeyValuePair <string, string> item in commands)
            {
                Console.WriteLine(item.Key + " - " + item.Value);
            }
        }
예제 #7
0
        public MonitoredUPS(XmlReader reader)
            : this()
        {
            if (reader.NodeType == XmlNodeType.EndElement)
            {
                return;
            }
            if (reader.NodeType != XmlNodeType.Element || reader.Name != "monitor")
            {
                throw new XmlException("Malformed XML found in configuration file!");
            }
            string host   = reader.GetAttribute("host");
            string user   = reader.GetAttribute("username");
            string pass   = reader.GetAttribute("password");
            string pwrval = reader.GetAttribute("powervalue");
            string mode   = reader.GetAttribute("mode");

            if (host == null || user == null || pass == null)
            {
                throw new XmlException("Malformed XML found in configuration file! Invalid <monitor> declaration!");
            }
            this.Host     = host;
            this.Username = user;
            this.Password = pass;

            if (mode != null)
            {
                MonMode temp;
                if (Enum.TryParse <MonMode>(mode.ToUpper(), out temp) == false)
                {
                    throw new XmlException("Malformed XML found in configuration file! Invalid <monitor> mode attribute!");
                }

                this.Mode = temp;
            }
            if (pwrval != null)
            {
                int valtemp;
                if (Int32.TryParse(pwrval, out valtemp) == false)
                {
                    throw new XmlException("Malformed XML found in configuration file! Invalid <monitor> powervalue attribute!");
                }

                this.PowerValue = valtemp;
            }

            this.Device = new UPS(this.Host);

            this.upsd = new UPSDClient(this.Device.Host);

            reader.ReadStartElement("monitor");
        }
예제 #8
0
파일: Program.cs 프로젝트: sschocke/netNUT
        private static void ListVariables(UPS target, UPSDClient client)
        {
            List <UPS.VariableDescription> vars = client.ListUPSReadWrite(target.Name);

            foreach (UPS.VariableDescription rwVar in vars)
            {
                Console.WriteLine("[" + rwVar.Name + "]");
                Console.WriteLine(rwVar.Description);
                Console.WriteLine("Type: " + rwVar.Type);
                Console.WriteLine("Value: " + rwVar.Value);
                Console.WriteLine();
            }
        }
예제 #9
0
파일: Program.cs 프로젝트: sschocke/netNUT
 private static void SetVariable(UPS target, UPSDClient client)
 {
     string[] variableParts = variable.Split(new char[] { '=' }, 2);
     variable = variableParts[0];
     if (variableParts.Length < 2)
     {
         Console.Write("Enter value for " + variable + ":");
         newValue = Console.ReadLine();
     }
     if (client.SetUPSVariable(target.Name, variable, newValue) == false)
     {
         Console.WriteLine("UNKNOWN ERROR");
         return;
     }
     Console.WriteLine("OK");
 }
예제 #10
0
        private static void PrintUPSVar(UPS ups, string varName)
        {
            UPSDClient client = new UPSDClient(ups.Host);

            try
            {
                client.Connect();
                string result = client.GetUPSVar(ups.Name, varName);
                Console.WriteLine(result);
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }
예제 #11
0
파일: Program.cs 프로젝트: sschocke/netNUT
        static void Main(string[] args)
        {
            if ((args.Length == 0) || (args[0] == "-h") || (args[0] == "-?") || (args[0] == "--help"))
            {
                HelpText();
                return;
            }

            if (AnalyzeCommandLineParams(args) == false)
            {
                return;
            }

            Console.WriteLine("ups={0}, command={1}, user={2}, password={3}, addParam={4}, listMode={5}",
                              new object[] { ups, command, authUser, authPass, addParam, listMode });

            UPS        target = new UPS(ups);
            UPSDClient client = new UPSDClient(target.Host);

            try
            {
                client.Connect();
                if (listMode)
                {
                    ListCommands(target, client);
                    return;
                }

                if (String.IsNullOrEmpty(authUser) == true)
                {
                    Console.Write("Username: "******"Error: Could not set username for authentication");
                    return;
                }

                if (String.IsNullOrEmpty(authPass) == true)
                {
                    Console.Write("Password: "******"Error: Could not set password for authentication");
                    return;
                }

                ExecuteCommand(target, client);
            }
            catch (SocketException sockex)
            {
                Console.WriteLine("Error: " + sockex.Message);
            }
            catch (UPSException upsex)
            {
                Console.WriteLine("Error: " + upsex.Description);
            }
            finally
            {
                client.Disconnect();
            }
        }