private void AddMessenger(IMessengerConfiguration configuration) { IMessenger newMessenger = null; try { var messengerType = Type.GetType(configuration.MessengerTypeName); if (messengerType != null) { newMessenger = (IMessenger)Activator.CreateInstance(messengerType); } } catch (Exception) { } //next step: initialize it if (newMessenger != null) { try { newMessenger.Initialize(this, configuration); //now add it to our collection lock (m_ConfigLock) { m_Messengers.Add(newMessenger); } } catch (Exception) { } } }
public MessengerWrapper(IMessengerConfiguration configuration, IFileSerializer serializer) { this.configuration = configuration; this.serializer = serializer; messenger = new BaseClient { On2FACodeCallback = OnTwoFactorRequestedAsync, FbEventCallback = OnFbEventCallback, DeleteCookiesCallback = OnDeleteCookiesCallback, ReadCookiesFromDiskCallback = OnReadCookiesFromDiskCallback, WriteCookiesToDiskCallback = OnWriteCookiesToDiskCallback }; }
/// <summary> /// Inheritors should override this method to implement custom initialize functionality. /// </summary> /// <remarks>This method will be called exactly once before any call to OnFlush or OnWrite is made. /// Code in this method is protected by a Thread Lock. /// This method is called with the Message Dispatch thread exclusively.</remarks> protected override void OnInitialize(IMessengerConfiguration configuration) { //do our first time initialization Caption = "Standard File Messenger"; Description = "Messenger implementation that writes messages to files through a buffer. Supports synchronous and asynchronous messaging."; //try to up cast the configuration to our specific configuration type var fileConfiguration = (SessionFileConfiguration)configuration; //If the max file size is unbounded (zero or less) then we want 1GB. m_MaxFileSizeBytes = fileConfiguration.MaxFileSize < 1 ? 1024 : fileConfiguration.MaxFileSize; m_MaxFileSizeBytes = m_MaxFileSizeBytes * 1048576; //the configured value is in MB, we use bytes for faster comparisons m_MaxLogDurationSeconds = fileConfiguration.MaxFileDuration * 60; //the configured value is in minutes, we use seconds for consistency m_RepositoryMaintenanceEnabled = fileConfiguration.EnableFilePruning; m_MaxLocalDiskUsage = fileConfiguration.MaxLocalDiskUsage; m_MaxLocalFileAge = fileConfiguration.MaxLocalFileAge; //what are the very best folders for us to use? m_RepositoryFolder = LocalRepository.CalculateRepositoryPath(Publisher.SessionSummary.Product, fileConfiguration.Folder); m_SessionLockFolder = Path.Combine(m_RepositoryFolder, SessionLockFolderName); //we also have to be sure the path exists now. FileSystemTools.EnsurePathExists(m_RepositoryFolder); FileSystemTools.EnsurePathExists(m_SessionLockFolder); //Since we update the index during a flush, and the index update is about as bad as a flush we look at both together. AutoFlush = true; AutoFlushInterval = Math.Min(fileConfiguration.AutoFlushInterval, fileConfiguration.IndexUpdateInterval); //If we aren't able to initialize our log folder, throw an exception if (string.IsNullOrEmpty(m_RepositoryFolder)) { throw new DirectoryNotFoundException("No log folder could be determined, so the file messenger can't log."); } ScheduleRepositoryMaintenance(0, 0); GetSessionFileLock(); }
/// <summary> /// Inheritors should override this method to implement custom initialize functionality. /// </summary> /// <remarks>This method will be called exactly once before any call to OnFlush or OnWrite is made. /// Code in this method is protected by a Thread Lock. /// This method is called with the Message Dispatch thread exclusively.</remarks> protected override void OnInitialize(IMessengerConfiguration configuration) { //do our first time initialization Caption = "Network Viewer Messenger"; Description = "Messenger implementation that sends session data live over a TCP connection."; OverflowMode = OverflowMode.Drop; //important so we don't block in this mode. //try to up cast the configuration to our specific configuration type var messengerConfiguration = (NetworkViewerConfiguration)configuration; if (messengerConfiguration.AllowLocalClients) { //set up our local discovery file monitor so we will connect with local proxies. m_DiscoveryFileMonitor = new LocalServerDiscoveryFileMonitor(); m_DiscoveryFileMonitor.FileChanged += DiscoveryFileMonitorOnFileChanged; m_DiscoveryFileMonitor.FileDeleted += DiscoveryFileMonitorOnFileDeleted; m_DiscoveryFileMonitor.Start(); } if (messengerConfiguration.AllowRemoteClients) { //we need to monitor & keep a server configuration going. var server = Log.Configuration.Server; if (server.Enabled) { m_HubConnection = new HubConnection(server); m_EnableOutbound = true; if (!Log.SilentMode) { Log.Write(LogMessageSeverity.Verbose, LogCategory, "Remote live view enabled, will be available once connected to server", "Server Configuration:\r\n{0}", server); } } } AutoFlush = true; AutoFlushInterval = 5; }