internal NegotiationHandler CreateNegotiationHandler(NegotiationState state) { switch (state) { case NegotiationState.InitialClientConnection: return(new ClientConnection(this, false)); case NegotiationState.RenegotiatingClientConnection: return(new ClientConnection(this, true)); case NegotiationState.ClientKeyExchange: return(new ClientKeyExchange(this)); case NegotiationState.InitialServerConnection: return(new ServerConnection(this, false)); case NegotiationState.RenegotiatingServerConnection: return(new ServerConnection(this, true)); case NegotiationState.ServerHello: return(new ServerHello(this)); case NegotiationState.ServerFinished: return(new ServerFinished(this)); default: throw new InvalidOperationException(); } }
private void OnButtonTradeClick(object sender, EventArgs e) { if (this.textBoxQuantity.Text != String.Empty) { this.quantity = 0.0M; if (this.textBoxQuantity.Text != string.Empty) { this.quantity = Convert.ToDecimal(this.textBoxQuantity.Text); } if (quantity < 100000.0m) { MessageBox.Show("Value must meet the minimum quantity."); return; } if (quantity > this.leavesQuantity) { MessageBox.Show("Value must be less than the quantity leaves."); return; } FluidTrade.Core.ThreadPoolHelper.QueueUserWorkItem(new WaitCallback(NegotiateTrade), this.quantity / 100.0M); DisableKeypad(); this.negotiationId = Guid.Empty; this.negotiationState = NegotiationState.None; } }
internal NegotiationHandler CreateNegotiationHandler(TlsContext context, NegotiationState state) { NegotiationInstrument instrument; if (negotiationInstruments.TryGetValue(state, out instrument)) { return(instrument.Factory(context)); } return(null); }
/// <summary> /// Update the negotiation state from <paramref name="oldState"/> to <paramref name="newState"/>, /// while raising the appropriate property changed events for all related properties. /// </summary> /// <param name="oldState">The expected previous state. Code will assert on this state being current.</param> /// <param name="newState">The new state to set <see cref="_negotiationState"/> to.</param> private void ExchangeNegotiationState(NegotiationState oldState, NegotiationState newState) { lock (_stateLock) { Debug.Assert(_negotiationState == oldState); _negotiationState = newState; } RaisePropertyChanged("NegotiationState"); if ((oldState == NegotiationState.Stable) || (newState == NegotiationState.Stable)) { RaisePropertyChanged("CanNegotiate"); } }
private void SetDialogAttributes(string title, string symbol, string name, Bitmap logo, decimal leavesQuantity, NegotiationState negotiationState) { // Submitted Quantity is saved here this.leavesQuantity = leavesQuantity; this.negotiationState = negotiationState; // Initialize the dialog elements with the data retrieved from the data model. this.Text = title; this.pictureBoxLogo.BackgroundImage = logo; this.decimalDomainQuantity.StartDecimal = 25000.0m; this.decimalDomainQuantity.StopDecimal = leavesQuantity; this.decimalDomainQuantity.Interval = 25000.0m; this.decimalDomainQuantity.Value = 25000.0m; this.labelLeavesQuantity.Text = leavesQuantity.ToString("#,##0"); this.labelMinimumQuantity.Text = string.Format("{0:#,##0}", 25000.0m); this.labelTicker.Text = symbol; this.labelName.Text = name; // The keypad can now be enabled. EnableKeypad(); }
internal NegotiationHandler CreateNegotiationHandler(NegotiationState state) { #if INSTRUMENTATION if (Instrument != null) { var handler = Instrument.CreateNegotiationHandler(this, state); if (handler != null) { return(handler); } } #endif switch (state) { case NegotiationState.InitialClientConnection: return(new ClientConnection(this, false)); case NegotiationState.RenegotiatingClientConnection: return(new ClientConnection(this, true)); case NegotiationState.ClientKeyExchange: return(new ClientKeyExchange(this)); case NegotiationState.InitialServerConnection: return(new ServerConnection(this, false)); case NegotiationState.RenegotiatingServerConnection: return(new ServerConnection(this, true)); case NegotiationState.ServerHello: return(new ServerHello(this)); case NegotiationState.ServerFinished: return(new ServerFinished(this)); default: throw new InvalidOperationException(); } }
/// <summary> /// Start a new session negotiation. /// </summary> /// <exception cref="InvalidOperationException"> /// The session is not in an internal state where a new negotiation can be started, either because /// the signaler is not ready (see <see cref="SignalerReady"/>), or because the internal negotiation /// state is not <see cref="NegotiationState.Stable"/> meaning that another session negotiation is /// already in process. /// </exception> public void StartNegotiation() { if (!_signalerReady) { throw new InvalidOperationException($"Cannot start a new session negotiation before the signaler is ready."); } lock (_stateLock) { if (_negotiationState != NegotiationState.Stable) { throw new InvalidOperationException($"Cannot start a new session negotiation in {_negotiationState} state."); } _negotiationState = NegotiationState.Starting; _needsNegotiation = false; // FIXME - Race condition here; if receiving a RenegotiationNeeded event between this point // and the moment the peer connection actually starts creating the offer message. In that case // _needsNegotiation will become true, but might conceptually be false since the change that // raised the event will be taken into account in the call to CreateOffer() below. This is because // we are crafting a state machine in C# instead of taping into the native implementation one. } RaisePropertyChanged("NegotiationState"); RaisePropertyChanged("CanNegotiate"); // TODO - Use per-transceiver properties instead of per-connection ones // FIXME - null string crashes, need to pass empty string _peerConnection.PreferredAudioCodec = PreferredAudioCodec ?? ""; _peerConnection.PreferredAudioCodecExtraParamsLocal = PreferredAudioCodecExtraParamsLocal ?? ""; _peerConnection.PreferredAudioCodecExtraParamsRemote = PreferredAudioCodecExtraParamsRemote ?? ""; _peerConnection.PreferredVideoCodec = PreferredVideoCodec ?? ""; _peerConnection.PreferredVideoCodecExtraParamsLocal = PreferredVideoCodecExtraParamsLocal ?? ""; _peerConnection.PreferredVideoCodecExtraParamsRemote = PreferredVideoCodecExtraParamsRemote ?? ""; PeerConnection.SetH264Config(H264Config); // This cannot be inside the lock, otherwise the UI thread has the lock and block on the WebRTC // signaling thread, which itself might invoked a callback into the UI thread which might require // the lock, in which case we'd have a deadlock. _peerConnection.CreateOffer(); }
/// <summary> /// Initialize the data used in this application. /// </summary> private void InitializeData(object parameter) { String title = String.Empty; String symbol = String.Empty; String name = String.Empty; String logoSource = null; Decimal leavesQuantity = 0.0m; NegotiationState negotiationState = NegotiationState.None; lock (DataModel.SyncRoot) { // Find the Match record. MatchRow matchRow = DataModel.Match.MatchKey.Find(this.matchId); WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow; OrderTypeRow orderTypeRow = workingOrderRow.OrderTypeRow; SecurityRow securityRow = workingOrderRow.SecurityRowByFK_Security_WorkingOrder_SecurityId; symbol = securityRow.Symbol; name = securityRow.EntityRow.Name; logoSource = securityRow.IsLogoNull() ? String.Empty : securityRow.Logo; title = String.Format("{0} of {1}", orderTypeRow.Description, symbol); leavesQuantity = 0.0M; foreach (SourceOrderRow sourceOrderRow in workingOrderRow.GetSourceOrderRows()) { leavesQuantity += sourceOrderRow.OrderedQuantity; } foreach (DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows()) { foreach (ExecutionRow executionRow in destinationOrderRow.GetExecutionRows()) { leavesQuantity -= executionRow.ExecutionQuantity; } } leavesQuantity /= securityRow.QuantityFactor; } this.Dispatcher.Invoke(DispatcherPriority.Normal, new SetDialogAttributesDelegate(SetDialogAttributes), title, symbol, name, logoSource, leavesQuantity, negotiationState); }
private void timer_Tick(object sender, EventArgs e) { foreach (KeyValuePair <int, int> keyPair in this.countdownTable) { int counter = keyPair.Value - 1; if (counter == 0) { this.countdownTable.Remove(keyPair.Key); if (keyPair.Key == this.matchId) { this.negotiationState = NegotiationState.Rejected; } // disable the keypad when the timer is up DisableKeypad(); } else { this.countdownTable[keyPair.Key] = counter; } } }
private void SetDialogAttributes(String title, String symbol, String name, String logoSource, Decimal leavesQuantity, NegotiationState negotiationState) { // Submitted Quantity is saved here this.leavesQuantity = leavesQuantity; this.negotiationState = negotiationState; // Initialize the dialog elements with the data retrieved from the data model. if (logoSource != String.Empty) { BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = new MemoryStream(Convert.FromBase64String(logoSource)); bitmapImage.EndInit(); this.logoImage.Source = bitmapImage; } this.textBoxQuantity.Text = Convert.ToString(100000.0m); this.labelLeavesQuantity.Content = leavesQuantity.ToString("#,##0"); this.labelMinimumQuantity.Content = String.Format("{0:#,##0}", 100000.0m); // The keypad can now be enabled. EnableKeypad(); }
internal NegotiationHandler CreateNegotiationHandler (NegotiationState state) { switch (state) { case NegotiationState.InitialClientConnection: return new ClientConnection (this, false); case NegotiationState.RenegotiatingClientConnection: return new ClientConnection (this, true); case NegotiationState.ClientKeyExchange: return new ClientKeyExchange (this); case NegotiationState.InitialServerConnection: return new ServerConnection (this, false); case NegotiationState.RenegotiatingServerConnection: return new ServerConnection (this, true); case NegotiationState.ServerHello: return new ServerHello (this); case NegotiationState.ServerFinished: return new ServerFinished (this); default: throw new InvalidOperationException (); } }
private void SetNegotiationState(NegotiationState negotiationState) { this.negotiationState = negotiationState; }
/// <summary> /// Initialize the data used in this application. /// </summary> private void InitializeData(object parameter) { string title = string.Empty; string symbol = string.Empty; string name = string.Empty; Bitmap logo = null; decimal leavesQuantity = 0.0m; decimal minimumQuantity = 0.0m; NegotiationState negotiationState = NegotiationState.None; try { // Lock the tables. System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); ClientMarketData.MatchLock.AcquireReaderLock(ClientTimeout.LockWait); ClientMarketData.NegotiationLock.AcquireReaderLock(ClientTimeout.LockWait); ClientMarketData.ObjectLock.AcquireReaderLock(ClientTimeout.LockWait); ClientMarketData.OrderTypeLock.AcquireReaderLock(ClientTimeout.LockWait); ClientMarketData.SecurityLock.AcquireReaderLock(ClientTimeout.LockWait); ClientMarketData.WorkingOrderLock.AcquireReaderLock(ClientTimeout.LockWait); // Find the Match record. ClientMarketData.MatchRow matchRow = ClientMarketData.Match.FindByMatchId(this.matchId); ClientMarketData.WorkingOrderRow workingOrderRow = matchRow.WorkingOrderRow; ClientMarketData.OrderTypeRow orderTypeRow = workingOrderRow.OrderTypeRow; ClientMarketData.SecurityRow securityRow = workingOrderRow.SecurityRowBySecurityWorkingOrderSecurityId; symbol = securityRow.Symbol; name = securityRow.ObjectRow.Name; minimumQuantity = securityRow.MinimumQuantity; if (!securityRow.IsLogoNull()) { MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(securityRow.Logo)); logo = new Bitmap(memoryStream); } title = string.Format("{0} of {1}", orderTypeRow.Description, symbol); leavesQuantity = workingOrderRow.SubmittedQuantity; foreach (ClientMarketData.DestinationOrderRow destinationOrderRow in workingOrderRow.GetDestinationOrderRows()) { foreach (ClientMarketData.ExecutionRow executionRow in destinationOrderRow.GetExecutionRows()) { leavesQuantity -= executionRow.ExecutionQuantity; } } } finally { // Release the locks. if (ClientMarketData.MatchLock.IsReaderLockHeld) { ClientMarketData.MatchLock.ReleaseReaderLock(); } if (ClientMarketData.NegotiationLock.IsReaderLockHeld) { ClientMarketData.NegotiationLock.ReleaseReaderLock(); } if (ClientMarketData.ObjectLock.IsReaderLockHeld) { ClientMarketData.ObjectLock.ReleaseReaderLock(); } if (ClientMarketData.OrderTypeLock.IsReaderLockHeld) { ClientMarketData.OrderTypeLock.ReleaseReaderLock(); } if (ClientMarketData.SecurityLock.IsReaderLockHeld) { ClientMarketData.SecurityLock.ReleaseReaderLock(); } if (ClientMarketData.WorkingOrderLock.IsReaderLockHeld) { ClientMarketData.WorkingOrderLock.ReleaseReaderLock(); } System.Diagnostics.Debug.Assert(!ClientMarketData.IsLocked); } Invoke(new SetDialogAttributesDelegate(SetDialogAttributes), new object[] { title, symbol, name, logo, leavesQuantity, negotiationState }); }
protected NegotiationHandler (TlsContext context, NegotiationState state) { Context = context; State = state; }
internal void Add(NegotiationState state, NegotiationHandlerFactory factory) { Context.Add(state, factory); }
internal void Add(NegotiationState state, NegotiationHandlerFactory factory) { negotiationInstruments.Add(state, new NegotiationInstrument(state, factory)); }
protected NegotiationHandler(TlsContext context, NegotiationState state) { Context = context; State = state; }
internal NegotiationInstrument(NegotiationState state, NegotiationHandlerFactory factory) { State = state; Factory = factory; }