Exemplo n.º 1
0
        public AskRequest ParseAskRequest()
        {
            var r = new AskRequest();

            GetBool();
            r.Label = GetLabel("Request");
            return(r);
        }
Exemplo n.º 2
0
        public override Task <AskResponse> Ask(AskRequest request, ServerCallContext context)
        {
            var model = new AskResponse()
            {
                Content = $"Ask: {request.Key}: {DateTime.Now.ToString()} --- address: {string.Join(",", Dns.GetHostEntry(Dns.GetHostName()).AddressList.Select(oo => oo.ToString()))}"
            };

            return(Task.FromResult(model));
        }
Exemplo n.º 3
0
 public void Output(StringBuilder sb, AskRequest ask)
 {
     AddValueCk(0, sb, "AskRequest", true);
     if (!ask.Label.HasValue())
     {
         ask.Label = "Request";
     }
     AddValueCk(1, sb, "Label", ask.Label);
     sb.AppendLine();
 }
Exemplo n.º 4
0
        public override Task <AskResponse> Ask(AskRequest request, ServerCallContext context)
        {
            var v = _configuration.GetSection("GrpcServer").GetSection("Service").GetValue <int>("Port");

            var model = new AskResponse()
            {
                Content = $"Ask: {request.Key}: {DateTime.Now.ToString()} -- configuration: {v} --- address: {string.Join(",", Dns.GetHostEntry(Dns.GetHostName()).AddressList.Select(oo => oo.ToString()))}"
            };

            return(Task.FromResult(model));
        }
Exemplo n.º 5
0
            /// <inheritdoc cref="AirDropPeer"/>.
            public override async ValueTask <bool> CanAcceptFilesAsync(AskRequest request)
            {
                var requestMessage = await AirDropHubMessage.CreateAsync(
                    (CanAcceptFilesRequestMessage m, AskRequest r) =>
                {
                    m.SenderComputerName = r.SenderComputerName;
                    m.FileIcon           = r.FileIcon;
                    m.Files = r.Files
                              .Select(
                        f => new CanAcceptFileMetadata
                    {
                        Name = f.FileName,
                        Type = f.FileType
                    })
                              .ToList();

                    return(default);
Exemplo n.º 6
0
        public override async Task <AskResponse> Ask(AskRequest request, ServerCallContext context)
        {
            Console.WriteLine($"{request.Id}:{request.Message}");

            var result = await _luis.Predict(request.Message);



            var intent = result.Intents.First();

            var response = new AskResponse();

            response.Id      = request.Id;
            response.Message = request.Message;

            Console.WriteLine($"   [Intent] {intent.Name} ({intent.Score:N2})");
            switch (intent.Name)
            {
            case "Bonjour":
                response.Answers.Add($"Bonjour à vous !");
                break;

            case "Reservite.Reserver":
                response.Answers.Add($"Vous souhaitez réserver une salle.");
                string        salle  = null;
                string        jour   = null;
                List <string> heures = new List <string>();
                foreach (var e in result.Entities)
                {
                    switch (e.Key)
                    {
                    case "salle":
                        salle = e.Value.First().Value;
                        Console.WriteLine($"   [Entity] {e.Key} : {salle}");
                        response.Answers.Add($"   {e.Key} : {salle}");
                        break;

                    case "heure":
                        foreach (var v in e.Value)
                        {
                            heures.Add(v.Value);
                            Console.WriteLine($"   [Entity] {e.Key} : {v.Value}");
                            response.Answers.Add($"   {e.Key} : {v.Value}");
                        }
                        break;

                    case "date":
                        jour = e.Value.First().Value;
                        Console.WriteLine($"   [Entity] {e.Key} : {jour}");
                        response.Answers.Add($"   {e.Key} : {jour}");
                        break;
                    }
                }
                var reservationBuilder = ReservationSalle.Parse(salle, jour, heures);
                foreach (var missing in reservationBuilder.MissingInformations)
                {
                    response.Answers.Add(missing.Question);
                }
                break;

            case "Reservite.InfosSalle":
                response.Answers.Add($"Vous souhaitez obtenir des informations sur une salle.");
                break;

            case "Reservite.SallesDisponibles":
                response.Answers.Add($"Vous souhaitez savoir quelles salles sont disponibles.");
                break;

            case "Quitter":
                break;

            case "Annuler":
                response.Answers.Add($"Vous souhaitez annuler l'opération en cours.");
                break;

            case "None":
                response.Answers.Add($"Je n'ai pas compris votre question.");
                break;

            default:
                response.Answers.Add($"Veuillez répéter svp.");
                break;
            }

            return(response);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 消息处理.
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public SystemMessage DoMessageProcess(IPEndPoint ipEndPoint, SystemMessage message)
        {
            SystemMessage result = new SystemMessage()
            {
                Header = new MessageHeader()
                {
                    CommandID  = message.Header.CommandID + 0x80000000,
                    SequenceNo = message.Header.SequenceNo,
                },
            };


            switch (message.Header.CommandID)
            {
            case MessageHeader.QM_Login_Req:
                // 登录.
                LoginRequest request = message.Body as LoginRequest;

                MyClient loginResult = clientManager.Login(ipEndPoint, request.UserName, request.Password);

                if (loginResult != null)
                {
                    result.Body = new LoginRespond()
                    {
                        UserToken = loginResult.UserToken
                    };
                }
                else
                {
                    result.Body = new LoginRespond()
                    {
                        UserToken = Guid.Empty
                    };
                }

                break;


            case MessageHeader.QM_KeepAlive_Req:
                // 心跳包.
                bool keepAliveResult = clientManager.KeepAlive(ipEndPoint, ((KeepAliveRequest)(message.Body)).UserToken);

                result.Body = new KeepAliveRespond()
                {
                    Status = keepAliveResult?1:-1
                };

                break;


            case MessageHeader.QM_Logout_Req:
                // 登出.
                clientManager.Logout(ipEndPoint, ((LogoutRequest)(message.Body)).UserToken);

                result.Body = new LogoutRespond();

                break;



            case MessageHeader.QM_UserList_Req:
                // 用户列表.
                UserListRequest userListRequest = message.Body as UserListRequest;

                if (!clientManager.IsActiveToken(userListRequest.UserToken))
                {
                    // 无效用户.
                    result.Body = new UserListRespond()
                    {
                        UserList = new List <string>()
                    };
                }
                else
                {
                    // 有效用户.
                    result.Body = new UserListRespond()
                    {
                        UserList = clientManager.GetUserList()
                    };
                }
                break;



            case MessageHeader.QM_Ask_Req:
                // 请求通话.
                AskRequest askRequest = message.Body as AskRequest;

                if (!clientManager.IsActiveToken(askRequest.UserToken))
                {
                    // 无效用户.
                    result.Body = new AskRespond()
                    {
                        Status    = -1,
                        UserName  = askRequest.AskUserName,
                        IpAddress = String.Empty,
                        Port      = 0,
                    };
                }
                else
                {
                    // 有效用户.
                    MyClient user = clientManager.GetUser(askRequest.AskUserName);

                    if (user == null)
                    {
                        // 目标用户不存在.
                        result.Body = new AskRespond()
                        {
                            Status    = -2,
                            UserName  = askRequest.AskUserName,
                            IpAddress = String.Empty,
                            Port      = 0,
                        };
                    }
                    else
                    {
                        // 目标用户存在
                        result.Body = new AskRespond()
                        {
                            Status    = 1,
                            UserName  = askRequest.AskUserName,
                            IpAddress = user.ClientIP,
                            Port      = user.ClientPort,
                        };
                    }
                }
                break;
            }

            // 返回.
            return(result);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Determines whether the peer wants to receive files from a sender.
 /// </summary>
 /// <param name="request">
 /// An <see cref="AskRequest"/> object representing information about the sender
 /// and the files that they wish to send.
 /// sender
 /// </param>
 /// <returns>
 /// <c>true</c> if the receiver wants to accept the file transfer, <c>false</c> otherwise.
 /// </returns>
 public abstract ValueTask <bool> CanAcceptFilesAsync(AskRequest request);