Ejemplo n.º 1
0
 /// <summary>
 /// Processes the usage meter XML feed for Xnet.
 /// </summary>
 /// <param name="MeterObj">The meter Object currently in use.</param>
 /// <returns>true if Meter Object has been successfully altered; Otherwise false if there is an error</returns>
 public static bool ProccessUsageMeter(MeterObject MeterObj)
 {
     CookieAwareWebClient Client = new CookieAwareWebClient();
     string Xml = Encoding.ASCII.GetString(Client.DownloadData(Constants.APIURL + "?username="******";token=" + Functions.ApiToken(MeterBase.MeterBase.DecodeFrom64(MeterObj.Password))));
     XmlDocument xdoc = new XmlDocument();
     xdoc.LoadXml(Xml);
     MeterObj.LastError = Functions.ReadXmlValue(xdoc, "errstr");
     if (MeterObj.LastError == "")
     {
         MeterObj.Used = Math.Round(Convert.ToDecimal(Functions.ReadXmlValue(xdoc, "total")) / 1024, 2);
         MeterObj.PPM = Convert.ToBoolean(Functions.ReadXmlValue(xdoc, "ppm"));
         if (!MeterObj.PPM)
         {
             MeterObj.Total = Math.Round(Convert.ToDecimal(Functions.ReadXmlValue(xdoc, "cap")) / 1024, 2);
         }
         else
         {
             MeterObj.Total = 0.00M;
         }
         MeterObj.UnmeteredData = Math.Round((Convert.ToDecimal(Functions.ReadXmlValue(xdoc, "rxlocal")) + (Convert.ToDecimal(Functions.ReadXmlValue(xdoc, "txlocal")))) / 1024, 2);
         MeterObj.Cost = Math.Round(Convert.ToDecimal(Functions.ReadXmlValue(xdoc, "bpc")), 2);
         DateTime today = DateTime.Today;
         DateTime lastday = new DateTime(today.Year, today.Month, 1).AddMonths(1).AddDays(-1);
         TimeSpan ts = lastday - DateTime.Today;
         MeterObj.RenewDate = (byte)lastday.Day;
         MeterObj.DaysLeft = (byte)ts.TotalDays;
         return true;
     }
     else
     {
         return false;
     }
     //TODO: Correct bool Statements
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Searches through the Vodafone data meter for the Meter Objet values.
        /// </summary>
        /// <param name="MeterObj">The meter Object currently in use.</param>
        /// <returns>true if Meter Object has been successfully altered; Otherwise false if there is an error</returns>
        public static bool ProcessSite(MeterObject MeterObj)
        {
            try
            {
                CookieAwareWebClient Client = new CookieAwareWebClient();
                string Response = Encoding.ASCII.GetString(Client.UploadData(Constants.LoginPage, "POST", Encoding.ASCII.GetBytes("login="******"&password="******"&cmd=login")));
                if (Response.IndexOf("incorrect") == -1)
                {
                    Response = Client.DownloadString(Constants.AccountOverviewPage);
                    Match m = Regex.Match(Response, Constants.MatchTotal);
                    MeterObj.Total = Math.Round(Convert.ToDecimal(m.Groups[1].Value), 2);

                    m = Regex.Match(Response, Constants.MatchUsed);
                    MeterObj.Used = Math.Round(Convert.ToDecimal(m.Groups[1].Value), 2);

                    m = Regex.Match(Response, Constants.MatchLastDay);

                    try
                    {
                        DateTime Date = DateTime.Parse(m.Groups[2].Value);
                        TimeSpan ts = Date - DateTime.Today;

                        MeterObj.RenewDate = (byte)Date.Day;
                        MeterObj.DaysLeft = (byte)ts.TotalDays;
                        return true;
                    }
                    catch (ArgumentException are)
                    {

                        MeterObj.LastError = "Error occurred while collecting data: " + are.Message;
                        return false;
                    }
                }
                else
                {
                    MeterObj.LastError = "The Username or Password supplied is incorrect or site is currently down!";
                    return false;
                }
            }
            catch (System.Net.WebException e)
            {
                MeterObj.LastError = "Error occurred while collecting data: " + e.Status.ToString();
                return false;
            }
        }