Exemple #1
0
        private bool Analyze(string source, bool updateClient, out List <Period> period, out bool updateHistory)
        {
            //File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DateTime.Now.ToString("yyyyMMddHHmmssf")) + ".html", source);
            updateHistory = true;

            UsagePageDecoder page = new UsagePageDecoder();

            if (page.Extract(source))
            {
                if (updateClient)
                {
                    _client.PeriodStart = page.PeriodStart;
                    _client.PeriodEnd   = page.PeriodEnd.AddDays(1).AddMinutes(-1);
                    _client.Download    = page.Download;
                    _client.Upload      = page.Upload;
                    //_client.CurrentCombined = page.TotalCombined;
                }

                period = page.BillPeriods;

                // Enregistrement de la consommation
                for (int i = page.DailyUsages.Count - 1; i >= 0; i--)
                {
                    // Ne pas enregistrer la date courante, car elle n'est pas encore finale
                    if (page.DailyUsages[i].Day.Date.CompareTo(DateTime.Today.Date) != 0)
                    {
                        DoReadDailyUsage(_client.Username, page.DailyUsages[i], ref updateHistory);
                        if (!updateHistory)
                        {
                            break;
                        }
                    }
                }

                return(true);
            }
            else
            {
                period        = new List <Period>();
                updateHistory = false;
                if (page.decodeException != null)
                {
                    DoError(page.decodeException);
                }
                return(false);
            }
        }
Exemple #2
0
        private bool Analyze(string source, bool updateClient, out List<Period> period, out bool updateHistory)
        {
            //File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, DateTime.Now.ToString("yyyyMMddHHmmssf")) + ".html", source);
            updateHistory = true;

            UsagePageDecoder page = new UsagePageDecoder();

            if (page.Extract(source))
            {
                if (updateClient)
                {
                    _client.PeriodStart = page.PeriodStart;
                    _client.PeriodEnd = page.PeriodEnd.AddDays(1).AddMinutes(-1);
                    _client.Download = page.Download;
                    _client.Upload = page.Upload;
                    //_client.CurrentCombined = page.TotalCombined;
                }

                period = page.BillPeriods;

                // Enregistrement de la consommation
                for (int i = page.DailyUsages.Count - 1; i >= 0; i--)
                {
                    // Ne pas enregistrer la date courante, car elle n'est pas encore finale
                    if (page.DailyUsages[i].Day.Date.CompareTo(DateTime.Today.Date) != 0)
                    {
                        DoReadDailyUsage(_client.Username, page.DailyUsages[i], ref updateHistory);
                        if (!updateHistory)
                            break;
                    }
                }

                return true;
            }
            else
            {
                period = new List<Period>();
                updateHistory = false;
                if (page.decodeException != null)
                    DoError(page.decodeException);
                return false;
            }
        }