Example #1
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (args.Kind == ActivationKind.ToastNotification)
            {
                var      toastArgs = args as ToastNotificationActivatedEventArgs;
                var      arguments = toastArgs.Argument;
                string[] lineData  = arguments.Split('-');
                Utilities.LineSerializer lineSerializer = new Utilities.LineSerializer(Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse());
                var savedLines = await lineSerializer.readLines();

                foreach (Line line in savedLines)
                {
                    if (lineData[0] == line.FromsID && lineData[1] == line.FromlsID && lineData[2] == line.TosID && lineData[3] == line.TolsID)
                    {
                        rootFrame.Navigate(typeof(Results), line);
                    }
                }
            }

            Window.Current.Activate();
        }
Example #2
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();
        }
        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();
        }
Example #4
0
        private async Task getSavedData(UpdateMethod update = UpdateMethod.IFOUTOFDATE, int toupdate = -1)
        {
            lastRefreshed = DateTime.Now;

            // LOAD SAVED DATA
            lineSerializer = new Utilities.LineSerializer(ResourceLoader.GetForViewIndependentUse());
            savedLines     = await lineSerializer.readLines();

            LineList.Items.Clear();

            //DISPLAY DATA
            if (savedLines.Count == 0) // no data
            {
                error.Visibility          = Visibility.Visible;
                title.Visibility          = Visibility.Collapsed;
                inprogress.IsActive       = false;
                inprogressbg.Visibility   = Visibility.Collapsed;
                inprogresstext.Visibility = Visibility.Collapsed;
#if WINDOWS_UWP
                if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
                {
                    Loaded += (s, e) =>
                    {
                        Frame.Navigate(typeof(Search), null, new EntranceNavigationTransitionInfo());
                        SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                    };
                }
#endif
            }
            else                       // create cards
            {
                error.Visibility = Visibility.Collapsed;
                title.Visibility = Visibility.Visible;

                inprogress.IsActive     = true;
                inprogressbg.Visibility = Visibility.Visible;
                AppbarUpdate.IsEnabled  = false;

                /*var gridVisual = ElementCompositionPreview.GetElementVisual(this.myGrid);
                 * var compositor = gridVisual.Compositor;
                 * this.effectVisual = compositor.CreateSpriteVisual();
                 * GaussianBlurEffect blurEffect = new GaussianBlurEffect()
                 * {
                 *  BorderMode = EffectBorderMode.Hard, // NB: default mode here isn't supported yet.
                 *  Source = new CompositionEffectSourceParameter("source")
                 * };
                 * var effectFactory = compositor.CreateEffectFactory(blurEffect);
                 * var effectBrush = effectFactory.CreateBrush();
                 * effectBrush.SetSourceParameter("source", compositor.CreateBackdropBrush());
                 * this.effectVisual.Brush = effectBrush;
                 * ElementCompositionPreview.SetElementChildVisual(this.myGrid, this.effectVisual);*/

                string tomorrow;
                Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
                Windows.Storage.ApplicationDataContainer localSettings   = Windows.Storage.ApplicationData.Current.LocalSettings;

                //List<Card> toAdd = new List<Card>();
                for (int i = 0; i < savedLines.Count; i++) // for each line
                {
                    int toDisplay = -1;
                    tomorrow = "";
                    for (int k = 0; k < 2; k++) // try next day as well if there are no more Buses today
                    {
                        toDisplay = -1;
                        DateTime        updateday = DateTime.Today.Date.AddDays(k);
                        var             profile   = NetworkInformation.GetInternetConnectionProfile();
                        NetworkCostType cost      = NetworkCostType.Unknown;
                        if (profile != null)
                        {
                            cost = profile.GetConnectionCost().NetworkCostType;
                        }

                        if (update != UpdateMethod.NEVER && (update == UpdateMethod.ALWAYS || toupdate == i || (((bool)localSettings.Values["alwaysupdate"] || cost == NetworkCostType.Unrestricted) && savedLines[i].LastUpdated < updateday))) // update if we haven't updated yet today
                        {
                            inprogresstext.Visibility = Visibility.Visible;
                            savedLines[i].Buses       = null;
                            try
                            {
                                await savedLines[i].updateOn(updateday);
                                savedLines[i].LastUpdated = updateday;
                                await lineSerializer.saveLine(savedLines[i]);
                            }
                            catch (HttpRequestException)
                            {
                                inprogress.IsActive       = false;
                                inprogresstext.Visibility = Visibility.Collapsed;
                                AppbarUpdate.IsEnabled    = true;
                                var dialog = new MessageDialog(resourceLoader.GetString("NetworkError"), resourceLoader.GetString("NetworkErrorTitle"));
                                dialog.Commands.Add(new UICommand("OK"));
                                dialog.CancelCommandIndex  = 0;
                                dialog.DefaultCommandIndex = 0;
                                try { await dialog.ShowAsync(); } catch (UnauthorizedAccessException) { }
                                await getSavedData(UpdateMethod.NEVER);

                                return;
                            }
                        }
                        for (int j = 0; j < savedLines[i].Buses.Count && savedLines[i].LastUpdated >= DateTime.Today; j++) // get first bus after current time (for each line)
                        {
                            string start, name, from, to;
                            savedLines[i].Buses[j].TryGetValue("indulasi_ido", out start);
                            savedLines[i].Buses[j].TryGetValue("vonalnev", out name);
                            savedLines[i].Buses[j].TryGetValue("indulasi_hely", out from);
                            savedLines[i].Buses[j].TryGetValue("erkezesi_hely", out to);
                            if ((TimeSpan.Parse(start).TotalSeconds >= DateTime.Now.TimeOfDay.TotalSeconds || savedLines[i].LastUpdated > DateTime.Today) && !(!(bool)roamingSettings.Values["canchange"] && name.Split('|')[0] == " ∙∙∙"))
                            {
                                if (!((bool)roamingSettings.Values["exact"] && ((savedLines[i].From != from && savedLines[i].From.Contains(",")) || (savedLines[i].To != to && savedLines[i].To.Contains(",")))))
                                {
                                    toDisplay = j;
                                    break;
                                }
                            }
                        }
                        if (savedLines[i].LastUpdated > DateTime.Today && toDisplay != -1)
                        {
                            tomorrow = resourceLoader.GetString("CardTomorrowLong");
                        }
                        if (toDisplay > -1)
                        {
                            break;
                        }
                        if (savedLines[i].LastUpdated > DateTime.Today)
                        {
                            k++;
                        }

                        /*if (!(bool)localSettings.Values["alwaysupdate"] && cost != NetworkCostType.Unrestricted && (toupdate != i || !update))
                         * {
                         *  if (k == 0 && toDisplay == -1 && savedLines[i].LastUpdated <= DateTime.Today)
                         *      savedLines[i].LastUpdated = DateTime.Today.AddDays(-1);
                         *  k++;
                         * }*/
                    }
                    //if (toDisplay == -1)
                    //    savedLines[i].LastUpdated = DateTime.ParseExact("1000.01.01", "yyyy.MM.dd", System.Globalization.CultureInfo.InvariantCulture);
                    Card newcard = new Card(savedLines[i], toDisplay);    // create card for next bus
                    newcard.LineName = tomorrow + newcard.LineName;

                    if (toDisplay != -1 || savedLines[i].LastUpdated < DateTime.Today)
                    {
                        int num = i;

                        newcard.Tapped += (s, e) => OpenLine(newcard, num);
                        //newcard.KeyUp += LineList_KeyUp;
                    }

                    // Context menu
                    tiles = await SecondaryTile.FindAllForPackageAsync();

#if WINDOWS_UWP
                    if (!ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "ContextFlyout"))
#endif
                    {
                        newcard.RightTapped += (s, e) =>
                        {
                            var contextMenu = CreateContextMenu(newcard);
                            var point       = e.GetPosition((Card)s);
                            contextMenu.ShowAt(newcard /*, point*/);
                        };
                    }
#if WINDOWS_UWP
                    else
                    {
                        newcard.ContextFlyout = CreateContextMenu(newcard);
                    }
#endif

                    //toAdd.Add(newcard);
                    LineList.Items.Add(newcard);
                }
                LineList.SelectedIndex    = 0;
                inprogresstext.Visibility = Visibility.Collapsed;
                //LineList.ItemsSource = toAdd;

                inprogress.IsActive       = false;
                inprogressbg.Visibility   = Visibility.Collapsed;
                inprogresstext.Visibility = Visibility.Collapsed;
            }

            AppbarUpdate.IsEnabled = true;
#if WINDOWS_UWP
            UpdateJumplist();
#endif
            WindowResized(null, null);
        }
Example #5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            /*if (System.Diagnostics.Debugger.IsAttached)
             * {
             *  this.DebugSettings.EnableFrameRateCounter = true;
             * }*/
            Frame rootFrame = Window.Current.Content as Frame;

#if WINDOWS_UWP
            if (ApiInformation.IsTypePresent("Windows.UI.Xaml.Media.AcrylicBrush"))
            {
                aBrush = new AcrylicBrush()
                {
                    BackgroundSource = AcrylicBackgroundSource.HostBackdrop,
                    TintOpacity      = 0.6
                };

                if (Application.Current.RequestedTheme == ApplicationTheme.Dark)
                {
                    ((AcrylicBrush)aBrush).TintColor     = (Color)Resources["SystemAccentColorDark2"];
                    ((AcrylicBrush)aBrush).FallbackColor = (Color)Resources["SystemAccentColorDark2"];
                }
                else
                {
                    ((AcrylicBrush)aBrush).TintColor     = (Color)Resources["SystemAccentColor"];
                    ((AcrylicBrush)aBrush).FallbackColor = (Color)Resources["SystemAccentColor"];
                }
            }
            else
            {
                aBrush = Resources["SystemControlBackgroundAccentBrush"] as SolidColorBrush;
            }

            // title bar customization
            if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) // mobile
#endif
            {
                var statusBar = StatusBar.GetForCurrentView();
                statusBar.ForegroundColor   = Colors.White;
                statusBar.BackgroundOpacity = 0;
            }
#if WINDOWS_UWP
            if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView")) // PC
            {
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
                var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                titleBar.ButtonBackgroundColor         = Colors.Transparent;
                titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                titleBar.ButtonForegroundColor         = Colors.White;
                titleBar.ButtonInactiveForegroundColor = Colors.Gray;
            }

            if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
            {
                ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
            }
            else
            {
                ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
            }
#endif

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

#if WINDOWS_UWP
                rootFrame.NavigationFailed += OnNavigationFailed;
#elif WINDOWS_PHONE_APP
                // TODO: change this value to a cache size that is appropriate for your application
                rootFrame.CacheSize = 1;

                // Set the default language
                rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];
#endif

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;

                rootFrame.SizeChanged += RootFrame_SizeChanged;
            }

            var lineSerializer = new Utilities.LineSerializer(Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse());
#if WINDOWS_UWP
            if (e.PrelaunchActivated == false)
#endif
            {
                if (e.Arguments == "opensearch")
                {
                    rootFrame.Navigate(typeof(Search));
                    rootFrame.BackStack.Clear();
                    rootFrame.BackStack.Add(new PageStackEntry(typeof(MainPage), null, null));
#if WINDOWS_UWP
                    SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
#endif
                }
                else
                {
                    string[] tileData  = e.TileId.Split('-'); // handle secondary tile
                    string[] tileData2 = e.Arguments.Split('|');
                    if (tileData[0] == "MenetrendApp")
                    {
                        Line line = await lineSerializer.openLine(tileData[1], tileData[2], tileData[3], tileData[4], tileData2[0], tileData2[1]);

                        if (!line.Error)
                        {
                            rootFrame.Navigate(typeof(Results), line);
                            rootFrame.BackStack.Clear();
                            rootFrame.BackStack.Add(new PageStackEntry(typeof(MainPage), null, null));
#if WINDOWS_UWP
                            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
#endif
                        }
                        else
                        {
                            rootFrame.Navigate(typeof(MainPage));
                        }
                    }
                    else
                    {
                        string[] lineData = e.Arguments.Split('-'); //uwp jumplist, wp8 notification
                        if (lineData.Length == 4)
                        {
                            Line line = await lineSerializer.openLine(lineData[0], lineData[1], lineData[2], lineData[3]);

                            if (!line.Error)
                            {
                                rootFrame.Navigate(typeof(Results), line);
                                rootFrame.BackStack.Clear();
                                rootFrame.BackStack.Add(new PageStackEntry(typeof(MainPage), null, null));
#if WINDOWS_UWP
                                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
#endif
                            }
                            else
                            {
                                rootFrame.Navigate(typeof(MainPage));
                            }
                        }
                    }
                }

                if (rootFrame.Content == null)
                {
#if WINDOWS_PHONE_APP
                    // Removes the turnstile navigation for startup.
                    if (rootFrame.ContentTransitions != null)
                    {
                        transitions = new Windows.UI.Xaml.Media.Animation.TransitionCollection();
                        foreach (var c in rootFrame.ContentTransitions)
                        {
                            transitions.Add(c);
                        }
                    }

                    rootFrame.ContentTransitions = null;
                    rootFrame.Navigated         += this.RootFrame_FirstNavigated;
#endif
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing required information as a navigation
                    // parameter
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }

#if WINDOWS_UWP
            SystemNavigationManager snm = SystemNavigationManager.GetForCurrentView();
            snm.BackRequested += (sender, backReqEvArgs) =>
            {
                if (rootFrame.CanGoBack)
                {
                    backReqEvArgs.Handled = true;
                    rootFrame.GoBack();
                }
                snm.AppViewBackButtonVisibility = rootFrame.CanGoBack ?
                                                  AppViewBackButtonVisibility.Visible :
                                                  AppViewBackButtonVisibility.Collapsed;
            };
#endif
        }