Exemple #1
0
        private void InitControls()
        {
            ToolTipService.SetToolTip(ExitCompactOverlayButton, _resourceLoader.GetString("App_ExitCompactOverlayMode_Text"));
            RootSplitView.PaneOpening += delegate { SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo()); };
            RootSplitView.PaneClosed  += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            NewSetButton.Click        += delegate { NotepadsCore.OpenNewTextEditor(); };
            MainMenuButton.Click      += (sender, args) => FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
            MenuCreateNewButton.Click += (sender, args) => NotepadsCore.OpenNewTextEditor();
            MenuOpenFileButton.Click  += async(sender, args) => await OpenNewFiles();

            MenuSaveButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : false);

            MenuSaveAsButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : true);

            MenuSaveAllButton.Click += async(sender, args) => { foreach (var textEditor in NotepadsCore.GetAllTextEditors())
                                                                {
                                                                    await Save(textEditor, saveAs : false, ignoreUnmodifiedDocument : true);
                                                                }
            };
            MenuFindButton.Click           += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: false);
            MenuReplaceButton.Click        += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: true);
            MenuFullScreenButton.Click     += (sender, args) => EnterExitFullScreenMode();
            MenuCompactOverlayButton.Click += (sender, args) => EnterExitCompactOverlayMode();
            MenuSettingsButton.Click       += (sender, args) => RootSplitView.IsPaneOpen = true;

            MainMenuButtonFlyout.Opening += (sender, o) =>
            {
                var selectedTextEditor = NotepadsCore.GetSelectedTextEditor();
                if (selectedTextEditor == null)
                {
                    MenuSaveButton.IsEnabled    = false;
                    MenuSaveAsButton.IsEnabled  = false;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                    //MenuPrintButton.IsEnabled = false;
                }
                else if (selectedTextEditor.IsEditorEnabled() == false)
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                    //MenuPrintButton.IsEnabled = true;
                }
                else
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = true;
                    MenuReplaceButton.IsEnabled = true;
                    //MenuPrintButton.IsEnabled = true;
                }

                MenuFullScreenButton.Text = _resourceLoader.GetString(ApplicationView.GetForCurrentView().IsFullScreenMode ?
                                                                      "App_ExitFullScreenMode_Text" : "App_EnterFullScreenMode_Text");
                MenuCompactOverlayButton.Text = _resourceLoader.GetString(ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.CompactOverlay ?
                                                                          "App_ExitCompactOverlayMode_Text" : "App_EnterCompactOverlayMode_Text");
                MenuSaveAllButton.IsEnabled = NotepadsCore.HaveUnsavedTextEditor();
            };
        }
Exemple #2
0
        /// <summary>
        /// Writes the SETTINGS frame.
        /// </summary>
        /// <param name="settings">The settings pairs.</param>
        /// <param name="isAck">The ACK flag.</param>
        public void WriteSettings(SettingsPair[] settings, bool isAck)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            var frame = new SettingsFrame(new List <SettingsPair>(settings), isAck);

            Http2Logger.LogDebug("Sending SETTINGS frame: stream id={0}, payload len={1}, is ack={2}, count={3}",
                                 frame.StreamId, frame.PayloadLength, frame.IsAck, frame.EntryCount);

            foreach (var s in settings)
            {
                Http2Logger.LogDebug("{0}: {1}", s.Id.ToString(), s.Value);
            }

            _writeQueue.WriteFrame(frame);

            if (!isAck && !_settingsAckReceived.WaitOne(60000))
            {
                WriteGoAway(ResetStatusCode.SettingsTimeout);
                Dispose();
            }

            _settingsAckReceived.Reset();

            if (OnSettingsSent != null)
            {
                OnSettingsSent(this, new SettingsSentEventArgs(frame));
            }
        }
Exemple #3
0
 public Shell()
 {
     this.InitializeComponent();
     mainFrame.Navigate(typeof(WritingView));
     InfoBarFrame.Navigate(typeof(InfoBarView));
     SettingsFrame.Navigate(typeof(SettingsView));
 }
        private void SettingsNav_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            var    selectedItem = (NavigationViewItem)args.SelectedItem;
            string Tag          = (string)selectedItem.Tag;

            switch (Tag)
            {
            case "General":
                SettingsFrame.Navigate(typeof(SettingsPages.General));
                break;

            case "AutoBrightness":
                SettingsFrame.Navigate(typeof(SettingsPages.AutoBrightness));
                break;

            case "Appearance":
                SettingsFrame.Navigate(typeof(SettingsPages.Appearance));
                break;

            case "Hotkeys":
                SettingsFrame.Navigate(typeof(SettingsPages.Hotkeys));
                break;

            case "About":
                SettingsFrame.Navigate(typeof(SettingsPages.About));
                break;
            }
        }
        private void NavigateFrame(string page)
        {
            switch (page)
            {
            default:
            case "General":
                SettingsFrame.Navigate(typeof(SettingsGeneral));
                SettingsNavView.SelectedItem = SettingsNavView.MenuItems[0];
                break;

            case "Appearance":
                SettingsFrame.Navigate(typeof(SettingsAppearance));
                break;

            case "Alerts":
                SettingsFrame.Navigate(typeof(SettingsAlerts));
                break;

            case "Changelog":
                SettingsFrame.Navigate(typeof(SettingsChangelog));
                break;

            case "Feedback":
                SettingsFrame.Navigate(typeof(SettingsFeedback));
                break;

            case "About":
                SettingsFrame.Navigate(typeof(SettingsAbout));
                break;

            case "Calculator":
                SettingsFrame.Navigate(typeof(SettingsCalculator));
                break;
            }
        }
        public void UpdateFromFrame(SettingsFrame frame, IFlowControlManager flowControlStateManager)
        {
            if (frame.EnablePush.HasValue)
            {
                EnablePush = frame.EnablePush.Value;
            }
            if (frame.HeaderTableSize.HasValue)
            {
                HeaderTableSize = frame.HeaderTableSize.Value;
            }
            if (frame.MaxConcurrentStreams.HasValue)
            {
                MaxConcurrentStreams = frame.MaxConcurrentStreams.Value;
            }
            if (frame.MaxFrameSize.HasValue)
            {
                MaxFrameSize = frame.MaxFrameSize.Value;
            }
            if (frame.MaxHeaderListSize.HasValue)
            {
                MaxHeaderListSize = frame.MaxHeaderListSize.Value;
            }

            if (frame.InitialWindowSize.HasValue)
            {
                InitialWindowSize = frame.InitialWindowSize.Value;

                // Try and update the flow control manager's initial size
                if (flowControlStateManager != null)
                {
                    flowControlStateManager.InitialWindowSize = InitialWindowSize;
                }
            }
        }
Exemple #7
0
 private void InitializeControls()
 {
     ToolTipService.SetToolTip(ExitCompactOverlayButton, _resourceLoader.GetString("App_ExitCompactOverlayMode_Text"));
     RootSplitView.PaneOpening += delegate { SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo()); };
     RootSplitView.PaneClosed  += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
     NewSetButton.Click        += delegate { NotepadsCore.OpenNewTextEditor(_defaultNewFileName); };
 }
        public SettingsNav()
        {
            this.InitializeComponent();

            SettingsFrame.Navigate(typeof(General), new SuppressNavigationTransitionInfo());

            App.Settings.PropertyChanged += SettingsOnPropertyChanged;
        }
 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     MainFrame.Navigate(typeof(MainView));
     SettingsFrame.Navigate(typeof(SettingsView));
     SettingsFrame.Visibility = Visibility.Collapsed;
     await ReviewHelper.TryRequestReviewAsync();
 }
Exemple #10
0
        private void SettingsFrame_Navigated(object sender, NavigationEventArgs e)
        {
            SettingsFrame.RemoveBackEntry();

            if (!(SettingsFrame.Content is FrameworkElement content))
            {
                return;
            }

            content.DataContext = _viewModel;
        }
Exemple #11
0
        /// <summary>
        /// Writes the settings frame.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public void WriteSettings(SettingsPair[] settings)
        {
            var frame = new SettingsFrame(new List <SettingsPair>(settings));

            _writeQueue.WriteFrame(frame);

            if (OnSettingsSent != null)
            {
                OnSettingsSent(this, new SettingsSentEventArgs(frame));
            }
        }
Exemple #12
0
        private void InitControls()
        {
            RootSplitView.PaneOpening += delegate { SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo()); };
            RootSplitView.PaneClosed  += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            NewSetButton.Click        += delegate { NotepadsCore.OpenNewTextEditor(); };
            MainMenuButton.Click      += (sender, args) => FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
            MenuCreateNewButton.Click += (sender, args) => NotepadsCore.OpenNewTextEditor();
            MenuOpenFileButton.Click  += async(sender, args) => await OpenNewFiles();

            MenuSaveButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : false);

            MenuSaveAsButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : true);

            MenuSaveAllButton.Click += async(sender, args) => { foreach (var textEditor in NotepadsCore.GetAllTextEditors())
                                                                {
                                                                    await Save(textEditor, saveAs : false, ignoreUnmodifiedDocument : true);
                                                                }
            };
            MenuFindButton.Click     += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: false);
            MenuReplaceButton.Click  += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: true);
            MenuSettingsButton.Click += (sender, args) => RootSplitView.IsPaneOpen = true;

            MainMenuButtonFlyout.Closing += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            MainMenuButtonFlyout.Opening += (sender, o) =>
            {
                var selectedTextEditor = NotepadsCore.GetSelectedTextEditor();
                if (selectedTextEditor == null)
                {
                    MenuSaveButton.IsEnabled    = false;
                    MenuSaveAsButton.IsEnabled  = false;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                    //MenuPrintButton.IsEnabled = false;
                }
                else if (selectedTextEditor.IsEditorEnabled() == false)
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                    //MenuPrintButton.IsEnabled = true;
                }
                else
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = true;
                    MenuReplaceButton.IsEnabled = true;
                    //MenuPrintButton.IsEnabled = true;
                }
                MenuSaveAllButton.IsEnabled = NotepadsCore.HaveUnsavedTextEditor();
            };
        }
        private void SettingsControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox settingsListBox = sender as ListBox;
            var     s = settingsListBox.SelectedItem as ShutterinoSettingDefinition;

            if (s?.DeviceViewModel?.Available == true)
            {
                SettingsFrame.Navigate(s.ViewType);
                // TODO: this should be properly done with binding
                StatusBlock.Text = s.DeviceViewModel.Status ?? String.Empty;
            }
        }
Exemple #14
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            HomePage         = new SettingsPages.HomePage();
            DisplaysPage     = new SettingsPages.DisplaysPage();
            ScreenSpacePage  = new SettingsPages.ScreenSpacePage();
            WindowsPage      = new SettingsPages.WindowsPage();
            AutomationPage   = new SettingsPages.AutomationPage();
            LogsPage         = new SettingsPages.LogsPage();
            ExperimentalPage = new SettingsPages.ExperimentalPage();

            NavService = SettingsFrame.NavigationService;
            SettingsFrame.Navigate(HomePage);
        }
        private void SettingsFrame_OnNavigated(object sender, NavigationEventArgs e)
        {
            SettingsFrame.RemoveBackEntry();

            var content = SettingsFrame.Content as FrameworkElement;

            if (content == null)
            {
                return;
            }

            content.DataContext = _viewModel;
        }
Exemple #16
0
        private void InitControls()
        {
            RootSplitView.PaneOpening += delegate { SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo()); };
            RootSplitView.PaneClosed  += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            NewSetButton.Click        += delegate { NotepadsCore.OpenNewTextEditor(); };
            MainMenuButton.Click      += (sender, args) => FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
            MenuCreateNewButton.Click += (sender, args) => NotepadsCore.OpenNewTextEditor();
            MenuOpenFileButton.Click  += async(sender, args) => await OpenNewFiles();

            MenuSaveButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), false);

            MenuSaveAsButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), true);

            MenuSaveAllButton.Click += async(sender, args) => { foreach (var textEditor in NotepadsCore.GetAllTextEditors())
                                                                {
                                                                    await Save(textEditor, false);
                                                                }
            };
            MenuFindButton.Click     += (sender, args) => ShowFindAndReplaceControl(false);
            MenuReplaceButton.Click  += (sender, args) => ShowFindAndReplaceControl(true);
            MenuSettingsButton.Click += (sender, args) => RootSplitView.IsPaneOpen = true;

            MainMenuButtonFlyout.Closing += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            MainMenuButtonFlyout.Opening += (sender, o) =>
            {
                if (NotepadsCore.GetNumberOfOpenedTextEditors() == 0)
                {
                    MenuSaveButton.IsEnabled    = false;
                    MenuSaveAsButton.IsEnabled  = false;
                    MenuSaveAllButton.IsEnabled = false;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                    //MenuPrintButton.IsEnabled = false;
                }
                else
                {
                    MenuSaveButton.IsEnabled    = true;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuSaveAllButton.IsEnabled = true;
                    MenuFindButton.IsEnabled    = true;
                    MenuReplaceButton.IsEnabled = true;
                    //MenuPrintButton.IsEnabled = true;
                }
            };
        }
        public async Task InitialHttp2StreamWindowSize_SentInSettingsFrame()
        {
            const int WindowSize = 123456;

            using Http2LoopbackServer server = Http2LoopbackServer.CreateServer();
            using var handler = CreateHttpClientHandler();
            GetUnderlyingSocketsHttpHandler(handler).InitialHttp2StreamWindowSize = WindowSize;
            using HttpClient client = CreateHttpClient(handler);

            Task <HttpResponseMessage> clientTask = client.GetAsync(server.Address);
            Http2LoopbackConnection    connection = await server.AcceptConnectionAsync().ConfigureAwait(false);

            SettingsFrame clientSettingsFrame = await connection.ReadSettingsAsync().ConfigureAwait(false);

            SettingsEntry entry = clientSettingsFrame.Entries.First(e => e.SettingId == SettingId.InitialWindowSize);

            Assert.Equal(WindowSize, (int)entry.Value);
        }
        private Type ShowTab(SettingsTabs settingsTab)
        {
            var pageType = settingsTab switch
            {
                SettingsTabs.General => typeof(General),
                SettingsTabs.Theme => typeof(Theme),
                SettingsTabs.Fonts => typeof(Font),
                SettingsTabs.Advanced => typeof(Advanced),
                SettingsTabs.About => typeof(About),
                _ => null
            };

            if (pageType != null)
            {
                SettingsFrame.Navigate(pageType, new SuppressNavigationTransitionInfo());
            }

            return(pageType);
        }
Exemple #19
0
        private void SettingsButtonOnClicked(object sender, EventArgs e)
        {
            if (!_isSettingsShown)
            {
                BlurStyleRow.Height     = _isAcrylicBlurEnabled ? SettingsRowHeight : 0;
                SettingsFrame.IsVisible = true;

                TaskMonitor.Create(SettingsFrame.FadeTo(1));
                _isSettingsShown = true;
                return;
            }

            // Hide
            _isSettingsShown = false;
            TaskMonitor.Create(async() =>
            {
                await SettingsFrame.FadeTo(0);
                SettingsFrame.IsVisible = false;
            });
        }
Exemple #20
0
        public void ProcessSettings(SettingsFrame settingsFrame, Http2Session session,
                                    FlowControlManager flCtrlManager)
        {
            for (int i = 0; i < settingsFrame.EntryCount; i++)
            {
                switch (settingsFrame[i].Id)
                {
                case SettingsIds.MaxCurrentStreams:
                    session.RemoteMaxConcurrentStreams = settingsFrame[i].Value;
                    break;

                case SettingsIds.InitialWindowSize:
                    flCtrlManager.StreamsInitialWindowSize = settingsFrame[i].Value;
                    break;

                case SettingsIds.FlowControlOptions:
                    flCtrlManager.Options = settingsFrame[i].Value;
                    break;
                }
            }
        }
Exemple #21
0
        private SettingsFrame DecodeSettingsFrame(DecodingContext context, int payloadLength, byte flags,
                                                  int streamIdentifier)
        {
            if (streamIdentifier != 0)
            {
                throw new DecoderException(Http2ErrorCode.ProtocolError,
                                           "SETTINGS frame should not have a stream identifier. You specified: " + streamIdentifier);
            }
            if (payloadLength % 6 != 0)
            {
                throw new DecoderException(Http2ErrorCode.FrameSizeError,
                                           "SETTINGS frame payload length should be a multiple of 6. You specified:" + payloadLength);
            }

            if ((flags & 1) == 1)
            {
                if (payloadLength > 0)
                {
                    throw new DecoderException(Http2ErrorCode.ProtocolError,
                                               "SETTINGS frame with the acknowledgment flag may not contain a payload.");
                }
                return(new SettingsFrame {
                    IsAcknowledgment = true
                });
            }

            var originalLength = payloadLength;
            var settingsFrame  = new SettingsFrame();

            while (payloadLength > 0)
            {
                var identifier = BitConverter.ToInt16(context.Buffer, context.Offset);
                var value      = BitConverter.ToInt32(context.Buffer, context.Offset + 2);
                settingsFrame.Add(identifier, value);
                context.Offset += 6;
                payloadLength  -= 6;
            }
            context.BytesLeftToProcess -= originalLength;
            return(settingsFrame);
        }
Exemple #22
0
        public async Task ConnectAsync(Uri uri)
        {
            if (uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
            {
                _channel = new SecureSocketChannel();
                await _channel.ConnectAsync(uri.Host, uri.Port == 0? 443 : uri.Port);
            }
            else
            {
                _channel = new SocketChannel();
                await _channel.ConnectAsync(uri.Host, uri.Port == 0? 443 : uri.Port);
            }

            _encodingContext = new EncodingContext(_channel);
            _encoder         = new FrameEncoder(_encodingContext);

            Buffer.BlockCopy(ClientPreface, 0, _encodingContext.Buffer, _encodingContext.Offset, ClientPreface.Length);
            _encodingContext.Offset += ClientPreface.Length;
            var settingsFrame = new SettingsFrame();
            await _encoder.EncodeAsync(settingsFrame);

            if (_encodingContext.ContainsData)
            {
                await _encodingContext.SendAsync();
            }

            var ackOnOurFrame = await _decoder.DecodeAsync(_decodingContext) as SettingsFrame;

            if (ackOnOurFrame == null)
            {
                //TODO: Protocol error
            }

            var serverSettings = await _decoder.DecodeAsync(_decodingContext) as SettingsFrame;

            if (serverSettings == null)
            {
                //TODO: protocol error
            }
        }
Exemple #23
0
        public async Task ConnectAsync(Uri uri)
        {
            int port = uri.Port;

            if (uri.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase))
            {
                _socket = new SecureSocketChannel();
                if (port == 0)
                {
                    port = uri.Port == 0 ? 443 : uri.Port;
                }
            }
            else
            {
                _socket = new SocketChannel();
                if (port == 0)
                {
                    port = uri.Port == 0 ? 80 : uri.Port;
                }
            }


            await _socket.ConnectAsync(uri.Host, port);

            _context = new EncodingContext(_socket);
            _encoder = new FrameEncoder(_context);


            var http2Settings = new SettingsFrame();

            http2Settings.Encode(1, new EncodingContext());

            var handshake = string.Format(@"GET / HTTP/1.1
Host: {0}
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: {1}
     ", uri.Host, http2Settings);
        }
Exemple #24
0
        /// <summary>
        /// Process a setting frame request.
        /// </summary>
        /// <param name="httpContext">The current http context.</param>
        /// <param name="settingFrame">The setting frame.</param>
        private static void ProcessSettingFrameRequest(Nequeo.Net.Http2.HttpContext httpContext, SettingsFrame settingFrame)
        {
            bool isAck = false;

            /*  If an endpoint receives a SETTINGS frame whose stream identifier
             *  field is other than 0x0, the endpoint MUST respond with a connection
             *  error of type PROTOCOL_ERROR. */
            if (settingFrame.StreamId != 0)
            {
                throw new ProtocolError(ErrorCodeRegistry.Protocol_Error, "Settings frame stream id is not equal to 0.");
            }

            /*  Receipt of a SETTINGS frame with the ACK flag set and a length
             *  field value other than 0 MUST be treated as a connection error
             *  of type FRAME_SIZE_ERROR. */
            if (settingFrame.IsAck)
            {
                if (settingFrame.PayloadLength != 0)
                {
                    throw new ProtocolError(ErrorCodeRegistry.Frame_Size_Error,
                                            "Settings frame with ACK flag set and non-zero payload.");
                }

                isAck = true;
            }

            // If is not acknowledged.
            if (!isAck)
            {
                // For the settings data received.
                for (int i = 0; i < settingFrame.EntryCount; i++)
                {
                    SettingsPair setting = settingFrame[i];
                    switch (setting.Id)
                    {
                    case SettingsRegistry.Enable_Push:
                        httpContext.SetSettingsPair(SettingsRegistry.Enable_Push, setting.Value);
                        break;

                    case SettingsRegistry.Header_Table_Size:
                        httpContext.SetSettingsPair(SettingsRegistry.Header_Table_Size, setting.Value);
                        break;

                    case SettingsRegistry.Initial_Window_Size:
                        httpContext.SetSettingsPair(SettingsRegistry.Initial_Window_Size, setting.Value);
                        break;

                    case SettingsRegistry.Max_Concurrent_Streams:
                        httpContext.SetSettingsPair(SettingsRegistry.Max_Concurrent_Streams, setting.Value);
                        break;

                    case SettingsRegistry.Max_Frame_Size:
                        httpContext.SetSettingsPair(SettingsRegistry.Max_Frame_Size, setting.Value);
                        break;

                    case SettingsRegistry.Max_Header_List_Size:
                        httpContext.SetSettingsPair(SettingsRegistry.Max_Header_List_Size, setting.Value);
                        break;

                    default:
                        /*  An endpoint that receives a SETTINGS frame with any other identifier
                         *  MUST treat this as a connection error of type PROTOCOL_ERROR. */
                        throw new ProtocolError(ErrorCodeRegistry.Protocol_Error, "Unknown setting identifier.");
                    }
                }
            }

            // If is not acknowledged.
            if (!settingFrame.IsAck)
            {
                // Sending ACK settings
                SettingsFrame frame = new SettingsFrame(new List <SettingsPair>(new SettingsPair[0]), true);

                // Write the frame.
                httpContext.ResponseWrite(frame.Buffer);
            }
        }
Exemple #25
0
        private void HandleSettingsFrame(SettingsFrame settingsFrame)
        {
            Http2Logger.LogDebug("SETTINGS frame: stream id={0}, payload len={1}, is ack={2}, count={3}",
                                 settingsFrame.StreamId, settingsFrame.PayloadLength, settingsFrame.IsAck, settingsFrame.EntryCount);

            _wasSettingsReceived = true;

            /* 12 -> 6.5
             * If an endpoint receives a SETTINGS frame whose stream identifier
             * field is other than 0x0, the endpoint MUST respond with a connection
             * error of type PROTOCOL_ERROR. */
            if (settingsFrame.StreamId != 0)
            {
                throw new ProtocolError(ResetStatusCode.ProtocolError, "Settings frame stream id is not 0");
            }

            /* 12 -> 6.5
             * Receipt of a SETTINGS frame with the ACK flag set and a length
             * field value other than 0 MUST be treated as a connection error
             * of type FRAME_SIZE_ERROR. */
            if (settingsFrame.IsAck)
            {
                _settingsAckReceived.Set();

                if (settingsFrame.PayloadLength != 0)
                {
                    throw new ProtocolError(ResetStatusCode.FrameSizeError,
                                            "Settings frame with ACK flag set and non-zero payload");
                }
                return;
            }

            for (int i = 0; i < settingsFrame.EntryCount; i++)
            {
                var setting = settingsFrame[i];
                Http2Logger.LogDebug("{0}: {1}", setting.Id.ToString(), setting.Value);

                switch (setting.Id)
                {
                case SettingsIds.HeadersTableSize:
                    if (_comprProc is CompressionProcessor)
                    {
                        (_comprProc as CompressionProcessor).NotifySettingsChanges(setting.Value);
                    }
                    break;

                case SettingsIds.EnablePush:
                    IsPushEnabled = setting.Value != 0;
                    break;

                case SettingsIds.MaxConcurrentStreams:
                    RemoteMaxConcurrentStreams = setting.Value;

                    /* 12 -> 8.2.2
                     * Advertising a SETTINGS_MAX_CONCURRENT_STREAMS value of zero disables
                     * server push by preventing the server from creating the necessary streams. */
                    IsPushEnabled = setting.Value == 0;
                    break;

                case SettingsIds.InitialWindowSize:
                    int newInitWindowSize = setting.Value;
                    int windowSizeDiff    = newInitWindowSize - _flowControlManager.StreamsInitialWindowSize;

                    foreach (var stream in StreamDictionary.FlowControlledStreams.Values)
                    {
                        stream.WindowSize += windowSizeDiff;
                    }

                    _flowControlManager.StreamsInitialWindowSize = newInitWindowSize;
                    InitialWindowSize = newInitWindowSize;
                    break;

                // TODO:
                // _GzipCompressionProcessor.Enabled = true;
                // ignore CompressData setting for now
                case SettingsIds.CompressData:
                    break;

                /* 12 -> 5.2.1
                 * Flow control cannot be disabled. */
                /*case SettingsIds.FlowControlOptions:
                 *  _flowControlManager.Options = settingsFrame[i].Value;
                 *  break;*/
                default:
                    /* 12 -> 6.5.2
                     * An endpoint that receives a SETTINGS frame with any other identifier
                     * MUST treat this as a connection error of type PROTOCOL_ERROR. */
                    throw new ProtocolError(ResetStatusCode.ProtocolError, "Unknown setting identifier");
                }
            }
        }
Exemple #26
0
 protected virtual void ProcessSettings(SettingsFrame frame)
 {
     _isPushEnabled = _session.IsPushEnabled;
 }
        /// <summary>
        /// Deserializes the data into control frame.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns>Deserialized frame.</returns>
        private BaseFrame DeserializeControlFrame(byte[] data)
        {
            FrameType    type  = GetFrameType(data);
            ControlFrame frame = new ControlFrame();

            switch (type)
            {
            case FrameType.RTS:
                frame.StreamId   = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame.StatusCode = (StatusCode)BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                break;

            case FrameType.Headers:
            case FrameType.SynReply:
                ParseControlFrameHeader(ref frame, data);

                frame.StreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));

                ParseControlFrameHeaders(ref frame, data, 12);
                break;

            case FrameType.SynStream:
                ParseControlFrameHeader(ref frame, data);

                frame.StreamId             = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame.AssociatedToStreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                frame.Priority             = (byte)(data[16] >> 5);
                frame.Slot = data[17];

                ParseControlFrameHeaders(ref frame, data, 18);
                break;

            case FrameType.Settings:
                int numberOfEntries = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame = new SettingsFrame(numberOfEntries);
                int headersOffset = 12;

                for (int i = 0; i < numberOfEntries; i++)
                {
                    int key = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, headersOffset, 4));
                    headersOffset += 4;
                    int value = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, headersOffset, 4));
                    headersOffset += 4;

                    frame.SettingsHeaders.Add(key, value);
                }

                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.GoAway:
                int        lastSeenGoodStreamId = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                StatusCode status = StatusCode.Success;

                if (data.Length > 12)
                {
                    status = (StatusCode)BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 12, 4));
                }

                frame = new GoAwayFrame(lastSeenGoodStreamId, status);
                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.Ping:
                int streamID = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 4, 4));
                frame = new ControlFrame {
                    StreamId = streamID
                };

                ParseControlFrameHeader(ref frame, data);
                break;

            case FrameType.WindowUpdate:
                int streamId        = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 4, 4));
                int deltaWindowSize = BinaryHelper.Int32FromBytes(new ArraySegment <byte>(data, 8, 4));
                frame = new WindowUpdateFrame(streamId, deltaWindowSize);

                ParseControlFrameHeader(ref frame, data);
                break;
            }
            frame.Type = type;

            return(frame);
        }
Exemple #28
0
 private void RootSplitView_OnPaneOpening(SplitView sender, object args)
 {
     SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo());
 }
Exemple #29
0
        private void InitControls()
        {
            ToolTipService.SetToolTip(ExitCompactOverlayButton, _resourceLoader.GetString("App_ExitCompactOverlayMode_Text"));
            RootSplitView.PaneOpening       += delegate { SettingsFrame.Navigate(typeof(SettingsPage), null, new SuppressNavigationTransitionInfo()); };
            RootSplitView.PaneClosed        += delegate { NotepadsCore.FocusOnSelectedTextEditor(); };
            NewSetButton.Click              += delegate { NotepadsCore.OpenNewTextEditor(_defaultNewFileName); };
            MainMenuButton.Click            += (sender, args) => FlyoutBase.ShowAttachedFlyout((FrameworkElement)sender);
            MenuCreateNewButton.Click       += (sender, args) => NotepadsCore.OpenNewTextEditor(_defaultNewFileName);
            MenuCreateNewWindowButton.Click += async(sender, args) => await OpenNewAppInstance();

            MenuOpenFileButton.Click += async(sender, args) => await OpenNewFiles();

            MenuSaveButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : false);

            MenuSaveAsButton.Click += async(sender, args) => await Save(NotepadsCore.GetSelectedTextEditor(), saveAs : true);

            MenuSaveAllButton.Click += async(sender, args) =>
            {
                var success = false;
                foreach (var textEditor in NotepadsCore.GetAllTextEditors())
                {
                    if (await Save(textEditor, saveAs: false, ignoreUnmodifiedDocument: true, rebuildOpenRecentItems: false))
                    {
                        success = true;
                    }
                }
                if (success)
                {
                    await BuildOpenRecentButtonSubItems();
                }
            };
            MenuFindButton.Click           += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: false);
            MenuReplaceButton.Click        += (sender, args) => NotepadsCore.GetSelectedTextEditor()?.ShowFindAndReplaceControl(showReplaceBar: true);
            MenuFullScreenButton.Click     += (sender, args) => EnterExitFullScreenMode();
            MenuCompactOverlayButton.Click += (sender, args) => EnterExitCompactOverlayMode();
            MenuPrintButton.Click          += async(sender, args) => await Print(NotepadsCore.GetSelectedTextEditor());

            MenuPrintAllButton.Click += async(sender, args) => await PrintAll(NotepadsCore.GetAllTextEditors());

            MenuSettingsButton.Click += (sender, args) => RootSplitView.IsPaneOpen = true;

            MainMenuButtonFlyout.Opening += (sender, o) =>
            {
                var selectedTextEditor = NotepadsCore.GetSelectedTextEditor();
                if (selectedTextEditor == null)
                {
                    MenuSaveButton.IsEnabled     = false;
                    MenuSaveAsButton.IsEnabled   = false;
                    MenuFindButton.IsEnabled     = false;
                    MenuReplaceButton.IsEnabled  = false;
                    MenuPrintButton.IsEnabled    = false;
                    MenuPrintAllButton.IsEnabled = false;
                }
                else if (selectedTextEditor.IsEditorEnabled() == false)
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = false;
                    MenuReplaceButton.IsEnabled = false;
                }
                else
                {
                    MenuSaveButton.IsEnabled    = selectedTextEditor.IsModified;
                    MenuSaveAsButton.IsEnabled  = true;
                    MenuFindButton.IsEnabled    = true;
                    MenuReplaceButton.IsEnabled = true;

                    if (PrintManager.IsSupported())
                    {
                        MenuPrintButton.IsEnabled    = !string.IsNullOrEmpty(selectedTextEditor.GetText());
                        MenuPrintAllButton.IsEnabled = NotepadsCore.HaveNonemptyTextEditor();
                    }
                }

                MenuFullScreenButton.Text = _resourceLoader.GetString(ApplicationView.GetForCurrentView().IsFullScreenMode ?
                                                                      "App_ExitFullScreenMode_Text" : "App_EnterFullScreenMode_Text");
                MenuCompactOverlayButton.Text = _resourceLoader.GetString(ApplicationView.GetForCurrentView().ViewMode == ApplicationViewMode.CompactOverlay ?
                                                                          "App_ExitCompactOverlayMode_Text" : "App_EnterCompactOverlayMode_Text");
                MenuSaveAllButton.IsEnabled = NotepadsCore.HaveUnsavedTextEditor();
            };

            if (!App.IsFirstInstance)
            {
                MainMenuButton.Foreground    = new SolidColorBrush(ThemeSettingsService.AppAccentColor);
                MenuSettingsButton.IsEnabled = false;
            }

            if (App.IsGameBarWidget)
            {
                MenuFullScreenSeparator.Visibility = Visibility.Collapsed;
                MenuPrintSeparator.Visibility      = Visibility.Collapsed;
                MenuSettingsSeparator.Visibility   = Visibility.Collapsed;

                MenuCompactOverlayButton.Visibility = Visibility.Collapsed;
                MenuFullScreenButton.Visibility     = Visibility.Collapsed;
                MenuPrintButton.Visibility          = Visibility.Collapsed;
                MenuPrintAllButton.Visibility       = Visibility.Collapsed;
                MenuSettingsButton.Visibility       = Visibility.Collapsed;
            }
        }
Exemple #30
0
        public async Task Http2_MaxConcurrentStreams_LimitEnforced()
        {
            HttpClientHandler handler = CreateHttpClientHandler();

            handler.ServerCertificateCustomValidationCallback = TestHelper.AllowAllCertificates;

            using (var server = Http2LoopbackServer.CreateServer())
                using (var client = new HttpClient(handler))
                {
                    Task <HttpResponseMessage> sendTask = client.GetAsync(server.Address);

                    await server.EstablishConnectionAsync();

                    server.IgnoreWindowUpdates();

                    // Process first request and send response.
                    int streamId = await server.ReadRequestHeaderAsync();

                    await server.SendDefaultResponseAsync(streamId);

                    HttpResponseMessage response = await sendTask;
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                    // Change MaxConcurrentStreams setting and wait for ack.
                    // (We don't want to send any new requests until we receive the ack, otherwise we may have a timing issue.)
                    SettingsFrame settingsFrame = new SettingsFrame(new SettingsEntry {
                        SettingId = SettingId.MaxConcurrentStreams, Value = 0
                    });
                    await server.WriteFrameAsync(settingsFrame);

                    Frame settingsAckFrame = await server.ReadFrameAsync(TimeSpan.FromSeconds(30));

                    Assert.Equal(FrameType.Settings, settingsAckFrame.Type);
                    Assert.Equal(FrameFlags.Ack, settingsAckFrame.Flags);

                    // Issue two more requests. We shouldn't send either of them.
                    sendTask = client.GetAsync(server.Address);
                    Task <HttpResponseMessage> sendTask2 = client.GetAsync(server.Address);

                    // Issue another read. It shouldn't complete yet. Wait a brief period of time to ensure it doesn't complete.
                    Task <Frame> readFrameTask = server.ReadFrameAsync(TimeSpan.FromSeconds(30));
                    await Task.Delay(500);

                    Assert.False(readFrameTask.IsCompleted);

                    // Change MaxConcurrentStreams again to allow a single request to come through.
                    server.ExpectSettingsAck();
                    settingsFrame = new SettingsFrame(new SettingsEntry {
                        SettingId = SettingId.MaxConcurrentStreams, Value = 1
                    });
                    await server.WriteFrameAsync(settingsFrame);

                    // First request should be sent
                    Frame frame = await readFrameTask;
                    Assert.Equal(FrameType.Headers, frame.Type);
                    streamId = frame.StreamId;

                    // Issue another read. Second request should not be sent yet.
                    readFrameTask = server.ReadFrameAsync(TimeSpan.FromSeconds(30));
                    await Task.Delay(500);

                    Assert.False(readFrameTask.IsCompleted);

                    // Send response for first request
                    await server.SendDefaultResponseAsync(streamId);

                    response = await sendTask;
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                    // Second request should be sent now
                    frame = await readFrameTask;
                    Assert.Equal(FrameType.Headers, frame.Type);
                    streamId = frame.StreamId;

                    // Send response for second request
                    await server.SendDefaultResponseAsync(streamId);

                    response = await sendTask;
                    Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                }
        }