private Enums.Mode SetConnection(CallEventArgs call) { Port portOut = Ports.FirstOrDefault(x => x.PhoneNumber == call.OutPhoneNumber); if (portOut == null) { return(Enums.Mode.NotExist); } Port portIn = Ports.First(x => x.PhoneNumber == call.InPhoneNumber); Enums.Mode modePort = portOut.Mode; if (modePort == Enums.Mode.Free) { if (!ActiveConnections.ContainsKey(call.InPhoneNumber)) { GetStation().TerminalAnswered += portIn.OutCallAnswered; GetStation().TerminalNoAnswered += portIn.OutCallNoAnswered; GetStation().TerminalRejected += portIn.OutCallRejected; ActiveConnections.Add(call.InPhoneNumber, call.OutPhoneNumber); portOut.Mode = Enums.Mode.Ringing; portIn.Mode = Enums.Mode.Ringing; portOut.AnswerEvent += AnsweredCall; portOut.RejectEvent += RejectedCall; portOut.NoAnswerEvent += NoAnsweredCall; portOut.IncomingCall(call.InPhoneNumber); } } if (modePort == Enums.Mode.Ringing) { return(Enums.Mode.Busy); } return(modePort); }
private async void LoggingInMessageHandler(NotificationMessage <ConnectionInfo> message) { if (message.Notification == Constants.LoggingInMessage) { var _mongoDbService = SimpleIoc.Default.GetInstanceWithoutCaching <IMongoDbService>(); MongoDbServerViewModel serverVm = new MongoDbServerViewModel(_mongoDbService); serverVm.IsBusy = true; serverVm.Name = message.Content.Address + ":" + message.Content.Port; DispatcherHelper.CheckBeginInvokeOnUI(() => { ActiveConnections.Add(serverVm); }); try { LoggerHelper.Logger.Info("Connecting to server " + message.Content.Address + ":" + message.Content.Port); var serverInfo = await _mongoDbService.ConnectAsync(message.Content); serverVm.ServerVersion = SemanticVersion.Parse(serverInfo.ServerStatus["version"].AsString); LoggerHelper.Logger.Info("Connected to server " + message.Content.Address + ":" + message.Content.Port); serverVm.LoadDatabases(serverInfo.Databases); } catch (Exception ex) { LoggerHelper.Logger.Error("Failed to connect to server " + message.Content.Address + ":" + message.Content.Port, ex); } serverVm.IsBusy = false; } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { _activeConnections = new ObservableCollection <MongoDbServerViewModel>(); _tabs = new ObservableCollection <TabViewModel>(); LogEvents = LoggerHelper.LogEvents; ViewLogDetails = new RelayCommand <log4net.Core.LoggingEvent>((param) => { Messenger.Default.Send(new NotificationMessage <log4net.Core.LoggingEvent>(param, Constants.ShowLogDetailsMessage)); }); Messenger.Default.Register <NotificationMessage <ConnectionInfo> >(this, (message) => LoggingInMessageHandler(message)); Messenger.Default.Register <NotificationMessage <TabViewModel> >(this, (message) => TabMessageHandler(message)); Messenger.Default.Register <NotificationMessage <MongoDbServerViewModel> >(this, (message) => MongoDbServerMessageHandler(message)); if (IsInDesignModeStatic) { var _mongoDbService = GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.GetInstanceWithoutCaching <IMongoDbService>(); MongoDbServerViewModel serverVm = new MongoDbServerViewModel(_mongoDbService); serverVm.Name = "127.0.0.1:27017"; ActiveConnections.Add(serverVm); var task = _mongoDbService.ConnectAsync(new ConnectionInfo()); task.Wait(); var serverInfo = task.Result; serverVm.LoadDatabases(serverInfo.Databases); TabViewModel tabDesign1 = SimpleIoc.Default.GetInstanceWithoutCaching <TabViewModel>(); tabDesign1.Name = "Collection1"; tabDesign1.SelectedOperation = tabDesign1.FindOperation; this.Tabs.Add(tabDesign1); this.SelectedTab = tabDesign1; TabViewModel tabDesign2 = SimpleIoc.Default.GetInstanceWithoutCaching <TabViewModel>(); tabDesign2.Name = "localhost:27017"; tabDesign2.SelectedOperation = tabDesign2.AggregateOperation; this.Tabs.Add(tabDesign2); LogEvents = new ObservableCollection <log4net.Core.LoggingEvent>(); LogEvents.Add(new log4net.Core.LoggingEvent(new log4net.Core.LoggingEventData() { Level = log4net.Core.Level.Debug, Message = "Test debug message", TimeStamp = DateTime.Parse("2015/11/09 00:01:00") })); LogEvents.Add(new log4net.Core.LoggingEvent(new log4net.Core.LoggingEventData() { Level = log4net.Core.Level.Info, Message = "Test info message", TimeStamp = DateTime.Parse("2015/11/09 00:02:00") })); LogEvents.Add(new log4net.Core.LoggingEvent(new log4net.Core.LoggingEventData() { ExceptionString = "TestException", Level = log4net.Core.Level.Warn, Message = "Test warn message", TimeStamp = DateTime.Parse("2015/11/09 00:03:00") })); LogEvents.Add(new log4net.Core.LoggingEvent(new log4net.Core.LoggingEventData() { ExceptionString = "TestException", Level = log4net.Core.Level.Error, Message = "Test error message", TimeStamp = DateTime.Parse("2015/11/09 00:04:00") })); } }
/// <summary> /// create a new managed connection. /// </summary> /// <param name="connection">connection</param> /// <param name="attemptToPool">true if we are going to try and reuse the /// connection if possible</param> public ManagedConnection(SqlOlapConnectionInfoBase sourceConnection, bool attemptToPool) { // parameter check if (sourceConnection == null) { throw new ArgumentNullException("sourceConnection"); } // see if the connection can restrict access (single user mode) IRestrictedAccess access = sourceConnection as IRestrictedAccess; // see if it is cloneable ICloneable cloneable = sourceConnection as ICloneable; lock (ActiveConnections) { // if it's not single user mode then we can see if the object can be cloned if (access == null || access.SingleConnection == false) { // if we are going to attempt to pool, see if the connection is in use if (attemptToPool && !ActiveConnections.Contains(SharedConnectionUtil.GetConnectionKeyName(sourceConnection))) { // add it to the hashtable to indicate use. ActiveConnections.Add(SharedConnectionUtil.GetConnectionKeyName(sourceConnection), sourceConnection); this.connection = sourceConnection; this.closeOnDispose = false; this.connectionAddedToActiveConnections = true; } else if (cloneable != null) { this.connection = (SqlOlapConnectionInfoBase)cloneable.Clone(); this.closeOnDispose = true; } else if (sourceConnection is SqlConnectionInfoWithConnection) { this.connection = ((SqlConnectionInfoWithConnection)sourceConnection).Copy(); this.closeOnDispose = true; } } } // if everything else has failed just use to passed in connection. if (this.connection == null) { this.connection = sourceConnection; } // always set the lock timeout to prevent the shell from not responding if (this.connection is SqlConnectionInfoWithConnection) { // set lock_timeout to 10 seconds ((SqlConnectionInfoWithConnection)this.connection).ServerConnection.LockTimeout = 10; } }
public virtual void Connected(ConnectionServer con) { ActiveConnections.Add(con); OnClientConnected?.Invoke(con); Logger.Info("Connection established: {connection}.", con); }