Exemple #1
0
        public override void Send(InformationReader reader, bool sendBatteryInformation)
        {
            MailMessage mail   = new MailMessage("*****@*****.**", mailAddress);
            SmtpClient  client = new SmtpClient(smtpHost, smtpPort);

            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = true;

            mail.Subject = Environment.MachineName + ": Bad battery health";
            mail.Body   += "The following computer may need a replacement battery because of a low health:\r\n\r\n";
            mail.Body   += "Hostname:\t\t\t" + ComputerInformation.MachineName + "\r\n";
            mail.Body   += "IP Address(es):\t\t\t" + String.Join("\r\n\t\t\t\t", ComputerInformation.IPAddresses) + "\r\n\r\n";
            mail.Body   += "Vendor:\t\t\t" + ComputerInformation.Vendor + "\r\n";
            mail.Body   += "Type:\t\t\t\t" + ComputerInformation.Type + "\r\n";
            mail.Body   += "Service Tag:\t\t\t" + ComputerInformation.ServiceTag + "\r\n\r\n";
            mail.Body   += "Design capacity:\t\t" + reader.FullCapacity + " mWh\r\n";
            mail.Body   += "Last Full Charge capacity:\t" + reader.LastCapacity + " mWh\r\n";
            mail.Body   += "Full Charge percentage:\t" + reader.Percentage + "%";

            if (sendBatteryInformation)
            {
                MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(reader.BatteryInfo));
                mail.Attachments.Add(new Attachment(stream, "batteryInformation.xml"));
            }

            client.Send(mail);
        }
Exemple #2
0
        public override void Send(InformationReader reader, bool sendBatteryInformation)
        {
            string sSource = "Battery Health Information";
            string sLog    = "Application";
            string sEvent  = "";

            sEvent += "Hostname:\t\t" + ComputerInformation.MachineName + "\r\n";
            sEvent += "IP Address(es):\t\t" + String.Join("\r\n\t\t\t", ComputerInformation.IPAddresses) + "\r\n\r\n";
            sEvent += "Vendor:\t\t\t" + ComputerInformation.Vendor + "\r\n";
            sEvent += "Type:\t\t\t" + ComputerInformation.Type + "\r\n";
            sEvent += "Service Tag:\t\t" + ComputerInformation.ServiceTag + "\r\n\r\n";
            sEvent += "Design capacity:\t\t" + reader.FullCapacity + " mWh\r\n";
            sEvent += "Last Full Charge capacity:\t" + reader.LastCapacity + " mWh\r\n";
            sEvent += "Full Charge percentage:\t" + reader.Percentage + "%\r\n\r\n\r\n";

            if (sendBatteryInformation)
            {
                sEvent += "Details: \r\n";
                sEvent += reader.BatteryInfo;
            }


            if (!EventLog.SourceExists(sSource))
            {
                EventLog.CreateEventSource(sSource, sLog);
            }

            EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);
        }
Exemple #3
0
        public override void Send(InformationReader reader, bool sendBatteryInformation)
        {
            if (sendBatteryInformation)
            {
                Console.WriteLine(reader.BatteryInfo);
                Console.WriteLine();
            }

            Console.WriteLine("Battery Health: " + reader.Percentage + "%");
        }
Exemple #4
0
        public override void Send(InformationReader reader, bool sendBatteryInformation)
        {
            ExportConfigFile();

            SoapConnectorClient client = new SoapConnectorClient("BasicHttpBinding_SoapConnector");

            client.Endpoint.Address = new System.ServiceModel.EndpointAddress(url);

            string description = "";

            description += "<table width=\"80%\">";
            description += "<tr><td>Hostname:</td><td>" + ComputerInformation.MachineName + "</td></tr>";
            description += "<tr><td>IP Address(es):</td><td>" + String.Join("</td></tr><tr><td></td><td>", ComputerInformation.IPAddresses) + "</td></tr>";
            description += "<tr><td colspan=\"2\"></td></tr>";
            description += "<tr><td>Vendor:</td><td>" + ComputerInformation.Vendor + "</td></tr>";
            description += "<tr><td>Type:</td><td>" + ComputerInformation.Type + "</td></tr>";
            description += "<tr><td>Service Tag:</td><td>" + ComputerInformation.ServiceTag + "</td></tr>";
            description += "<tr><td colspan=\"2\"></td></tr>";
            description += "<tr><td>Design capacity:</td><td>" + reader.FullCapacity + " mWh</td></tr>";
            description += "<tr><td>Last Full Charge capacity:</td><td>" + reader.LastCapacity + " mWh</td></tr>";
            description += "<tr><td>Full Charge percentage:</td><td>" + reader.Percentage + "%</td></tr>";
            description += "</table>";

            if (sendBatteryInformation)
            {
                description += "<br/><br/>Extra information:<br/>";
                description += "<textarea width=\"50%\" height=\"300px\">" + reader.BatteryInfo + "<textarea>";
            }

            XElement data_object = CreateElement("Data");
            XElement obj         = CreateElement("Object", data_object, "Type", "Job", "Action", "InsertOrUpdate");

            CreateElement("Property", obj, "Name", "Context", "Value", "128");
            CreateElement("Property", obj, "Name", "SkillCategory", "Value", skillgroup);
            CreateElement("Property", obj, "Name", "Status", "Value", "4");
            CreateElement("Property", obj, "Name", "Description", "Value", ComputerInformation.MachineName + ": Bad battery health");
            CreateElement("Property", obj, "Name", "ReportText", "Value", description);
            CreateElement("Property", obj, "Name", "SupportLine", "Value", "FirstLine");
            CreateElement("Property", obj, "Name", "Equipment", "Value", GetNumeric(ComputerInformation.MachineName));
            CreateElement("Property", obj, "Name", "ReportForeignKeyEmployee", "Value", employeeId);
            CreateElement("Property", obj, "Name", "_TELEFOONNUMMER", "Value", "9");

            string xml = data_object.ToString();

            client.ImportData(jobName, username, password, xml);
            client.Close();
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            IntPtr ptr = GetConsoleWindow();

            ShowWindow(ptr, SW_HIDE);

            List <OutputInformation> outputTypes   = new List <OutputInformation>();
            OutputInformation        consoleOutput = null;

            bool GetFullInfo = false;
            int  belowMarge  = 100;

            string[] argv    = Environment.GetCommandLineArgs();
            bool     isQuiet = false;

            if (argv.Length > 1)
            {
                for (int i = 0; i < argv.Length; i++)
                {
                    switch (argv[i])
                    {
                    case "-b":
                    case "/b":
                    case "--below":
                        belowMarge = (int)Convert.ToSingle(argv[i + 1]);
                        break;

                    case "/oc":
                    case "-oc":
                    case "--console":
                        outputTypes.Add(new ConsoleOutput());
                        break;

                    case "/oe":
                    case "-oe":
                    case "--email":
                        outputTypes.Add(new EmailOutput(argv[i + 1], argv[i + 2], Convert.ToInt32(argv[i + 3])));
                        i += 3;
                        break;

                    case "-ov":
                    case "/ov":
                    case "--eventlog":
                        outputTypes.Add(new EventLogOutput());
                        break;

                    case "-?":
                    case "/?":
                    case "-h":
                    case "/h":
                    case "--help":
                        isQuiet = false;
                        ShowWindow(ptr, SW_SHOW);
                        PrintHelp();
                        Environment.Exit(0);
                        break;

                    case "-i":
                    case "/i":
                    case "--info":
                        GetFullInfo = true;
                        break;

                    case "-q":
                    case "/q":
                    case "--quiet":
                        isQuiet = true;
                        break;

                    case "-ou":
                    case "/ou":
                    case "--ultimo":
                        outputTypes.Add(new UltimoOutput(argv[i + 1], argv[i + 2], argv[i + 3], argv[i + 4], argv[i + 5], argv[i + 6]));
                        i += 6;
                        break;
                    }
                }
            }

            ShowWindow(ptr, isQuiet ? SW_HIDE : SW_SHOW);

            if (outputTypes.Count == 0)
            {
                consoleOutput = new ConsoleOutput();
                outputTypes.Add(consoleOutput);
            }

            if (outputTypes.Count > 0)
            {
                InformationReader reader = new InformationReader();
                reader.Start();

                foreach (OutputInformation output in outputTypes)
                {
                    if (reader.Percentage <= belowMarge)
                    {
                        output.Send(reader, GetFullInfo);
                    }
                }
            }
        }
 public abstract void Send(InformationReader reader, bool sendBatteryInformation);