Ejemplo n.º 1
0
        activeLbl newLabel(XmlNode xelem, bool active)
        {
            //
            // dataLbl
            //
            activeLbl dataLbl;

            dataLbl             = new activeLbl();
            dataLbl.xml         = xelem;
            dataLbl.AutoSize    = true;
            dataLbl.BackColor   = (xelem.Attributes["bColor"] != null ? Color.FromName(xelem.Attributes["bColor"].Value) : Color.LightGray);
            dataLbl.BorderStyle = ((xelem.Attributes["noborder"] != null) && (xelem.Attributes["noborder"].Value == "1") ? System.Windows.Forms.BorderStyle.None : System.Windows.Forms.BorderStyle.FixedSingle);
            dataLbl.ForeColor   = (xelem.Attributes["fColor"] != null ? Color.FromName(xelem.Attributes["fColor"].Value) : Color.Black);
            dataLbl.Location    = new System.Drawing.Point(8, 8);
            dataLbl.Margin      = new System.Windows.Forms.Padding(3);
            dataLbl.Name        = xelem.Attributes["title"].Value;
            dataLbl.Padding     = new System.Windows.Forms.Padding(3);
            dataLbl.MaximumSize = new System.Drawing.Size(150, 100);
            dataLbl.MinimumSize = new System.Drawing.Size(150, 25);
            dataLbl.TabIndex    = 0;
            dataLbl.Text        = "Loading";
            dataLbl.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
            return(dataLbl);
        }
Ejemplo n.º 2
0
        string getDatumValue(activeLbl label)
        {
            int refreshRate = 100;

            switch (label.xml.Name)
            {
            default: return("");

            case "StaticDatum":
                if (label.xml.Attributes["Value"] != null)
                {
                    return(label.xml.Attributes["Value"].Value);
                }
                else
                {
                    return("");
                }

            case "CmdDatum":
                refreshRate = (((activeLbl)label).xml.Attributes["refresh"] != null ? Convert.ToInt32(((activeLbl)label).xml.Attributes["refresh"].Value) : 12);
                if (clockTick % refreshRate == 0 || ((activeLbl)label).firstRun)
                {
                    ((activeLbl)label).firstRun = false;
                    string x = "";
                    if (c != null && c.domain != null && ((activeLbl)label).xml.Attributes["cmd"] != null)
                    {
                        x = (c.RunAs(((activeLbl)label).xml.Attributes["cmd"].Value, (((activeLbl)label).xml.Attributes["args"] != null?((activeLbl)label).xml.Attributes["args"].Value:""), true)).Last();
                    }
                    else if (((activeLbl)label).xml.Attributes["cmd"] != null)
                    {
                        System.Diagnostics.ProcessStartInfo pS = new System.Diagnostics.ProcessStartInfo(((activeLbl)label).xml.Attributes["cmd"].Value, (((activeLbl)label).xml.Attributes["args"] != null ? ((activeLbl)label).xml.Attributes["args"].Value : ""));
                        pS.UseShellExecute = false;
                        pS.CreateNoWindow  = true;
                        System.Diagnostics.Process.Start(pS);

                        pS.RedirectStandardOutput = true;
                        System.Diagnostics.Process p = System.Diagnostics.Process.Start(pS);
                        List <string> output         = new List <String>();
                        while (!p.StandardOutput.EndOfStream)
                        {
                            output.Add(p.StandardOutput.ReadLine());
                        }
                        return(output.Last());;
                    }
                    else
                    {
                        return("Bad XML entry");
                    }

                    return(x);
                }
                else
                {
                    return(label.Text.Replace(label.xml.Attributes["title"].Value + "\r\n-------\r\n", ""));
                }

            case "PerfDatum":
                refreshRate = (((activeLbl)label).xml.Attributes["refresh"] != null ? Convert.ToInt32(((activeLbl)label).xml.Attributes["refresh"].Value) : 12);
                if (clockTick % refreshRate == 0 || ((activeLbl)label).firstRun)
                {
                    ((activeLbl)label).firstRun = false;
                    float i = -1;
                    try
                    {
                        if (label.pc != null)
                        {
                            i = label.pc.NextValue();
                        }
                    }
                    catch (EventLogNotFoundException e)
                    {
                        Console.WriteLine("Error while reading the perf logs");
                        return("Error");
                    }
                    return(i.ToString());
                }
                else
                {
                    return(label.Text.Replace(label.xml.Attributes["title"].Value + "\r\n-------\r\n", ""));
                }

            case "EvtDatum":
                refreshRate = (((activeLbl)label).xml.Attributes["refresh"] != null ? Convert.ToInt32(((activeLbl)label).xml.Attributes["refresh"].Value) : 12);
                if (clockTick % refreshRate == 0 || ((activeLbl)label).firstRun)
                {
                    ((activeLbl)label).firstRun = false;
                    int count = 0;
                    foreach (EventLogQuery q in label.eventsQuery)
                    {
                        try
                        {
                            EventLogReader r = new EventLogReader(q);

                            for (EventRecord eventdetail = r.ReadEvent(); eventdetail != null; eventdetail = r.ReadEvent())
                            {
                                // Read Event details
                                count++;
                            }
                        }
                        catch (EventLogNotFoundException e)
                        {
                            Console.WriteLine("Error while reading the event logs");
                            return("Error");
                        }
                    }
                    return(count.ToString());
                }
                else
                {
                    return(label.Text.Replace(label.xml.Attributes["title"].Value + "\r\n-------\r\n", ""));
                }
            }
        }