public ReactorAcceptorTest(IPAddress acceptorAddress, int acceptorPort,
                                   int reactorTimerMicroSeconds, int pendingConnections, bool keepAlive, bool isStream)
        {
            reactor        = new ReactorSocketImpl();
            reactorTimeout = reactorTimerMicroSeconds;
            connectionList = new List <IServiceHandler>();
            IPEndPoint endpoint = new IPEndPoint(acceptorAddress, acceptorPort);

            if (keepAlive && !isStream)
            {
                acceptor = new Tcp_SocketAcceptor(endpoint, reactor, pendingConnections, true, 5000, false);
            }
            else if (!keepAlive && !isStream)
            {
                acceptor = new Tcp_SocketAcceptor(endpoint, reactor, pendingConnections, false, 0, false);
            }
            else if (isStream)
            {
                acceptor = new Tcp_SocketAcceptor(endpoint, reactor, pendingConnections, false, 0, true);
            }

            acceptor.AcceptNotification += AcceptNotification;
            ThreadStart threadStart = new ThreadStart(Run);

            reactorThread = new Thread(threadStart);
            running       = true;
            reactorThread.Start();
        }
Esempio n. 2
0
 public Agent(Node n, IAcceptor read_acceptor, IAcceptor write_acceptor) {
   _rand = new Random();
   /**
    * @todo Make a heartbeat handler which will use the Node HeartbeatEvent
    * to resend packets after the timeout
    */
 }
Esempio n. 3
0
 public void OnStopDrag(IAcceptor acceptor)
 {
     if (lineRenderer)
     {
         DestroyImmediate(lineRenderer.gameObject);
     }
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
            var mode = args.FirstOrDefault();

            Serilog.Log.Logger = new LoggerConfiguration()
                                 .Enrich.FromLogContext()
                                 .WriteTo.Console()
                                 .WriteTo.File($"logs/{mode}-.log", rollingInterval: RollingInterval.Day)
                                 .CreateLogger();

            IInitiator initiator = null;
            IAcceptor  acceptor  = null;

            if (mode == "client")
            {
                var clientSettings = new SessionSettings("client.cfg");
                initiator = new SocketInitiator(new ClientApp(100_000), new MemoryStoreFactory(), clientSettings, new FileLogFactory(clientSettings), new MessageFactory());
                initiator.Start();
            }
            else
            {
                var serverSettings = new SessionSettings("server.cfg");
                acceptor = new ThreadedSocketAcceptor(new ServerApp(), new MemoryStoreFactory(), serverSettings, new FileLogFactory(serverSettings), new MessageFactory());
                acceptor.Start();
            }

            Console.ReadLine();
            Console.WriteLine("Bye");

            initiator?.Stop(true);
            acceptor?.Stop(true);
        }
Esempio n. 5
0
 public AppTitleSocket(
     IAcceptor <string> nameAcceptor,
     IAcceptor <string> titleAcceptor)
 {
     _nameAcceptor  = nameAcceptor;
     _titleAcceptor = titleAcceptor;
 }
Esempio n. 6
0
 public AppRunSocket(
     IAcceptor <string> nameAcceptor,
     IAcceptor <bool> runningAcceptor)
 {
     _nameAcceptor    = nameAcceptor;
     _runningAcceptor = runningAcceptor;
 }
Esempio n. 7
0
 public AsyncReader(IByteParser parser, byte[] buffer, IAcceptor acceptor, ISocketErrorHandler errorHandler, Socket socket)
 {
     _parser = parser;
     _buffer = buffer;
     _acceptor = acceptor;
     _errorHandler = errorHandler;
     _socket = socket;
     _endpoint = socket.RemoteEndPoint;
     _log = LogManager.GetLogger(_endpoint.ToString());
 }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var title = type.Value.IsGenericType
                ? namingStrategy.GetPropertyName(type.Value.Name.Split('`').First(), hasSpecifiedName: false) + "_" +
                        string.Join("_",
                                    type.Value.GenericTypeArguments.Select(a => namingStrategy.GetPropertyName(a.Name, false)))
                : namingStrategy.GetPropertyName(type.Value.Name, hasSpecifiedName: false);

            this.Visit(acceptor, name: type.Key, title: title, dataType: "object", dataFormat: null, attributes: attributes);
        }
Esempio n. 9
0
 public AsyncReader(IByteParser parser, byte[] buffer, IAcceptor acceptor, ISocketErrorHandler errorHandler, Socket socket)
 {
     _parser       = parser;
     _buffer       = buffer;
     _acceptor     = acceptor;
     _errorHandler = errorHandler;
     _socket       = socket;
     _endpoint     = socket.RemoteEndPoint;
     _log          = LogManager.GetLogger(_endpoint.ToString());
 }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            var underlyingType = type.Value.GetUnderlyingType();
            var types          = new Dictionary <string, Type>()
            {
                { type.Key, underlyingType }
            };
            var schemas = new Dictionary <string, OpenApiSchema>();

            var subAcceptor = new OpenApiSchemaAcceptor()
            {
                Types   = types,
                Schemas = schemas,
            };

            subAcceptor.Accept(this.VisitorCollection, namingStrategy);

            // Adds the schema for the underlying type.
            var name   = subAcceptor.Schemas.First().Key;
            var schema = subAcceptor.Schemas.First().Value;

            schema.Nullable = true;

            // Adds the extra properties.
            if (attributes.Any())
            {
                Attribute attr = attributes.OfType <OpenApiPropertyAttribute>().SingleOrDefault();
                if (!attr.IsNullOrDefault())
                {
                    schema.Nullable    = this.GetOpenApiPropertyNullable(attr as OpenApiPropertyAttribute);
                    schema.Default     = this.GetOpenApiPropertyDefault(attr as OpenApiPropertyAttribute);
                    schema.Description = this.GetOpenApiPropertyDescription(attr as OpenApiPropertyAttribute);
                    schema.Deprecated  = this.GetOpenApiPropertyDeprecated(attr as OpenApiPropertyAttribute);
                }

                attr = attributes.OfType <OpenApiSchemaVisibilityAttribute>().SingleOrDefault();
                if (!attr.IsNullOrDefault())
                {
                    var extension = new OpenApiString((attr as OpenApiSchemaVisibilityAttribute).Visibility.ToDisplayName());

                    schema.Extensions.Add("x-ms-visibility", extension);
                }
                schema.ApplyValidationAttributes(attributes.OfType <ValidationAttribute>());
            }
            instance.Schemas.Add(name, schema);
        }
Esempio n. 11
0
        protected void Add(int index, object target, IAcceptor itemView)
        {
            while (Items.Count <= index)
            {
                Items.Add(null);
            }
            var item = new Item(target, itemView);

            Items[index] = item;
            (itemView as IController)?.RegisterSelectionTrigger(() => CurrentTarget = target);
        }
Esempio n. 12
0
 protected override void StopImpl()
 {
     if (this._acceptor != null)
     {
         this._acceptor.Stop();
         this._acceptor = null;
     }
     foreach (ClientSession session in this.Sessions)
     {
         session.Stop();
     }
 }
Esempio n. 13
0
        public RpcServer()
        {
            _cacheContainer = new ServerCacheContainer();

            _localCacheService = new LocalCacheService(_section, _cacheContainer);

            _serializer = SerializerFactory.GetSerializer(_section.Serializer);

            _transportProvider = new TransportProvider(_cacheContainer, _serializer);

            _acceptor = _transportProvider.GetAcceptor();
        }
Esempio n. 14
0
 protected override bool InitializeImpl()
 {
     this._acceptor = base.NetworkStrategy.CreateAcceptor();
     if (this._acceptor == null)
     {
         Logger.LogError("Fail to create acceptor!", new object[0]);
         return(false);
     }
     this._acceptor.OnAcceptNew += new AcceptReactorDelegate(this.Acceptor_OnAcceptNew);
     this._acceptor.Start();
     return(true);
 }
Esempio n. 15
0
        /// <summary>
        /// Instanciates a millipede acceptor and wraps it around an existing underlying
        /// IAcceptor.
        /// </summary>
        /// <param name="underlyingAcceptor">The existing underlying IAcceptor</param>
        /// <param name="recorder">The Millipede Replayer/Recorder</param>
        protected MillipedeAcceptor(IAcceptor underlyingAcceptor, MillipedeRecorder recorder)
        {
            this.underlyingAcceptor = underlyingAcceptor;
            this.underlyingAcceptor.ValidateTransport += UnderlyingAcceptor_ValidateTransport;

            this.recorder = recorder;
            milliDescriptor = recorder.GenerateDescriptor(underlyingAcceptor);
            if (recorder.Mode != MillipedeMode.Playback)
            {
                // we only pass-through recorded connections in playback mode
                this.underlyingAcceptor.NewTransportAccepted += UnderlyingAcceptor_NewTransportEvent;
            }
        }
Esempio n. 16
0
 public override void Run()
 {
     Document = new FixedDocument();
     foreach (var page in Pages)
     {
         IAcceptor acceptor = page as IAcceptor;
         if (acceptor != null)
         {
             visitor.Visit(page);
         }
         AddPageToDocument(Document, visitor.FixedPage);
     }
 }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            type.Value.IsOpenApiNullable(out var underlyingType);

            var types = new Dictionary <string, Type>()
            {
                { type.Key, underlyingType }
            };
            var schemas = new Dictionary <string, OpenApiSchema>();

            var subAcceptor = new OpenApiSchemaAcceptor()
            {
                Types   = types,
                Schemas = schemas,
            };

            var collection = VisitorCollection.CreateInstance();

            subAcceptor.Accept(collection, namingStrategy);

            // Adds the schema for the underlying type.
            var name   = subAcceptor.Schemas.First().Key;
            var schema = subAcceptor.Schemas.First().Value;

            schema.Nullable = true;

            // Adds the visibility property.
            if (attributes.Any())
            {
                var visibilityAttribute = attributes.OfType <OpenApiSchemaVisibilityAttribute>().SingleOrDefault();
                if (!visibilityAttribute.IsNullOrDefault())
                {
                    var extension = new OpenApiString(visibilityAttribute.Visibility.ToDisplayName());

                    schema.Extensions.Add("x-ms-visibility", extension);
                }
            }

            instance.Schemas.Add(name, schema);
        }
Esempio n. 18
0
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var title = type.Value.IsGenericType
                ? namingStrategy.GetPropertyName(type.Value.Name.Split('`').First(), hasSpecifiedName: false) + "_" +
                        string.Join("_",
                                    type.Value.GenericTypeArguments.Select(a => namingStrategy.GetPropertyName(a.Name, false)))
                : namingStrategy.GetPropertyName(type.Value.Name, hasSpecifiedName: false);
            var name = this.Visit(acceptor, name: type.Key, title: title, dataType: "object", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            if (!this.IsNavigatable(type.Value))
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Processes properties.
            var properties = type.Value
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(p => !p.ExistsCustomAttribute <JsonIgnoreAttribute>())
                             .ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);

            this.ProcessProperties(instance, name, properties, namingStrategy);

            // Adds the reference.
            var reference = new OpenApiReference()
            {
                Type = ReferenceType.Schema,
                Id   = type.Value.GetOpenApiReferenceId(isDictionary: false, isList: false, namingStrategy)
            };

            instance.Schemas[name].Reference = reference;

            instance.Schemas[name].Example = this.GetExample(type.Value, namingStrategy);
        }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = type.Key;

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Adds enum values to the schema.
            var enums = type.Value.ToOpenApiInt64Collection();

            var schema = new OpenApiSchema()
            {
                Type    = "integer",
                Format  = "int64",
                Enum    = enums,
                Default = enums.First()
            };

            // Adds the extra properties.
            if (attributes.Any())
            {
                Attribute attr = attributes.OfType <OpenApiPropertyAttribute>().SingleOrDefault();
                if (!attr.IsNullOrDefault())
                {
                    schema.Nullable    = this.GetOpenApiPropertyNullable(attr as OpenApiPropertyAttribute);
                    schema.Default     = this.GetOpenApiPropertyDefault <long>(attr as OpenApiPropertyAttribute);
                    schema.Description = this.GetOpenApiPropertyDescription(attr as OpenApiPropertyAttribute);
                    schema.Deprecated  = this.GetOpenApiPropertyDeprecated(attr as OpenApiPropertyAttribute);
                }

                attr = attributes.OfType <OpenApiSchemaVisibilityAttribute>().SingleOrDefault();
                if (!attr.IsNullOrDefault())
                {
                    var extension = new OpenApiString((attr as OpenApiSchemaVisibilityAttribute).Visibility.ToDisplayName());

                    schema.Extensions.Add("x-ms-visibility", extension);
                }
            }

            instance.Schemas.Add(name, schema);
        }
Esempio n. 20
0
 public void AcceptSocket(Socket receiveSocket, IAcceptor acceptor)
 {
     try
     {
         IByteParser parser = _parserFactory.Create(receiveSocket);
         PgmSocket.EnableGigabit(receiveSocket);
         if (_receiveBufferSize > 0)
         {
             receiveSocket.ReceiveBufferSize = _receiveBufferSize;
         }
         byte[] buffer = new byte[_readBuffer];
         AsyncReader reader = new AsyncReader(parser, buffer, acceptor, this, receiveSocket);
         reader.BeginReceive();
     }catch(Exception failed)
     {
         receiveSocket.Close();
         log.Error("BeginReceive Failed", failed);
     }
 }
Esempio n. 21
0
 public void AcceptSocket(Socket receiveSocket, IAcceptor acceptor)
 {
     try
     {
         IByteParser parser = _parserFactory.Create(receiveSocket);
         PgmSocket.EnableGigabit(receiveSocket);
         if (_receiveBufferSize > 0)
         {
             receiveSocket.ReceiveBufferSize = _receiveBufferSize;
         }
         byte[]      buffer = new byte[_readBuffer];
         AsyncReader reader = new AsyncReader(parser, buffer, acceptor, this, receiveSocket);
         reader.BeginReceive();
     }catch (Exception failed)
     {
         receiveSocket.Close();
         log.Error("BeginReceive Failed", failed);
     }
 }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = type.Key;

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Adds enum values to the schema.
            var enums = type.Value.ToOpenApiInt32Collection();

            var schema = new OpenApiSchema()
            {
                Type    = "integer",
                Format  = "int32",
                Enum    = enums,
                Default = enums.First()
            };

            // Adds the visibility property.
            if (attributes.Any())
            {
                var visibilityAttribute = attributes.OfType <OpenApiSchemaVisibilityAttribute>().SingleOrDefault();
                if (!visibilityAttribute.IsNullOrDefault())
                {
                    var extension = new OpenApiString(visibilityAttribute.Visibility.ToDisplayName());

                    schema.Extensions.Add("x-ms-visibility", extension);
                }
            }

            instance.Schemas.Add(name, schema);
        }
Esempio n. 23
0
 public SystemTimeCondition(IAcceptor <DateTime> acceptor)
 {
     _acceptor = acceptor;
     _request  = new SystemTimeRequest();
 }
Esempio n. 24
0
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = this.Visit(acceptor, name: type.Key, title: null, dataType: "array", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            var underlyingType = type.Value.GetUnderlyingType();
            var types          = new Dictionary <string, Type>()
            {
                { underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy), underlyingType }
            };
            var schemas = new Dictionary <string, OpenApiSchema>();

            OpenApiSchemaAcceptor subAcceptor;

            if (!this.visitedTypes.ContainsKey(underlyingType))
            {
                subAcceptor = new OpenApiSchemaAcceptor()
                {
                    Types = types, RootSchemas = instance.RootSchemas, Schemas = schemas,
                };
                this.visitedTypes.Add(underlyingType, subAcceptor);
                subAcceptor.Accept(this.VisitorCollection, namingStrategy);
            }
            else
            {
                subAcceptor = this.visitedTypes[underlyingType];
            }

            var items = subAcceptor.Schemas.First().Value;

            // Forces to remove the title value from the items attribute.
            items.Title = null;

            // Adds the reference to the schema for the underlying type.
            if (this.IsReferential(underlyingType))
            {
                var reference = new OpenApiReference()
                {
                    Type = ReferenceType.Schema,
                    Id   = underlyingType.GetOpenApiReferenceId(underlyingType.IsOpenApiDictionary(), underlyingType.IsOpenApiArray(), namingStrategy)
                };

                items.Reference = reference;
            }

            instance.Schemas[name].Items = items;

            // Adds schemas to the root.
            var schemasToBeAdded = subAcceptor.Schemas
                                   .Where(p => p.Value.IsOpenApiSchemaObject() ||
                                          p.Value.IsOpenApiSchemaArray() ||
                                          p.Value.IsOpenApiSchemaDictionary()
                                          )
                                   .ToDictionary(p => p.Key, p => p.Value);

            if (!schemasToBeAdded.Any())
            {
                return;
            }

            foreach (var schema in schemasToBeAdded)
            {
                if (instance.RootSchemas.ContainsKey(schema.Key))
                {
                    continue;
                }

                instance.RootSchemas.Add(schema.Key, schema.Value);
            }
        }
Esempio n. 25
0
 public Item(object target, IAcceptor itemView)
 {
     Target   = target;
     ItemView = itemView;
 }
Esempio n. 26
0
 internal Acceptor(Endpoint endpoint, IAcceptor acceptor)
 {
     _endpoint = endpoint;
     _acceptor = acceptor;
 }
Esempio n. 27
0
 public void TestUdpNonSequenced()
 {
     acceptor = new UdpAcceptor(IPAddress.Any, 8765,
         new TransportFactory<UdpHandle>(BaseUdpTransport.SequencedProtocolDescriptor,
             h => new ZBSequencedUdpTransport.UdpSequencedServerTestTransport(h),
             t => t is ZBSequencedUdpTransport.UdpSequencedServerTestTransport));
     connector = new UdpConnector(
         new TransportFactory<UdpClient>(BaseUdpTransport.UnorderedProtocolDescriptor,
             h => new UdpClientTransport(h),
             t => t is UdpClientTransport));
     CheckNonConnection("localhost", "8765");
 }
Esempio n. 28
0
 public void TearDown()
 {
     if(acceptor != null) { acceptor.Dispose(); }
     acceptor = null;
     if(connector != null) { connector.Dispose(); }
     connector = null;
     if(serverTransport != null) { serverTransport.Dispose(); }
     serverTransport = null;
     if(clientTransport != null) { clientTransport.Dispose(); }
     clientTransport = null;
 }
Esempio n. 29
0
 public void SetUp()
 {
     serverTransport = null;
     clientTransport = null;
     acceptor = null;
     connector = null;
 }
Esempio n. 30
0
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var title = namingStrategy.GetPropertyName(type.Value.Name, hasSpecifiedName: false);
            var name  = this.Visit(acceptor, name: type.Key, title: title, dataType: "object", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            if (!this.IsNavigatable(type.Value))
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Processes non-recursive properties
            var properties = type.Value
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(p => !p.ExistsCustomAttribute <JsonIgnoreAttribute>())
                             .Where(p => p.PropertyType != type.Value)
                             .ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);

            this.ProcessProperties(instance, name, properties, namingStrategy);

            // Processes recursive properties
            var recursiveProperties = type.Value
                                      .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                      .Where(p => !p.ExistsCustomAttribute <JsonIgnoreAttribute>())
                                      .Where(p => p.PropertyType == type.Value)
                                      .ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);
            var recursiveSchemas = recursiveProperties.ToDictionary(p => p.Key,
                                                                    p => new OpenApiSchema()
            {
                Type      = "object",
                Reference = new OpenApiReference()
                {
                    Type = ReferenceType.Schema,
                    Id   = p.Value.PropertyType.GetOpenApiReferenceId(isDictionary: false, isList: false, namingStrategy)
                }
            });

            foreach (var recursiveSchema in recursiveSchemas)
            {
                instance.Schemas[name].Properties.Add(recursiveSchema);
            }

            // Adds the reference.
            var reference = new OpenApiReference()
            {
                Type = ReferenceType.Schema,
                Id   = type.Value.GetOpenApiReferenceId(isDictionary: false, isList: false, namingStrategy)
            };

            instance.Schemas[name].Reference = reference;
        }
Esempio n. 31
0
 /// <inheritdoc />
 public virtual void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
 {
     return;
 }
Esempio n. 32
0
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var title = namingStrategy.GetPropertyName(type.Value.Name, hasSpecifiedName: false);

            this.Visit(acceptor, name: type.Key, title: title, dataType: "object", dataFormat: null, attributes: attributes);
        }
Esempio n. 33
0
 public void TearDown()
 {
     if (server != null) { server.Dispose(); }
     if (acceptor != null) { acceptor.Dispose(); }
     if (connector != null) { connector.Dispose(); }
     if (client != null) { client.Dispose(); }
     if (acceptorThread != null) { acceptorThread.Abort(); }
     if (serverThread != null) { serverThread.Abort(); }
     server = null;
     acceptor = null;
     client = null;
     acceptorThread = null;
     serverThread = null;
 }
        /// <inheritdoc />
        public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
        {
            var name = this.Visit(acceptor, name: type.Key, title: null, dataType: "array", dataFormat: null, attributes: attributes);

            if (name.IsNullOrWhiteSpace())
            {
                return;
            }

            var instance = acceptor as OpenApiSchemaAcceptor;

            if (instance.IsNullOrDefault())
            {
                return;
            }

            // Gets the schema for the underlying type.
            var underlyingType = type.Value.GetUnderlyingType();
            var types          = new Dictionary <string, Type>()
            {
                { underlyingType.GetOpenApiTypeName(namingStrategy), underlyingType }
            };
            var schemas = new Dictionary <string, OpenApiSchema>();

            var subAcceptor = new OpenApiSchemaAcceptor()
            {
                Types       = types,
                RootSchemas = instance.RootSchemas,
                Schemas     = schemas,
            };

            subAcceptor.Accept(this.VisitorCollection, namingStrategy);

            var items = subAcceptor.Schemas.First().Value;

            // Adds the reference to the schema for the underlying type.
            if (this.IsReferential(underlyingType))
            {
                var reference = new OpenApiReference()
                {
                    Type = ReferenceType.Schema,
                    Id   = underlyingType.GetOpenApiReferenceId(isDictionary: false, isList: false, namingStrategy)
                };

                items.Reference = reference;
            }

            instance.Schemas[name].Items = items;

            // Adds schemas to the root.
            var schemasToBeAdded = subAcceptor.Schemas
                                   .Where(p => !instance.Schemas.Keys.Contains(p.Key))
                                   .Where(p => p.Value.Type == "object" &&
                                          p.Value.Format.IsNullOrWhiteSpace() &&
                                          p.Value.Items.IsNullOrDefault() &&
                                          p.Value.AdditionalProperties.IsNullOrDefault())
                                   .ToDictionary(p => p.Key, p => p.Value);

            if (!schemasToBeAdded.Any())
            {
                return;
            }

            foreach (var schema in schemasToBeAdded)
            {
                if (instance.RootSchemas.ContainsKey(schema.Key))
                {
                    continue;
                }

                instance.RootSchemas.Add(schema.Key, schema.Value);
            }
        }
Esempio n. 35
0
        public void TestTransport(IAcceptor acc, IConnector conn, string address, string port)
        {
            acceptor = acc;
            connector = conn;

            acceptor.Start();
            acceptor.NewTransportAccepted += SetupServer;
            acceptorThread = new Thread(RunAcceptor);
            acceptorThread.Name = "Acceptor";
            acceptorThread.IsBackground = true;
            acceptorThread.Start();

            client = connector.Connect(address, port, new Dictionary<string, string>());
            Assert.IsNotNull(client);
            client.PacketReceived += ClientReceivedPacket;

            for (int i = 0; i < 10; i++)
            {
                sourceData[0] = (byte)i;
                Debug("client: sending packet#" + i + ": "
                    + ByteUtils.DumpBytes(sourceData, 0, sourceData.Length));
                client.SendPacket(new TransportPacket(sourceData));
                if (failure.Length != 0)
                {
                    Assert.Fail(failure);
                }
                Thread.Sleep(500);
                client.Update();
            }
            Assert.AreEqual(10, serverPacketCount);
            Assert.AreEqual(10, clientPacketCount);

            try
            {
                client.SendPacket(new TransportPacket(new byte[client.MaximumPacketSize * 2]));
                Assert.Fail("Transport allowed sending packets exceeding its capacity");
            }
            catch (ContractViolation) { /* expected */ }
        }
Esempio n. 36
0
File: Guest.cs Progetto: mkryuk/DP
 public void Visit(IAcceptor acceptor)
 {
     acceptor.Accept(this);
 }
Esempio n. 37
0
 /// <summary>
 /// Wrap the provided acceptor for use with Millipede.
 /// If the Millipede recorder is unconfigured, we cause
 /// a dialog to configure the recorder.
 /// If the Millipede recorder is configured to be passthrough,
 /// we return the acceptor unwrapped.
 /// </summary>
 /// <param name="acceptor">the acceptor to be wrapped</param>
 /// <param name="recorder">the Millipede recorder</param>
 /// <returns>an appropriately configured acceptor</returns>
 public static IAcceptor Wrap(IAcceptor acceptor, MillipedeRecorder recorder)
 {
     if (recorder.Mode == MillipedeMode.PassThrough)
     {
         return acceptor;
     }
     return new MillipedeAcceptor(acceptor, recorder);
 }
Esempio n. 38
0
 /// <inheritdoc />
 public override void Visit(IAcceptor acceptor, KeyValuePair <string, Type> type, NamingStrategy namingStrategy, params Attribute[] attributes)
 {
     this.Visit(acceptor, name: type.Key, title: null, dataType: "integer", dataFormat: "int64", attributes: attributes);
 }
Esempio n. 39
0
 public static bool IsLoggedOn(this IAcceptor acc)
 {
     return(acc.IsLoggedOn);
 }
Esempio n. 40
0
        public void SetUp()
        {
            acceptor = new UdpAcceptor(IPAddress.Any, 8765,
                new TransportFactory<UdpHandle>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedServerTestTransport(h),
                    t => t is UdpSequencedServerTestTransport));
            connector = new UdpConnector(
                new TransportFactory<UdpClient>(BaseUdpTransport.SequencedProtocolDescriptor,
                    h => new UdpSequencedClientTestTransport(h),
                    t => t is UdpSequencedClientTestTransport));

            acceptor.NewTransportAccepted += delegate(ITransport transport, IDictionary<string, string> capabilities)
            {
                serverTransport = (UdpSequencedServerTestTransport)transport;
            };
            acceptor.Start();
            Thread acceptorThread = new Thread(delegate()
            {
                for (int i = 0; serverTransport == null && i < 100; i++)
                {
                    try
                    {
                        acceptor.Update();
                        Thread.Sleep(50);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Acceptor Thread: " + e);
                    }
                }
            });
            acceptorThread.IsBackground = true;
            acceptorThread.Name = "Acceptor Thread";
            acceptorThread.Start();
            Thread.Sleep(50);

            clientTransport = (UdpSequencedClientTestTransport)connector.Connect("127.0.0.1", "8765", new Dictionary<string, string>());
            acceptorThread.Join();
            Assert.IsNotNull(clientTransport);
            Assert.IsNotNull(serverTransport);

            acceptor.Dispose();
            connector.Dispose();
        }
Esempio n. 41
0
 internal WSAcceptor(WSEndpoint endpoint, TransportInstance instance, IAcceptor del)
 {
     _endpoint = endpoint;
     _instance = instance;
     _delegate = del;
 }