示例#1
0
        public StateBankAccount()
        {
            _confirmingIdentity = new ConfirmingIdentity(this);
            _accountActive = new AccountActive(this);
            _frozen = new Frozen(this);
            _closing = new Closing(this);
            _closed = new Closed(this);

            Balance = 0.0;
            _state = _confirmingIdentity;
        }
示例#2
0
        private async Task StartAsyncInternal()
        {
            _logger.HttpConnectionStarting();

            try
            {
                var connectUrl = Url;
                if (_requestedTransportType == TransportType.WebSockets)
                {
                    _transport = _transportFactory.CreateTransport(TransportType.WebSockets);
                }
                else
                {
                    var negotiationResponse = await Negotiate(Url, _httpClient, _logger);

                    _connectionId = negotiationResponse.ConnectionId;

                    // Connection is being disposed while start was in progress
                    if (_connectionState == ConnectionState.Disposed)
                    {
                        _logger.HttpConnectionClosed(_connectionId);
                        return;
                    }

                    _transport = _transportFactory.CreateTransport(GetAvailableServerTransports(negotiationResponse));
                    connectUrl = CreateConnectUrl(Url, negotiationResponse);
                }

                _logger.StartingTransport(_connectionId, _transport.GetType().Name, connectUrl);
                await StartTransport(connectUrl);
            }
            catch
            {
                // The connection can now be either in the Connecting or Disposed state - only change the state to
                // Disconnected if the connection was in the Connecting state to not resurrect a Disposed connection
                ChangeState(from: ConnectionState.Connecting, to: ConnectionState.Disconnected);
                throw;
            }

            // if the connection is not in the Connecting state here it means the user called DisposeAsync while
            // the connection was starting
            if (ChangeState(from: ConnectionState.Connecting, to: ConnectionState.Connected) == ConnectionState.Connecting)
            {
                _closeTcs = new TaskCompletionSource <object>();

                _ = Input.Completion.ContinueWith(async t =>
                {
                    // Grab the exception and then clear it.
                    // See comment at AbortAsync for more discussion on the thread-safety
                    // StartAsync can't be called until the ChangeState below, so we're OK.
                    var abortException = _abortException;
                    _abortException    = null;

                    // There is an inherent race between receive and close. Removing the last message from the channel
                    // makes Input.Completion task completed and runs this continuation. We need to await _receiveLoopTask
                    // to make sure that the message removed from the channel is processed before we drain the queue.
                    // There is a short window between we start the channel and assign the _receiveLoopTask a value.
                    // To make sure that _receiveLoopTask can be awaited (i.e. is not null) we need to await _startTask.
                    _logger.ProcessRemainingMessages(_connectionId);

                    await _startTcs.Task;
                    await _receiveLoopTask;

                    _logger.DrainEvents(_connectionId);

                    await Task.WhenAny(_eventQueue.Drain().NoThrow(), Task.Delay(_eventQueueDrainTimeout));

                    _logger.CompleteClosed(_connectionId);

                    // At this point the connection can be either in the Connected or Disposed state. The state should be changed
                    // to the Disconnected state only if it was in the Connected state.
                    // From this point on, StartAsync can be called at any time.
                    ChangeState(from: ConnectionState.Connected, to: ConnectionState.Disconnected);

                    _closeTcs.SetResult(null);

                    try
                    {
                        if (t.IsFaulted)
                        {
                            Closed?.Invoke(t.Exception.InnerException);
                        }
                        else
                        {
                            // Call the closed event. If there was an abort exception, it will be flowed forward
                            // However, if there wasn't, this will just be null and we're good
                            Closed?.Invoke(abortException);
                        }
                    }
                    catch (Exception ex)
                    {
                        // Suppress (but log) the exception, this is user code
                        _logger.ErrorDuringClosedEvent(ex);
                    }
                });

                _receiveLoopTask = ReceiveAsync();
            }
        }
示例#3
0
 private void OnClosed()
 {
     Closed?.Invoke(this, EventArgs.Empty);
 }
示例#4
0
 private void OnClosed(StateChangedEventArgs e)
 {
     Closed?.Invoke(this, e);
 }
示例#5
0
 private void handleClosed(
     Object sender,
     EventArgs eventArgs) =>
 Closed?.Invoke();
示例#6
0
 /// <summary>
 /// Handles the <see cref="Snackbar.Snackbar"/> closing event.
 /// </summary>
 /// <param name="eventArgs"></param>
 /// <returns></returns>
 protected virtual Task OnSnackbarClosed(SnackbarClosedEventArgs eventArgs)
 {
     return(eventArgs.CloseReason == SnackbarCloseReason.UserClosed
         ? Okayed.InvokeAsync()
         : Closed.InvokeAsync());
 }
 public void RaiseClosed() => Closed?.Invoke(this, EventArgs.Empty);
示例#8
0
 private void OnClosed(object sender, CoreWindowEventArgs e)
 {
     Closed?.Invoke(this, EventArgs.Empty);
 }
示例#9
0
 private void PopupClosed(object sender, object e)
 {
     Closed?.Invoke(sender, null);
 }
 private void Button_Click_1(object sender, System.Windows.RoutedEventArgs e)
 {
     Closed?.Invoke(this, new DialogClosedEventArgs(null));
 }
 private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     Closed?.Invoke(this, new DialogClosedEventArgs(new InputResult(TBIP.Text, TBPort.Text)));
 }
示例#12
0
 protected virtual void OnClosed(EventArgs e) => Closed?.Invoke(this, e);
示例#13
0
 internal void OnSessionClosed(EventArgs e)
 {
     Closed?.Invoke(this, e);
 }
 public void Close()
 {
     Closed?.Invoke(this, EventArgs.Empty);
 }
示例#15
0
 /// ------------------------------------------------------------------------------------------------
 #region Protected Functions
 /// ------------------------------------------------------------------------------------------------
 ///
 protected virtual void OnClosed(bool changed)
 {
     Closed?.Invoke(PopupChanged);
 }
 // The case where the user closes Flight Simulator
 void Simconnect_OnRecvQuit(SimConnect sender, SIMCONNECT_RECV data)
 {
     logger.LogInformation("Flight Simulator has exited");
     CloseConnection();
     Closed?.Invoke(this, new EventArgs());
 }
示例#17
0
 protected void OnClosed(EventArgs e)
 {
     Closed?.Invoke(this, e);
 }
 /// <summary>
 /// Raises the Closed event.
 /// </summary>
 /// <param name="e">An ToolStripDropDownClosedEventArgs containing the event data.</param>
 protected virtual void OnClosed(ToolStripDropDownClosedEventArgs e)
 {
     Closed?.Invoke(this, e);
 }
示例#19
0
 void HexView_Closed(object?sender, EventArgs e)
 {
     hexView.Closed -= HexView_Closed;
     Closed?.Invoke(this, EventArgs.Empty);
     hexView.Properties.RemoveProperty(typeof(HexTextView));
 }
示例#20
0
 internal void ProcessKilled(int exitCode) => Closed?.Invoke(this, new BrowserAppClosedEventArgs {
     ExitCode = exitCode
 });
 private void OnNotificationCollapsed()
 {
     Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind));
     Visibility = Visibility.Collapsed;
 }
示例#22
0
 private void OnCoreWindowClosed(CoreWindow sender, CoreWindowEventArgs args)
 {
     Closing?.Invoke();
     Closed?.Invoke();
 }
示例#23
0
        public void Close()
        {
            var ex = new NotImplementedException();

            Closed.Invoke(ex);
        }
示例#24
0
        internal override void OnMessage(string method, JsonElement?serverParams)
        {
            switch (method)
            {
            case "close":
                Closed?.Invoke(this, EventArgs.Empty);
                break;

            case "crash":
                Crashed?.Invoke(this, EventArgs.Empty);
                break;

            case "domcontentloaded":
                DOMContentLoaded?.Invoke(this, EventArgs.Empty);
                break;

            case "load":
                Load?.Invoke(this, EventArgs.Empty);
                break;

            case "bindingCall":
                BindingCall?.Invoke(
                    this,
                    new BindingCallEventArgs
                {
                    BidingCall = serverParams?.GetProperty("binding").ToObject <BindingCallChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "route":
                Route?.Invoke(
                    this,
                    new RouteEventArgs
                {
                    Route   = serverParams?.GetProperty("route").ToObject <RouteChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "popup":
                Popup?.Invoke(this, new PageChannelPopupEventArgs
                {
                    Page = serverParams?.GetProperty("page").ToObject <PageChannel>(Connection.GetDefaultJsonSerializerOptions()).Object,
                });
                break;

            case "pageError":
                PageError?.Invoke(this, serverParams?.GetProperty("error").GetProperty("error").ToObject <PageErrorEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "fileChooser":
                FileChooser?.Invoke(this, serverParams?.ToObject <FileChooserChannelEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "frameAttached":
                FrameAttached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "frameDetached":
                FrameDetached?.Invoke(this, new FrameEventArgs(serverParams?.GetProperty("frame").ToObject <FrameChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "dialog":
                Dialog?.Invoke(this, new DialogEventArgs(serverParams?.GetProperty("dialog").ToObject <DialogChannel>(Connection.GetDefaultJsonSerializerOptions()).Object));
                break;

            case "console":
                Console?.Invoke(this, new ConsoleEventArgs(serverParams?.GetProperty("message").ToObject <ConsoleMessage>(Connection.GetDefaultJsonSerializerOptions())));
                break;

            case "request":
                Request?.Invoke(this, new RequestEventArgs {
                    Request = serverParams?.GetProperty("request").ToObject <RequestChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "requestFinished":
                RequestFinished?.Invoke(this, serverParams?.ToObject <PageChannelRequestEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "requestFailed":
                RequestFailed?.Invoke(this, serverParams?.ToObject <PageChannelRequestEventArgs>(Connection.GetDefaultJsonSerializerOptions()));
                break;

            case "response":
                Response?.Invoke(this, new ResponseEventArgs {
                    Response = serverParams?.GetProperty("response").ToObject <ResponseChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "webSocket":
                WebSocket?.Invoke(this, new WebSocketEventArgs {
                    WebSocket = serverParams?.GetProperty("webSocket").ToObject <WebSocketChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "download":
                Download?.Invoke(this, new DownloadEventArgs()
                {
                    Download = serverParams?.GetProperty("download").ToObject <DownloadChannel>(Connection.GetDefaultJsonSerializerOptions()).Object
                });
                break;

            case "video":
                Video?.Invoke(this, new VideoEventArgs()
                {
                    RelativePath = serverParams?.GetProperty("relativePath").ToString()
                });
                break;

            case "worker":
                Worker?.Invoke(
                    this,
                    new WorkerChannelEventArgs
                {
                    WorkerChannel = serverParams?.GetProperty("worker").ToObject <WorkerChannel>(Connection.GetDefaultJsonSerializerOptions()),
                });
                break;
            }
        }
示例#25
0
        protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd);

            const double wheelDelta = 120.0;
            uint         timestamp  = unchecked ((uint)UnmanagedMethods.GetMessageTime());

            RawInputEventArgs e = null;

            WindowsMouseDevice.Instance.CurrentWindow = this;

            switch ((UnmanagedMethods.WindowsMessage)msg)
            {
            case UnmanagedMethods.WindowsMessage.WM_ACTIVATE:
                var wa = (UnmanagedMethods.WindowActivate)(ToInt32(wParam) & 0xffff);

                switch (wa)
                {
                case UnmanagedMethods.WindowActivate.WA_ACTIVE:
                case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE:
                    Activated?.Invoke();
                    break;

                case UnmanagedMethods.WindowActivate.WA_INACTIVE:
                    Deactivated?.Invoke();
                    break;
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_CLOSE:
                bool?preventClosing = Closing?.Invoke();
                if (preventClosing == true)
                {
                    return(IntPtr.Zero);
                }
                break;

            case UnmanagedMethods.WindowsMessage.WM_DESTROY:
                //Window doesn't exist anymore
                _hwnd = IntPtr.Zero;
                //Remove root reference to this class, so unmanaged delegate can be collected
                s_instances.Remove(this);
                Closed?.Invoke();
                //Free other resources
                Dispose();
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DPICHANGED:
                var dpi            = ToInt32(wParam) & 0xffff;
                var newDisplayRect = Marshal.PtrToStructure <UnmanagedMethods.RECT>(lParam);
                Position = new Point(newDisplayRect.left, newDisplayRect.top);
                _scaling = dpi / 96.0;
                ScalingChanged?.Invoke(_scaling);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyDown,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_KEYUP:
            case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP:
                e = new RawKeyEventArgs(
                    WindowsKeyboardDevice.Instance,
                    timestamp,
                    RawKeyEventType.KeyUp,
                    KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_CHAR:
                // Ignore control chars
                if (ToInt32(wParam) >= 32)
                {
                    e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp,
                                                  new string((char)ToInt32(wParam), 1));
                }

                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN
                            ? RawMouseEventType.LeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN
                                ? RawMouseEventType.RightButtonDown
                                : RawMouseEventType.MiddleButtonDown,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP:
            case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP
                            ? RawMouseEventType.LeftButtonUp
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP
                                ? RawMouseEventType.RightButtonUp
                                : RawMouseEventType.MiddleButtonUp,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE:
                if (!_trackingMouse)
                {
                    var tm = new UnmanagedMethods.TRACKMOUSEEVENT
                    {
                        cbSize      = Marshal.SizeOf <UnmanagedMethods.TRACKMOUSEEVENT>(),
                        dwFlags     = 2,
                        hwndTrack   = _hwnd,
                        dwHoverTime = 0,
                    };

                    UnmanagedMethods.TrackMouseEvent(ref tm);
                }

                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawMouseEventType.Move,
                    DipFromLParam(lParam), GetMouseModifiers(wParam));

                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(0, (ToInt32(wParam) >> 16) / wheelDelta), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL:
                e = new RawMouseWheelEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    PointToClient(PointFromLParam(lParam)),
                    new Vector(-(ToInt32(wParam) >> 16) / wheelDelta, 0), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE:
                _trackingMouse = false;
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    RawMouseEventType.LeaveWindow,
                    new Point(), WindowsKeyboardDevice.Instance.Modifiers);
                break;

            case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN:
            case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN:
                e = new RawMouseEventArgs(
                    WindowsMouseDevice.Instance,
                    timestamp,
                    _owner,
                    msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN
                            ? RawMouseEventType.NonClientLeftButtonDown
                            : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN
                                ? RawMouseEventType.RightButtonDown
                                : RawMouseEventType.MiddleButtonDown,
                    new Point(0, 0), GetMouseModifiers(wParam));
                break;

            case UnmanagedMethods.WindowsMessage.WM_PAINT:
                UnmanagedMethods.PAINTSTRUCT ps;

                if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero)
                {
                    var f = Scaling;
                    var r = ps.rcPaint;
                    Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f));
                    UnmanagedMethods.EndPaint(_hwnd, ref ps);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_SIZE:
                var size = (UnmanagedMethods.SizeCommand)wParam;

                if (Resized != null &&
                    (size == UnmanagedMethods.SizeCommand.Restored ||
                     size == UnmanagedMethods.SizeCommand.Maximized))
                {
                    var clientSize = new Size(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16);
                    Resized(clientSize / Scaling);
                }

                var windowState = size == SizeCommand.Maximized ? WindowState.Maximized
                        : (size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal);

                if (windowState != _lastWindowState)
                {
                    _lastWindowState = windowState;
                    WindowStateChanged?.Invoke(windowState);
                }

                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_MOVE:
                PositionChanged?.Invoke(new Point((short)(ToInt32(lParam) & 0xffff), (short)(ToInt32(lParam) >> 16)));
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_GETMINMAXINFO:

                MINMAXINFO mmi = Marshal.PtrToStructure <UnmanagedMethods.MINMAXINFO>(lParam);

                if (_minSize.Width > 0)
                {
                    mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (_minSize.Height > 0)
                {
                    mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0)
                {
                    mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right);
                }

                if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0)
                {
                    mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom);
                }

                Marshal.StructureToPtr(mmi, lParam, true);
                return(IntPtr.Zero);

            case UnmanagedMethods.WindowsMessage.WM_DISPLAYCHANGE:
                (Screen as ScreenImpl)?.InvalidateScreensCache();
                return(IntPtr.Zero);
            }

#if USE_MANAGED_DRAG
            if (_managedDrag.PreprocessInputEvent(ref e))
            {
                return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
            }
#endif

            if (e != null && Input != null)
            {
                Input(e);

                if (e.Handled)
                {
                    return(IntPtr.Zero);
                }
            }

            return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam));
        }
 private void MainWindow_Closed()
 {
     Closed?.Invoke();
 }
 private void ViewOnClosed(object sender, EventArgs e) => Closed?.Invoke(this, e);
示例#28
0
 protected virtual void OnClosed()
 {
     Closed?.Invoke(this, EventArgs.Empty);
 }
 public void Close()
 {
     CloseStoryboard.Begin();
     Closed?.Invoke();
 }
示例#30
0
 protected void InvokeClosedEvent(DeviceDisconnectedEventArgs args)
 {
     Closed?.Invoke(this, args);
 }
示例#31
0
 void INativeMenuExporterEventsImplBridge.RaiseClosed()
 {
     Closed?.Invoke(this, EventArgs.Empty);
 }