public async Task <AuthenticationResponse> Authenticate(AgentName agentName, string username, string password)
        {
            AuthenticationResponse response;

            try
            {
                response = await Constants.ApiConstants.YggdrasilUrl
                           .AppendPathSegment("authenticate")
                           .PostJsonAsync(new AuthenticationRequest()
                {
                    Agent       = AgentFactory.GetAgent(agentName),
                    Username    = username,
                    Password    = password,
                    RequestUser = true
                })
                           .ReceiveJson <AuthenticationResponse>();
            }
            catch (FlurlHttpException ex)
            {
                var error = await ex.GetResponseJsonAsync <ApiError>();

                var errorWriter = Console.Error;
                errorWriter.WriteLine(error.ErrorMessage);

                throw new Exception($"An error occurred while authenticating: {error.ErrorMessage}.");
            }

            return(response);
        }
Exemple #2
0
    public void AddAgent(AgentFactory agent, string role = null)
    {
        Agent a = agent.GetAgent();

        if (role != null)
        {
            a.SetRole(role);
        }
        else
        {
            if (a.role == null)
            {
                throw new ArgumentNullException("[MICELIO] Impossível inserir um agente sem uma role definida." +
                                                " Adicione uma role antes de inserir o objeto ou na criação dele.");
            }
        }
        this.agents.Add(a);
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        // 生成羊群,已在SheepGroup类中实现

        if (Config.randomBorn)
        {
            RandomBorn();
        }

        // 添加目标点
        GameObject go = Resources.Load <GameObject>("Prefabs/target") as GameObject;

        target = Instantiate(go, Config.targetPos, Quaternion.identity);

        // 添加牧羊犬
        go       = AgentFactory.GetAgent();
        shepherd = Instantiate(go, Config.shepherdPos, Quaternion.identity);
    }