コード例 #1
0
 internal void Connect()
 {
     try
     {
         upsd.Connect();
         this.Status            &= ~UPSMonStatus.COMMBAD;
         this.Status            |= UPSMonStatus.COMMOK;
         this.Device.Description = upsd.GetUPSDescription(this.Device.Name);
         upsd.SetUsername(this.Username);
         upsd.SetPassword(this.Password);
         upsd.Login(this.Device.Name);
     }
     catch (SocketException sockex)
     {
         UPSMonThreads.AppendLog("Could not connect to UPS " + this.Device.ToString() + "! " + sockex.Message);
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
         upsd.Disconnect();
     }
     catch (UPSException upsex)
     {
         UPSMonThreads.AppendLog("Error on UPS " + this.Device.ToString() + "! " + upsex.Code.ToString() + ":" + upsex.Description
                                 + (String.IsNullOrEmpty(upsex.Message) ? "" : " (" + upsex.Message + ")"));
         if (this.Status != UPSMonStatus.NOCOMMS)
         {
             this.Status &= ~UPSMonStatus.COMMOK;
             this.Status |= UPSMonStatus.COMMBAD;
         }
     }
 }
コード例 #2
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();
            }
        }
コード例 #3
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();
            }
        }
コード例 #4
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();
            }
        }
コード例 #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
        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();
            }
        }
コード例 #7
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();
            }
        }