Пример #1
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Register all the tasks...
            RegisterTasks.Run();

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            var 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 { CacheSize = 1 };

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

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

            if (rootFrame.Content == null)
            {
                // Removes the turnstile navigation for startup.
                if (rootFrame.ContentTransitions != null)
                {
                    this.transitions = new TransitionCollection();
                    foreach (var c in rootFrame.ContentTransitions)
                    {
                        this.transitions.Add(c);
                    }
                }

                rootFrame.ContentTransitions = null;
                rootFrame.Navigated += this.RootFrameFirstNavigated;

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            if (!string.IsNullOrEmpty(e.Arguments))
            {
                var linkRepo = new NewSlapsStore();
                var link = linkRepo.Links.FirstOrDefault(l => l.Id == int.Parse(e.Arguments));

                var page = rootFrame.Content as Page;
                if (link != null && page != null)
                {
                    var lvms = Mapper.Map<IEnumerable<Link>, ObservableCollection<LinkViewModel>>(linkRepo.Links);
                    var linkViewModel = lvms.FirstOrDefault(l => l.Id == link.Id);

                    var viewLinksViewModel = new ViewLinksViewModel(linkViewModel, lvms);
                    page.Frame.Navigate(typeof(View), viewLinksViewModel);
                }
            }

            // Ensure the current window is active
            Window.Current.Activate();
        }
        /// <summary>
        /// The send link notification.
        /// </summary>
        /// <param name="content">
        /// The content.
        /// </param>
        /// <param name="showNotifications">
        /// The show notifications.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private static bool SendLinkNotification(string content, bool showNotifications)
        {
            Link link;
            try
            {
                link = JsonConvert.DeserializeObject<Link>(content);
            }
            catch (Exception exception)
            {
                return false;
            }

            var store = new NewSlapsStore();

            if (store.Links.All(l => l.Id != link.Id))
            {
                store.AddLink(link);
            }
            

            // Do not show notification if processing from inside the app.
            if (!showNotifications)
            {
                return true;
            }


            var settings = new SettingsStore();
            if (!settings.ShowPushNotification(link.StreamKey))
            {
                return true;
            }

            var notification = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);
            var toastElement = ((XmlElement)notification.SelectSingleNode("/toast"));
            toastElement.SetAttribute("launch", link.Id.ToString());

            var badgeElements = notification.DocumentElement.SelectNodes(".//text");

            badgeElements[0].InnerText = "Linkslap";
            badgeElements[1].InnerText = "New link in " + link.StreamName;
            
            dynamic toast = new ToastNotification(notification); //{ Tag = link.Id.ToString() };
            toast.Tag = link.Id.ToString();

            ToastNotificationManager.CreateToastNotifier().Show(toast);

            return true;
        }