public Response Get(string id) { SocketClientComponent SocketEndpoint = null; if (!string.IsNullOrEmpty(id)) { SocketEndpoint = Core.Instance.SocketClients.FirstOrDefault(t => t.Guid == id); if (SocketEndpoint == null) { return(new Response { Template = Templates.SettingsNotFound }); } } SocketClientHomeModel Model; Subscription[] Subscriptions = null; if (SocketEndpoint != null) { Model = new SocketClientHomeModel { Guid = SocketEndpoint.Guid, LoggingLevel = SocketEndpoint.LoggingLevel, TraceLog = SocketEndpoint.TraceLog, Connected = SocketEndpoint.Connected, ConnectionInError = SocketEndpoint.ConnectionInError }; Subscriptions = new Subscription[] { new Subscription { Id = SocketEndpoint.LogEventId } }; } else { string Guid = System.Guid.NewGuid().ToString(); Model = new SocketClientHomeModel { Guid = string.Empty, LoggingLevel = 0, TraceLog = string.Empty, Connected = false, ConnectionInError = false }; Subscriptions = new Subscription[0]; } return(new Response { Model = Model, Template = Templates.SettingsSocketClientHome, Subscriptions = Subscriptions }); }
internal void RemoveSocketClientSubcription(string theSocketClientGuid, string theSubcriptionGuid) { SocketClientComponent SocketClient = SocketClients.FirstOrDefault(c => c.Guid == theSocketClientGuid); if (SocketClient != null) { SocketClient.RemoveSubcription(theSubcriptionGuid); } }
public Response Post(string id) { if (id != null) { SocketClientComponent SocketClient = Core.Instance.SocketClients.FirstOrDefault(t => t.Guid == id); if (SocketClient != null) { Core.Instance.Remove(new[] { SocketClient }); } } return(new Response { StatusCode = System.Net.HttpStatusCode.Redirect, Location = Context.Referrer }); }
internal void Remove(SocketClientComponent[] theSocketClientComponents) { foreach (SocketClientComponent SocketClientComponent in theSocketClientComponents) { SocketClientComponent.SubscriptionsUpdated -= OnSubscriptionsUpdated; SocketClientComponent.EventsUpdated -= OnEventsUpdated; SocketClientComponent.Shutdown(); var SocketClientsList = new List <SocketClientComponent>(SocketClients); SocketClientsList.Remove(SocketClientComponent); SocketClients = SocketClientsList.ToArray(); } if (theSocketClientComponents.Any()) { OnSubscriptionsUpdated(); OnEventsUpdated(); } }
internal void Update(SocketClientProperties[] theSocketClientProperties) { foreach (var item in theSocketClientProperties) { SocketClientComponent SocketClient = SocketClients.FirstOrDefault(c => c.Guid == item.Guid); if (SocketClient != null) { SocketClient.UpdateProperties(item); } else { if (!string.IsNullOrEmpty(item.Guid)) { var Logger = MultiPlugServices.Logging.New(item.Guid, Diagnostics.EventLogDefinitions.DefinitionsId); SocketClient = new SocketClientComponent(item.Guid, Logger); Add(new SocketClientComponent[] { SocketClient }); SocketClient.UpdateProperties(item); } } } }
public Response Get(string id) { SocketClientComponent SocketClient = null; if (!string.IsNullOrEmpty(id)) { SocketClient = Core.Instance.SocketClients.FirstOrDefault(Client => Client.Guid == id); if (SocketClient == null) { return(new Response { Template = Templates.SettingsNotFound }); } } SocketClientSetupModel model; Subscription[] Subscriptions = null; if (SocketClient != null) { model = new SocketClientSetupModel { Guid = SocketClient.Guid, HostName = SocketClient.HostName, Port = SocketClient.Port, ReadEventId = SocketClient.ReadEvent.Id, ReadEventDescription = SocketClient.ReadEvent.Description, ReadEventSubject = (SocketClient.ReadEvent.Subjects.Length > 0) ? SocketClient.ReadEvent.Subjects[0] : string.Empty, WriteSubscriptionGuid = SocketClient.WriteSubscriptions.Select(s => s.Guid).ToArray(), WriteSubscriptionId = SocketClient.WriteSubscriptions.Select(s => s.Id).ToArray(), WriteSubscriptionIndex = SocketClient.WriteSubscriptions.Select(s => s.Subjects[0].ToString()).ToArray(), WriteSubscriptionConnected = SocketClient.WriteSubscriptions.Select(s => s.Connected).ToArray(), }; Subscriptions = new Subscription[] { new Subscription { Id = SocketClient.LogEventId } }; } else { string Guid = System.Guid.NewGuid().ToString(); model = new SocketClientSetupModel { Guid = string.Empty, HostName = string.Empty, Port = 0, ReadEventId = Guid, ReadEventDescription = "Socket Read", ReadEventSubject = "value", WriteSubscriptionGuid = new string[0], WriteSubscriptionId = new string[0], WriteSubscriptionIndex = new string[0], WriteSubscriptionConnected = new bool[0] }; Subscriptions = new Subscription[0]; } return(new Response { Model = model, Template = Templates.SettingsSocketClientSetup, Subscriptions = Subscriptions }); }