Exemplo n.º 1
0
 public Splash(ProtocolActivatedEventArgs args)
     : this(args.SplashScreen)
 {
     var _Decoder = new WwwFormUrlDecoder(args.Uri.Query);
     var _Id = _Decoder.Where(q => q.Name.ToLower() == "module").Select(q => q.Value).FirstOrDefault();
     if (string.IsNullOrWhiteSpace(_Id))
         _Decoder.Where(q => q.Name.ToLower() == "episode").Select(q => q.Value).FirstOrDefault();
     if (string.IsNullOrWhiteSpace(_Id))
     {
         Services.Navigation.GotoFail("The Uri specified was incorrect.");
         return;
     }
     AllowResume = false;
     GotoType = typeof(Views.Detail);
     GotoParam = _Id;
 }
Exemplo n.º 2
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="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            SuspensionManager.KnownTypes.Add(typeof(Catalog));
            SuspensionManager.KnownTypes.Add(typeof(Cart));

            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();
                //Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                if (!SuspensionManager.SessionState.ContainsKey(SuspensionManagerConstants.Catalog))
                {
                    Window.Current.Content = new ExtendedSplash();
                    Window.Current.Activate();
        
                    var repository = ServiceLocator.Get<CatalogRepository>();
                    var catalog = await repository.GetCatalog();
                    SuspensionManager.SessionState.Add(SuspensionManagerConstants.Catalog, catalog);
                }

                if (!SuspensionManager.SessionState.ContainsKey(SuspensionManagerConstants.Cart))
                {
                    SuspensionManager.SessionState.Add(SuspensionManagerConstants.Cart, new Cart());
                }

                var pushNotificationRegistration = ServiceLocator.Get<PushNotificationRegistrationService>();
                pushNotificationRegistration.AcquirePushChannel();

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // 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(GroupedItemsPage), "AllCategories"))
                {
                    throw new Exception("Failed to create initial page");
                }
            }

            if (!string.IsNullOrEmpty(args.Arguments))
            {
                var decoder = new WwwFormUrlDecoder(args.Arguments);

                var category = decoder.Where(v => v.Name == "category").Select(v => v.Value).FirstOrDefault();
                if (!string.IsNullOrEmpty(category))
                {
                    // if category exists then its launched from a secondary tile.
                    rootFrame.Navigate(typeof (GroupDetailPage), category);
                }

                var cartParam = decoder.Where(v => v.Name == "cartId").Select(v => v.Value).FirstOrDefault();
                long cartId;
                if (long.TryParse(cartParam, out cartId))
                {
                    // if cartId exists then its launched from a toast.
                    rootFrame.Navigate(typeof (CartPage), cartId);
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
Exemplo n.º 3
0
        private async Task<WebResponse> ApiPage(WebRequest request)
        {
            // Prepare the response object
            var response = new WebResponse
            {
                // Create a new dictionary for headers - this could be done using a more advanced class for 
                // WebResponse object - I just used a simple structure
                Header = new Dictionary<string, string>
                {
                    // Add content type header
                    {
                        "Content-Type",
                        "application/json'"
                    }
                }
            };

            Stream responseText = new MemoryStream();

            if (request.Uri.IndexOf('?') > -1)
            {
                var queryString = request.Uri.Substring(request.Uri.IndexOf('?'));

                var decoder = new WwwFormUrlDecoder(queryString);

                foreach (var color in decoder.Where(param => param.Name == "color").Select(param => Color.FromArgb(255,
                    Convert.ToByte(param.Value.Substring(0, 2), 16),
                    Convert.ToByte(param.Value.Substring(2, 2), 16),
                    Convert.ToByte(param.Value.Substring(4, 2), 16))))
                {
                    try
                    {
                        await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                            () =>
                            {
                                var colorBrush = new SolidColorBrush(color);
                                LightColor = colorBrush;

                                var contentWriter = new StreamWriter(responseText);
                                contentWriter.WriteLine(
                                    "{\"status\":200,\"message\":\"Color was set to " + LightColor.Color + "\"}"
                                    );
                                contentWriter.Flush();
                            }
                            );
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            }

            // Assign the response
            response.Content = responseText;

            // Return the response
            return response;
        }