Пример #1
0
        /// <summary>
        /// Builds the XML results.
        /// </summary>
        /// <param name="dataResults">The data results.</param>
        /// <returns></returns>
        private string BuildXmlResults(ResultDTO dataResults)
        {
            string buildxml = "";
            XmlDocument doc = new XmlDocument();
            XmlNode prtg = doc.CreateElement("prtg");
            XmlNode result;

            if (dataResults.Error.Length == 0)
            {
                result = doc.CreateElement("result");
                result.AppendChild(GetNodeItemChannel(doc, "channel", "DLink - Temperature"));
                result.AppendChild(GetNodeItemChannel(doc, "unit", "Temperature"));
                result.AppendChild(GetNodeItemChannel(doc, "mode", "Absolute"));
                result.AppendChild(GetNodeItemChannel(doc, "showChart", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "showTable", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "warning", "140"));
                result.AppendChild(GetNodeItemChannel(doc, "float", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "value", dataResults.Temp.ToString()));
                prtg.AppendChild(result);

                result = doc.CreateElement("result");
                result.AppendChild(GetNodeItemChannel(doc, "channel", "Disk Space - Total"));
                result.AppendChild(GetNodeItemChannel(doc, "unit", "Custom"));
                result.AppendChild(GetNodeItemChannel(doc, "customUnit", "GB"));
                //result.AppendChild(GetNodeItemChannel(doc, "unit", "BytesDisk"));
                //result.AppendChild(GetNodeItemChannel(doc, "volumesize", "GigaByte"));
                result.AppendChild(GetNodeItemChannel(doc, "mode", "Absolute"));
                result.AppendChild(GetNodeItemChannel(doc, "showChart", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "showTable", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "warning", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "float", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "value", dataResults.TotalDiskSpace.ToString()));
                prtg.AppendChild(result);

                result = doc.CreateElement("result");
                result.AppendChild(GetNodeItemChannel(doc, "channel", "Disk Space - Used"));
                result.AppendChild(GetNodeItemChannel(doc, "unit", "Custom"));
                result.AppendChild(GetNodeItemChannel(doc, "customUnit", "GB"));
                //result.AppendChild(GetNodeItemChannel(doc, "unit", "BytesDisk"));
                //result.AppendChild(GetNodeItemChannel(doc, "volumesize", "GigaByte"));
                result.AppendChild(GetNodeItemChannel(doc, "mode", "Absolute"));
                result.AppendChild(GetNodeItemChannel(doc, "showChart", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "showTable", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "warning", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "float", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "value", dataResults.UsedDiskSpace.ToString()));
                prtg.AppendChild(result);

                result = doc.CreateElement("result");
                result.AppendChild(GetNodeItemChannel(doc, "channel", "Disk Space - UnUsed"));
                result.AppendChild(GetNodeItemChannel(doc, "unit", "Custom"));
                result.AppendChild(GetNodeItemChannel(doc, "customUnit", "GB"));
                //result.AppendChild(GetNodeItemChannel(doc, "unit", "BytesDisk"));
                //result.AppendChild(GetNodeItemChannel(doc, "volumesize", "GigaByte"));
                result.AppendChild(GetNodeItemChannel(doc, "mode", "Absolute"));
                result.AppendChild(GetNodeItemChannel(doc, "showChart", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "showTable", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "warning", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "float", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "value", dataResults.UnUsedDiskSpace.ToString()));
                prtg.AppendChild(result);

                result = doc.CreateElement("result");
                result.AppendChild(GetNodeItemChannel(doc, "channel", "Disk Space - Percent Used"));
                result.AppendChild(GetNodeItemChannel(doc, "unit", "Percent"));
                result.AppendChild(GetNodeItemChannel(doc, "mode", "Absolute"));
                result.AppendChild(GetNodeItemChannel(doc, "showChart", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "showTable", "1"));
                result.AppendChild(GetNodeItemChannel(doc, "warning", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "float", "0"));
                result.AppendChild(GetNodeItemChannel(doc, "value", dataResults.PercentUsedDiskSpace.ToString()));
                prtg.AppendChild(result);

                result = doc.CreateElement("text");
                result.InnerText = "Dlink Sensor";
                prtg.AppendChild(result);  
            }
            else
            {
                result = doc.CreateElement("error");
                result.InnerText = "1";
                prtg.AppendChild(result);  

                result = doc.CreateElement("text");
                result.InnerText = dataResults.Error;
                prtg.AppendChild(result);  
            }

            doc.AppendChild(prtg);
            return doc.OuterXml;
        }
Пример #2
0
        /// <summary>
        /// Logins the page.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        private ResultDTO LoginPage(string[] args)
        {
            Uri address;
            int iTotalSpace = 0;
            int iUsedSpace = 0;
            int iUnUsedSpace = 0;
            int iTemp = 0;

            ResultDTO results = new ResultDTO
            {
                UsedDiskSpace = 0,
                UnUsedDiskSpace = 0,
                PercentUsedDiskSpace = 0,
                Temp = 0,
                TotalDiskSpace = 0,
                Error = ""
            };
            
            try
            {
                string strUrl = @"http://10.10.1.37/goform/formLogin";

                WebPostRequest myPost = new WebPostRequest(new Uri(strUrl));
                myPost.Add("f_LOGIN_NAME", "admin");
                myPost.Add("f_LOGIN_PASSWD", "");
                myPost.Add("f_login_type", "0");
                myPost.Add("f_url", "");                

                string webpage = myPost.GetResponse();

                if (webpage.ToLower().Contains("wizard"))
                {
                    //-- Need to test for valid login page
                    //-- before continuing on.

                    //-- now goto the http://10.10.1.37/goform/adv_status
                    WebPostRequest myPost2 = new WebPostRequest(new Uri("http://10.10.1.37/goform/adv_status"));

                    string webpage2 = myPost2.GetResponse();

                    if (webpage2.ToLower().Contains("temperture"))
                    {
                        HtmlDocument doc = new HtmlDocument();

                        //-- Removes all html tags
                        //webpage2 = Regex.Replace(webpage2, @"<(.|\n)*?>", String.Empty);
                        //webpage2 = Regex.Replace(webpage2, @"^\n*", String.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                        //webpage2 = Regex.Replace(webpage2, @"\n*$", String.Empty, RegexOptions.Singleline | RegexOptions.IgnoreCase);
                        //webpage2 = webpage2.Replace("\n", " ");

                        doc.LoadHtml(webpage2);

                        // There are various options, set as needed
                        //doc.OptionFixNestedTags = true;
                        //doc.OptionAutoCloseOnEnd = true;
                        //doc.OptionCheckSyntax = true;

                        results.Temp = GetTemp(webpage2);

                        results.TotalDiskSpace = GetTotalSpace(webpage2);
                        results.TotalDiskSpace = results.TotalDiskSpace / 1024;

                        results.UsedDiskSpace  = GetUsedSpace(webpage2);
                        results.UsedDiskSpace = results.UsedDiskSpace / 1024;

                        results.UnUsedDiskSpace = GetUnUsedSpace(webpage2);
                        results.UnUsedDiskSpace = results.UnUsedDiskSpace / 1024;

                        if(results.TotalDiskSpace > 0)
                        {
                            var percentUsed = (Convert.ToDouble(results.UsedDiskSpace) / Convert.ToDouble(results.TotalDiskSpace)) * 100;
                            results.PercentUsedDiskSpace = Convert.ToInt32(percentUsed);
                        }
                    }
                    //-- logout
                    PageLogout(args);
                }
                else if (webpage.ToLower().Contains("another party"))
                {
                    results.Error = "Web page in use.";
                }
                else
                {
                    results.Error = "Unknow Error.";
                }
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                results.Error = ex.Message;
            }
            finally
            {
                
            }
            return results;
        }