private void Register(IClientConfiguration clientConfiguration) { if (clientConfiguration == null) { throw new ArgumentNullException("clientConfiguration"); } lock (_SyncRootRegisteredCallbackClients) { if (_RegisteredCallbackClients.ContainsKey(clientConfiguration.Id)) { // remove old registration _RegisteredCallbackClients.Remove(clientConfiguration.Id); } // log it var logs = new Logging.Logs(); NetworkShared.LogClientConfigurationDetails(logs, LogSourceId, clientConfiguration, ShowRegistrationDetails); RaiseActivityLogsEvent(new ActivityLogsEventArgs(ActivityLogsEventType.Network_Register, logs)); // add client to registration var callbackChannel = System.ServiceModel.OperationContext.Current.GetCallbackChannel <IServiceCallback>(); if (callbackChannel == null) { throw new NullReferenceException("ServerActual.Register()-->creating callbackChannel failed."); } _RegisteredCallbackClients.Add(clientConfiguration.Id, new DataHolder() { LastUsed = DateTime.Now, ClientConfiguration = clientConfiguration, CallbackClient = callbackChannel }); } }
/// <summary> /// Creates an instance of the <see cref="ActivityLogsEventArgs"/> using the <paramref name="logs"/>. /// </summary> /// <param name="logs">The logs involved with the event.</param> /// <param name="header">The type of activity represented by this log.</param> public ActivityLogsEventArgs(ActivityLogsEventType header, Logging.Logs logs) : this() { Header = header; Logs = logs ?? throw new ArgumentNullException(nameof(logs)); }
// Facilitates the Network namespace by providing shared code to log registration information, including optional details. internal static void LogClientConfigurationDetails(Logging.Logs logs, string serverLogsSourceId, IClientConfiguration clientConfiguration, bool showRegistrationDetails) { logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"Registering Client={clientConfiguration.Id}"); logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"Receive Own Messages={clientConfiguration.ReceiveSelfSentMessages}"); if (showRegistrationDetails) { var clientRecievableTypesCount = clientConfiguration.ReceivableTypesFilter.Count(); logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"Receivable Types: ({clientRecievableTypesCount})"); if (clientRecievableTypesCount > 0) { int count = 0; foreach (var item in clientConfiguration.ReceivableTypesFilter) { logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"#{++count}={item.TypeName}"); } } var clientTransmittableTypesCount = clientConfiguration.TransmittableTypesFilter.Count(); logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"Transmittable Types: ({clientTransmittableTypesCount})"); if (clientTransmittableTypesCount > 0) { int count = 0; foreach (var item in clientConfiguration.TransmittableTypesFilter) { logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"#{++count}={item.TypeName}"); } } } logs.Add(dodSON.Core.Logging.LogEntryType.Information, serverLogsSourceId, $"Completed Registering Client={clientConfiguration.Id}"); }
/// <summary> /// Writes all of the logs in the <paramref name="logs"/> to this log. /// </summary> /// <param name="logs">The source of the logs to write.</param> public void Write(Logging.Logs logs) { if (logs == null) { throw new ArgumentNullException(nameof(logs)); } Write((IEnumerable <Logging.ILogEntry>)logs); }
private void Unregister(string clientId) { lock (_SyncRootRegisteredCallbackClients) { if (_RegisteredCallbackClients.ContainsKey(clientId)) { // log it var logs = new Logging.Logs(); logs.Add(Logging.LogEntryType.Information, LogSourceId, $"Unregistering Client={clientId}, Date Started={_RegisteredCallbackClients[clientId].DateCreated}, Runtime={(DateTime.Now - _RegisteredCallbackClients[clientId].DateCreated)}"); RaiseActivityLogsEvent(new ActivityLogsEventArgs(ActivityLogsEventType.Network_Unregister, logs)); // remove client from registration _RegisteredCallbackClients.Remove(clientId); } } }
/// <summary> /// Called during the component's startup sequence. Will call the abstract method <see cref="OnComponentStarted"/> at the proper time. /// </summary> protected override void OnStart() { var logs = new Logging.Logs(); logs.Add(Logging.LogEntryType.Information, LogSourceId, $"Starting Plugin Component {Id}"); // open the client if (Client.State == Networking.ChannelStates.Closed) { if (Client.Open(out Exception clientOpenException) != Networking.ChannelStates.Open) { throw new Exception("Could not open client.", clientOpenException); } } else { throw new Exception($"Could not open client. Client State={Client.State}"); } // connect to the message bus, enqueue SupportsComponentDesignationRequest messages; otherwise, allow the message to pass Client.MessageBus += new EventHandler <Networking.MessageEventArgs>((s, e) => { // check for auto SupportsComponentDesignationRequest messages if (e.Message.TypeInfo.TypeName.Equals(typeof(SupportsComponentDesignationRequest).AssemblyQualifiedName)) { if (!string.IsNullOrWhiteSpace(ComponentDesignation)) { var request = e.Message.PayloadMessage <SupportsComponentDesignationRequest>(); if ((request != null) && (request.ComponentDesignation.Equals(ComponentDesignation))) { Log.Write(Logging.LogEntryType.Information, LogSourceId, $"{typeof(SupportsComponentDesignationRequest).Name} received, ComponentDesignation={ComponentDesignation}, ClientId={e.Message.ClientId}, ProcessId={request.ProcessId}"); SendMessage(e.Message.ClientId, new SupportsComponentDesignationResponse(ComponentDesignation, ComponentName, Id, request.ProcessId)); } } } // allow the messages to pass OnMessageReceived(e.Message); }); // call abstract start OnComponentStarted(logs); // write all startup logs logs.Add(Logging.LogEntryType.Information, LogSourceId, $"Plugin Component Started {Id}"); Log.Write(logs); }
/// <summary> /// Called during the component's shutdown sequence. Will call the abstract method <see cref="OnComponentStopping"/> at the proper time. /// </summary> protected override void OnStop() { var logs = new Logging.Logs(); logs.Add(Logging.LogEntryType.Information, LogSourceId, $"Stopping Plugin Component {Id}"); // call abstract stop OnComponentStopping(logs); // close client if (Client.State == Networking.ChannelStates.Open) { if (!Client.Close(out Exception clientCloseException)) { throw new Exception("Could not close client.", clientCloseException); } } else { throw new Exception($"Could not close client. Client State={Client.State}"); } // // ######## log statistics for the client; SEE: dodSON.Core.Networking.ServerActual.RegistrationChannel(byte[] data) // var stats = Client.TransportController.TransportStatisticsLive; logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Shutting Down Client, Id={stats.ClientServerId}, Uri={Client.AddressUri}"); logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Total Incoming Bytes={Common.ByteCountHelper.ToString(stats.IncomingBytes)} ({stats.IncomingBytes:N0})"); logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Total Incoming Envelopes={stats.IncomingEnvelopes:N0}"); logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Total Outgoing Bytes={Common.ByteCountHelper.ToString(stats.OutgoingBytes)} ({stats.OutgoingBytes:N0})"); logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Total Outgoing Envelopes={stats.OutgoingEnvelopes:N0}"); logs.Add(Logging.LogEntryType.Information, _NetworkLogSourceId, $"Client Closed Successfully."); // release client Client = null; // write all logs logs.Add(Logging.LogEntryType.Information, LogSourceId, $"Plugin Component Stopped {Id}, Start Time={this.DateLastStarted}, Run Time={this.LastRunDuration}"); Log.Write(logs); }
/// <summary> /// Inheritors should override this method when they need to shut down their type; before the component's subsystems shutdown. /// </summary> /// <param name="log">The <see cref="Logging.Logs"/> to write any logs to.</param> protected abstract void OnComponentStopping(Logging.Logs log);
/// <summary> /// Inheritors should override this method when they need to initialize their type; after the component's subsystems have started. /// </summary> /// <param name="log">The <see cref="Logging.Logs"/> to write any logs to.</param> protected abstract void OnComponentStarted(Logging.Logs log);
/// <summary> /// Adds all the <see cref="Logging.ILogEntry"/>s from <paramref name="entries"/> to the <see cref="Logging.Logs"/>. /// </summary> /// <param name="entries">The <see cref="Logging.Logs"/> to add the <see cref="Logging.ILogEntry"/>s from.</param> public void Write(Logging.Logs entries) => Write((IEnumerable <Logging.ILogEntry>)entries);
/// <summary> /// Instantiates a new instance of <see cref="GetLogsResponse"/> with some logs. /// </summary> /// <param name="logs">Some of the <see cref="Logging.Logs"/> requested.</param> public GetLogsResponse(Logging.Logs logs) { Logs = logs ?? throw new ArgumentNullException(nameof(logs)); }