public IAccount CreateAccountProxy(IAccountInternal account) { System.Diagnostics.Contracts.Contract.Requires(account != null); return new AccountProxy(this.dispatcher, account, this.CreateOrdersStorageProxy(account.OrdersStorage), this.CreateExecutionsStorageProxy(account.ExecutionsStorage), this.CreatePositionsStorage(account.PositionsStorage)); }
public void RegisterAccount(IAccountInternal account, bool @default) { Helper.GuardNotNull(account); lock (_lock) { if (account.Transport == null) { account.SetTransport(_localRegistry.SipTransport); } int id = -1; if (account.IsLocal) { id = _provider.AddLocalAccountAndGetId(_localRegistry.SipTransport.Id, @default); } else { id = _provider.AddAccountAndGetId(account.Config, @default); } account.SetId(id); _accounts.Add(account.Id, account); account.HandleStateChanged(); } }
public IAccount Register() { if (string.IsNullOrEmpty(_registrarDomain)) { throw new ArgumentNullException("domain"); } IAccountInternal account = CreateAccount(); using (account.InitializationScope()) { account.Credential = new NetworkCredential(_login, _password, "*"); var sb = new SipUriBuilder(); sb.AppendExtension(_login).AppendDomain(_registrarDomain); if (!string.IsNullOrEmpty(_port)) { sb.AppendPort(_port); } _transport = _transport ?? _localRegistry.SipTransport; if (_transport is TcpTransport) { sb.AppendTransportSuffix(TransportType.Tcp); } else if (_transport is TlsTransport) { sb.AppendTransportSuffix(TransportType.Tls); } account.AccountId = sb.ToString(); sb.Clear(); sb.AppendDomain(_registrarDomain); if (!string.IsNullOrEmpty(_port)) { sb.AppendPort(_port); } if (_transport is TcpTransport) { sb.AppendTransportSuffix(TransportType.Tcp); } else if (_transport is TlsTransport) { sb.AppendTransportSuffix(TransportType.Tls); } account.RegistrarUri = sb.ToString(); account.SetTransport(_transport); account.PublishPresence = _publish; if (_regTimeout != default(int)) { account.RegistrationTimeout = _regTimeout; } } InternalRegister(account); return(account); }
protected override void CleanUp() { _logger.Debug("Call " + Id + " disposed"); _accountLock.Dispose(); _account = null; _accountLock = null; _inviteSession.Dispose(); _mediaSession.Dispose(); }
public void SetAccount(IAccountInternal account) { Helper.GuardNotNull(account); _account = account; if (IsIncoming) { _accountLock = _account.Lock(); } }
public DefaultAccountBuilder(IObjectFactory objectFactory, IAccountManagerInternal accountManager, ILocalRegistry localRegistry) { Helper.GuardNotNull(objectFactory); Helper.GuardNotNull(accountManager); Helper.GuardNotNull(localRegistry); _objectFactory = objectFactory; _accountManager = accountManager; _localRegistry = localRegistry; _account = CreateAccount(); _accountScope = _account.InitializationScope(); }
public AccountProxy(Dispatcher dispatcher, IAccountInternal internalAccount, IOrdersStorage ordersStorage, IExecutionsStorage executionsStorage, IPositionsStorage positionsStorage) { this.dispatcher = dispatcher; this.internalAccount = internalAccount; this.ordersStorage = ordersStorage; this.executionsStorage = executionsStorage; this.positionsStorage = positionsStorage; this.internalAccount.AccountChanged += this.OnAccountChanged; this.accountChangedEvent = this.dispatcher.RegisterEvent(); }
public void RegisterAccount(IAccountInternal account, bool @default) { Helper.GuardNotNull(account); lock (_lock) { if (account.Transport == null) account.SetTransport(_localRegistry.SipTransport); int id = -1; if (account.IsLocal) id = _provider.AddLocalAccountAndGetId(_localRegistry.SipTransport.Id, @default); else id = _provider.AddAccountAndGetId(account.Config, @default); account.SetId(id); _accounts.Add(account.Id, account); account.HandleStateChanged(); } }
public void UnregisterAccount(IAccountInternal account) { if (account.IsInUse) { throw new InvalidOperationException("Can't delete account as long as it's being used by other parties"); } lock (_lock) if (_accounts.ContainsKey(account.Id)) { //if (account.IsRegistered) // Helper.GuardError(PJSUA_DLL.Accounts.pjsua_acc_set_registration(account.Id, false)); //_deleting.Enqueue(account);//TODO raise events for accounts being deleted _provider.DeleteAccount(account.Id); _accounts.Remove(account.Id); account.SetId(-1); if (account.IsLocal) { account.HandleStateChanged(); } account.InternalDispose(); } }
private async Task <WebAccount> FindWamAccountForMsalAccountAsync( WebAccountProvider provider, IWamPlugin wamPlugin, IAccount msalAccount, string loginHint, string clientId) { if (msalAccount == null && string.IsNullOrEmpty(loginHint)) { return(null); } IAccountInternal accountInternal = (msalAccount as IAccountInternal); if (accountInternal?.WamAccountIds != null && accountInternal.WamAccountIds.TryGetValue(clientId, out string wamAccountId)) { _logger.Info("WAM will try to find an account based on the wam account id from the cache"); WebAccount result = await _wamProxy.FindAccountAsync(provider, wamAccountId).ConfigureAwait(false); if (result != null) { return(result); } _logger.Warning("WAM account was not found for given wam account id."); } var wamAccounts = await _wamProxy.FindAllWebAccountsAsync(provider, clientId).ConfigureAwait(false); return(MatchWamAccountToMsalAccount( wamPlugin, msalAccount, loginHint, wamAccounts)); }
public void RaiseStateChanged(IAccountInternal account) { AccountStateChanged(this, account.GetEventArgs()); }
public void UnregisterAccount(IAccountInternal account) { if (account.IsInUse) throw new InvalidOperationException("Can't delete account as long as it's being used by other parties"); lock (_lock) if (_accounts.ContainsKey(account.Id)) { //if (account.IsRegistered) // Helper.GuardError(PJSUA_DLL.Accounts.pjsua_acc_set_registration(account.Id, false)); //_deleting.Enqueue(account);//TODO raise events for accounts being deleted _provider.DeleteAccount(account.Id); _accounts.Remove(account.Id); account.SetId(-1); if (account.IsLocal) account.HandleStateChanged(); account.InternalDispose(); } }
internal virtual void InternalRegister(IAccountInternal account) { _accountManager.RegisterAccount(account, _default); }
public RegistrationSession(IAccountInternal owner) { Helper.GuardNotNull(owner); _account = new WeakReference(owner); _state = new InitializingAccountState(this); }
public void OnIncomingCall(IncomingCallRecieved e) { IAccountInternal account = _accMgr.GetAccount(e.AccountId); if (account == null) // || !account.IsRegistered) { account = _accMgr.GetAccount(_accMgr.DefaultAccount.Id); } _logger.DebugFormat("incoming call for account {0}", account.AccountId); if (account != null) { Monitor.Enter(_lock); if (_activeCalls.Count < MaxCalls) { var call = _objectFactory.Create <ICallInternal>(); using (call.InitializationScope()) { call.SetId(e.CallId); call.SetAccount(account); call.SetAsIncoming(); } AddCallAndUpdateEaCache(account.AccountId, call); Monitor.Exit(_lock); if (_localRegistry.Config.AutoAnswer) { call.Answer(true); if (_activeCalls.Count > 0) { _barrier.Reset(); } return; } RaiseRingEvent(call, true); var ea = new EventArgs <ICall>(call); //try //{ // if (_syncContext != null) // _syncContext.Post(delegate { IncomingCall(this, ea); }, null); // else // IncomingCall(this, ea); //} //catch (InvalidOperationException) //{ IncomingCall(this, ea); //} if (_activeCalls.Count > 0) { _barrier.Reset(); } } else { Monitor.Exit(_lock); //Don't have to create an object here - simply closing this session _callApi.AnswerCall(e.CallId, SipStatusCode.Decline, "Too much calls"); } } }