Пример #1
0
        public object Target(Type type, string url)
        {
            var clientDescriptor = new ClientDescriptor
            {
                MethodDescriptorTable = new MethodDescriptorTable(),
                Name = _clientName,
                Type = type
            };

            foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                clientDescriptor.MethodDescriptorTable.Set(type, method);
                var methodDescriptor = clientDescriptor.MethodDescriptorTable.Get(type, method);
                if (methodDescriptor.Decoder == null)
                {
                    methodDescriptor.Decoder = _decoder;
                }

                if (methodDescriptor.Encoder == null)
                {
                    methodDescriptor.Encoder = _encoder;
                }
            }

            var httpClientFactory        = _services.GetRequiredService <IHttpClientFactory>();
            var parameterExpanderLocator = _services.GetRequiredService <IParameterExpanderLocator>();

            var goInterceptor = new FeignInterceptor(clientDescriptor, httpClientFactory, parameterExpanderLocator);

            var feignProxy = ProxyGenerator.CreateInterfaceProxyWithoutTarget(type, Enumerable.Empty <Type>().ToArray(), goInterceptor);

            return(ProxyGenerator.CreateInterfaceProxyWithTarget(type, feignProxy,
                                                                 new HystrixInterceptor(_clientName, type, feignProxy, _fallbackType, _services)));
        }
Пример #2
0
 void OnClientConnected(ClientDescriptor client)
 {
     UpdateClientSetOnline(client.MPFrontendServerUUID, client.System);
     // This method is called as a result of our control point's attempt to connect to the (allegedly attached) client;
     // But maybe the client isn't attached any more to this server (it could have detached while the server wasn't online).
     // So we will validate if the client is still attached.
     ServiceRegistration.Get <IThreadPool>().Add(() => CompleteClientConnection(client));
 }
Пример #3
0
 protected void CompleteClientConnection(ClientDescriptor client)
 {
     if (!ValidateAttachmentState(client))
     {
         return;
     }
     UpdateClientSystem(client.MPFrontendServerUUID, client.System, client.ClientName);
     ClientManagerMessaging.SendConnectionStateChangedMessage(ClientManagerMessaging.MessageType.ClientOnline, client);
 }
        protected void InvokeClientDisconnected(ClientDescriptor clientDescriptor)
        {
            ClientStateChangedDlgt dlgt = ClientDisconnected;

            if (dlgt != null)
            {
                dlgt(clientDescriptor);
            }
        }
        protected void InvokeClientUnavailable(ClientDescriptor clientDescriptor)
        {
            ClientStateChangedDlgt dlgt = ClientUnavailable;

            if (dlgt != null)
            {
                dlgt(clientDescriptor);
            }
        }
Пример #6
0
        public void Generate()
        {
            _context.Register(_query);

            GenerateEnumTypes();

            var backlog = new Queue <FieldSelection>();

            foreach (var operation in
                     _document.Definitions.OfType <OperationDefinitionNode>())
            {
                Path root = Path.New(operation.Name !.Value);

                ObjectType operationType =
                    _schema.GetOperationType(operation.Operation);

                ICodeDescriptor resultType =
                    GenerateOperationSelectionSet(
                        operationType, operation, root, backlog);

                while (backlog.Any())
                {
                    FieldSelection current = backlog.Dequeue();
                    Path           path    = current.Path.Append(current.ResponseName);

                    if (!current.Field.Type.NamedType().IsLeafType())
                    {
                        GenerateFieldSelectionSet(
                            operation, current.Field.Type,
                            current.Selection, path, backlog);
                    }
                }

                GenerateResultParserDescriptor(operation, resultType);
            }

            var clientDescriptor = new ClientDescriptor(
                _context.ClientName,
                _namespace,
                _context.Descriptors.OfType <IOperationDescriptor>().ToList());

            var servicesDescriptor = new ServicesDescriptor(
                _context.ClientName + "ServiceCollectionExtensions",
                _context.Namespace,
                clientDescriptor,
                _context.Descriptors.OfType <IInputClassDescriptor>().ToList(),
                _context.Descriptors.OfType <IEnumDescriptor>().ToList(),
                _context.Descriptors.OfType <IResultParserDescriptor>().ToList());

            _context.Register(clientDescriptor);
            _context.Register(servicesDescriptor);

            FieldTypes  = _context.FieldTypes;
            Descriptors = _context.Descriptors;
        }
Пример #7
0
 private void btnChoose_Click(object sender, EventArgs e)
 {
     if (comboboxClients.Text.Length > 0)
     {
         ClientDescriptor client = (ClientDescriptor)comboboxClients.SelectedItem;
         Client.Tibia       = client.Process;
         Client.TibiaHandle = client.Process.Handle;
         if (Addresses.SetAddresses(Client.Tibia.MainModule.FileVersionInfo.FileVersion))
         {
             Forms.UI ui = new UI();
             ui.Show();
             this.Hide();
         }
     }
 }
        void OnClientDisconnected(ClientConnection clientConnection)
        {
            ClientDescriptor descriptor = clientConnection.Descriptor;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                string deviceUuid = descriptor.MPFrontendServerUUID;
                if (!_clientConnections.ContainsKey(deviceUuid))
                {
                    return;
                }
                _clientConnections.Remove(deviceUuid);
            }
            InvokeClientDisconnected(descriptor);
        }
        protected void CheckConnect(ClientDescriptor clientDescriptor)
        {
            // Check if client is attached and connect if it is an attached client
            string clientSystemId = clientDescriptor.MPFrontendServerUUID;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                if (!_attachedClientSystemIds.Contains(clientSystemId))
                {
                    return;
                }
                if (_clientConnections.ContainsKey(clientSystemId))
                {
                    return;
                }
            }
            DeviceConnection connection;

            try
            {
                connection = _controlPoint.Connect(clientDescriptor.ClientDeviceDescriptor.RootDescriptor, clientSystemId,
                                                   UPnPExtendedDataTypes.ResolveDataType);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn(
                    "UPnPServerControlPoint: Error connecting to UPnP MP 2 frontend server '{0}'", e, clientSystemId);
                return;
            }
            try
            {
                ClientConnection clientConnection = new ClientConnection(_controlPoint, connection, clientDescriptor);
                lock (_networkTracker.SharedControlPointData.SyncObj)
                    _clientConnections.Add(clientDescriptor.MPFrontendServerUUID, clientConnection);
                clientConnection.ClientDeviceDisconnected += OnClientDisconnected;
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn(
                    "UPnPServerControlPoint: Error connecting to services of UPnP MP 2 frontend server '{0}'", e, clientSystemId);
                _controlPoint.Disconnect(connection);
                return;
            }
            InvokeClientConnected(clientDescriptor);
        }
        void OnUPnPRootDeviceRemoved(RootDescriptor rootDescriptor)
        {
            ClientDescriptor clientDescriptor;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                clientDescriptor = ClientDescriptor.GetMPFrontendServerDescriptor(rootDescriptor);
                if (clientDescriptor == null || !_availableClients.Contains(clientDescriptor))
                {
                    return;
                }
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerControlPoint: MP 2 client '{0}' (system ID '{1}') at host '{2}' was removed from the network",
                                                          clientDescriptor.ClientName, clientDescriptor.MPFrontendServerUUID, clientDescriptor.System.HostName);
                _availableClients.Remove(clientDescriptor);
            }
            InvokeClientUnavailable(clientDescriptor);
            // The client connection has its own event handler for disconnects - it will trigger method OnClientDisconnected
            // as result of disconnection, this will remove the client connection from the _clientConnections collection
        }
        void OnUPnPRootDeviceAdded(RootDescriptor rootDescriptor)
        {
            ClientDescriptor clientDescriptor;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                clientDescriptor = ClientDescriptor.GetMPFrontendServerDescriptor(rootDescriptor);
                if (clientDescriptor == null || _availableClients.Contains(clientDescriptor))
                {
                    return;
                }
                ServiceRegistration.Get <ILogger>().Debug("UPnPServerControlPoint: Found MP 2 client '{0}' (system ID '{1}') at host '{2}' ({3})",
                                                          clientDescriptor.ClientName, clientDescriptor.MPFrontendServerUUID, clientDescriptor.System.HostName,
                                                          _attachedClientSystemIds.Contains(clientDescriptor.MPFrontendServerUUID) ? "attached" : "not attached");
                _availableClients.Add(clientDescriptor);
            }
            InvokeClientAvailable(clientDescriptor);
            CheckConnect(clientDescriptor);
        }
Пример #12
0
        protected bool ValidateAttachmentState(ClientDescriptor client)
        {
            string clientSystemId = client.MPFrontendServerUUID;

            ServiceRegistration.Get <ILogger>().Info("ClientManager: Validating attachment state of client '{0}' (system ID '{1}')",
                                                     client.ClientName, clientSystemId);
            ClientConnection connection = _controlPoint.GetClientConnection(clientSystemId);

            if (connection != null)
            {
                string          homeServerSystemId = connection.ClientController.GetHomeServerSystemId();
                ISystemResolver systemResolver     = ServiceRegistration.Get <ISystemResolver>();
                if (homeServerSystemId != systemResolver.LocalSystemId)
                {
                    ServiceRegistration.Get <ILogger>().Info(
                        "ClientManager: Client '{0}' is no longer attached to this server, cleaning up client data", clientSystemId);
                    DetachClientAndRemoveShares(clientSystemId);
                    return(false);
                }
            }
            return(true);
        }
Пример #13
0
 void OnClientDisconnected(ClientDescriptor client)
 {
     UpdateClientSetOffline(client.MPFrontendServerUUID);
     ClientManagerMessaging.SendConnectionStateChangedMessage(ClientManagerMessaging.MessageType.ClientOffline, client);
 }