Пример #1
0
        internal void RemoveSocketEndpointSubcription(string theSocketEndpointGuid, string theSubcriptionGuid)
        {
            SocketEndpointComponent SocketEndpoint = SocketEndpoints.FirstOrDefault(e => e.Guid == theSocketEndpointGuid);

            if (SocketEndpoint != null)
            {
                SocketEndpoint.RemoveSubcription(theSubcriptionGuid);
            }
        }
Пример #2
0
        public Response Get(string id)
        {
            SocketEndpointComponent SocketEndpoint = null;

            if (!string.IsNullOrEmpty(id))
            {
                SocketEndpoint = Core.Instance.SocketEndpoints.FirstOrDefault(t => t.Guid == id);

                if (SocketEndpoint == null)
                {
                    return(new Response
                    {
                        StatusCode = HttpStatusCode.NotFound,
                        Template = Templates.SettingsNotFound
                    });
                }
            }

            SocketEndpointHomeModel model;

            Subscription[] Subscriptions = null;

            if (SocketEndpoint != null)
            {
                model = new SocketEndpointHomeModel
                {
                    Guid             = SocketEndpoint.Guid,
                    ConnectedClients = SocketEndpoint.ConnectedClients(),
                    LoggingLevel     = SocketEndpoint.LoggingLevel,
                    TraceLog         = SocketEndpoint.TraceLog,
                };
                Subscriptions = new Subscription[] { new Subscription {
                                                         Id = SocketEndpoint.LogEventId
                                                     } };
            }
            else
            {
                model = new SocketEndpointHomeModel
                {
                    Guid             = string.Empty,
                    ConnectedClients = new string[0],
                    LoggingLevel     = 0,
                    TraceLog         = string.Empty,
                };
            }

            return(new Response
            {
                Model = model,
                Template = Templates.SettingsSocketEndpointHome,
                Subscriptions = Subscriptions
            });
        }
Пример #3
0
        public Response Post(string id)
        {
            if (id != null)
            {
                SocketEndpointComponent SocketEndpoint = Core.Instance.SocketEndpoints.FirstOrDefault(t => t.Guid == id);

                if (SocketEndpoint != null)
                {
                    Core.Instance.Remove(new[] { SocketEndpoint });
                }
            }

            return(new Response
            {
                StatusCode = System.Net.HttpStatusCode.Redirect,
                Location = Context.Referrer
            });
        }
Пример #4
0
        internal void Remove(SocketEndpointComponent[] theSocketClientComponents)
        {
            foreach (SocketEndpointComponent SocketEndpointComponent in theSocketClientComponents)
            {
                SocketEndpointComponent.SubscriptionsUpdated -= OnSubscriptionsUpdated;
                SocketEndpointComponent.EventsUpdated        -= OnEventsUpdated;
                SocketEndpointComponent.Shutdown();

                var SocketEndpointsList = new List <SocketEndpointComponent>(SocketEndpoints);
                SocketEndpointsList.Remove(SocketEndpointComponent);

                SocketEndpoints = SocketEndpointsList.ToArray();
            }

            if (theSocketClientComponents.Any())
            {
                OnSubscriptionsUpdated();
                OnEventsUpdated();
            }
        }
Пример #5
0
        internal void Update(SocketEndpointProperties[] theSocketEndpointProperties)
        {
            foreach (SocketEndpointProperties SocketEndpointProperties in theSocketEndpointProperties)
            {
                SocketEndpointComponent SocketEndpoint = SocketEndpoints.FirstOrDefault(e => e.Guid == SocketEndpointProperties.Guid);

                if (SocketEndpoint != null)
                {
                    SocketEndpoint.UpdateProperties(SocketEndpointProperties);
                }
                else
                {
                    if (!string.IsNullOrEmpty(SocketEndpointProperties.Guid))
                    {
                        var Logger = MultiPlugServices.Logging.New(SocketEndpointProperties.Guid, Diagnostics.EventLogDefinitions.DefinitionsId);
                        SocketEndpoint = new SocketEndpointComponent(SocketEndpointProperties.Guid, Logger);
                        Add(new SocketEndpointComponent[] { SocketEndpoint });
                        SocketEndpoint.UpdateProperties(SocketEndpointProperties);
                    }
                }
            }
        }
Пример #6
0
        public Response Get(string id)
        {
            SocketEndpointComponent SocketEndpoint = null;

            if (!string.IsNullOrEmpty(id))
            {
                SocketEndpoint = Core.Instance.SocketEndpoints.FirstOrDefault(Endpoint => Endpoint.Guid == id);

                if (SocketEndpoint == null)
                {
                    return(new Response
                    {
                        StatusCode = HttpStatusCode.NotFound,
                        Template = Templates.SettingsNotFound
                    });
                }
            }

            SocketEndpointSetupModel model;

            Subscription[] Subscriptions = null;

            if (SocketEndpoint != null)
            {
                model = new SocketEndpointSetupModel
                {
                    Guid          = SocketEndpoint.Guid,
                    IPAddressList = LocalIPAddressList.Get(),
                    Port          = SocketEndpoint.Port,
                    Backlog       = SocketEndpoint.Backlog,
                    NICIndex      = SocketEndpoint.NICIndex,

                    ReadEventId          = SocketEndpoint.ReadEvent.Id,
                    ReadEventDescription = SocketEndpoint.ReadEvent.Description,
                    ReadEventSubject     = (SocketEndpoint.ReadEvent.Subjects.Length > 0) ? SocketEndpoint.ReadEvent.Subjects[0] : string.Empty,

                    WriteSubscriptionGuid      = SocketEndpoint.WriteSubscriptions.Select(s => s.Guid).ToArray(),
                    WriteSubscriptionId        = SocketEndpoint.WriteSubscriptions.Select(s => s.Id).ToArray(),
                    WriteSubscriptionIndex     = SocketEndpoint.WriteSubscriptions.Select(s => s.Subjects[0].ToString()).ToArray(),
                    WriteSubscriptionConnected = SocketEndpoint.WriteSubscriptions.Select(s => s.Connected).ToArray(),
                };
                Subscriptions = new Subscription[] { new Subscription {
                                                         Id = SocketEndpoint.LogEventId
                                                     } };
            }
            else
            {
                string Guid = System.Guid.NewGuid().ToString();

                model = new SocketEndpointSetupModel
                {
                    Guid          = string.Empty,
                    IPAddressList = LocalIPAddressList.Get(),
                    Port          = 0,
                    Backlog       = 100,
                    NICIndex      = 0,

                    ReadEventId          = Guid,
                    ReadEventDescription = "Socket Read",
                    ReadEventSubject     = "value",

                    WriteSubscriptionGuid      = new string[0],
                    WriteSubscriptionId        = new string[0],
                    WriteSubscriptionIndex     = new string[0],
                    WriteSubscriptionConnected = new bool[0]
                };
            }

            return(new Response
            {
                Model = model,
                Template = Templates.SettingsSocketEndpointSetup,
                Subscriptions = Subscriptions
            });
        }