예제 #1
0
        public static async Task <bool> TryShowWindowAsync(EbookViewModel ebookViewModel)
        {
            if (App.ReadingWindows.Keys.Any(rw => rw.Isbn == ebookViewModel.Isbn))
            {
                return(await App.ReadingWindows[App.ReadingWindows.Keys.First(evm => evm.Isbn == ebookViewModel.Isbn)].TryShowAsync());
            }

            AppWindow readingWindow = await AppWindow.TryCreateAsync();

            App.ReadingWindows.Add(ebookViewModel, readingWindow);
            readingWindow.Title = ebookViewModel.Title;

            readingWindow.Closed += (sender, e) =>
            {
                App.ReadingWindows.Remove(App.ReadingWindows.First(_ => _.Value == sender).Key);
            };

            Frame readingWindowContentFrame = new Frame();

            readingWindowContentFrame.Navigate(typeof(ReadingPage), ebookViewModel);

            ElementCompositionPreview.SetAppWindowContent(readingWindow, readingWindowContentFrame);

            return(await readingWindow.TryShowAsync());
        }
예제 #2
0
        private void SetDragRegionForCustomTitleBar(AppWindow appWindow)
        {
            //Infer titlebar height
            int titleBarHeight = appWindow.TitleBar.Height;

            MyTitleBar.Height = titleBarHeight;

            // Get caption button occlusion information
            // Use LeftInset if you've explicitly set your window layout to RTL or if app language is a RTL language
            int CaptionButtonOcclusionWidth = appWindow.TitleBar.RightInset;

            // Define your drag Regions
            int windowIconWidthAndPadding = MyWindowIcon.Width + MyWindowIcon.Margin.Right;
            int dragRegionWidth           = appWindow.Size.Width - (CaptionButtonOcclusionWidth + windowIconWidthAndPadding);

            Windows.Graphics.RectInt32[] dragRects = new Windows.Graphics.RectInt32[] { };
            Windows.Graphics.RectInt32   dragRect;

            dragRect.X      = windowIconWidthAndPadding;
            dragRect.Y      = 0;
            dragRect.Height = titleBarHeight;
            dragRect.Width  = dragRegionWidth;

            appWindow.TitleBar.SetDragRectangles(dragRects.Append(dragRect).ToArray());
        }
        public async Task <bool> ShowWindow(Type type, ToggleButton toggleButton)
        {
            AppWindow appWindow = await AppWindow.TryCreateAsync();

            Frame frame = new Frame();

            frame.Navigate(type, this);
            ElementCompositionPreview.SetAppWindowContent(appWindow, frame);
            UIContext uIContext = frame.UIContext;

            appWindows.Add(uIContext, appWindow);
            appWindow.Closed += delegate
            {
                MainPage.appWindows.Remove(uIContext);
                frame.Content          = null;
                appWindow              = null;
                toggleButton.IsChecked = false;
            };
            try
            {
                Debug.WriteLine("Is de Nuget Pakage");
                await appWindow.TryShowAsync();
            }
            catch (Exception exception)
            {
                Debug.WriteLine("Exeption in ShowWindow");
                Debug.WriteLine(exception.Message);
            }
            return(true);
        }
예제 #4
0
        // todo: work out a huge mem leak, the windowContent is still running even when we destroy the appWindow ????
        // i.e. the mediaPlayerElement is still running , i can here the media playing
        public static async void OpenWindow(UIElement windowContent, double width, double height, Action finishedOpeningAction)
        {
            AppWindow appWindow = await AppWindow.TryCreateAsync();

            appWindow.Title = "desktopxx";
            appWindow.RequestSize(new Size(width, height));

            Grid appWindowRootGrid = new Grid();

            appWindowRootGrid.Children.Add(windowContent);

            ElementCompositionPreview.SetAppWindowContent(appWindow, windowContent);

            appWindow.Closed += (a, o) =>
            {
                appWindowRootGrid.Children.Remove(windowContent);
                appWindowRootGrid = null;

                windowContent = null;
                appWindow     = null;
            };

            await appWindow.TryShowAsync();

            finishedOpeningAction?.Invoke();

            //DesktopHelper.SendWindowToBackground("desktopxx");
        }
예제 #5
0
        private void AppWindowChangedHandler(AppWindow sender, AppWindowChangedEventArgs args)
        {
            // The presenter changed so we need to update the button captions to reflect the new state
            if (args.DidPresenterChange)
            {
                switch (_mainAppWindow.Presenter.Kind)
                {
                case AppWindowPresenterKind.CompactOverlay:
                    CompactoverlaytBtn.Content = "Exit CompactOverlay";
                    FullscreenBtn.Content      = "Enter FullScreen";
                    break;

                case AppWindowPresenterKind.FullScreen:
                    CompactoverlaytBtn.Content = "Enter CompactOverlay";
                    FullscreenBtn.Content      = "Exit FullScreen";
                    break;

                case AppWindowPresenterKind.Overlapped:
                    CompactoverlaytBtn.Content = "Enter CompactOverlay";
                    FullscreenBtn.Content      = "Enter FullScreen";
                    break;

                default:
                    // If we end up here the presenter was changed to something we don't know what it is.
                    // This would happen if a new presenter is introduced.
                    // We can ignore this situation since we are not aware of the presenter and have no UI that
                    // reacts to this unknown presenter.
                    break;
                }
            }
        }
예제 #6
0
        private async void LibraryProperties_Click(object sender, RoutedEventArgs e)
        {
            if (LibraryGrid.SelectedItem is LibraryFolder Library)
            {
                if (await FileSystemStorageItemBase.CreateFromStorageItemAsync(Library.Folder) is FileSystemStorageFolder Folder)
                {
                    await Folder.LoadMorePropertiesAsync();

                    AppWindow NewWindow = await AppWindow.TryCreateAsync();

                    NewWindow.RequestSize(new Size(420, 600));
                    NewWindow.RequestMoveRelativeToCurrentViewContent(new Point(Window.Current.Bounds.Width / 2 - 200, Window.Current.Bounds.Height / 2 - 300));
                    NewWindow.PersistedStateId = "Properties";
                    NewWindow.Title            = Globalization.GetString("Properties_Window_Title");
                    NewWindow.TitleBar.ExtendsContentIntoTitleBar    = true;
                    NewWindow.TitleBar.ButtonBackgroundColor         = Colors.Transparent;
                    NewWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

                    ElementCompositionPreview.SetAppWindowContent(NewWindow, new PropertyBase(NewWindow, Folder));
                    WindowManagementPreview.SetPreferredMinSize(NewWindow, new Size(420, 600));

                    await NewWindow.TryShowAsync();
                }
            }
        }
예제 #7
0
        public T ShowWindow <T>(UIParamInfo info, bool effect, bool mask) where T : AppWindow
        {
            if (overlayMask != null)
            {
                overlayMask.SetActive(mask);
            }
            T clone = ZAssetController.Instance.ActivateAsset <T>(windowBox);

            _alertWindow      = clone;
            openedWindow      = typeof(T).Name;
            clone.effectPoint = effectBox;
            if (historyWindows.ContainsKey(openedWindow))
            {
                historyWindows.Remove(openedWindow);
            }
            historyWindows.Add(openedWindow, info);

            if (effect && openDelay > 0.01f)
            {
                StartCoroutine(ShowInspector(clone, info));
            }
            else
            {
                StartCoroutine(OpenDelay(clone, info));
            }
            return(clone);
        }
예제 #8
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException +=
                (sender, e) => new UnhandledExceptionDialog(_main, e.ExceptionObject as Exception).ShowDialog();


            ExceptionManager.UnhandledException +=
                e => new UnhandledExceptionDialog(_main, e.ExceptionObject as Exception).ShowDialog();


            AppController.Instance.Initialize();
            if (args.Length > 0 && System.IO.File.Exists(args[0]))
            {
                AppController.Instance.FileName = args[0];
                var saved = ConfigManager.Read <PrimitivesSurface>(AppController.Instance.FileName);
                AppController.Instance.ResetSurface();
                AppController.Instance.ReloadSurface(saved);
            }

            var localFile     = ConfigurationManager.AppSettings["LocalFile"];
            var remoteFile    = ConfigurationManager.AppSettings["RemoteFile"];
            var remoteVersion = ConfigurationManager.AppSettings["RemoteVersion"];

            UpdateHelper.LocalFile     = string.IsNullOrEmpty(localFile) ? UpdateHelper.LocalFile : localFile;
            UpdateHelper.RemoteFile    = string.IsNullOrEmpty(remoteFile) ? UpdateHelper.RemoteFile : remoteFile;
            UpdateHelper.RemoteVersion = string.IsNullOrEmpty(remoteVersion) ? UpdateHelper.RemoteVersion : remoteVersion;

            Application.Init();
            _main = new AppWindow();
            Application.Run();
        }
예제 #9
0
        static DisplayRotation CalculateRotation(DEVMODE devMode, AppWindow appWindow)
        {
            DisplayOrientations native = DisplayOrientations.Portrait;

            switch (devMode.dmDisplayOrientation)
            {
            case 0:
                native = DisplayOrientations.Landscape;
                break;

            case 1:
                native = DisplayOrientations.Portrait;
                break;

            case 2:
                native = DisplayOrientations.LandscapeFlipped;
                break;

            case 3:
                native = DisplayOrientations.PortraitFlipped;
                break;
            }

            var current = GetWindowOrientationWin32(appWindow);

            return(CalculateRotation(native, current));
        }
 private void AppWindow_Changed(AppWindow sender, AppWindowChangedEventArgs args)
 {
     if (args.DidSizeChange)
     {
         TryExitFullScreen();
     }
 }
예제 #11
0
        private void UpdateWindowsList()
        {
            List <AppWindow> list = mWindowExplorerDriver.GetAppWindows();

            WindowsComboBox.ItemsSource       = list;
            WindowsComboBox.DisplayMemberPath = "WinInfo";

            AppWindow ActiveWindow = mWindowExplorerDriver.GetActiveWindow();

            if (ActiveWindow != null)
            {
                foreach (AppWindow w in list)
                {
                    if (w.Title == ActiveWindow.Title && w.Path == ActiveWindow.Path)
                    {
                        WindowsComboBox.SelectedValue = w;
                        return;
                    }
                }
            }

            //TODO: If no selection then select the first if only one window exist in list
            if (!(mWindowExplorerDriver is SeleniumAppiumDriver))//FIXME: need to work for all drivers and from some reason failing for Appium!!
            {
                if (WindowsComboBox.Items.Count == 1)
                {
                    WindowsComboBox.SelectedValue = WindowsComboBox.Items[0];
                }
            }
        }
예제 #12
0
        public static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException +=
                (sender, e) => new UnhandledExceptionDialog(_main, e.ExceptionObject as Exception).ShowDialog();

            ExceptionManager.UnhandledException +=
                e => new UnhandledExceptionDialog(_main, e.ExceptionObject as Exception).ShowDialog();

            AppController.Instance.Initialize();
            if (args.Length > 0 && System.IO.File.Exists(args[0]))
            {

                AppController.Instance.FileName = args[0];
                var saved = ConfigManager.Read<PrimitivesSurface>(AppController.Instance.FileName);
                AppController.Instance.ResetSurface();
                AppController.Instance.ReloadSurface(saved);

            }

            var localFile = ConfigurationManager.AppSettings["LocalFile"];
            var remoteFile = ConfigurationManager.AppSettings["RemoteFile"];
            var remoteVersion = ConfigurationManager.AppSettings["RemoteVersion"];

            UpdateHelper.LocalFile = string.IsNullOrEmpty(localFile) ? UpdateHelper.LocalFile : localFile;
            UpdateHelper.RemoteFile = string.IsNullOrEmpty(remoteFile) ? UpdateHelper.RemoteFile : remoteFile;
            UpdateHelper.RemoteVersion = string.IsNullOrEmpty(remoteVersion) ? UpdateHelper.RemoteVersion : remoteVersion;

            Application.Init ();
            _main = new AppWindow();
            Application.Run();
        }
예제 #13
0
        protected BaseWelcomePopupViewModel(Onboarding.Onboarding onboarding, AppWindow appWindow)
            : base(appWindow)
        {
            _onboarding = onboarding;

            TakeATourCommand = new RelayCommand(TakeATourAction);
        }
예제 #14
0
        /// <summary>
        /// Открываем окно загрузки. Начало программы.
        /// </summary>
        private void InitialLoading()
        {
            var vm = new LoadingViewModel();

            var window = new AppWindow
            {
                MinWidth  = 320,
                MaxWidth  = 320 * 2,
                MinHeight = 400,
                MaxHeight = 400 * 2,

                Content = vm
            };

            // загружаем данные в Store
            var result = window.ShowDialog();

            // загрузили, что-то отредактировали и готовы сохранить
            if (true.Equals(result) ||
                vm.HasError ||
                AfterLoading())
            {
                if (OnSaving())
                {
                    App.Current.Shutdown();
                }
            }

            InitialLoading();
        }
예제 #15
0
        private async void NewWindowButton_Click(object sender, RoutedEventArgs e)
        {
            //CoreApplicationView newView = CoreApplication.CreateNewView();
            //int newViewId = 0;
            //await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            //{
            //    Frame frame = new Frame();
            //    frame.Navigate(typeof(InstancePage), null);
            //    Window.Current.Content = frame;
            //    // You have to activate the window in order to show it later.
            //    Window.Current.Activate();

            //    newViewId = ApplicationView.GetForCurrentView().Id;
            //});
            //bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
            AppWindow appWindow = await AppWindow.TryCreateAsync();

            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(InstancePage));
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
            await appWindow.TryShowAsync();

            appWindow.Closed += delegate
            {
                appWindowContentFrame.Content = null;
                appWindow = null;
            };
        }
        /// <summary>
        /// Gets the AppWindow from the Window.
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public static AppWindow GetAppWindow(this Window window)
        {
            IntPtr hWnd     = WinRT.Interop.WindowNative.GetWindowHandle(window);
            var    windowId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(windowId));
        }
예제 #17
0
        protected BaseUpgradePlanPopupViewModel(IActiveUrls urls, AppWindow appWindow)
            : base(appWindow)
        {
            _urls = urls;

            UpgradeCommand = new RelayCommand(UpgradeAction);
        }
예제 #18
0
        private AppWindow GetAppWindowForCurrentWindow()
        {
            IntPtr   hWnd  = WindowNative.GetWindowHandle(this);
            WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(wndId));
        }
예제 #19
0
        private async void Settings_Click(object sender, RoutedEventArgs e)
        {
            appWindow = await AppWindow.TryCreateAsync();

            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(Settings), RecognizerViewModel);
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
            appWindow.RequestSize(new Size(500, 900));
            await appWindow.TryShowAsync();

            this.mainPage.IsEnabled = false;

            appWindow.Closed += delegate
            {
                appWindowContentFrame.Content = null;
                appWindow = null;
                this.mainPage.IsEnabled = true;
            };

            //CoreApplicationView newView = CoreApplication.CreateNewView();
            //int newViewId = 0;
            //await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            //{
            //    Frame frame = new Frame();
            //    frame.Navigate(typeof(settings), RecognizerViewModel);
            //    Window.Current.Content = frame;
            //    Window.Current.Activate();
            //    newViewId = ApplicationView.GetForCurrentView().Id;
            //});
            //bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
        }
예제 #20
0
        private async void SaveAs_Click(object sender, RoutedEventArgs e)
        {
            appWindow = await AppWindow.TryCreateAsync();

            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(SaveAs), dictationTextBox.Text);
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
            appWindow.RequestSize(new Size(640, 545));
            //bool switched = appWindow.TitleBar.is     //.Presenter.RequestPresentation(AppWindowPresentationKind.FullScreen);
            //if (switched)
            //{
            //    appWindow.RequestSize(new Size(640, 545));
            //    // If the request was satisfied, show the window
            //    await appWindow.TryShowAsync();
            //}

            await appWindow.TryShowAsync();

            //this.mainPage.IsEnabled = false;

            appWindow.Closed += delegate
            {
                appWindowContentFrame.Content = null;
                appWindow = null;
                this.mainPage.IsEnabled = true;
            };
        }
예제 #21
0
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            await ApplicationDataMigration.Migrate();

            await DatabaseManager.Instance.InitializeDb();

            await SettingsViewModel.Instance.Load();

            await SearchResultsViewModel.Instance.Load();

            if (!Resources.ContainsKey("settings"))
            {
                Resources.Add("settings", Settings.Instance);
            }

            string[] args            = Environment.GetCommandLineArgs();
            string   launchArguments = args.Length >= 2 ? args[1] : null;

            mainWindow = new MainWindow(launchArguments);

            IntPtr    hWnd      = WindowNative.GetWindowHandle(mainWindow);
            WindowId  windowId  = Win32Interop.GetWindowIdFromWindow(hWnd);
            AppWindow appWindow = AppWindow.GetFromWindowId(windowId);

            mainWindow.Activate();

            appWindow.Closing += AppWindow_Closing;
        }
예제 #22
0
        public static AppWindow GetAppWindowForCurrentWindow(this Window window)
        {
            var hWnd  = WindowNative.GetWindowHandle(window);
            var winId = Win32Interop.GetWindowIdFromWindow(hWnd);

            return(AppWindow.GetFromWindowId(winId));
        }
예제 #23
0
        private async void ShowProperties(object parameter)
        {
            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
            {
                AppWindow appWindow = await AppWindow.TryCreateAsync();

                Frame frame = new Frame();
                appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
                frame.Navigate(typeof(Properties), null, new SuppressNavigationTransitionInfo());
                WindowManagementPreview.SetPreferredMinSize(appWindow, new Size(400, 475));

                appWindow.RequestSize(new Size(400, 475));
                appWindow.Title = ResourceController.GetTranslation("PropertiesTitle");

                ElementCompositionPreview.SetAppWindowContent(appWindow, frame);
                AppWindows.Add(frame.UIContext, appWindow);

                appWindow.Closed += delegate
                {
                    AppWindows.Remove(frame.UIContext);
                    frame.Content = null;
                    appWindow     = null;
                };

                await appWindow.TryShowAsync();
            }
            else
            {
                App.PropertiesDialogDisplay.propertiesFrame.Tag = App.PropertiesDialogDisplay;
                App.PropertiesDialogDisplay.propertiesFrame.Navigate(typeof(Properties), parameter, new SuppressNavigationTransitionInfo());
                await App.PropertiesDialogDisplay.ShowAsync(ContentDialogPlacement.Popup);
            }
        }
예제 #24
0
        void SetupWindow(AppWindow window)
        {
            //https://github.com/microsoft/Xaml-Controls-Gallery/blob/f2d4568ec53464c3d290940282d2f70cfd62fa94/XamlControlsGallery/TabViewPages/TabViewWindowingSamplePage.xaml.cs
            if (window == null)
            {
                // Extend into the titlebar
                var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
                coreTitleBar.ExtendViewIntoTitleBar = true;

                coreTitleBar.LayoutMetricsChanged += CoreTitleBar_LayoutMetricsChanged;

                var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                titleBar.ButtonBackgroundColor         = Windows.UI.Colors.Transparent;
                titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent;

                Window.Current.SetTitleBar(CustomDragRegion);
            }
            else
            {
                // Secondary AppWindows --- keep track of the window
                RootAppWindow = window;

                // Extend into the titlebar
                window.TitleBar.ExtendsContentIntoTitleBar    = true;
                window.TitleBar.ButtonBackgroundColor         = Windows.UI.Colors.Transparent;
                window.TitleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent;

                // Due to a bug in AppWindow, we cannot follow the same pattern as CoreWindow when setting the min width.
                // Instead, set a hardcoded number.
                CustomDragRegion.MinWidth = 188;

                window.Frame.DragRegionVisuals.Add(CustomDragRegion);
            }
        }
예제 #25
0
 private void Page_loaded(object sender, RoutedEventArgs e)
 {
     if (this.appWindow == null)
     {
         this.appWindow = (AppWindow)System.Windows.Application.Current.MainWindow;
     }
 }
예제 #26
0
        private async void AppBarButton_Click_3(object sender, RoutedEventArgs e)
        {
            try
            {
                StoreServicesCustomEventLogger logger = StoreServicesCustomEventLogger.GetDefault();
                logger.Log("ChartEvent");
                blankPagePlot = new BlankPagePlot();

                appWindow = await AppWindow.TryCreateAsync();

                ElementCompositionPreview.SetAppWindowContent(appWindow, blankPagePlot);

                v = await appWindow.TryShowAsync();

                if (v)
                {
                    blankPagePlot.iniPlot(device.namea);
                    blankPagePlot.PlotModel.addSeries();
                    Size size = new Size()
                    {
                        Height = 100, Width = 100
                    };
                    appWindow.RequestSize(size);
                    appWindow.Closed += delegate
                    {
                        v             = false;
                        blankPagePlot = null;
                        appWindow     = null;
                    };
                }
            }
            catch (Exception)
            {
            }
        }
예제 #27
0
        private async void CreateSecondScreen()
        {
            // Create a new window.
            AppWindow appWindow = await AppWindow.TryCreateAsync();

            // Create a Frame and navigate to the Page you want to show in the new window.
            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(AppWindowPage));

            // Attach the XAML content to the window.
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);

            // Add the new page to the Dictionary using the UIContext as the Key.
            AppWindows.Add(appWindowContentFrame.UIContext, appWindow);
            appWindow.Title = "App Window " + AppWindows.Count.ToString();

            // When the window is closed, be sure to release
            // XAML resources and the reference to the window.
            appWindow.Closed += delegate
            {
                MainPage.AppWindows.Remove(appWindowContentFrame.UIContext);
                appWindowContentFrame.Content = null;
                appWindow = null;
            };

            // Show the window.
            await appWindow.TryShowAsync();
        }
 public SubscriptionExpiredPopupViewModel(IActiveUrls urls,
                                          Lazy <ConnectionStatusViewModel> connectionStatusViewModel,
                                          AppWindow appWindow)
     : base(urls, appWindow)
 {
     _connectionStatusViewModel = connectionStatusViewModel;
 }
예제 #29
0
 public ConnectionUserControl(AppWindow window)
 {
     InitializeComponent();
     _appWindow = window;
     HandleResize();
     errorLabel.Visible = false;
 }
예제 #30
0
 public MainWindow()
 {
     this.InitializeComponent();
     m_AppWindow       = GetAppWindowForCurrentWindow();
     m_AppWindow.Title = "小破站下载工具";
     m_AppWindow.TitleBar.IconShowOptions = IconShowOptions.HideIconAndSystemMenu;
 }
예제 #31
0
        public async void ToPage()
        {
            appWindow = await AppWindow.TryCreateAsync();

            Frame appWindowContentFrame = new Frame();

            appWindowContentFrame.Navigate(typeof(RecentList), RecognizerViewModel);
            ElementCompositionPreview.SetAppWindowContent(appWindow, appWindowContentFrame);
            appWindow.RequestSize(new Size(500, 900));
            await appWindow.TryShowAsync();

            //this.mainPage.IsEnabled = false;

            appWindow.Closed += delegate
            {
                //    //Task.Delay(1000);
                //    dictationTextBox.Text = "";
                //    appWindowContentFrame.Content = null;
                //    appWindow = null;
                //this.mainPage.IsEnabled = true;
                //    recentFile = RecentList.openFile;
                //    RecentList.openFile = null;
                //    OpenFileDialog_Click(null, null);
                //
            };
        }
        public WindowDrawingContext(GraphicsContext graphics, IInputContext input)
            : base(graphics.DeviceManager)
        {
            Graphics = graphics;

            _window = new AppWindow(input);
            _window.SizeChanged += win => Initialize();

            _depthBuffer = new DepthBuffer(DeviceManager, _window.ClientWidth, _window.ClientHeight);
            _windowTextureBuffer = new WindowTextureBuffer(DeviceManager, _window.Form.Handle, _window.ClientWidth, _window.ClientHeight);
        }
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     var handle = (IntPtr) value;
     var key = "IconImage-" + handle;
     var shortCacheKey = key + "-shortCache";
     var longCacheKey = key + "-longCache";
     var iconImage = MemoryCache.Default.Get(shortCacheKey) as BitmapImage;
     if (iconImage == null)
     {
         var window = new AppWindow(handle);
         var icon = ShouldUseSmallTaskbarIcons() ? window.SmallWindowIcon : window.LargeWindowIcon;
         iconImage = _iconToBitmapConverter.Convert(icon) ?? new BitmapImage();
         MemoryCache.Default.Add(shortCacheKey, iconImage, DateTimeOffset.Now.AddSeconds(5));
         MemoryCache.Default.Add(longCacheKey, iconImage, DateTimeOffset.Now.AddMinutes(120));
     }
     return iconImage;
 }
예제 #34
0
        private void LoginOperation()
        {
            UserDomain userDomain = new UserDomain(1, Common.Enums.LanguagesEnum.Arabic);
            User userEntity = new User();
            userEntity = userDomain.CheckUserLogin(txt_Username.Text, txt_Password.Password);
            if (userDomain.ActionState.Status != Common.Enums.ActionStatusEnum.NoError)
            {
                SetError(0, userDomain.ActionState.Result);
            }
            else
            {
                UISecurity.UserEntity = userEntity;
                AppWindow appWindow = new AppWindow();

                appWindow.Show();
                ((Window)((Grid)this.Parent).Parent).Close();

            }
        }
예제 #35
0
        public Application(IApp page)
        {
            // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeTabsExperiment\ChromeTabsExperiment\Application.cs
            Console.WriteLine("enter HybridHopToUDPChromeApp Application");


            dynamic self = Native.self;
            dynamic self_chrome = self.chrome;


            #region self_chrome_socket app
            object self_chrome_socket = self_chrome.socket;

            if (self_chrome_socket != null)
            {
                if (!(Native.window.opener == null && Native.window.parent == Native.window.self))
                {
                    Console.WriteLine("appwindow chrome.app.window.create, is that you?");

                    MessagePort appwindow_to_app = null;

                    // called by? 619  app:HopToChromeAppWindow
                    #region  appwindow Native.window.onmessage
                    Native.window.onmessage += e =>
                    {
                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow

                        // appwindow Native.window.onmessage {{ data = app to appwindow! }}

                        var message = e.data;

                        //Console.WriteLine("appwindow Native.window.onmessage " + new { e.data });


                        // extension  port.onMessage {{ message = from app hello to extension }}
                        //var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString;

                        // look app sent a message to extension
                        //Console.WriteLine("app  port.onMessage " + new { message });

                        if (message is string)
                        {
                            Console.WriteLine("appwindow    Native.window.onmessage: " + message);
                            //Console.WriteLine("appwindow    Native.window.onmessage: " + new { e.ports });

                            if (e.ports != null)
                                foreach (var port in e.ports)
                                {
                                    Console.WriteLine("appwindow    Native.window.onmessage " + new { port });

                                    appwindow_to_app = port;
                                }

                            //e.po

                            return;
                        }

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp




                        // casting from anonymous object.

                        // defined at?
                        // "Z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync.csproj"
                        // clean and rebuild
                        // 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1612,5): warning : The referenced project '..\..\..\..\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync.csproj' does not exist.
                        var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message;

                        // or constructor id?
                        Console.WriteLine("appwindow     Native.window.onmessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName });

                        // 12468ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                        //2015-08-22 15:49:45.729 view-source:53670 12471ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }}
                        //2015-08-22 15:49:45.733 view-source:53670 12475ms extension  port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }}
                        //2015-08-22 15:49:45.737 view-source:53670 12479ms extension  port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }}


                        #region xAsyncStateMachineType
                        var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                            xAsyncStateMachineTypeCandidate =>
                            {
                                // safety check 1

                                //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                if (xisIAsyncStateMachine)
                                {
                                    //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                    return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                }

                                return false;
                            }
                        );
                        #endregion


                        var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                        var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                        var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                        #region 1__state
                        xAsyncStateMachineType.GetFields(
                          System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                          ).WithEach(
                           AsyncStateMachineSourceField =>
                           {

                               //Console.WriteLine(new { AsyncStateMachineSourceField });

                               if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                               {
                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xShadowIAsyncStateMachine.state
                                    );
                               }

                               // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                               // field names/ tokens need to be encrypted like typeinfo.

                               // some do manual restore
                               // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                               // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                               // or, are we supposed to initialize a string value here?

                               var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                   f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                               );

                               if (xStringField != null)
                               {
                                   // once we are to go back to client. we need to reverse it?

                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xStringField.value
                                    );
                                   // next xml?
                                   // before lets send our strings back with the new state!
                                   // what about exceptions?
                               }
                           }
                      );
                        #endregion

                        NewStateMachineI.MoveNext();

                    };
                    #endregion


                    #region appwindow:HopToChromeApp
                    HopToChromeApp.VirtualOnCompleted = async (that, continuation) =>
                    {
                        // do we have the port to send back our portal warp?

                        // state 0 ? or state -1 ?
                        Console.WriteLine("appwindow HopToChromeApp VirtualOnCompleted enter " + new { appwindow_to_app });

                        //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        //// async dont like ref?
                        TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);
                        // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}
                        appwindow_to_app.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state });
                        // now send the jump instruction... will it make it?
                        appwindow_to_app.postMessage(r.shadowstate);
                    };
                    #endregion


                }
                else
                {
                    //Console.WriteLine("running as app");

                    // running as app {{ FullName = HybridHopToUDPChromeApp.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null }}
                    //Console.WriteLine("running as app " + new { typeof(Application).Assembly.FullName });

                    // running as app {{ Name = HybridHopToUDPChromeApp.Application }}
                    Console.WriteLine("running as app " + new { typeof(Application).Assembly.GetName().Name } + " now reenable extension..");


                    // called by?
                    #region app:appwindow_to_app
                    Action<object> appwindow_to_app = data =>
                    {
                        // what if its a string not a dictinary?

                        var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)data;

                        Console.WriteLine("app:appwindow_to_app " + new { xShadowIAsyncStateMachine.TypeName });

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150905/hoptoudpchromeapp
                        //13882ms app HopToChromeAppWindow MessageChannel onmessage {{ data = do HopToChromeAppWindow {{ TypeName = <Namespace>.___ctor_b__5_19_d, state = 2 }} }}
                        //view-source:54032 13883ms app appwindow_to_app {{ TypeName = null }}

                        #region xAsyncStateMachineType
                        var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                            xAsyncStateMachineTypeCandidate =>
                            {
                                // safety check 1

                                //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                if (xisIAsyncStateMachine)
                                {
                                    Console.WriteLine(new { xAsyncStateMachineTypeCandidate.FullName, xisIAsyncStateMachine });

                                    return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                }

                                return false;
                            }
                        );
                        #endregion

                        Console.WriteLine("app:appwindow_to_app " + new { xAsyncStateMachineType });

                        if (xAsyncStateMachineType == null)
                            Debugger.Break();



                        var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                        var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                        var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                        #region 1__state
                        xAsyncStateMachineType.GetFields(
                          System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                          ).WithEach(
                           AsyncStateMachineSourceField =>
                           {

                               //Console.WriteLine(new { AsyncStateMachineSourceField });

                               if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                               {
                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xShadowIAsyncStateMachine.state
                                    );
                               }

                               // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                               // field names/ tokens need to be encrypted like typeinfo.

                               // some do manual restore
                               // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                               // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                               // or, are we supposed to initialize a string value here?

                               var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                       f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                                   );

                               if (xStringField != null)
                               {
                                   // once we are to go back to client. we need to reverse it?

                                   AsyncStateMachineSourceField.SetValue(
                                           NewStateMachineI,
                                           xStringField.value
                                        );
                                   // next xml?
                                   // before lets send our strings back with the new state!
                                   // what about exceptions?
                               }
                           }
                      );
                        #endregion

                        NewStateMachineI.MoveNext();
                    };
                    #endregion


                    #region app:HopToChromeAppWindow
                    HopToChromeAppWindow.VirtualOnCompleted = async (that, continuation) =>
                    {
                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150824/webgliframebuffer

                        // state 0 ? or state -1 ?
                        Console.WriteLine("app HopToChromeAppWindow VirtualOnCompleted enter ");

                        #region outputWindow
                        if (that.window == null)
                        {
                            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow

                            if (outputWindow == null)
                            {
                                // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions
                                outputWindow = await chrome.app.window.create(
                                                       Native.document.location.pathname,

                                                       // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions
                                                       // this ctually works. but we wont see console on app log..
                                                       options: new { hidden = true, alwaysOnTop = true }
                                                );

                                ////xappwindow.setAlwaysOnTop

                                // or can we stay hidden?
                                //that.window.show();

                                await outputWindow.contentWindow.async.onload;
                            }
                            // reuse the window...
                            that.window = outputWindow;
                        }
                        #endregion


                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        // async dont like ref?
                        TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);
                        // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}



                        // Z:\jsc.svn\core\ScriptCoreLib\JavaScript\DOM\IWindow.postMessage.cs
                        // how do we use this thing?
                        var c = new MessageChannel();

                        c.port1.onmessage += e =>
                        {
                            //10818ms app HopToChromeAppWindow MessageChannel onmessage {{ data = do HopToChromeAppWindow {{ TypeName = <Namespace>.___ctor_b__5_19_d, state = 2 }} }}
                            //view-source:54032 10820ms app:appwindow_to_app {{ TypeName = null }}

                            if (e.data is string)
                            {
                                // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150905/hoptoudpchromeapp
                                Console.WriteLine("app   c.port1.onmessage: " + e.data);
                                return;
                            }

                            Console.WriteLine("app HopToChromeAppWindow MessageChannel onmessage " + new { e.data });

                            appwindow_to_app(e.data);
                        };

                        c.port1.start();
                        c.port2.start();


                        //                    15ms appwindow    Native.window.onmessage: {{ ports = [object MessagePort] }}
                        //2015-08-22 20:50:18.019 view-source:53702 17ms appwindow    Native.window.onmessage: {{ port = [object MessagePort] }}
                        that.window.contentWindow.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state }, transfer: c.port2);

                        // now send the jump instruction... will it make it?
                        that.window.contentWindow.postMessage(r.shadowstate);
                    };
                    #endregion




                    // called by?
                    #region app:ConnectExternal
                    chrome.runtime.ConnectExternal += port =>
                    {
                        // app chrome.runtime.ConnectExternal {{ name = , id = jadmeogmbokffpkdfeiemjplohfgkidd }}

                        //Console.WriteLine("app chrome.runtime.ConnectExternal " + new { port.name, port.sender.id });
                        Console.WriteLine("app chrome.runtime.ConnectExternal " + new { port.sender.id } + " now click launch!");

                        new chrome.Notification(title: "HybridHopToUDPChromeApp", message: "service connected. click launch").Clicked += delegate
                        {
                            // https://developer.chrome.com/apps/app_runtime

                            // management_api
                        };

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hybrid

                        // should we now be able to hop to our tab?
                        // what about if we are in an app window?

                        // called by?
                        port.onMessage.addListener(
                            new Action<object>(
                                (message) =>
                                {
                                    // extension  port.onMessage {{ message = from app hello to extension }}
                                    //var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString;

                                    // look app sent a message to extension
                                    //Console.WriteLine("app  port.onMessage " + new { message });


                                    // did we not fix jsc?
                                    if (message is string)
                                    {
                                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150905/hoptoudpchromeapp
                                        Console.WriteLine("app  port.onMessage: " + message);
                                        return;
                                    }

                                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp




                                    // casting from anonymous object.
                                    var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message;

                                    // or constructor id?
                                    Console.WriteLine("app  port.onMessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName });

                                    // 12468ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                                    //2015-08-22 15:49:45.729 view-source:53670 12471ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }}
                                    //2015-08-22 15:49:45.733 view-source:53670 12475ms extension  port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }}
                                    //2015-08-22 15:49:45.737 view-source:53670 12479ms extension  port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }}


                                    #region xAsyncStateMachineType
                                    var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                                        xAsyncStateMachineTypeCandidate =>
                                        {
                                            // safety check 1

                                            //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                            var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                            if (xisIAsyncStateMachine)
                                            {
                                                //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                                return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                            }

                                            return false;
                                        }
                                    );
                                    #endregion


                                    var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                                    var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                                    var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                                    #region 1__state
                                    xAsyncStateMachineType.GetFields(
                                      System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                                      ).WithEach(
                                       AsyncStateMachineSourceField =>
                                       {

                                           //Console.WriteLine(new { AsyncStateMachineSourceField });

                                           if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                                           {
                                               AsyncStateMachineSourceField.SetValue(
                                                   NewStateMachineI,
                                                   xShadowIAsyncStateMachine.state
                                                );
                                           }


                                           // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                                           // field names/ tokens need to be encrypted like typeinfo.

                                           // some do manual restore
                                           // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                                           // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                                           // or, are we supposed to initialize a string value here?

                                           var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                               f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                                           );

                                           if (xStringField != null)
                                           {
                                               // once we are to go back to client. we need to reverse it?

                                               AsyncStateMachineSourceField.SetValue(
                                                   NewStateMachineI,
                                                   xStringField.value
                                                );
                                               // next xml?
                                               // before lets send our strings back with the new state!
                                               // what about exceptions?
                                           }
                                       }
                                  );
                                    #endregion

                                    NewStateMachineI.MoveNext();
                                }
                            )
                        );



                        //port.postMessage(
                        //    new
                        //    {
                        //        text = "from app hello to extension"
                        //    }
                        //);

                        port.postMessage("from app hello to extension, click launch?");

                        // enable
                        //await default(HopToChromeExtension);

                        #region HopToChromeExtension
                        HopToChromeExtension.VirtualOnCompleted = async (that, continuation) =>
                        {
                            // state 0 ? or state -1 ?
                            Console.WriteLine("app HopToChromeExtension VirtualOnCompleted enter ");

                            // where is it defined?
                            // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\ShadowIAsyncStateMachine.cs

                            // async dont like ref?
                            TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);

                            // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}
                            port.postMessage("do HopToChromeExtension " + new { r.shadowstate.TypeName, r.shadowstate.state });


                            // now send the jump instruction... will it make it?
                            port.postMessage(r.shadowstate);


                            // how would we know to continue from current continuation?
                            // or are we fine to rebuild the scope if we jump back?
                        };
                        #endregion




                    };
                    #endregion

                    chrome.runtime.MessageExternal += (message, sender, sendResponse) =>
                    {
                        // was the extension able to pass us a message?

                        //Console.WriteLine("chrome.runtime.MessageExternal " + new { message, sender, sendResponse });
                        Console.WriteLine("app: chrome.runtime.MessageExternal " + new { message });

                        // app chrome.runtime.MessageExternal {{ message = extension to app! }}

                        // remember the connection to enable hop to extension?
                    };

                    //Action AtLaunch = delegate { };


                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150905/hoptoudpchromeapp
                    // jsc servicing compiler does it already let the apps know they need to reload?
                    #region  Launched
                    // can the extension launch us too?
                    // either the user launches by a click or we launch from extension?
                    chrome.app.runtime.Launched += async delegate
                    {
                        // state 0 ? or state -1 ?

                        Console.WriteLine("app: chrome.app.runtime.Launched before delay");

                        await Task.Delay(1);

                        Console.WriteLine("app: before HopToChromeAppWindow");

                        //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        // defined at?
                        await default(HopToChromeAppWindow);

                        // cant select ffs
                        (Native.body.style as dynamic).webkitUserSelect = "text";

                        Native.body.style.overflow = IStyle.OverflowEnum.auto;
                        Native.body.Clear();
                        chrome.app.window.current().show();
                        new IHTMLPre { "appwindow:  chrome.app.window.current().show();" }.AttachToDocument();

                        var NetworkList = await chrome.socket.getNetworkList();

                        //appwindow:  chrome.app.window.current().show();
                        //appwindow:  {{ prefixLength = 64, name = {5AE7FDA4-3FE5-42B2-905A-90962F983884}, address = 2001:7d0:8424:1f01:18fb:7bdf:54a7:e32 }}
                        //appwindow:  {{ prefixLength = 64, name = {5AE7FDA4-3FE5-42B2-905A-90962F983884}, address = fe80::18fb:7bdf:54a7:e32 }}
                        //appwindow:  {{ prefixLength = 24, name = {5AE7FDA4-3FE5-42B2-905A-90962F983884}, address = 192.168.1.13 }}
                        //appwindow:  {{ prefixLength = 64, name = {7F261BE1-E637-4E3E-B766-BD56F87515A5}, address = fe80::9cb1:846a:f8c0:ae4d }}
                        //appwindow:  {{ prefixLength = 16, name = {7F261BE1-E637-4E3E-B766-BD56F87515A5}, address = 169.254.174.77 }}
                        //appwindow:  {{ prefixLength = 64, name = {296E36A9-A4D6-4994-9496-69CCFD248303}, address = fe80::742a:74b2:f2a0:d632 }}
                        //appwindow:  {{ prefixLength = 16, name = {296E36A9-A4D6-4994-9496-69CCFD248303}, address = 169.254.214.50 }}
                        //appwindow:  {{ prefixLength = 64, name = {A588C792-795A-49EA-B7B7-FF2791BD0DDA}, address = fe80::b102:9f72:e61b:59b6 }}
                        //appwindow:  {{ prefixLength = 24, name = {A588C792-795A-49EA-B7B7-FF2791BD0DDA}, address = 192.168.81.1 }}

                        // should figure out which nics to broadcast to by default?

                        foreach (var item in NetworkList)
                        {
                            new IHTMLPre { "appwindow:  " + new { item.prefixLength, item.name, item.address } }.AttachToDocument();

                            // if we have multiple NICs broadcast em all?
                            // Z:\jsc.svn\examples\javascript\chrome\apps\ChromeAppWindowUDPPointerLock\ChromeAppWindowUDPPointerLock\Application.cs
                        }


                        Console.WriteLine("appwindow: appwindow to app");
                        await default(HopToChromeApp);
                        Console.WriteLine("app: appwindow to app");

                        // send intent over udp?


                    };
                    #endregion


                    chrome.runtime.Startup += async delegate
                    {
                        Console.WriteLine(@"app: chrome.runtime.Startup
                        // lets start listening for udp. as the other device may want to click launch and jump into us. 
                        ");

                        // Z:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPReceiveAsync\ChromeUDPReceiveAsync\Application.cs
                        // Z:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPFloats\ChromeUDPFloats\Application.cs

                        // can we run this on CLR too?
                        var socket = new UdpClient(40014);

                        //socket.Client.Bind(
                        //    //new IPEndPoint(IPAddress.Any, port: 40000)
                        //    new IPEndPoint(IPAddress.Any, port)
                        //);


                        // no port?
                        socket.JoinMulticastGroup(
                            IPAddress.Parse("239.1.2.3")
                        );

                        while (true)
                        {
                            Console.WriteLine(@"app: chrome.runtime.Startup await socket.ReceiveAsync");

                            // Z:\jsc.svn\examples\javascript\chrome\hybrid\HybridHopToUDPChromeApp\Application.cs

                            // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPNotification\ChromeUDPNotification\Application.cs
                            // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPNotification\ChromeUDPNotification\Application.cs
                            var s = await socket.ReceiveAsync();

                            Console.WriteLine($"app: recvFrom: {s.Buffer.Length}");

                        }
                    };

                    return;
                }
            }
            #endregion


            // running as regular web page?

            Console.WriteLine("running as content?");

            // were we loaded into chrome.app.window?


            //new IHTMLButton { "openDirectory" }.AttachToDocument().onclick += async delegate
            // {
            //     var dir = (DirectoryEntry)await chrome.fileSystem.chooseEntry(new { type = "openDirectory" });

            // };

        }
예제 #36
0
        public Application(IApp page)
        {
            // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeTabsExperiment\ChromeTabsExperiment\Application.cs
            Console.WriteLine("enter ChromeHybridCapture Application");


            dynamic self = Native.self;
            dynamic self_chrome = self.chrome;



            #region self_chrome_tabs extension
            object self_chrome_tabs = self_chrome.tabs;
            if (self_chrome_tabs != null)
            {
                // running as extension {{ FullName = <Namespace>.Application }}

                //Console.WriteLine("running as extension " + new { typeof(Application).FullName });
                //Console.WriteLine("running as extension " + new { typeof(Application).Assembly.FullName });

                // can we find and connect to app?
                Console.WriteLine("running as extension " + new { typeof(Application).Assembly.GetName().Name });

                //70ms chrome.management.getAll
                //2015-08-22 13:41:33.591 view-source:53670 98ms chrome.management.getAll {{ Length = 28 }}
                //2015-08-22 13:41:33.594 view-source:53670 101ms ExtensionInfo {{ id = aemlnmcokphbneegoefdckonejmknohh, name = ChromeHybridCapture }}
                //2015-08-22 13:41:33.597 view-source:53670 104ms ExtensionInfo {{ id = apdfllckaahabafndbhieahigkjlhalf, name = Google Drive }}
                //2015-08-22 13:41:33.599 view-source:53670 106ms ExtensionInfo {{ id = blpcfgokakmgnkcojhhkbfbldkacnbeo, name = YouTube }}
                //2015-08-22 13:41:33.602 view-source:53670 109ms ExtensionInfo {{ id = cgnjcccfcjhdnbfgjgllglbhfcgndmea, name = WebGLHZBlendCharacter }}
                //2015-08-22 13:41:33.604 view-source:53670 111ms ExtensionInfo {{ id = coobgpohoikkiipiblmjeljniedjpjpf, name = Google Search }}
                //2015-08-22 13:41:33.608 view-source:53670 114ms ExtensionInfo {{ id = fkgibadjpabiongmgoeomdbcefhabmah, name = ChromeCaptureToFile.Application.exe }}
                //2015-08-22 13:41:33.610 view-source:53670 117ms ExtensionInfo {{ id = ghbmnnjooekpmoecnnnilnnbdlolhkhi, name = Google Docs Offline }}
                //2015-08-22 13:41:33.612 view-source:53670 119ms ExtensionInfo {{ id = haebnnbpedcbhciplfhjjkbafijpncjl, name = TinEye Reverse Image Search }}
                //2015-08-22 13:41:33.614 view-source:53670 121ms ExtensionInfo {{ id = lchcahaldakdnjlkchkgncecgpcnabgo, name = Heat Zeeker }}
                //2015-08-22 13:41:33.616 view-source:53670 123ms ExtensionInfo {{ id = nhkcfbkpodjkallcfebgihcoglfaniep, name = freenode irc }}
                //2015-08-22 13:41:33.619 view-source:53670 126ms ExtensionInfo {{ id = ogmpedngmnolclkmlpcdgmfonlagkejp, name = Private Joe: Urban Warfare }}
                //2015-08-22 13:41:33.621 view-source:53670 128ms ExtensionInfo {{ id = pcklgpcdddecpmkiinpkhehanbijjepn, name = idea-remixer }}
                //2015-08-22 13:41:33.624 view-source:53670 131ms ExtensionInfo {{ id = pjkljhegncpnkpknbcohdijeoejaedia, name = Gmail }}
                //2015-08-22 13:41:33.626 view-source:53670 133ms ExtensionInfo {{ id = plgmlhohecdddhbmmkncjdmlhcmaachm, name = draw.io (Legacy) }}
                //2015-08-22 13:41:33.629 view-source:53670 136ms ExtensionInfo {{ id = aapbdbdomjkkjkaonfhkkikfgjllcleb, name = Google Translate }}
                //2015-08-22 13:41:33.631 view-source:53670 138ms ExtensionInfo {{ id = bcfddoencoiedfjgepnlhcpfikgaogdg, name = QR-Code Tag Extension }}
                //2015-08-22 13:41:33.633 view-source:53670 139ms ExtensionInfo {{ id = coblegoildgpecccijneplifmeghcgip, name = Web Cache }}
                //2015-08-22 13:41:33.635 view-source:53670 142ms ExtensionInfo {{ id = ganlifbpkcplnldliibcbegplfmcfigp, name = Collusion for Chrome }}
                //2015-08-22 13:41:33.638 view-source:53670 145ms ExtensionInfo {{ id = gighmmpiobklfepjocnamgkkbiglidom, name = AdBlock }}
                //2015-08-22 13:41:33.640 view-source:53670 147ms ExtensionInfo {{ id = iiabebggdceojiejhopnopmbkgandhha, name = Operation Heat Zeeker }}
                //2015-08-22 13:41:33.642 view-source:53670 149ms ExtensionInfo {{ id = jkgfnfnagdnjicmonpfhhdnkdjgjdamo, name = Avalon Spider Solitaire }}
                //2015-08-22 13:41:33.644 view-source:53670 151ms ExtensionInfo {{ id = kdifgkljkjhpflhalpkhehlldfakggdi, name = my.jsc-solutions.net }}
                //2015-08-22 13:41:33.646 view-source:53670 153ms ExtensionInfo {{ id = lmjegmlicamnimmfhcmpkclmigmmcbeh, name = Application Launcher for Drive (by Google) }}
                //2015-08-22 13:41:33.648 view-source:53670 155ms ExtensionInfo {{ id = mmfbcljfglbokpmkimbfghdkjmjhdgbg, name = Text }}
                //2015-08-22 13:41:33.650 view-source:53670 157ms ExtensionInfo {{ id = molncoemjfmpgdkbdlbjmhlcgniigdnf, name = Project Naptha }}
                //2015-08-22 13:41:33.652 view-source:53670 159ms ExtensionInfo {{ id = ogkcjmbhnfmlnielkjhedpcjomeaghda, name = WebGL Inspector }}
                //2015-08-22 13:41:33.653 view-source:53670 160ms ExtensionInfo {{ id = pkngagjebplcgimojegcakmnlggmcjlc, name = LBA Redux }}
                //2015-08-22 13:41:33.657 view-source:53670 164ms ExtensionInfo {{ id = ppmibgfeefcglejjlpeihfdimbkfbbnm, name = Change HTTP Request Header }}

                Action<string> __ChromeCaptureToFile_Application_sendMessage = delegate { };

                new { }.With(
                    async delegate
                    {
                        //  TypeError: chrome.management.getAll is not a function

                        Console.WriteLine("chrome.management.getAll");
                        var extensions = await chrome.management.getAll();

                        Console.WriteLine("chrome.management.getAll " + new { extensions.Length });
                        // https://developer.chrome.com/extensions/management#type-ExtensionInfo

                        //                        view - source:53670 69ms chrome.management.getAll
                        //2015 - 08 - 22 13:34:13.514 view - source:53670 89ms chrome.management.getAll { { Length = 28 } }
                        //                        2015 - 08 - 22 13:34:13.518 view - source:53670 93ms ExtensionInfo { { item = [object Object] } }

                        foreach (var item in extensions)
                        {
                            //Console.WriteLine("ExtensionInfo " + new { item });
                            //Console.WriteLine("ExtensionInfo " + new { item.id, item.name });

                            //2015-08-22 13:41:33.608 view-source:53670 114ms ExtensionInfo {{ id = fkgibadjpabiongmgoeomdbcefhabmah, name = ChromeCaptureToFile.Application.exe }}

                            // typeof(self) ?
                            if (item.name.StartsWith(typeof(Application).Assembly.GetName().Name))
                            {
                                var __item = item;

                                // we will also know when it reloads? we have to reconnect then?

                                __ChromeCaptureToFile_Application_sendMessage = message =>
                                {
                                    Console.WriteLine("extension chrome.runtime.sendMessage " + new { message, __item.id, __item.name });

                                    chrome.runtime.sendMessage(item.id, message, null);
                                };

                                chrome.runtime.sendMessage(item.id, "extension to app!", null);


                                // extension chrome.runtime.connect done {{ name = , sender = null }}
                                chrome.runtime.connect(item.id).With(
                                    port =>
                                    {
                                        //Console.WriteLine("extension chrome.runtime.connect done " + new { port.name, port.sender.id });
                                        //Console.WriteLine("extension chrome.runtime.connect done " + new { port.name, port.sender });
                                        Console.WriteLine("extension chrome.runtime.connect done");




                                        #region extension: HopToChromeApp.VirtualOnCompleted
                                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp
                                        HopToChromeApp.VirtualOnCompleted = async (that, continuation) =>
                                       {
                                           // state 0 ? or state -1 ?
                                           Console.WriteLine("extension HopToChromeApp VirtualOnCompleted enter ");

                                           TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);

                                           // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}
                                           port.postMessage("do HopToChromeApp " + new { r.shadowstate.TypeName, r.shadowstate.state });


                                           // now send the jump instruction... will it make it?
                                           port.postMessage(r.shadowstate);
                                       };
                                        #endregion




                                        // is the app now able to send extension messages?

                                        port.onMessage.addListener(
                                            new Action<object>(
                                                (message) =>
                                                {
                                                    // 4847ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}



                                                    // extension  port.onMessage {{ message = from app hello to extension }}
                                                    // extension  port.onMessage {{ message = [object Object] }}

                                                    // look app sent a message to extension

                                                    // 191ms extension  port.onMessage {{ message = from app hello to extension, is_string = false, equals_typeofstring = false }}

                                                    // 219ms extension  port.onMessage {{ message = from app hello to extension, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                                                    //var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString;

                                                    // roslyn? wtf
                                                    //var is_string = message is string;
                                                    //var equals_typeofstring = message.GetType() == typeof(string);

                                                    //Console.WriteLine("extension  port.onMessage " + new { expando_isstring, is_string, equals_typeofstring });

                                                    // extension  port.onMessage {{ state = null, TypeName = null }}
                                                    if (message is string)
                                                    {
                                                        Console.WriteLine("extension  port.onMessage: " + message);

                                                        // Z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\ShadowIAsyncStateMachine.cs
                                                        return;
                                                    }


                                                    #region IAsyncStateMachine
                                                    // casting from anonymous object.
                                                    var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message;

                                                    // or constructor id?
                                                    Console.WriteLine("extension  port.onMessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName });

                                                    // 12468ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                                                    //2015-08-22 15:49:45.729 view-source:53670 12471ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }}
                                                    //2015-08-22 15:49:45.733 view-source:53670 12475ms extension  port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }}
                                                    //2015-08-22 15:49:45.737 view-source:53670 12479ms extension  port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }}


                                                    #region xAsyncStateMachineType
                                                    var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                                                        xAsyncStateMachineTypeCandidate =>
                                                        {
                                                            // safety check 1

                                                            //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                                            var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                                            if (xisIAsyncStateMachine)
                                                            {
                                                                //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                                                return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                                            }

                                                            return false;
                                                        }
                                                    );
                                                    #endregion


                                                    var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                                                    var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                                                    var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                                                    #region 1__state
                                                    xAsyncStateMachineType.GetFields(
                                                      System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                                                      ).WithEach(
                                                       AsyncStateMachineSourceField =>
                                                       {

                                                           //Console.WriteLine(new { AsyncStateMachineSourceField });

                                                           if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                                                           {
                                                               AsyncStateMachineSourceField.SetValue(
                                                                   NewStateMachineI,
                                                                   xShadowIAsyncStateMachine.state
                                                                );
                                                           }


                                                       }
                                                  );
                                                    #endregion

                                                    NewStateMachineI.MoveNext();
                                                    #endregion

                                                }
                                            )
                                        );



                                        //chrome.tabs.Created += async tab =>
                                        //{
                                        //    port.postMessage("chrome.tabs.Created " + new { tab });

                                        //};

                                        //chrome.tabs.Updated += async (tabId, x, tab) =>
                                        //{
                                        //    //  Updated {{ i = 0, x = null, tab = null }}

                                        //    port.postMessage("chrome.tabs.Updated  " + new { tabId, x, tab });


                                        //};
                                    }
                                );
                            }
                        }

                    }
                    );

                //chrome.tabs.Created += async tab =>
                //{
                //    Console.WriteLine("chrome.tabs.Created " + new { tab });

                //};

                //chrome.tabs.Updated += async (tabId, x, tab) =>
                //{
                //    //  Updated {{ i = 0, x = null, tab = null }}

                //    Console.WriteLine("chrome.tabs.Updated  " + new { tabId, x, tab });


                //};



                return;
            }
            #endregion


            #region self_chrome_socket app
            object self_chrome_socket = self_chrome.socket;

            if (self_chrome_socket != null)
            {
                if (!(Native.window.opener == null && Native.window.parent == Native.window.self))
                {
                    Console.WriteLine("appwindow chrome.app.window.create, is that you?");

                    MessagePort appwindow_to_app = null;

                    // called by? 619  app:HopToChromeAppWindow
                    #region  appwindow Native.window.onmessage
                    Native.window.onmessage += e =>
                    {
                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow

                        // appwindow Native.window.onmessage {{ data = app to appwindow! }}

                        var message = e.data;

                        //Console.WriteLine("appwindow Native.window.onmessage " + new { e.data });


                        // extension  port.onMessage {{ message = from app hello to extension }}
                        //var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString;

                        // look app sent a message to extension
                        //Console.WriteLine("app  port.onMessage " + new { message });

                        if (message is string)
                        {
                            Console.WriteLine("appwindow    Native.window.onmessage: " + message);
                            //Console.WriteLine("appwindow    Native.window.onmessage: " + new { e.ports });

                            if (e.ports != null)
                                foreach (var port in e.ports)
                                {
                                    Console.WriteLine("appwindow    Native.window.onmessage " + new { port });

                                    appwindow_to_app = port;
                                }

                            //e.po

                            return;
                        }

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp




                        // casting from anonymous object.
                        var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message;

                        // or constructor id?
                        Console.WriteLine("appwindow     Native.window.onmessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName });

                        // 12468ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                        //2015-08-22 15:49:45.729 view-source:53670 12471ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }}
                        //2015-08-22 15:49:45.733 view-source:53670 12475ms extension  port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }}
                        //2015-08-22 15:49:45.737 view-source:53670 12479ms extension  port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }}


                        #region xAsyncStateMachineType
                        var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                            xAsyncStateMachineTypeCandidate =>
                            {
                                // safety check 1

                                //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                if (xisIAsyncStateMachine)
                                {
                                    //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                    return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                }

                                return false;
                            }
                        );
                        #endregion


                        var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                        var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                        var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                        #region 1__state
                        xAsyncStateMachineType.GetFields(
                          System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                          ).WithEach(
                           AsyncStateMachineSourceField =>
                           {

                               //Console.WriteLine(new { AsyncStateMachineSourceField });

                               if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                               {
                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xShadowIAsyncStateMachine.state
                                    );
                               }

                               // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                               // field names/ tokens need to be encrypted like typeinfo.

                               // some do manual restore
                               // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                               // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                               // or, are we supposed to initialize a string value here?

                               var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                   f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                               );

                               if (xStringField != null)
                               {
                                   // once we are to go back to client. we need to reverse it?

                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xStringField.value
                                    );
                                   // next xml?
                                   // before lets send our strings back with the new state!
                                   // what about exceptions?
                               }
                           }
                      );
                        #endregion

                        NewStateMachineI.MoveNext();

                    };
                    #endregion


                    #region appwindow:HopToChromeApp
                    HopToChromeApp.VirtualOnCompleted = async (that, continuation) =>
                    {
                        // do we have the port to send back our portal warp?

                        // state 0 ? or state -1 ?
                        Console.WriteLine("appwindow HopToChromeApp VirtualOnCompleted enter " + new { appwindow_to_app });

                        //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        //// async dont like ref?
                        TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);
                        // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}
                        appwindow_to_app.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state });
                        // now send the jump instruction... will it make it?
                        appwindow_to_app.postMessage(r.shadowstate);
                    };
                    #endregion


                }
                else
                {
                    //Console.WriteLine("running as app");

                    // running as app {{ FullName = ChromeHybridCapture.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null }}
                    //Console.WriteLine("running as app " + new { typeof(Application).Assembly.FullName });

                    // running as app {{ Name = ChromeHybridCapture.Application }}
                    Console.WriteLine("running as app " + new { typeof(Application).Assembly.GetName().Name } + " now reenable extension..");


                    #region app:appwindow_to_app
                    Action<object> appwindow_to_app = data =>
                    {
                        var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)data;

                        Console.WriteLine("app appwindow_to_app " + new { xShadowIAsyncStateMachine.TypeName });

                        #region xAsyncStateMachineType
                        var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                            xAsyncStateMachineTypeCandidate =>
                            {
                                // safety check 1

                                //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                if (xisIAsyncStateMachine)
                                {
                                    //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                    return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                }

                                return false;
                            }
                        );
                        #endregion

                        Console.WriteLine("app appwindow_to_app " + new { xAsyncStateMachineType });

                        var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                        var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                        var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                        #region 1__state
                        xAsyncStateMachineType.GetFields(
                          System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                          ).WithEach(
                           AsyncStateMachineSourceField =>
                           {

                               //Console.WriteLine(new { AsyncStateMachineSourceField });

                               if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                               {
                                   AsyncStateMachineSourceField.SetValue(
                                       NewStateMachineI,
                                       xShadowIAsyncStateMachine.state
                                    );
                               }

                               // X:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                               // field names/ tokens need to be encrypted like typeinfo.

                               // some do manual restore
                               // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                               // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                               // or, are we supposed to initialize a string value here?

                               var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                       f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                                   );

                               if (xStringField != null)
                               {
                                   // once we are to go back to client. we need to reverse it?

                                   AsyncStateMachineSourceField.SetValue(
                                           NewStateMachineI,
                                           xStringField.value
                                        );
                                   // next xml?
                                   // before lets send our strings back with the new state!
                                   // what about exceptions?
                               }
                           }
                      );
                        #endregion

                        NewStateMachineI.MoveNext();
                    };
                    #endregion


                    #region app:HopToChromeAppWindow
                    HopToChromeAppWindow.VirtualOnCompleted = async (that, continuation) =>
                    {
                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150824/webgliframebuffer

                        // state 0 ? or state -1 ?
                        Console.WriteLine("app HopToChromeAppWindow VirtualOnCompleted enter ");

                        #region outputWindow
                        if (that.window == null)
                        {
                            // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow

                            if (outputWindow == null)
                            {
                                // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions
                                outputWindow = await chrome.app.window.create(
                                                       Native.document.location.pathname,

                                                       // https://developer.chrome.com/apps/app_window#type-CreateWindowOptions
                                                       // this ctually works. but we wont see console on app log..
                                                       options: new { hidden = true, alwaysOnTop = true }
                                                );

                                ////xappwindow.setAlwaysOnTop

                                // or can we stay hidden?
                                //that.window.show();

                                await outputWindow.contentWindow.async.onload;
                            }
                            // reuse the window...
                            that.window = outputWindow;
                        }
                        #endregion


                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        // async dont like ref?
                        TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);
                        // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}



                        // Z:\jsc.svn\core\ScriptCoreLib\JavaScript\DOM\IWindow.postMessage.cs
                        // how do we use this thing?
                        var c = new MessageChannel();

                        c.port1.onmessage += e =>
                        {
                            Console.WriteLine("app HopToChromeAppWindow MessageChannel onmessage " + new { e.data });

                            appwindow_to_app(e.data);
                        };

                        c.port1.start();
                        c.port2.start();


                        //                    15ms appwindow    Native.window.onmessage: {{ ports = [object MessagePort] }}
                        //2015-08-22 20:50:18.019 view-source:53702 17ms appwindow    Native.window.onmessage: {{ port = [object MessagePort] }}
                        that.window.contentWindow.postMessage("do HopToChromeAppWindow " + new { r.shadowstate.TypeName, r.shadowstate.state }, transfer: c.port2);

                        // now send the jump instruction... will it make it?
                        that.window.contentWindow.postMessage(r.shadowstate);
                    };
                    #endregion





                    #region app:ConnectExternal
                    chrome.runtime.ConnectExternal += port =>
                    {
                        // app chrome.runtime.ConnectExternal {{ name = , id = jadmeogmbokffpkdfeiemjplohfgkidd }}

                        //Console.WriteLine("app chrome.runtime.ConnectExternal " + new { port.name, port.sender.id });
                        Console.WriteLine("app chrome.runtime.ConnectExternal " + new { port.sender.id } + " now click launch!");

                        new chrome.Notification(title: "ChromeHybridCapture", message: "service connected. click launch").Clicked += delegate
                        {
                            // https://developer.chrome.com/apps/app_runtime

                            // management_api
                        };

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hybrid

                        // should we now be able to hop to our tab?
                        // what about if we are in an app window?

                        port.onMessage.addListener(
                            new Action<object>(
                                (message) =>
                                {
                                    // extension  port.onMessage {{ message = from app hello to extension }}
                                    var expando_isstring = ScriptCoreLib.JavaScript.Runtime.Expando.Of(message).IsString;

                                    // look app sent a message to extension
                                    //Console.WriteLine("app  port.onMessage " + new { message });

                                    if (expando_isstring)
                                    {
                                        Console.WriteLine("app  port.onMessage: " + message);
                                        return;
                                    }


                                    #region IAsyncStateMachine
                                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp
                                    // casting from anonymous object.
                                    var xShadowIAsyncStateMachine = (TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine)message;

                                    // or constructor id?
                                    Console.WriteLine("app  port.onMessage " + new { xShadowIAsyncStateMachine.state, xShadowIAsyncStateMachine.TypeName });

                                    // 12468ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }}, expando_isstring = true, is_string = false, equals_typeofstring = false }}
                                    //2015-08-22 15:49:45.729 view-source:53670 12471ms extension  port.onMessage {{ message = do HopToChromeExtension {{ TypeName = <Namespace>.___ctor_b__4_9_d, state = 0 }} }}
                                    //2015-08-22 15:49:45.733 view-source:53670 12475ms extension  port.onMessage {{ message = [object Object], expando_isstring = false, is_string = false, equals_typeofstring = false }}
                                    //2015-08-22 15:49:45.737 view-source:53670 12479ms extension  port.onMessage {{ state = 0, TypeName = <Namespace>.___ctor_b__4_9_d }}


                                    #region xAsyncStateMachineType
                                    var xAsyncStateMachineType = typeof(Application).Assembly.GetTypes().FirstOrDefault(
                                        xAsyncStateMachineTypeCandidate =>
                                        {
                                            // safety check 1

                                            //Console.WriteLine(new { sw.ElapsedMilliseconds, item.FullName });

                                            var xisIAsyncStateMachine = typeof(IAsyncStateMachine).IsAssignableFrom(xAsyncStateMachineTypeCandidate);
                                            if (xisIAsyncStateMachine)
                                            {
                                                //Console.WriteLine(new { item.FullName, isIAsyncStateMachine });

                                                return xAsyncStateMachineTypeCandidate.FullName == xShadowIAsyncStateMachine.TypeName;
                                            }

                                            return false;
                                        }
                                    );
                                    #endregion


                                    var NewStateMachine = FormatterServices.GetUninitializedObject(xAsyncStateMachineType);
                                    var isIAsyncStateMachine = NewStateMachine is IAsyncStateMachine;

                                    var NewStateMachineI = (IAsyncStateMachine)NewStateMachine;

                                    #region 1__state
                                    xAsyncStateMachineType.GetFields(
                                      System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                                      ).WithEach(
                                       AsyncStateMachineSourceField =>
                                       {

                                           //Console.WriteLine(new { AsyncStateMachineSourceField });

                                           if (AsyncStateMachineSourceField.Name.EndsWith("1__state"))
                                           {
                                               AsyncStateMachineSourceField.SetValue(
                                                   NewStateMachineI,
                                                   xShadowIAsyncStateMachine.state
                                                );
                                           }


                                           // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\CLRWebServiceInvoke.cs
                                           // field names/ tokens need to be encrypted like typeinfo.

                                           // some do manual restore
                                           // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTabThenIFrame\ChromeExtensionHopToTabThenIFrame\Application.cs
                                           // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                                           // or, are we supposed to initialize a string value here?

                                           var xStringField = TestSwitchToServiceContextAsync.ArrayListExtensions.AsEnumerable(xShadowIAsyncStateMachine.StringFields).FirstOrDefault(
                                               f => DecoratedString(f.FieldName) == DecoratedString(AsyncStateMachineSourceField.Name)
                                           );

                                           if (xStringField != null)
                                           {
                                               // once we are to go back to client. we need to reverse it?

                                               AsyncStateMachineSourceField.SetValue(
                                                   NewStateMachineI,
                                                   xStringField.value
                                                );
                                               // next xml?
                                               // before lets send our strings back with the new state!
                                               // what about exceptions?
                                           }
                                       }
                                  );
                                    #endregion

                                    NewStateMachineI.MoveNext();
                                    #endregion
                                }
                            )
                        );



                        //port.postMessage(
                        //    new
                        //    {
                        //        text = "from app hello to extension"
                        //    }
                        //);

                        port.postMessage("from app hello to extension, click launch?");

                        // enable
                        //await default(HopToChromeExtension);

                        #region HopToChromeExtension
                        HopToChromeExtension.VirtualOnCompleted = async (that, continuation) =>
                        {
                            // state 0 ? or state -1 ?
                            Console.WriteLine("app HopToChromeExtension VirtualOnCompleted enter ");

                            // where is it defined?
                            // z:\jsc.svn\examples\javascript\async\Test\TestSwitchToServiceContextAsync\TestSwitchToServiceContextAsync\ShadowIAsyncStateMachine.cs

                            // async dont like ref?
                            TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableContinuation r = TestSwitchToServiceContextAsync.ShadowIAsyncStateMachine.ResumeableFromContinuation(continuation);

                            // 29035ms extension  port.onMessage {{ message = do HopToChromeExtension }}
                            port.postMessage("do HopToChromeExtension " + new { r.shadowstate.TypeName, r.shadowstate.state });


                            // now send the jump instruction... will it make it?
                            port.postMessage(r.shadowstate);


                            // how would we know to continue from current continuation?
                            // or are we fine to rebuild the scope if we jump back?
                        };
                        #endregion




                    };
                    #endregion

                    chrome.runtime.MessageExternal += (message, sender, sendResponse) =>
                    {
                        // was the extension able to pass us a message?

                        //Console.WriteLine("chrome.runtime.MessageExternal " + new { message, sender, sendResponse });
                        Console.WriteLine("app chrome.runtime.MessageExternal " + new { message });

                        // app chrome.runtime.MessageExternal {{ message = extension to app! }}

                        // remember the connection to enable hop to extension?
                    };

                    //Action AtLaunch = delegate { };

                    #region  Launched
                    // can the extension launch us too?
                    // either the user launches by a click or we launch from extension?
                    chrome.app.runtime.Launched += async delegate
                    {
                        // state 0 ? or state -1 ?

                        Console.WriteLine("app chrome.app.runtime.Launched before delay");

                        await Task.Delay(1);

                        nexttake:
                        //Console.WriteLine("nexttake " + new { index });
                        Console.WriteLine("nexttake");

                        // using IDisposable ?
                        await default(HopToChromeExtension);

                        #region HopToChromeExtension
                        // now this would be cool if it worked?
                        Console.WriteLine("app to extension chrome.app.runtime.Launched, only state was sent over?");

                        // can we do our thing and jump back with the capture now?

                        // lets create a tab for us to jump into..
                        //var tab = await chrome.tabs.create(new { url = "http://example.com" });

                        // https://developer.chrome.com/extensions/activeTab

                        // implict/auto context hop?
                        var tabsw = Stopwatch.StartNew();

                        // which window station?
                        var tabwindow = await chrome.windows.create(new { state = "fullscreen", url = "http://www.flightradar24.com/59.15,23.86/9" });
                        //var tabwindow = await chrome.windows.create(new { state = "fullscreen", url = "http://example.com" });

                        //var tab = await chrome.tabs.create(new { url = "http://www.flightradar24.com/59.05,24.14/8" });
                        // would we need to hop into the tab to inspec data?
                        Console.WriteLine("extension chrome.tabs.create done. about to capture... " + new { tabsw.ElapsedMilliseconds });


                        // how do we know a tab is loaded?
                        // content takes a while to load doesnt it...
                        await Task.Delay(7000);

                        // Error: Invocation of form tabs.captureVisibleTab(object, null, function) doesn't match definition tabs.captureVisibleTab(optional integer windowId, optional object options, function callback)

                        //var captureVisibleTab = await tab.windowId.captureVisibleTab(null);

                        // Unchecked runtime.lastError while running tabs.captureVisibleTab: Failed to capture tab: unknown error

                        retry_captureVisibleTab:
                        var captureVisibleTab = await tabwindow.id.captureVisibleTab(options: new { format = "png" });


                        if (captureVisibleTab == null)
                        {
                            await Task.Delay(500);
                            Console.WriteLine("extension chrome.tabs.create done. about to capture... error");
                            goto retry_captureVisibleTab;
                        }

                        // extension captureVisibleTab {{ Length = 47743 }}
                        Console.WriteLine("extension captureVisibleTab " + new { captureVisibleTab.Length });

                        await Task.Delay(500);

                        // or just unload the window?
                        //await tab.id.remove();
                        await tabwindow.id.remove();


                        Console.WriteLine("extension to app chrome.tabs.create removed, jump back?");
                        #endregion

                        await default(HopToChromeApp);

                        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeapp
                        Console.WriteLine("extension to app chrome.tabs.create removed, jump back done! did the strings make it?");
                        if (captureVisibleTab == null)
                            Console.WriteLine("app chrome.tabs.create removed, jump back done! did the strings make it? no");
                        else
                            Console.WriteLine("app chrome.tabs.create removed, jump back done! did the strings make it? yes " + new { captureVisibleTab.Length });



                        Console.WriteLine("app chrome.fileSystem.chooseEntry");

                        // not available in background?
                        // TypeError: Cannot read property 'chooseEntry' of undefined
                        // Unchecked runtime.lastError while running fileSystem.chooseEntry: Invalid calling page. This function can't be called from a background page.
                        //var dir = (DirectoryEntry)await chrome.fileSystem.chooseEntry(new { type = "openDirectory" });

                        // can we jump to extension to open our tab?



                        //// https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150822/hoptochromeappwindow
                        // defined at?
                        await default(HopToChromeAppWindow);

                        #region HopToChromeAppWindow
                        if (captureVisibleTab == null)
                            Console.WriteLine("appwindow chrome.tabs.create removed, jump back done! did the strings make it? no");
                        else
                            Console.WriteLine("appwindow chrome.tabs.create removed, jump back done! did the strings make it? yes " + new { captureVisibleTab.Length });


                        // 182ms appwindow chrome.fileSystem.chooseEntry
                        Console.WriteLine("appwindow chrome.fileSystem.chooseEntry");

                        // Unchecked runtime.lastError while running fileSystem.chooseEntry: User cancelled

                        Native.body.style.overflow = IStyle.OverflowEnum.auto;
                        Native.body.Clear();

                        chrome.app.window.current().show();

                        var icaptureVisibleTabFull = await new IHTMLImage { src = captureVisibleTab }.async.oncomplete;
                        ;

                        // 200, 80
                        // 1600, 880

                        // 1920x1080
                        var focusw = icaptureVisibleTabFull.width - 320;
                        var focush = icaptureVisibleTabFull.height - 200;

                        new IHTMLPre { new { focusw, focush } }.AttachToDocument();

                        var focus = new CanvasRenderingContext2D(focusw, focush);

                        focus.drawImage(icaptureVisibleTabFull, 200, 80, focusw, focush, 0, 0, focusw, focush);



                        // this is a thumbnail
                        var icaptureVisibleTab = new IHTMLImage { src = captureVisibleTab }.AttachToDocument();

                        new IStyle(icaptureVisibleTab)
                        {
                            width = "120px",
                            border = "1px dashed blue"
                        };



                        Native.document.documentElement.style.overflow = IStyle.OverflowEnum.auto;

                        if (dir == null)
                        {
                            await new IHTMLButton { "openDirectory" }.AttachToDocument().async.onclick;

                            dir = (DirectoryEntry)await chrome.fileSystem.chooseEntry(new { type = "openDirectory" });
                        }

                        var file = index.ToString().PadLeft(5, '0') + ".png";

                        new IHTMLPre { "WriteAllBytes... " + new { file } }.AttachToDocument();

                        //await dir.WriteAllBytes("0001.png", icaptureVisibleTabFull);

                        // chrome://blob-internals/
                        // those blobs wont go away...
                        // GC kicks in at 36 it seems.
                        await dir.WriteAllBytes(file, focus);
                        focus = null;

                        //                        [Window Title]
                        //Location is not available

                        //[Content]
                        //R:\ is not accessible.

                        //Logon failure: unknown user name or bad password.


                        //[OK]

                        //                        ---------------------------
                        //                        Restoring Network Connections
                        //---------------------------
                        //An error occurred while reconnecting R:
                        //                            to
                        //\\192.168.1.12\x$
                        //Microsoft Windows Network: The local device name is already in use.


                        //This connection has not been restored.
                        //---------------------------
                        //OK
                        //-------------------------- -


                        new IHTMLPre { "WriteAllBytes... done " + new { file } }.AttachToDocument();

                        index++;
                        #endregion




                        //Console.WriteLine("app chrome.app.window content loaded!");


                        //Console.WriteLine("app chrome.app.runtime.Launched ready to exit");
                        //await Task.Delay(3000);

                        //// wont work?
                        //w.close();

                        ////1343ms app chrome.runtime.MessageExternal {{ message = extension to app! }}
                        ////2015-08-22 15:18:44.738 view-source:53670 1357ms app chrome.runtime.ConnectExternal {{ id = jadmeogmbokffpkdfeiemjplohfgkidd }}
                        ////2015-08-22 15:18:52.314 view-source:53670 8933ms app chrome.app.runtime.Launched
                        ////2015-08-22 15:18:52.342 view-source:53670 8961ms app chrome.app.runtime.Launched exit
                        ////2015-08-22 15:18:52.348 view-source:53670 8967ms app  port.onMessage {{ message = chrome.tabs.Created {{ tab = [object Object] }} }}
                        ////2015-08-22 15:18:52.652 view-source:53670 9271ms app  port.onMessage {{ message = chrome.tabs.Updated  {{ tabId = 419, x = [object Object], tab = [object Object] }} }}
                        ////2015-08-22 15:18:52.690 view-source:53670 9308ms app  port.onMessage {{ message = chrome.tabs.Updated  {{ tabId = 419, x = [object Object], tab = [object Object] }} }}

                        //Console.WriteLine("app chrome.app.runtime.Launched exit");


                        // or tcp?
                        //await new IHTMLButton { "next take" }.AttachToDocument().async.onclick;


                        // var countdown = Stopwatch.StartNew();

                        //Error CS1929  'int' does not contain a definition for 'GetAwaiter' and the best extension method overload 'IXMLHttpRequestAsyncExtensions.GetAwaiter(IXMLHttpRequest)' requires a receiver of type 'IXMLHttpRequest'  ChromeHybridCapture Z:\jsc.svn\examples\javascript\chrome\hybrid\ChromeHybridCapture\ChromeHybridCapture\Application.cs 1141    IntelliSense

                        // script: error JSC1000: No implementation found for this native method, please implement [static System.TimeSpan.op_Subtraction(System.TimeSpan, System.TimeSpan)]

                        // TypeError: Cannot set property 'countdown' of null

                        //  Cannot set property 'sw' of null
                        countdown = Stopwatch.StartNew();

                        new IHTMLPre { () => "close to abort... " + countdown.ElapsedMilliseconds }.AttachToDocument();

                        // GC?
                        await Task.Delay(2000);

                        //await Task.WhenAny(
                        //      new IHTMLButton {
                        //          "click next take or wait "
                        //      }.AttachToDocument().async.onclick,
                        //      Task.Delay(1000)
                        //  );


                        //await
                        //  new IHTMLButton {
                        //          "click next take "
                        //  }.AttachToDocument().async.onclick;


                        new IHTMLPre { "preparing..." }.AttachToDocument();

                        Console.WriteLine("appwindow: appwindow to app");

                        await default(HopToChromeApp);

                        Console.WriteLine("app: appwindow to app");

                        goto nexttake;



                    };
                    #endregion


                    return;
                }
            }
            #endregion


            // running as regular web page?

            Console.WriteLine("running as content?");

            // were we loaded into chrome.app.window?


            //new IHTMLButton { "openDirectory" }.AttachToDocument().onclick += async delegate
            // {
            //     var dir = (DirectoryEntry)await chrome.fileSystem.chooseEntry(new { type = "openDirectory" });

            // };

        }
 public static void Main()
 {
     AppWindow window = new AppWindow();
     window.Run(60);
 }
예제 #38
0
        private void ActivateAndFocusMainWindow()
        {
            // What happens below looks a bit weird, but for Switcheroo to get focus when using the Alt+Tab hook,
            // it is needed to simulate an Alt keypress will bring Switcheroo to the foreground. Otherwise Switcheroo
            // will become the foreground window, but the previous window will retain focus, and receive keep getting
            // the keyboard input.
            // http://www.codeproject.com/Tips/76427/How-to-bring-window-to-top-with-SetForegroundWindo

            var thisWindowHandle = new WindowInteropHelper(this).Handle;
            var thisWindow = new AppWindow(thisWindowHandle);

            var altKey = new KeyboardKey(Keys.Alt);
            var altKeyPressed = false;

            // Press the Alt key if it is not already being pressed
            if ((altKey.AsyncState & 0x8000) == 0)
            {
                altKey.Press();
                altKeyPressed = true;
            }

            // Bring the Switcheroo window to the foreground
            Show();
            SystemWindow.ForegroundWindow = thisWindow;
            Activate();

            // Release the Alt key if it was pressed above
            if (altKeyPressed)
            {
                altKey.Release();
            }
        }