/// <summary>Uninitializes this object.</summary> /// <param name="force">Indicates if the uninitialization shall be forced.</param> private static void Uninitialize(bool force) { lock (_initializationLock) { if (_initializationCount < 2 || force) { IDisposable disposable = _requestProcessor as IDisposable; if (disposable != null) { disposable.Dispose(); } if (_t2gManager != null) { _t2gManager.Dispose(); _t2gManager = null; } _remoteDataStoreFactory = null; _rtpisDataStore = null; _sessionManager = null; _notificationSender = null; _instanceCreator = null; _requestProcessor = null; } } if (_initializationCount != 0 && !force) { _initializationCount--; } }
/// <summary> /// Stops the data package service. /// </summary> protected void StopDataPackageService() { if (_datapackageServiceStub != null) { _datapackageServiceStub.Dispose(); _datapackageServiceStub = null; } if (_requestManager != null) { _requestManager.Dispose(); _requestManager = null; } DataPackageService.Uninitialize(); if (_baselineStatusUpdater != null) { _baselineStatusUpdater.Dispose(); _baselineStatusUpdater = null; } if (_t2gManager != null) { _t2gManager.Dispose(); _t2gManager = null; } T2GManagerContainer.T2GManager = null; _sessionManager = null; _requestFactory = null; }
/// <summary> /// Initializes a new instance of the <see cref="SessionService"/> class. /// </summary> /// <param name="sessionManager">The session manager.</param> /// <param name="t2gManager">The T2G manager.</param> /// <param name="notificationSender">The notification sender.</param> /// <exception cref="ArgumentNullException"> /// sessionManager /// or /// t2gManager /// or /// notificationSender is null. /// </exception> protected SessionService(ISessionManager sessionManager, IT2GManager t2gManager, INotificationSender notificationSender) { if (sessionManager == null) { throw new ArgumentNullException("sessionManager"); } else if (t2gManager == null) { throw new ArgumentNullException("t2gManager"); } else if (notificationSender == null) { throw new ArgumentNullException("notificationSender"); } lock (_initializationLock) { Uninitialize(); _sessionManager = sessionManager; _t2gManager = t2gManager; _notificationSender = notificationSender; CommonInitialize(); _initialized = true; } }
/// <summary>Initializes a new instance of the RequestProcessor class.</summary> /// <param name="t2gManager">The T2G manager to use local data store.</param> /// <param name="rtpisDataStore">The rtpis data store.</param> public RequestProcessor( IT2GManager t2gManager, IRTPISDataStore rtpisDataStore) { if (t2gManager != null) { _t2gManager = t2gManager; } else { throw new ArgumentNullException("t2gManager"); } // Register a callback that will start streaming on new trains _t2gManager.SubscribeToElementChangeNotification( SubscriberId, new EventHandler <ElementEventArgs>(OnElementInfoChanged)); if (rtpisDataStore != null) { _rtpisDataStore = rtpisDataStore; } else { _rtpisDataStore = new RTPISDataStore(); } // Register a callback that will start streaming on new trains _rtpisDataStore.Changed += new ChangedEventHandler(RTPISDataStoreChanged); }
/// <summary> /// Initializes the data package service. /// </summary> /// <param name="isRestart">Parameter that indicates if it is a restart simulation of the services.</param> protected void InitializeDataPackageService(bool isRestart) { Assert.IsTrue(HistoryLoggerConfiguration.Used, "The test application is misconfigured. HistoryLoggerConfiguration.Used is not set to proper value"); Assert.IsTrue(HistoryLoggerConfiguration.Valid, "The test application is misconfigured. HistoryLoggerConfiguration.Valid is not set to proper value"); // Create a complete T2G Manager _t2gManager = T2GManagerContainer.T2GManager; _sessionManager = new SessionManager(); _baselineStatusUpdater = new BaselineStatusUpdater(); if (!isRestart) { Assert.IsEmpty(_sessionManager.RemoveAllSessions(), "Cannot empty the session database"); } _requestFactory = new RequestContextFactory(_t2gManager, _remoteDataStoreFactoryMock.Object, _baselineStatusUpdater); _requestManager = new RequestManager(); _datapackageServiceStub = new DataPackageServiceStub(_sessionManager, _notificationsSender, _t2gManager, _requestFactory, _remoteDataStoreFactoryMock.Object, _requestManager, _baselineStatusUpdater ); }
/// <summary>Initializes this object.</summary> public static void Initialize() { if (!_initialized) { lock (_initializationLock) { if (!_initialized) { try { _sessionManager = new SessionManager(); _notificationSender = new NotificationSender(_sessionManager); _t2gManager = T2GManagerContainer.T2GManager; _transmitThread = new Thread(new ThreadStart(OnTransmitEvent)); _transmitThread.Name = "Journ. Transmit"; _t2gManager.SubscribeToElementChangeNotification(SubscriberId, new EventHandler <ElementEventArgs>(OnElementInfoChanged)); _t2gManager.SubscribeToFilePublishedNotification(SubscriberId, new EventHandler <FilePublishedNotificationArgs>(OnFilesPublished)); _t2gManager.SubscribeToFileReceivedNotification(SubscriberId, new EventHandler <FileReceivedArgs>(OnFileReceived)); _transmitThread.Start(); } catch (System.Exception e) { LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.Infotainment.Journaling.JournalingService.Initialize", e, EventIdEnum.InfotainmentJournaling); } _initialized = true; } } } }
public static void Initialize() { if (!_initialized) { lock (_initializationLock) { if (!_initialized) { try { _sessionManager = new SessionManager(); _notificationSender = new NotificationSender(_sessionManager); _t2gManager = T2GManagerContainer.T2GManager; CommonInitialize(); _initialized = true; } catch (System.Exception e) { LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.Session.SessionService.Initialize", e, EventIdEnum.Session); Uninitialize(); } } } } }
/// <summary>Initializes a new instance of the InstantMessageService class to be used for unitests purpose.</summary> /// <param name="sessionManager">Manager for session.</param> /// <param name="notificationSender">The notification sender.</param> /// <param name="trainToGoundManager">Manager for T2G.</param> /// <param name="logManager">Manager for log.</param> internal InstantMessageServiceStub( ISessionManager sessionManager, INotificationSender notificationSender, IT2GManager trainToGoundManager, ILogManager logManager) : this(sessionManager, notificationSender, trainToGoundManager, logManager, false) { // No logic body. }
/// <summary>Initializes a new instance of the InstantMessageService class to be used for unitests purpose.</summary> /// <param name="sessionManager">Manager for session.</param> /// <param name="notificationSender">The notification sender.</param> /// <param name="trainToGoundManager">Manager for T2G.</param> /// <param name="logManager">Manager for log.</param> /// <param name="keepOnlyLatestFreeTextMessageRequest">Indicates if only the latest free text message for a train shall be kept.</param> internal InstantMessageServiceStub( ISessionManager sessionManager, INotificationSender notificationSender, IT2GManager trainToGoundManager, ILogManager logManager, bool keepOnlyLatestFreeTextMessageRequest) : base(sessionManager, notificationSender, trainToGoundManager, logManager, keepOnlyLatestFreeTextMessageRequest) { _isElementKnownByDataStore = true; }
/// <summary>Initializes a new instance of the RealTimeService class.</summary> /// <param name="t2gManager">The manager to interact with T2G application.</param> /// <param name="sessionManager">Manager for session.</param> /// <param name="notificationSender">The object to use to send notifications.</param> /// <param name="requestProcessor">The request processor instance.</param> /// <param name="remoteDataStoreFactory">The remote data store factory.</param> /// <param name="rtpisDataStore">The rtpis data store.</param> public RealTimeService( IT2GManager t2gManager, ISessionManagerExtended sessionManager, INotificationSender notificationSender, IRequestProcessor requestProcessor, IRemoteDataStoreFactory remoteDataStoreFactory, IRTPISDataStore rtpisDataStore) { Initialize(this, t2gManager, sessionManager, notificationSender, requestProcessor, remoteDataStoreFactory, rtpisDataStore); }
/// <summary> /// Initializes a new instance of the <see cref="DataPackageServiceStub"/> class. /// </summary> /// <param name="sessionManager">The session manager.</param> /// <param name="notificationSender">The notification sender.</param> /// <param name="t2gManager">The T2G manager.</param> /// <param name="requestsFactory">The requests factory.</param> /// <param name="remoteDataStoreFactory">The remote data store factory.</param> /// <param name="requestManager">The request manager.</param> /// <param name="baselineStatusUpdater">The baseline status updater.</param> public DataPackageServiceStub(ISessionManager sessionManager, INotificationSender notificationSender, IT2GManager t2gManager, IRequestContextFactory requestsFactory, IRemoteDataStoreFactory remoteDataStoreFactory, IRequestManager requestManager, BaselineStatusUpdater baselineStatusUpdater) : base(sessionManager, notificationSender, t2gManager, requestsFactory, remoteDataStoreFactory, requestManager, baselineStatusUpdater) { // No logic body. }
/// <summary> /// Initializes the LiveVideoControl web service. This is only called once, when the service is /// instantiated. /// </summary> /// <param name="train2groundClient">The T2G client to use local data store.</param> /// <param name="sessionManager">Manager for session.</param> /// <param name="requestProcessor">The request processor instance.</param> /// <param name="configuration">The configuration accessor instance.</param> public static void Initialize( IT2GManager train2groundManager, ISessionManagerExtended sessionManager, INotificationSender notificationSender, IRequestProcessor requestProcessor, ILiveVideoControlConfiguration configuration) { try { if (train2groundManager != null) { _t2gManager = train2groundManager; // Register a callback that will start streaming on new trains _t2gManager.SubscribeToElementChangeNotification( SubscriberId, new EventHandler <ElementEventArgs>(OnElementInfoChanged)); } if (sessionManager != null) { _sessionManager = sessionManager; } if (notificationSender != null) { _notificationSender = notificationSender; } if (requestProcessor != null) { _requestProcessor = requestProcessor; _requestProcessor.SetT2GManager(_t2gManager, ConfigurationSettings.AppSettings["ApplicationId"]); _requestProcessor.SetSessionMgr(_sessionManager); _requestProcessor.SetNotificationSender(_notificationSender); } if (configuration != null) { LoadConfiguration(configuration); } _initialized = true; } catch (System.Exception e) { LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.Maintenance.MaintenanceService.Initialize", e, EventIdEnum.LiveVideoControl); } }
/// <summary>Sets Train2Ground client.</summary> /// <exception cref="ArgumentException">Thrown when one or more arguments have unsupported or /// illegal values.</exception> /// <exception cref="NullReferenceException">Thrown when a value was unexpectedly null.</exception> /// <param name="train2groundClient">The T2G client to use local data store.</param> /// <param name="applicationId">Identifier for the application.</param> public void SetT2GManager(IT2GManager train2groundManager, string applicationId) { if (train2groundManager != null) { RequestProcessor._train2groundManager = train2groundManager; if (applicationId == string.Empty) { RequestProcessor._train2groundManager.SubscribeToElementChangeNotification(SubscriberId, new EventHandler <ElementEventArgs>(RequestProcessor.OnElementInfoChanged)); } } else { throw new NullReferenceException("Provided IT2GManager is null."); } }
/// <summary> /// Uninitializes this instance. /// </summary> private void Uninitialize() { // First step is to stop that transmit thread and unsubscribe to subscribed notification. // Then wait that transmit thread completed. // Then finish the uninitialization. Thread threadCopy; lock (_lock) { if (_train2groundManager != null) { _train2groundManager.UnsubscribeFromElementChangeNotification(SubscriberId); } _stopTransmitThread = true; _TransmitEvent.Set(); threadCopy = _transmitThread; _newRequests.Clear(); } if (threadCopy != null) { // Wait that thread stop by itself up to one minute. bool stopped = true; if (threadCopy.ThreadState != ThreadState.Unstarted) { stopped = threadCopy.Join(new TimeSpan(0, 1, 0)); } if (!stopped) { // Force the thread to stop. threadCopy.Abort(); threadCopy.Join(new TimeSpan(0, 1, 0)); } } lock (_lock) { _transmitThread = null; _newRequests.Clear(); _train2groundManager = null; _notificationSender = null; } }
/// <summary>Initializes a new instance of the RequestContextFactory class.</summary> public RequestContextFactory(IT2GManager t2gManager, IRemoteDataStoreFactory remoteDataStoreFactory, BaselineStatusUpdater baselineStatusUpdater) { if (t2gManager == null) { throw new ArgumentNullException("t2gManager"); } else if (remoteDataStoreFactory == null) { throw new ArgumentNullException("remoteDataStoreFactory"); } else if (baselineStatusUpdater == null) { throw new ArgumentNullException("baselineStatusUpdater"); } _t2gManager = t2gManager; _remoteDataStoreFactory = remoteDataStoreFactory; _baselineStatusUpdater = baselineStatusUpdater; }
/// <summary> /// Initializes a new instance of the BaselineDistributingRequestContextProcessor class. /// </summary> /// <exception cref="ArgumentNullException">Thrown when one or more required arguments are null.</exception> /// <param name="remoteDataStoreFactory">The remote data store factory.</param> /// <param name="trainToGroundManager">Manager for train to ground.</param> public BaselineDistributingRequestContextProcessor(IRemoteDataStoreFactory remoteDataStoreFactory, IT2GManager trainToGroundManager, BaselineStatusUpdater baselineStatusUpdater) { if (null == remoteDataStoreFactory) { throw new ArgumentNullException("remoteDataStoreFactory"); } else if (null == trainToGroundManager) { throw new ArgumentNullException("trainToGroundManager"); } else if (null == baselineStatusUpdater) { throw new ArgumentNullException("baselineStatusUpdater"); } _remoteDataStoreFactory = remoteDataStoreFactory; _trainToGroundManager = trainToGroundManager; _baselineStatusUpdater = baselineStatusUpdater; }
/// <summary> /// Initializes the LiveVideoControl web service. This is only called once, when the service is /// instantiated. /// </summary> public static void Initialize() { if (!_initialized) { lock (_initializationLock) { if (!_initialized) { try { _sessionManager = new SessionManager(); _notificationSender = new NotificationSender(_sessionManager); _t2gManager = T2GManagerContainer.T2GManager; LiveVideoControlConfiguration.InitializeConfiguration(); // Register a callback that will start streaming on new trains _t2gManager.SubscribeToElementChangeNotification( SubscriberId, new EventHandler <ElementEventArgs>(OnElementInfoChanged)); _requestProcessor = new RequestProcessor(); _requestProcessor.SetT2GManager(_t2gManager, ConfigurationSettings.AppSettings["ApplicationId"]); _requestProcessor.SetSessionMgr(_sessionManager); _requestProcessor.SetNotificationSender(_notificationSender); LoadConfiguration(new LiveVideoControlConfiguration()); } catch (System.Exception e) { LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.Maintenance.MaintenanceService.Initialize", e, EventIdEnum.LiveVideoControl); } _initialized = true; } } } }
/// <summary> /// Uninitializes this instance. /// </summary> public static void Uninitialize() { lock (_initializationLock) { _initialized = false; if (_sessionManager != null) { _sessionManager.StopMonitoringSessions(); _sessionManager = null; } if (_t2gManager != null) { _t2gManager.UnsubscribeFromT2GOnlineStatusNotification("PIS.Ground.Session.SessionService"); _t2gManager = null; } _notificationSender = null; } }
/// <summary>Initializes this object.</summary> /// <exception cref="ArgumentNullException">Thrown when a value was unexpectedly null.</exception> /// <param name="train2groundManager">The T2G manager to use local data store.</param> /// <param name="notificationSender">The notification sender.</param> public void Initialize(PIS.Ground.Core.T2G.IT2GManager train2groundManager, PIS.Ground.Core.Common.INotificationSender notificationSender) { lock (_lock) { if (_transmitThread != null) { Uninitialize(); } if (train2groundManager != null) { _train2groundManager = train2groundManager; _train2groundManager.SubscribeToElementChangeNotification(SubscriberId, new EventHandler <ElementEventArgs>(OnElementInfoChanged)); } else { throw new ArgumentNullException("train2groundManager"); } if (notificationSender != null) { _notificationSender = notificationSender; } else { throw new ArgumentNullException("notificationSender"); } _stopTransmitThread = false; _transmitThread = new Thread(new ThreadStart(OnTransmitEvent)); _transmitThread.Name = "DataPkg Rqt Mgr"; if (_transmitThread.ThreadState != ThreadState.Running) { _transmitThread.Start(); } } }
/// <summary>Initializes this object.</summary> private void Initialize() { lock (_initializationLock) { if (_initializationCount == 0) { try { _instanceCreator = this; _sessionManager = new SessionManager(); _notificationSender = new NotificationSender(_sessionManager); _t2gManager = T2GManagerContainer.T2GManager; _remoteDataStoreFactory = new RemoteDataStoreFactory(); _rtpisDataStore = new RTPISDataStore(); _requestProcessor = new RequestProcessor( _t2gManager, _rtpisDataStore); _initializationCount = 1; } catch (System.Exception e) { Uninitialize(true); LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.RealTime.RealTimeService.Initialize", e, EventIdEnum.RealTime); } } else { _initializationCount++; } } }
/// <summary>Initializes this object.</summary> /// <param name="instance">The instance that create this object</param> /// <param name="t2gManager">The manager to interact with T2G application.</param> /// <param name="sessionManager">Manager for session.</param> /// <param name="notificationSender">The object to use to send notifications.</param> /// <param name="requestProcessor">The request processor instance.</param> /// <param name="remoteDataStoreFactory">The remote data store factory.</param> /// <param name="rtpisDataStore">The rtpis data store.</param> private static void Initialize( RealTimeService instance, IT2GManager t2gManager, ISessionManagerExtended sessionManager, INotificationSender notificationSender, IRequestProcessor requestProcessor, IRemoteDataStoreFactory remoteDataStoreFactory, IRTPISDataStore rtpisDataStore) { if (instance == null) { throw new ArgumentNullException("instance"); } if (t2gManager == null) { throw new ArgumentNullException("t2gManager"); } if (sessionManager == null) { throw new ArgumentNullException("sessionManager"); } if (notificationSender == null) { throw new ArgumentNullException("notificationSender"); } if (requestProcessor == null) { throw new ArgumentNullException("requestProcessor"); } if (remoteDataStoreFactory == null) { throw new ArgumentNullException("remoteDataStoreFactory"); } if (rtpisDataStore == null) { throw new ArgumentNullException("rtpisDataStore"); } lock (_initializationLock) { try { if (_initializationCount != 0) { Uninitialize(true); } RealTimeService._instanceCreator = instance; RealTimeService._t2gManager = t2gManager; RealTimeService._sessionManager = sessionManager; RealTimeService._notificationSender = notificationSender; RealTimeService._remoteDataStoreFactory = remoteDataStoreFactory; RealTimeService._rtpisDataStore = rtpisDataStore; RealTimeService._requestProcessor = requestProcessor; _initializationCount++; } catch (System.Exception e) { Uninitialize(true); LogManager.WriteLog(TraceType.ERROR, e.Message, "PIS.Ground.RealTime.RealTimeService.Initialize", e, EventIdEnum.RealTime); } } }
/// <summary> /// Initializes a new instance of the <see cref="SessionServiceStub"/> class. /// </summary> /// <param name="sessionManager">The session manager.</param> /// <param name="t2gManager">The T2G manager.</param> /// <param name="notificationSender">The notification sender.</param> public SessionServiceStub(ISessionManager sessionManager, IT2GManager t2gManager, INotificationSender notificationSender) : base(sessionManager, t2gManager, notificationSender) { // No logic body }
public void TearDown() { if (_datapackageServiceStub != null) { _datapackageServiceStub.Dispose(); _datapackageServiceStub = null; } if (_requestManager != null) { _requestManager.Dispose(); _requestManager = null; } foreach (ServiceHost service in new ServiceHost[] { _hostVehicleInfoService, _hostFileTransferService, _hostIdentificationService, _hostNotificationService, _hostTrainDataPackageService }) { if (service == null) { continue; } if (service.State == CommunicationState.Faulted) { service.Abort(); } service.Close(); } if (_vehicleInfoServiceStub != null) { _vehicleInfoServiceStub.Dispose(); } if (_baselineStatusUpdater != null) { _baselineStatusUpdater.Dispose(); } _hostIdentificationService = null; _hostFileTransferService = null; _hostVehicleInfoService = null; _hostNotificationService = null; _hostTrainDataPackageService = null; _fileTransferServiceStub = null; _identificationServiceStub = null; _vehicleInfoServiceStub = null; _notificationServiceStub = null; _trainDataPackageServiceStub = null; _baselineStatusUpdater = null; DataPackageService.Uninitialize(); T2GManagerContainer.T2GManager = null; _t2gManager = null; _sessionManager = null; _requestFactory = null; if (_dataStoreServiceStub != null) { _dataStoreServiceStub.Dispose(); _dataStoreServiceStub = null; } _remoteDataStoreFactoryMock = null; TestContext currentContext = TestContext.CurrentContext; Console.Out.WriteLine("==================================="); Console.Out.WriteLine("END TEST {0}", currentContext.Test.Name); Console.Out.WriteLine("==================================="); }
/// <summary>Sets Train2Ground client.</summary> /// <param name="train2groundClient">The T2G client to use local data store.</param> public void SetT2GManager(IT2GManager train2groundManager) { this.SetT2GManager(train2groundManager, string.Empty); }