Esempio n. 1
0
        public void Test1()
        {
            var success = MobileSocket.TryParseMobilePosition(
                @"{""operation"":""position"", ""payload"":{""latitude"": 37.4219983, ""longitude"": -122.081}}",
                out GeoPoint position);

            Assert.True(success);
            Assert.Equal(37.4219983, position.Latitude);
            Assert.Equal(-122.081, position.Longitude);
        }
Esempio n. 2
0
        public async Task <IActionResult> Post([FromBody] NewOrderDto newOrderDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _orderId++;

            var pickupPosition = await GetByAddress(newOrderDto.PickUp);

            if (pickupPosition == null)
            {
                return(BadRequest($"address = \"{newOrderDto.PickUp}\"  not found"));
            }

            var dropoffPosition = await GetByAddress(newOrderDto.DropOff);

            if (dropoffPosition == null)
            {
                return(BadRequest($"address = \"{newOrderDto.DropOff}\" address not found"));
            }

            var newOrder = new Order
            {
                Id     = _orderId.ToString(),
                Status = OrderStatus.unassigned,
                Pickup = new GLocation
                {
                    Address  = newOrderDto.PickUp,
                    Position = pickupPosition,
                },
                Dropoff = new GLocation
                {
                    Address  = newOrderDto.DropOff,
                    Position = dropoffPosition,
                }
            };

            Orders.Add(newOrder);

            BrowserSocket.SendToAllAsync(new OrdersSocketMessage
            {
                Payload = Orders
            });

            MobileSocket.SendToAllMobileSockets(new OrderAvailablePayload
            {
                Payload = newOrder
            });

            return(Ok(newOrder));
        }
Esempio n. 3
0
 private void demoSocket_Load(object sender, EventArgs e)
 {
     label1.Text          = "Connect方法打开连接,Send方法发送数据,IsOpen方法获取连接状态,Close方法关闭连接,DataReceived事件在获取到数据时发生 ";
     socket               = this.Client.Socket.Create(this.Client.HostAddress, this.Client.HostTcpPort);
     socket.DataReceived += (obj, args) =>
     {
         if (args.isError == true)
         {
             Toast(string.Format("接收异常: errorCode {0}/ errorInfo {1}", args.errorCode, args.error));
         }
         else
         {
             Toast(string.Format("接收到数据: {0}", System.Convert.ToBase64String(args.Data)));
         }
     };
 }
Esempio n. 4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseMiddleware <ErrorLoggingMiddleware>();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseWebSockets();


            #region AcceptWebSocket
            app.Use(async(context, next) =>
            {
                if (context.Request.Path == "/mobile")
                {
                    if (!await MobileSocket.TryConnect(context))
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else if (context.Request.Path == "/browser")
                {
                    if (!await BrowserSocket.TryConnect(context))
                    {
                        context.Response.StatusCode = 400;
                    }
                }
                else
                {
                    await next();
                }
            });
            #endregion

            app.UseMvc();
        }