Inheritance: ITileUpdater
示例#1
0
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            // test

            EventAggregator = new EventAggregator();

            Container.RegisterInstance<INavigationService>(NavigationService);
            Container.RegisterInstance<ISessionStateService>(SessionStateService);
            Container.RegisterInstance<IEventAggregator>(EventAggregator);
         //   Container.RegisterInstance<IResourceLoader>(new ResourceLoaderAdapter(new ResourceLoader()));
            //     Register any app specific types with the container

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            {
                var viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "Popmail.UILogic.ViewModels.{0}ViewModel, UILogic, Version=1.0.0.0, Culture=neutral", viewType.Name);
                var viewModelType = Type.GetType(viewModelTypeName);
                if (viewModelType == null)
                {
                    viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "PopMail.UILogic.ViewModels.{0}ViewModel, PopMail.UILogic.Windows, Version=1.0.0.0, Culture=neutral", viewType.Name);
                    viewModelType = Type.GetType(viewModelTypeName);
                }

                return viewModelType;
            });

            // Documentation on working with tiles can be found at http://go.microsoft.com/fwlink/?LinkID=288821&clcid=0x409
            _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            //   _tileUpdater.StartPeriodicUpdate(new Uri(Constants.ServerAddress + "/api/TileNotification"), PeriodicUpdateRecurrence.HalfHour);
            //var resourceLoader = Container.Resolve<IResourceLoader>();

            return base.OnInitializeAsync(args);
        }
        // Initialize the app's tiles on the Start page. There are three different sizes of tiles users can
        // choose from.
        private void InitializeTiles()
        {
            tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            var mediumSquareTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
            var largeSquareTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310ImageAndText02);
            var wideTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage02);

            tileUpdater.EnableNotificationQueue(true);

            mediumSquareTile.GetElementsByTagName("text")[0].InnerText = "TicTacToe";
            largeSquareTile.GetElementsByTagName("text")[0].InnerText = "TicTacToe";
            wideTile.GetElementsByTagName("text")[0].InnerText = "TicTacToe";

            var node1 = wideTile.ImportNode(mediumSquareTile.GetElementsByTagName("binding")[0], true);
            wideTile.GetElementsByTagName("visual")[0].AppendChild(node1);

            var node2 = wideTile.ImportNode(largeSquareTile.GetElementsByTagName("binding")[0], true);
            wideTile.GetElementsByTagName("visual")[0].AppendChild(node2);

            var testNotification = new TileNotification(wideTile);
            testNotification.Tag = "Test";
            tileUpdater.Update(testNotification);

            badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

        }
 /// <summary>
 /// Creates the builder.
 /// </summary>
 public TileXMLBuilder(string tileId)
 {
     // Now we can update the tile:
     this.tileId = tileId;
     this.tileUpdater = (string.IsNullOrEmpty(this.tileId))
         ? TileUpdateManager.CreateTileUpdaterForApplication()
         : TileUpdateManager.CreateTileUpdaterForSecondaryTile(this.tileId);
 }
示例#4
0
        public LiveTiles() {
            tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            tileUpdater.EnableNotificationQueue(true);

            badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();

            toastNotifier = ToastNotificationManager.CreateToastNotifier();
        }
示例#5
0
        public MainPage()
        {
            InitializeComponent();

            _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            _tileUpdater.Clear();
            _tileUpdater.EnableNotificationQueue(false);
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TileService" /> class.
        /// </summary>
        /// <param name="tileUpdater">The tile updater.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public TileService(TileUpdater tileUpdater)
        {
            if (tileUpdater == null)
            {
                throw new ArgumentNullException("tileUpdater");
            }


            _tileUpdater = tileUpdater;
            _tileUpdater.EnableNotificationQueue(true);
        }
示例#7
0
 public void Run(IBackgroundTaskInstance taskInstance)
 {
     BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
     tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
     tileUpdater.EnableNotificationQueue(true);
     AddTileNotification("Hey Everyone... Whats up", "tag1");
     AddTileNotification("Come see the new coffee shops", "tag2");
     AddTileNotification("I need caffine", "tag3");
     AddTileNotification("I drink coffee therfore I live", "tag4");
     AddTileNotification("Caffine Drip please", "tag5");
     GetData(); deferral.Complete();
 }
示例#8
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Tile test ...
            var tileContent = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareBlock);
             tileLines = tileContent.SelectNodes("tile/visual/binding/text");
            tileLines[0].InnerText = inputBox.Text.Substring(0,2);


            notification = new TileNotification(tileContent);

            updater = TileUpdateManager.CreateTileUpdaterForApplication();
            //updater.EnableNotificationQueue(true);


            MakeRequests(inputBox.Text);
            xivelyOutput.Text = "Requested " + inputBox.Text + " from Xively at " + "" + DateTime.Now.ToString("hh:mm:ss");
        }
示例#9
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
            ApplicationDataContainer localSettings   = ApplicationData.Current.LocalSettings;

            resourceLoader = ResourceLoader.GetForViewIndependentUse();

            //main tile
            Windows.UI.Notifications.TileUpdater mainmngr = null;
            try { mainmngr = TileUpdateManager.CreateTileUpdaterForApplication(); }
            catch (Exception)
            {
                deferral.Complete();
                return;
            }

            string town = null;

            if ((bool?)localSettings.Values["location"] != false)
            {
                town = await Utilities.LocationFinder.GetLocation();
            }

            if ((string)localSettings.Values["lastlocation"] == town && (string)localSettings.Values["lastupdate"] == DateTime.Today.Date.ToString())
            {
                deferral.Complete();
                return;
            }

            foreach (var tile in mainmngr.GetScheduledTileNotifications())
            {
                mainmngr.RemoveFromSchedule(tile);
            }
            mainmngr.Clear();

            var             profile = NetworkInformation.GetInternetConnectionProfile();
            NetworkCostType cost    = NetworkCostType.Unknown;

            if (profile != null)
            {
                cost = profile.GetConnectionCost().NetworkCostType;
            }

            if (town != null)
            {
                Utilities.LineSerializer lineSerializer = new Utilities.LineSerializer(resourceLoader);
                IList <Line>             linesfromhere  = await lineSerializer.readLinesFrom(town);

                List <int> busindices = new List <int>();

                if (((bool)localSettings.Values["alwaysupdate"] || cost == NetworkCostType.Unrestricted) && linesfromhere.Count == 0 && (bool)roamingSettings.Values["showhome"] && roamingSettings.Values["homename"] != null)
                {
                    List <Dictionary <string, string> > stops = await Utilities.Autocomplete.GetSuggestions(town, DateTime.Today.Date.ToString());

                    foreach (var stop in stops)
                    {
                        if (stop["Nev"] == town)
                        {
                            Line templine = new Line(stop["VarosID"], (string)roamingSettings.Values["homesid"], stop["MegalloID"], (string)roamingSettings.Values["homelsid"], stop["Nev"], (string)roamingSettings.Values["homename"]);
                            await templine.updateOn(true);

                            bool   isfirst      = true;
                            string previoustime = "";
                            foreach (var bus in templine.Buses)
                            {
                                if (!(!(bool)roamingSettings.Values["canchange"] && bus["vonalnev"].Split('|')[0] == " ∙∙∙") && !((bool)roamingSettings.Values["exact"] && (string)roamingSettings.Values["homename"] != bus["erkezesi_hely"] && ((string)roamingSettings.Values["homename"]).Contains(",")))
                                {
                                    DateTime showUpdateAt;
                                    if (isfirst)
                                    {
                                        showUpdateAt = DateTime.Now.AddSeconds(5);
                                        isfirst      = false;
                                    }
                                    else
                                    {
                                        showUpdateAt = DateTime.Parse(previoustime).AddSeconds(30);
                                    }

                                    previoustime = bus["indulasi_ido"];
                                    XmlDocument xmlDoc = getXML(town, bus["vonalnev"].Split('|')[0], bus["indulasi_ido"], bus["indulasi_hely"], bus["erkezesi_ido"], bus["erkezesi_hely"], false);
                                    ScheduledTileNotification scheduledUpdate = new ScheduledTileNotification(xmlDoc, new DateTimeOffset(showUpdateAt));
                                    scheduledUpdate.ExpirationTime = new DateTimeOffset(DateTime.Today.AddDays(1).AddHours(1));
                                    mainmngr.AddToSchedule(scheduledUpdate);
                                }
                            }
                            deferral.Complete();
                            return;
                        }
                    }
                }

                // update lines
                foreach (var line in linesfromhere)
                {
                    if (((bool)localSettings.Values["alwaysupdate"] || cost == NetworkCostType.Unrestricted) && line.LastUpdated < DateTime.Today.Date)
                    {
                        try { await line.updateOn(DateTime.Today); }
                        catch (System.Net.Http.HttpRequestException)
                        {
                            deferral.Complete();
                            return;
                        }
                        line.LastUpdated = DateTime.Today.Date;

                        await lineSerializer.saveLine(line);
                    }

                    busindices.Add(0);
                }

                bool   done = false;
                int    minind;
                string prevfromtime = "";
                bool   first        = true;

                // go through all possible lines
                while (!done)
                {
                    DateTime mintime = DateTime.Today.AddDays(1);
                    minind = -1;

                    for (int j = 0; j < linesfromhere.Count; j++) // find next time
                    {
                        if (linesfromhere[j].Buses.Count < 1 && j < linesfromhere.Count - 1)
                        {
                            j++;
                        }
                        else if (linesfromhere[j].Buses.Count < 1 && j == linesfromhere.Count - 1)
                        {
                            break;
                        }

                        int i = busindices[j];
                        if (i != -1 && i < linesfromhere[j].Buses.Count)
                        {
                            string fromtime, num, from, to;
                            linesfromhere[j].Buses[i].TryGetValue("vonalnev", out num);
                            linesfromhere[j].Buses[i].TryGetValue("indulasi_ido", out fromtime);
                            linesfromhere[j].Buses[i].TryGetValue("indulasi_hely", out from);
                            linesfromhere[j].Buses[i].TryGetValue("erkezesi_hely", out to);
                            num = num.Split('|')[0];

                            var fromtime_date = DateTime.ParseExact(fromtime, "HH:mm", CultureInfo.InvariantCulture);

                            if (fromtime_date >= DateTime.Now && !(!(bool)roamingSettings.Values["canchange"] && num == " ∙∙∙") &&
                                !((bool)roamingSettings.Values["exact"] && ((linesfromhere[j].From != from && linesfromhere[j].From.Contains(",")) || (linesfromhere[j].To != to && linesfromhere[j].To.Contains(",")))))
                            {
                                if (fromtime_date < mintime)
                                {
                                    minind  = j;
                                    mintime = fromtime_date;
                                }
                            }
                            else if (linesfromhere[j].Buses.Count - 1 > busindices[j])
                            {
                                busindices[j]++;
                                j--;
                            }
                            else
                            {
                                busindices[j] = -1;
                            }
                        }
                    }

                    if (minind != -1)
                    {
                        int    i = busindices[minind];
                        string fromtime, num, from, to, name, totime;
                        name = linesfromhere[minind].Name;
                        linesfromhere[minind].Buses[i].TryGetValue("erkezesi_ido", out totime);
                        linesfromhere[minind].Buses[i].TryGetValue("vonalnev", out num);
                        linesfromhere[minind].Buses[i].TryGetValue("indulasi_ido", out fromtime);
                        linesfromhere[minind].Buses[i].TryGetValue("indulasi_hely", out from);
                        linesfromhere[minind].Buses[i].TryGetValue("erkezesi_hely", out to);
                        num = num.Split('|')[0];

                        XmlDocument xmlDoc = getXML(name, num, fromtime, from, totime, to, false);

                        DateTime showUpdateAt;
                        if (first)
                        {
                            showUpdateAt = DateTime.Now.AddSeconds(5);
                            first        = false;
                        }
                        else
                        {
                            showUpdateAt = DateTime.Parse(prevfromtime).AddSeconds(30);
                        }

                        ScheduledTileNotification scheduledUpdate = new ScheduledTileNotification(xmlDoc, new DateTimeOffset(showUpdateAt));
                        scheduledUpdate.ExpirationTime = new DateTimeOffset(DateTime.Today.AddDays(1).AddHours(1));
                        mainmngr.AddToSchedule(scheduledUpdate);

                        prevfromtime = fromtime;
                        if (busindices[minind] != -1 && linesfromhere[minind].Buses.Count - 1 > busindices[minind])
                        {
                            busindices[minind]++;
                        }
                        else
                        {
                            busindices[minind] = -1;
                        }
                    }

                    done = true;
                    for (int i = 0; i < busindices.Count; i++)
                    {
                        if (busindices[i] == linesfromhere[i].Buses.Count)
                        {
                            busindices[i] = -1;
                        }
                        if (busindices[i] != -1)
                        {
                            done = false;
                        }
                    }
                }

                localSettings.Values["lastlocation"] = town;
                localSettings.Values["lastupdate"]   = DateTime.Today.Date.ToString();
            }
            deferral.Complete();
        }
        protected override Task OnInitializeAsync(IActivatedEventArgs args)
        {
            EventAggregator = new EventAggregator();
            
            Container.RegisterInstance<INavigationService>(NavigationService);
            Container.RegisterInstance<ISessionStateService>(SessionStateService);
            Container.RegisterInstance<IEventAggregator>(EventAggregator);
            Container.RegisterInstance<IResourceLoader>(new ResourceLoaderAdapter(new ResourceLoader()));
            Container.RegisterType<IAccountService, AccountService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ICredentialStore, RoamingCredentialStore>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ICacheService, TemporaryFolderCacheService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ISecondaryTileService, SecondaryTileService>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IAlertMessageService, AlertMessageService>(new ContainerControlledLifetimeManager());

            // Register repositories
            Container.RegisterType<IProductCatalogRepository, ProductCatalogRepository>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IShoppingCartRepository, ShoppingCartRepository>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ICheckoutDataRepository, CheckoutDataRepository>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IOrderRepository, OrderRepository>(new ContainerControlledLifetimeManager());

            // Register web service proxies
            Container.RegisterType<IProductCatalogService, ProductCatalogServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IOrderService, OrderServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IShoppingCartService, ShoppingCartServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IShippingMethodService, ShippingMethodServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IIdentityService, IdentityServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<ILocationService, LocationServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IAddressService, AddressServiceProxy>(new ContainerControlledLifetimeManager());
            Container.RegisterType<IPaymentMethodService, PaymentMethodServiceProxy>(new ContainerControlledLifetimeManager());

            // Register child view models
            Container.RegisterType<IShippingAddressUserControlViewModel, ShippingAddressUserControlViewModel>();
            Container.RegisterType<IBillingAddressUserControlViewModel, BillingAddressUserControlViewModel>();
            Container.RegisterType<IPaymentMethodUserControlViewModel, PaymentMethodUserControlViewModel>();
            Container.RegisterType<ISignInUserControlViewModel, SignInUserControlViewModel>();

            ViewModelLocationProvider.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
            {
                var viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "AdventureWorks.UILogic.ViewModels.{0}ViewModel, AdventureWorks.UILogic, Version=1.1.0.0, Culture=neutral", viewType.Name);
                var viewModelType = Type.GetType(viewModelTypeName);
                if (viewModelType == null)
                {
                    viewModelTypeName = string.Format(CultureInfo.InvariantCulture, "AdventureWorks.UILogic.ViewModels.{0}ViewModel, AdventureWorks.UILogic.Windows, Version=1.0.0.0, Culture=neutral", viewType.Name);
                    viewModelType = Type.GetType(viewModelTypeName);
                }

                return viewModelType;
            });

            // Documentation on working with tiles can be found at http://go.microsoft.com/fwlink/?LinkID=288821&clcid=0x409
            _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            _tileUpdater.StartPeriodicUpdate(new Uri(Constants.ServerAddress + "/api/TileNotification"), PeriodicUpdateRecurrence.HalfHour);
            var resourceLoader = Container.Resolve<IResourceLoader>();

            return base.OnInitializeAsync(args);
        }
示例#11
0
        public override void OnInitialize(IActivatedEventArgs args)
        {
            _eventAggregator = new EventAggregator();

            _container.RegisterInstance<INavigationService>(NavigationService);
            _container.RegisterInstance<ISuspensionManagerState>(SuspensionManagerState);
            _container.RegisterInstance<IFlyoutService>(FlyoutService);
            _container.RegisterInstance<IEventAggregator>(_eventAggregator);
            _container.RegisterInstance<ISettingsStoreService>(new SettingsStoreService());
            _container.RegisterInstance<IAssetsService>(new AssetsService("Logo.png", "WideLogo.scale-100.png"));
            _container.RegisterInstance<IResourceLoader>(new ResourceLoaderAdapter(new ResourceLoader()));

            _container.RegisterType<IRequestService, RequestService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IAccountService, AccountService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ICredentialStore, RoamingCredentialStore>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ICacheService, TemporaryFolderCacheService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ITileService, TileService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IAlertMessageService, AlertMessageService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ISearchPaneService, SearchPaneService>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IEncryptionService, EncryptionService>(new ContainerControlledLifetimeManager());

            // Register repositories
            _container.RegisterType<IProductCatalogRepository, ProductCatalogRepository>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IShoppingCartRepository, ShoppingCartRepository>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ICheckoutDataRepository, CheckoutDataRepository>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IOrderRepository, OrderRepository>(new ContainerControlledLifetimeManager());

            // Register web service proxies
            _container.RegisterType<IProductCatalogService, ProductCatalogServiceProxy>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IOrderService, OrderServiceProxy>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IShoppingCartService, ShoppingCartServiceProxy>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IShippingMethodService, ShippingMethodServiceProxy>(new ContainerControlledLifetimeManager());
            _container.RegisterType<IIdentityService, IdentityServiceProxy>(new ContainerControlledLifetimeManager());
            _container.RegisterType<ILocationService, LocationServiceProxy>(new ContainerControlledLifetimeManager());
            
            // Register child view models
            _container.RegisterType<IShippingAddressUserControlViewModel, ShippingAddressUserControlViewModel>();
            _container.RegisterType<IBillingAddressUserControlViewModel, BillingAddressUserControlViewModel>();
            _container.RegisterType<IPaymentMethodUserControlViewModel, PaymentMethodUserControlViewModel>();

            // <snippet302>
            ViewModelLocator.SetDefaultViewTypeToViewModelTypeResolver((viewType) =>
                {
                    var viewModelTypeName = string.Format("Kona.UILogic.ViewModels.{0}ViewModel, Kona.UILogic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=634ac3171ee5190a", viewType.Name);
                    var viewModelType = Type.GetType(viewModelTypeName);
                    return viewModelType;
                });
            //</snippet302>

            // <snippet800>
            _tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
            _tileUpdater.EnableNotificationQueue(true);
            _tileUpdater.StartPeriodicUpdate(new Uri(Kona.UILogic.Constants.ServerAddress + "/api/TileNotification"), PeriodicUpdateRecurrence.HalfHour);
            // </snippet800>
        }
示例#12
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings;
            ApplicationDataContainer localSettings   = ApplicationData.Current.LocalSettings;

            resourceLoader = ResourceLoader.GetForViewIndependentUse();
            Utilities.LineSerializer lineSerializer = new Utilities.LineSerializer(resourceLoader);
            //IList<Line> savedLines = await lineSerializer.readLines();

            var             profile = NetworkInformation.GetInternetConnectionProfile();
            NetworkCostType cost    = NetworkCostType.Unknown;

            if (profile != null)
            {
                cost = profile.GetConnectionCost().NetworkCostType;
            }

            // get secondary tiles
            var tiles = await SecondaryTile.FindAllForPackageAsync();

            if (tiles.Count != 0)
            {
                foreach (SecondaryTile tile in tiles) // get data from each tile
                {
                    string[] tileData  = tile.TileId.Split('-');
                    string[] tileData2 = tile.Arguments.Split('|');
                    Line     line      = await lineSerializer.openLine(tileData[1], tileData[2], tileData[3], tileData[4], tileData2[0], tileData2[1]);


                    if (((bool)localSettings.Values["alwaysupdate"] || cost == NetworkCostType.Unrestricted) && line.LastUpdated < DateTime.Today.Date) // update only if necessary
                    {
                        try { await line.updateOn(); }
                        catch (System.Net.Http.HttpRequestException)
                        {
                            deferral.Complete();
                            return;
                        }
                        line.LastUpdated = DateTime.Today.Date;

                        await lineSerializer.saveLine(line);
                    }

                    Windows.UI.Notifications.TileUpdater updatemngr = null;
                    try { updatemngr = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tile.TileId); }
                    catch (Exception)
                    {
                        deferral.Complete();
                        return;
                    }
                    if (updatemngr.GetScheduledTileNotifications().Count == 0 || (updatemngr.GetScheduledTileNotifications().Count > 0 && updatemngr.GetScheduledTileNotifications()[0].DeliveryTime < DateTime.Today)) // if scheduled updates are outdated or nonexistent
                    {
                        updatemngr.Clear();

                        if (!line.Error)
                        {
                            if (line.Buses.Count > 0)
                            {
                                string prevfromtime = "";
                                bool   first        = true;
                                for (int i = 0; i < line.Buses.Count; i++)   // get Buses from the line
                                {
                                    string fromtime, num, from, to;
                                    line.Buses[i].TryGetValue("vonalnev", out num);
                                    line.Buses[i].TryGetValue("indulasi_ido", out fromtime);
                                    line.Buses[i].TryGetValue("indulasi_hely", out from);
                                    line.Buses[i].TryGetValue("erkezesi_hely", out to);
                                    num = num.Split('|')[0];

                                    if (DateTime.ParseExact(fromtime, "HH:mm", CultureInfo.InvariantCulture) >= DateTime.Now && !(!(bool)roamingSettings.Values["canchange"] && num == " ∙∙∙") &&
                                        !((bool)roamingSettings.Values["exact"] && ((line.From != from && line.From.Contains(",")) || (line.To != to && line.To.Contains(",")))))
                                    {
                                        //found = true;
                                        string name, totime;
#if WINDOWS_UWP
                                        name = line.Name;
#elif WINDOWS_PHONE_APP
                                        name = "";
#endif
                                        line.Buses[i].TryGetValue("erkezesi_ido", out totime);

                                        XmlDocument xmlDoc = getXML(name, num, fromtime, from, totime, to, false);

                                        DateTime showUpdateAt;
                                        if (first)
                                        {
                                            showUpdateAt = DateTime.Now.AddSeconds(1);
                                            first        = false;
                                        }
                                        else
                                        {
                                            showUpdateAt = DateTime.Parse(prevfromtime).AddSeconds(30);
                                        }

                                        ScheduledTileNotification scheduledUpdate = new ScheduledTileNotification(xmlDoc, new DateTimeOffset(showUpdateAt));
                                        scheduledUpdate.ExpirationTime = new DateTimeOffset(DateTime.Today.AddDays(1).AddHours(1));
                                        updatemngr.AddToSchedule(scheduledUpdate);

                                        prevfromtime = fromtime;
                                    }
                                }
                            }
                            if (updatemngr.GetScheduledTileNotifications().Count == 0) // if there are no Buses today
                            {
                                try { await line.updateOn(DateTime.Today.AddDays(1)); }
                                catch (System.Net.Http.HttpRequestException)
                                {
                                    deferral.Complete();
                                    return;
                                }

                                if (!line.Error && line.Buses.Count > 0)
                                {
                                    int    i = 0;
                                    string num, from, to;
                                    do
                                    {
                                        string fromtime, name, totime;
#if WINDOWS_UWP
                                        name = line.Name;
#elif WINDOWS_PHONE_APP
                                        name = "";
#endif
                                        line.Buses[i].TryGetValue("erkezesi_ido", out totime);
                                        line.Buses[i].TryGetValue("indulasi_ido", out fromtime);
                                        line.Buses[i].TryGetValue("vonalnev", out num);
                                        line.Buses[i].TryGetValue("indulasi_hely", out from);
                                        line.Buses[i].TryGetValue("erkezesi_hely", out to);
                                        num = num.Split('|')[0];

                                        if (!(!(bool)roamingSettings.Values["canchange"] && num == " ∙∙∙") && !((bool)roamingSettings.Values["exact"] && ((line.From != from && line.From.Contains(",")) || (line.To != to && line.To.Contains(",")))))
                                        {
                                            XmlDocument xmlDoc       = getXML(name, num, fromtime, from, totime, to, true);
                                            DateTime    showUpdateAt = DateTime.Now.AddSeconds(1);

                                            ScheduledTileNotification scheduledUpdate = new ScheduledTileNotification(xmlDoc, new DateTimeOffset(showUpdateAt));
                                            scheduledUpdate.ExpirationTime = new DateTimeOffset(DateTime.Today.AddDays(1).AddHours(1));
                                            updatemngr.AddToSchedule(scheduledUpdate);
                                        }

                                        i++;
                                    } while (i < line.Buses.Count && ((!(bool)roamingSettings.Values["canchange"] && num == " ∙∙∙") || ((bool)roamingSettings.Values["exact"] && ((line.From != from && line.From.Contains(",")) || (line.To != to && line.To.Contains(","))))));
                                }
                            }
                        }
                    }
                }
            }
            deferral.Complete();
        }
示例#13
0
        /// <summary>
        /// 刷新磁贴
        /// </summary>
        /// <param name="updator">传入更新类型参数:应用磁贴,二级磁贴</param>
        private void UpdateTile(TileUpdater updator)
        {
            updator.Clear();
            updator.EnableNotificationQueue(true);

            XmlDocument tile = new XmlDocument();
            foreach (var item in gridNameDict)
            {
                tile = Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(item.Key.Value);
                var imageElement = tile.GetElementsByTagName("image")[0];
                imageElement.Attributes.GetNamedItem("src").NodeValue = "ms-appdata:///local/" + item.Key.Key + this.title??"" + ".png";
                var notification = new Windows.UI.Notifications.TileNotification(tile);
                updator.Update(notification);
            }
        }
 private void GetTileUpdate()
 {
     notifier = TileUpdateManager.CreateTileUpdaterForApplication();
     notifier.EnableNotificationQueue(true);
 }
 private void ClearQueue(TileUpdater tileUpdater)
 {
     foreach (var update in tileUpdater.GetScheduledTileNotifications())
     {
         tileUpdater.RemoveFromSchedule(update);
     }
 }
        private void ScheduleTileUpdate(DateTime baseTime, TimeSpan shift, TileUpdater tileUpdater, ClockFormat clockFormat)
        {
            var shiftedTime = baseTime.Add(shift);
            var interval = 60/_baseDateTimes.Count();
            var i = 0;
            var calculatedCitiesInfo = _baseDateTimes.Select(c => new CalculatedCityInfo { CityInfo = c.Key, DestinationTime = c.Value.Add(shift) }).ToList();
            foreach (var info in calculatedCitiesInfo)
            {
                var tileXmlNow = GetTileUpdateMessage(info, calculatedCitiesInfo, _baseDateTimes.Count(), clockFormat);
                var document = new XmlDocument();
                document.LoadXml(tileXmlNow);

                var deliveryTime = shiftedTime.AddSeconds(i * interval);
                if (deliveryTime <= DateTime.Now)
                {
                    tileUpdater.Update(new TileNotification(document) { ExpirationTime = shiftedTime.AddSeconds(interval) });
                }
                else
                {
                    var scheduledNotification = new ScheduledTileNotification(document, deliveryTime) { ExpirationTime = deliveryTime.AddSeconds(interval) };
                    tileUpdater.AddToSchedule(scheduledNotification);
                }
                i++;
            }
        }