Exemple #1
0
        private static CreditInfo CreateWindInformations(string usr, string pwd, string Type)
        {
            var tsk = CreditInfoRetriever.Get().RetrieveCreditInfo(usr, pwd, Type, Guid.Empty);

            tsk.Wait();
            var cd = tsk.Result;

            for (int i = 0; i < cd.NumberInfos.Count; i++)
            {
                cd.NumberInfos.ElementAt(i).Brush        = string.Empty;
                cd.NumberInfos.ElementAt(i).FriendlyName = cd.NumberInfos.ElementAt(i).Number;
            }

            return(cd);
        }
Exemple #2
0
        private bool Update(bool RetrieveAgain)
        {
            if (isUpdatding)
            {
                return(false);
            }

            try
            {
                isUpdatding = true;
                var current   = (App.Current as App).currentInfo;
                var currArray = (App.Current as App).currentInfoArray;

                if (currArray == null)
                {
                    currArray = Enumerable.Empty <CreditInfo>().ToList();
                }
                if (current == null)
                {
                    SafeDispatcher.Run(() =>
                    {
                        MessageBox.Show(AppResources.Whoops);
                        NavigationService.Navigate(new Uri("/NotWorking.xaml", UriKind.Relative));
                    });
                    return(true);
                }

                int i   = 0;
                int tot = currArray.Count + 1;

                foreach (var item in currArray.Concat(Enumerable.Repeat(current, 1)))
                {
                    if (item == null || string.IsNullOrEmpty(item.Password) || string.IsNullOrEmpty(item.Username) || !NetworkInterface.GetIsNetworkAvailable())
                    {
                        //Nothing to do here.
                        continue;
                    }

                    if (RetrieveAgain)
                    {
                        SafeDispatcher.Run(() =>
                        {
                            var pr             = SystemTray.GetProgressIndicator(this);
                            pr.Text            = string.Format(AppResources.UpdateSingleNumber, item.Username);
                            pr.IsIndeterminate = false;
                            pr.Value           = (((double)i++) / (double)tot);
                        });
                        var tsk1 = CreditInfoRetriever.Get().RetrieveCreditInfo(item.Username, item.Password, item.Type, Guid.Empty);
                        tsk1.Wait();
                        var nw = tsk1.Result;
                        if (nw == null)
                        {
                            return(true);
                        }
                        SafeDispatcher.Run(() => item.Merge(nw));



                        var Img = new ImageConverter();

                        foreach (var itm in item.NumberInfos)
                        {
                            Utils.RenderTiles(itm.Number, itm);

                            var smallpath  = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 159, 159, itm.Number));
                            var normalpath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 336, 336, itm.Number));
                            //var widepath = System.IO.Path.Combine(WPUtils.baseDir, string.Format("{0}_{1}_{2}.jpg", 691, 336, item.Number));

                            SafeDispatcher.Run(() =>
                            {
                                foreach (var str in new[] { new[] { "336", "336" }, new[] { "159", "159" } /*, new[] { "691", "336" }*/ })
                                {
                                    var hubtile = FindControl <HubTile>(this.pivotNumbers.ItemContainerGenerator.ContainerFromIndex(pivotNumbers.SelectedIndex), str[0]);
                                    if (hubtile != null)
                                    {
                                        hubtile.Source = Img.Convert(new[] { str[0], str[1], (pivotNumbers.SelectedItem as NumberInfo).Number }, null, null, null) as BitmapImage;
                                        hubtile.Source = Img.Convert(new[] { str[0], str[1], (pivotNumbers.SelectedItem as NumberInfo).Number }, null, null, null) as BitmapImage;
                                    }
                                }
                            });
                            if (ShellTile.ActiveTiles.Any(t => t.NavigationUri.ToString().Contains(itm.Number)))
                            {
                                FlipTileData tileData = new FlipTileData
                                {
                                    Title = " ",
                                    //WideBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute),
                                    BackgroundImage      = new Uri("isostore:" + normalpath, UriKind.Absolute),
                                    SmallBackgroundImage = new Uri("isostore:" + smallpath, UriKind.Absolute),
                                    BackBackgroundImage  = new Uri("isostore:" + normalpath, UriKind.Absolute),
                                    //WideBackBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute),
                                };
                                ShellTile.ActiveTiles.Single(t => t.NavigationUri.ToString().Contains(itm.Number)).Update(tileData);
                            }
                        }
                    }
                }

                Utils.SaveCreditState(current);
                Utils.SaveCreditState(currArray);

                return(true);
            }
            catch (Exception e)
            {
                SafeDispatcher.Run(() => MessageBox.Show(e.Message));
            }
            finally
            {
                isUpdatding = false;
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected async override void OnInvoke(ScheduledTask task)
        {
            DebugOutputMemoryUsage("Agent start");
            try
            {
                var c = Utils.GetSavedState();
                var o = Utils.GetArraySavedState();

                var current = Enumerable.Repeat(c, 1).Concat(o).OrderByDescending(x => x.NumberInfos.First().LastUpdate).First();
                var nw      = await CreditInfoRetriever.Get().RetrieveCreditInfo(current.Username, current.Password, current.Type, Guid.Empty);

                if (current == null || nw == null || string.IsNullOrEmpty(current.Password) || string.IsNullOrEmpty(current.Username) || !NetworkInterface.GetIsNetworkAvailable())
                {
                    //Nothing to do here.
                    NotifyComplete();
                    return;
                }


                DebugOutputMemoryUsage("Credit downloaded");
                current.Merge(nw);

                #region Toast display

                foreach (var number in current.NumberInfos.Where(n => n.NotifyEnabled))
                {
                    var toast = (new ShellToast {
                        Title = AppResources.GenericLimit, NavigationUri = new Uri(string.Concat("/DataPage.xaml?number=", HttpUtility.UrlEncode(number.Number)), UriKind.Relative)
                    });

                    if (number.CreditLimitReached && !number.clShowed)
                    {
                        toast.Content   = string.Format(AppResources.CreditLimitReached, number.FriendlyName);
                        number.clShowed = true;
                        toast.Show();
                    }
                    else if (number.Credit > number.CreditLimit)
                    {
                        number.clShowed = false;
                    }

                    if (number.SMSLimitReached && !number.smsShowed)
                    {
                        toast.Content    = string.Format(AppResources.SMSLimitReached, number.FriendlyName);
                        number.smsShowed = true;
                        toast.Show();
                    }
                    else if (number.SMS > number.SMSLimit)
                    {
                        number.smsShowed = false;
                    }

                    if (number.GigabytesLimitReached && !number.gigaShowed)
                    {
                        number.gigaShowed = true;
                        toast.Content     = string.Format(AppResources.TrafficLimitReached, number.FriendlyName);
                        toast.Show();
                    }
                    else if (number.Gigabytes > number.GigabytesLimit)
                    {
                        number.gigaShowed = false;
                    }

                    if (number.MinutesLimitReached && !number.minShowed)
                    {
                        number.minShowed = true;
                        toast.Content    = string.Format(AppResources.MinutesLimitReached, number.FriendlyName);
                        toast.Show();
                    }
                    else if (number.Minutes > number.MinutesLimit)
                    {
                        number.minShowed = false;
                    }
                }
                #endregion

                var tsk = Task.Factory.StartNew(new Action(() =>
                {
                    Utils.SaveCreditState(o);
                    Utils.SaveCreditState(c);
                }));

                const string baseDir = "/Shared/ShellContent/";
                DebugOutputMemoryUsage("Starting rendering");
                foreach (var item in current.NumberInfos)
                {
                    DebugOutputMemoryUsage("Before");
                    tsk.Wait();
                    Utils.RenderTiles(item.Number, item);
                    DebugOutputMemoryUsage("After");

                    if (ShellTile.ActiveTiles.Any(t => t.NavigationUri.ToString().Contains(item.Number)))
                    {
                        var smallpath  = Path.Combine(baseDir, string.Format("{0}_{1}_{2}.jpg", 159, 159, item.Number));
                        var normalpath = Path.Combine(baseDir, string.Format("{0}_{1}_{2}.jpg", 336, 336, item.Number));
                        //var widepath = Path.Combine(baseDir, string.Format("{0}_{1}_{2}.jpg", 691, 336, item.Number));

                        FlipTileData tileData = new FlipTileData
                        {
                            Title = " ",
                            //WideBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute),
                            BackgroundImage      = new Uri("isostore:" + normalpath, UriKind.Absolute),
                            SmallBackgroundImage = new Uri("isostore:" + smallpath, UriKind.Absolute),
                            BackBackgroundImage  = new Uri("isostore:" + normalpath, UriKind.Absolute),
                            //WideBackBackgroundImage = new Uri("isostore:" + widepath, UriKind.Absolute),
                        };
                        ShellTile.ActiveTiles.Single(t => t.NavigationUri.ToString().Contains(item.Number)).Update(tileData);
                    }
                }

                await tsk;
            }
            catch (Exception e)
            {
                if (e.Message.Contains("err") || e.Message.Contains("pass") || e.Message.Contains("user") || e.Message.Contains("valid"))
                {
                    ShellToast t = new ShellToast {
                        Content = e.Message
                    };
                    t.Show();
                }
            }
            finally
            {
                NotifyComplete();
            }
        }