Esempio n. 1
0
        public static WiredAccount CreateWiredAccount(WiredInternetUsage wiredInternetUsage, string username)
        {
            WiredAccount result = new WiredAccount();

            result.Username      = username;
            result.PeriodStart   = wiredInternetUsage.PeriodStartDate;
            result.PeriodEnd     = wiredInternetUsage.PeriodEndDate;
            result.DaysElapsed   = wiredInternetUsage.DaysFromStart;
            result.DaysRemaining = wiredInternetUsage.DaysToEnd;

            foreach (Message message in wiredInternetUsage.Messages.Message)
            {
                result.Messages.Add(WiredMessageFactory.CreateMessage(message.Code,
                                                                      message.Severity,
                                                                      message.Text));
            }

            WiredInternetAccountUsage accountUsage = wiredInternetUsage.InternetAccounts.WiredInternetAccountUsage.FirstOrDefault(x => x.InternetAccountNo == username);

            if (accountUsage != null)
            {
                // Les données arrivent en octets, on sauvegarde en kilo-octets
                result.MaxDownloadBytes  = accountUsage.MaxDownloadBytes / 1024;
                result.MaxUploadBytes    = accountUsage.MaxUploadBytes / 1024;
                result.MaxCombinedBytes  = accountUsage.MaxCombinedBytes / 1024;
                result.DownloadedBytes   = accountUsage.DownloadedBytes / 1024;
                result.UploadedBytes     = accountUsage.UploadedBytes / 1024;
                result.DownloadedPercent = accountUsage.DownloadedPercent;
                result.UploadedPercent   = accountUsage.UploadedPercent;
                result.CombinedPercent   = accountUsage.CombinedPercent;

                foreach (WiredInternetDailyUsage usage in accountUsage.DailyUsage.WiredInternetDailyUsage)
                {
                    result.DailyUsage.Add(new WiredDailyUsage(usage.Date,
                                                              usage.UploadedBytes / 1024,
                                                              usage.DownloadedBytes / 1024)
                    {
                        Period = new Period(result.PeriodStart, result.PeriodEnd)
                    });
                }

                foreach (Message message in accountUsage.Messages.Message)
                {
                    result.Messages.Add(WiredMessageFactory.CreateMessage(message.Code,
                                                                          message.Severity,
                                                                          message.Text));
                }
            }

            return(result);
        }
Esempio n. 2
0
        public static WiredAccount CreateWiredAccount(WiredInternetUsage wiredInternetUsage, string username)
        {
            WiredAccount result = new WiredAccount();

            result.Username = username;
            result.PeriodStart = wiredInternetUsage.PeriodStartDate;
            result.PeriodEnd = wiredInternetUsage.PeriodEndDate;
            result.DaysElapsed = wiredInternetUsage.DaysFromStart;
            result.DaysRemaining = wiredInternetUsage.DaysToEnd;

            foreach (Message message in wiredInternetUsage.Messages.Message)
                result.Messages.Add(WiredMessageFactory.CreateMessage(message.Code,
                                                                      message.Severity,
                                                                      message.Text));

            WiredInternetAccountUsage accountUsage = wiredInternetUsage.InternetAccounts.WiredInternetAccountUsage.FirstOrDefault(x => x.InternetAccountNo == username);

            if (accountUsage != null)
            {
                // Les données arrivent en octets, on sauvegarde en kilo-octets
                result.MaxDownloadBytes = accountUsage.MaxDownloadBytes / 1024;
                result.MaxUploadBytes = accountUsage.MaxUploadBytes / 1024;
                result.MaxCombinedBytes = accountUsage.MaxCombinedBytes / 1024;
                result.DownloadedBytes = accountUsage.DownloadedBytes / 1024;
                result.UploadedBytes = accountUsage.UploadedBytes / 1024;
                result.DownloadedPercent = accountUsage.DownloadedPercent;
                result.UploadedPercent = accountUsage.UploadedPercent;
                result.CombinedPercent = accountUsage.CombinedPercent;

                foreach (WiredInternetDailyUsage usage in accountUsage.DailyUsage.WiredInternetDailyUsage)
                {
                    result.DailyUsage.Add(new WiredDailyUsage(usage.Date,
                                                              usage.UploadedBytes / 1024,
                                                              usage.DownloadedBytes / 1024)
                                                              { Period = new Period(result.PeriodStart, result.PeriodEnd) });
                }

                foreach (Message message in accountUsage.Messages.Message)
                    result.Messages.Add(WiredMessageFactory.CreateMessage(message.Code,
                                                                          message.Severity,
                                                                          message.Text));
            }

            return result;
        }
Esempio n. 3
0
        private void OnDownloadDataEnd(WiredAccount wiredAccount)
        {
            if (wiredAccount != null)
            {
                Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new ThreadStart(delegate
                {
                    Account.Account.PeriodStart = wiredAccount.PeriodStart;
                    Account.Account.PeriodEnd = wiredAccount.PeriodEnd.AddDays(1).AddMinutes(-1);
                    Account.Account.Download = wiredAccount.DownloadedBytes;
                    Account.Account.Upload = wiredAccount.UploadedBytes;
                    Account.Account.CombinedMaximum = wiredAccount.MaxCombinedBytes;
                    //Account.Account.Combined = wiredAccount.c
                    //Account.Account.CombinedPercent = wiredAccount.CombinedPercent;

                    UpdateUI();
                    Account.Account.Refresh();
                }));
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Met à jours un objet dans le cache
 /// </summary>
 /// <param name="token"></param>
 /// <param name="wiredAccount"></param>
 public void SetCache(string token, int period, WiredAccount wiredAccount)
 {
     _cache[GetKey(token, period)].WiredAccount = wiredAccount;
 }
Esempio n. 5
0
        private bool Parse(string source, bool updateClient, out WiredAccount wiredAccount)
        {
            WiredInternetUsage wiredInternetUsage;

            try
            {
                // Convertir la source en objet
                using (XmlReader r = XmlReader.Create(new StringReader(source)))
                {
                    XmlSerializer s = new XmlSerializer(typeof(WiredInternetUsage));
                    wiredInternetUsage = (WiredInternetUsage)s.Deserialize(r);
                }
            }
            catch (Exception seria)
            {
                wiredAccount = null;
                ParseException parseException = new ParseException(null, seria);
                parseException.OriginException = seria;
                DoError(parseException);
                return false;
            }

            Message error = wiredInternetUsage.Messages.Message.FirstOrDefault(x => x.Severity == "error");
            if (error != null)
            {
                throw new ApiException(error.Text);
            }

            // Transformation des données
            wiredAccount = WiredAccountFactory.CreateWiredAccount(wiredInternetUsage, Username);
            return true;
        }
Esempio n. 6
0
 protected void DoDownloadDataEnd(WiredAccount wiredAccount)
 {
     if (OnDownloadDataEnd != null)
         OnDownloadDataEnd(wiredAccount);
 }