コード例 #1
0
        // ref: https://social.msdn.microsoft.com/Forums/en-US/ec977327-291e-4409-8ef7-2cefeca7698c/problem-using-bitmapimagesetsourceasync?forum=winappswithcsharp
        private async Task <string> SendImageThumbsAsync()
        {
            List <StorageItemThumbnail> thumbs = ImagePage.GetThumbnailList();

            // First, send the number of thumbnail (images)
            streamWriter.WriteLine(thumbs.Count);
            streamWriter.Flush();

            // Second, send bitmap with Base64.
            for (int i = 0; i < thumbs.Count; i++)
            {
                BitmapImage img   = new BitmapImage();
                var         dr    = new DataReader(thumbs[i].GetInputStreamAt(0));
                byte[]      bytes = new byte[thumbs[i].Size];
                await dr.LoadAsync((uint)thumbs[i].Size);

                dr.ReadBytes(bytes);

                // Send base64
                streamWriter.WriteLine(System.Convert.ToBase64String(bytes));
                streamWriter.Flush();
            }

            // Finally, send status code.
            return("OK");
        }
コード例 #2
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 void OnLaunched(LaunchActivatedEventArgs e)
        {
            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;

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

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

            if (e.PrelaunchActivated == false)
            {
                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
                    rootFrame.Navigate(typeof(StartPage), e.Arguments);
                }
                // Ensure the current window is active
                Window.Current.Activate();
            }

            var titleBar = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TitleBar;

            // Make titlebar as view
            CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;

            // Set active window colors
            titleBar.ForegroundColor              = Windows.UI.Colors.White;
            titleBar.BackgroundColor              = Windows.UI.Colors.Transparent;
            titleBar.ButtonForegroundColor        = Windows.UI.Colors.White;
            titleBar.ButtonBackgroundColor        = Windows.UI.Colors.Transparent;
            titleBar.ButtonHoverForegroundColor   = Windows.UI.Colors.White;
            titleBar.ButtonHoverBackgroundColor   = Windows.UI.Colors.LightGray;
            titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White;
            titleBar.ButtonPressedBackgroundColor = Windows.UI.Colors.DarkGray;

            // Enter to fullscreen mode
            Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

            // Manage key listener
            Window.Current.CoreWindow.KeyDown += KeyDownEventHandler;

            // Add mouse cursor pointer handler
            AutoHideCursor.Start();
            Window.Current.CoreWindow.PointerPressed += AutoHideCursor.AutoHider_PointerUsed;
            Window.Current.CoreWindow.PointerMoved   += AutoHideCursor.AutoHider_PointerUsed;

            // Create socket datagram
            socket = new Socket();
            socket.CreateSocketListener();
            socket.setRootFrame(rootFrame);

            // Get file list of Video Page and Image page
            ImagePage.GetImageList();
            VideoPage.GetVideoList();
        }
コード例 #3
0
        // http://garicchi.com/?p=5891
        // string CheckCommand(String msg)
        private async Task CheckCommand(String msg, Windows.Networking.Sockets.StreamSocketListenerConnectionReceivedEventArgs args)
        {
            await Task.Run(async() =>
            {
                string result = "";
                outStream     = args.Socket.OutputStream.AsStreamForWrite();
                streamWriter  = new StreamWriter(outStream);

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    try
                    {
                        Debug.WriteLine(msg);
                        switch (msg)
                        {
                        case "ECHO":
                            result = await streamReader.ReadLineAsync();
                            break;

                        case "IMAGE":
                            // change mode to image mode and set the specified picture
                            rootFrame.ContentTransitions = new TransitionCollection();
                            rootFrame.ContentTransitions.Add(new NavigationThemeTransition());
                            rootFrame.Navigate(typeof(ImagePage));
                            result = "OK";
                            break;

                        case "VIDEO":
                            // change mode to video mode and set the specified video
                            rootFrame.ContentTransitions = new TransitionCollection();
                            rootFrame.ContentTransitions.Add(new NavigationThemeTransition());
                            rootFrame.Navigate(typeof(VideoPage));
                            result = "OK";
                            break;

                        case "LIVE":
                            // change mode to live mode
                            rootFrame.ContentTransitions = new TransitionCollection();
                            rootFrame.ContentTransitions.Add(new NavigationThemeTransition());
                            rootFrame.Navigate(typeof(LivePage));
                            result = "OK";
                            break;

                        case "BLANK":
                            // change mode to blank mode
                            rootFrame.ContentTransitions = new TransitionCollection();
                            rootFrame.ContentTransitions.Add(new NavigationThemeTransition());
                            rootFrame.Navigate(typeof(BlankPage));
                            result = "OK";
                            break;

                        case "HOME":
                            // change mode to blank mode
                            rootFrame.ContentTransitions = new TransitionCollection();
                            rootFrame.ContentTransitions.Add(new NavigationThemeTransition());
                            rootFrame.Navigate(typeof(StartPage));
                            rootFrame.BackStack.Clear();
                            result = "OK";
                            break;

                        case "NEXT":
                            Debug.WriteLine(App.GetMode());
                            switch (App.GetMode())
                            {
                            case "ImagePage":
                                ImagePage.NextImage(); break;

                            case "VideoPage":
                                VideoPage.NextVideo(); break;

                            default:
                                break;
                            }
                            result = "OK";
                            break;

                        case "PREVIOUS":
                            switch (App.GetMode())
                            {
                            case "ImagePage":
                                ImagePage.PreviousImage(); break;

                            case "VideoPage":
                                VideoPage.PreviousVideo(); break;

                            default:
                                break;
                            }
                            result = "OK";
                            break;

                        case "SET_IMAGE_BY_ID":
                            {
                                string id = await streamReader.ReadLineAsync();
                                ImagePage.SetImageIndex(int.Parse(id));
                                result = "OK";
                                break;
                            }

                        case "SET_VIDEO_BY_ID":
                            {
                                string id = await streamReader.ReadLineAsync();
                                VideoPage.SetVideoIndex(int.Parse(id));
                                result = "OK";
                                break;
                            }

                        case "TOGGLE_FULLSCREEN":
                            {
                                if (Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().IsFullScreenMode)
                                {
                                    Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().ExitFullScreenMode();
                                }
                                else
                                {
                                    Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
                                }
                                break;
                            }

                        case "GET_MODE":
                            result = App.GetMode();
                            break;

                        case "GET_IMAGE_THUMBS":
                            result = await SendImageThumbsAsync();
                            break;

                        case "GET_VIDEO_THUMBS":
                            result = await SendVideoThumbsAsync();
                            break;

                        default:
                            result = "Invalid command.";
                            break;
                        }
                    }
                    catch
                    {
                        Debug.WriteLine("Failed to send command.");
                        result = "Failed to send command.";
                    }
                });

                // send back result strings
                //await writer.WriteLineAsync(result);
                //await writer.FlushAsync();
                streamWriter.WriteLine(result);
                streamWriter.Flush();

                Debug.WriteLine(result);
            });
        }