/// <summary> /// Initializes a new instance of the <see cref="SessionDispatcher"/> class. /// </summary> public SessionDispatcher() { TraceFactory.Logger.Debug("Initializing dispatcher..."); EventPublisher = new SessionDispatcherEventPublisher(); _backupFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "proxies.dat"); AppDomain.CurrentDomain.ProcessExit += OnDispatcherProcessExit; int maxEntries = 1; if (GlobalSettings.IsDistributedSystem) { try { string count = GlobalSettings.Items["MaxSessionsPerDispatcher"]; if (int.TryParse(count, out maxEntries)) { TraceFactory.Logger.Debug("Max proxy instances set to {0}".FormatWith(maxEntries)); } } catch (SettingNotFoundException ex) { TraceFactory.Logger.Error(ex.Message); } } _proxyControllers = new SessionProxyControllerSet(maxEntries); // Load any existing data in case the dispatcher service died. //SessionDataLoad(); }
/// <summary> /// Loads the session data from a local cache /// </summary> public void SessionDataLoad() { TraceFactory.Logger.Debug("Loading proxy references and subscribers"); EventPublisher.LoadSubscriberData(); // If there is a proxy entries cache file, load it and process it. if (File.Exists(_backupFile)) { TraceFactory.Logger.Debug("Cache file exists, loading"); var proxies = LegacySerializer.DeserializeDataContract <SessionProxyControllerSet>(File.ReadAllText(_backupFile)); // If the number of entries is greater than the max, then we need to adjust // the max to account for all entries. if (proxies.Count > _proxyControllers.Maximum) { _proxyControllers = new SessionProxyControllerSet(proxies.Count); } // Create a new entry in the proxie entries and then tell the proxy // entry to refresh all subscribers. foreach (var proxy in proxies.Values) { try { proxy.Channel.Ping(); _proxyControllers.Add(proxy); TraceFactory.Logger.Debug("Endpoint reloaded for {0}".FormatWith(proxy.SessionId)); } catch (EndpointNotFoundException ex) { TraceFactory.Logger.Debug("Endpoint skipped for {0}:{1}".FormatWith(proxy.SessionId, ex.Message)); } } try { File.Delete(_backupFile); TraceFactory.Logger.Debug("deleted {0}".FormatWith(_backupFile)); } catch (Exception ex) { TraceFactory.Logger.Error("Error deleting saved proxies file", ex); } } else { TraceFactory.Logger.Debug("Nothing to load..."); } }