Example #1
0
        public async Task <Response <FeedNoticia> > ObterPrincipaisPalavrasAsync()
        {
            var response = new Response <FeedNoticia>();

            var conteudo = await _blogMinutoSeguroService.ObterConteudoFeedAsync();

            if (string.IsNullOrEmpty(conteudo))
            {
                response.RasonPhrase = "Conteudo da página não encontrado";
                return(response);
            }

            response.AddContent(new FeedNoticia(conteudo));

            return(response);
        }
        public async Task GetSinglePersonRegistrationShouldReturnSingleItemLink()
        {
            // arrange
            RegistrationClass.Registering = container =>
                                            container
                                            .Register <Person>("self", p => p.Id)
                                            .Get <PersonController>();

            var person = new Person {
                Id = Guid.NewGuid()
            };

            Response.AddContent(person);

            // act & assert
            var result = await RegisterGetAndAssertResponse(true, person, 1, 0);

            // assert
            result.HateoasResponse
            .Links.First()
            .Should().Match((LinkResponse lr) => $"/api/person/{person.Id}".Equals(lr.Href));

            /*
             * {
             *  "Data": {
             *      "Id": "3cc857e2-acd2-4780-a73b-5996ffb0ea82",
             *      ...
             *  },
             *  "Links": [
             *      {
             *          "Href": "/api/person/3cc857e2-acd2-4780-a73b-5996ffb0ea82",
             *          "Template": null,
             *          "Rel": "self",
             *          "Method": "GET",
             *          "Command": null
             *      }
             *   ],
             *   "Commands": []
             * }
             */
        }
Example #3
0
 private void SendKey(Transceiver connection, User request, string userPluginHash)
 {
     string publickey;
     string username;
     Message message = new Message();
     message.creator_plugin_hash = this._hash_code;
     message.type = Message.Type.ServerToUser;
     if(request == null)
     {
         publickey = this._server_public_key;
         username = "******";
     }
     else
     {
         publickey = (string)this._user_keys[request.connection];
         username = request.username;
     }
     Response content = new Response();
     message.content = content;
     content.type = BasicContent.Type.Response;
     content.rtype = "success";
     content.AddContent("command", "publickey");
     content.AddContent("username", username);
     content.AddContent("publickey", publickey);
     string mess = message.DumpMessage();
     connection.Write(mess);
 }
Example #4
0
 private void UserInformation(string username, Message message)
 {
     User userinfo = this.GetUser(username);
     Message response = new Message();
     response.type = Message.Type.ServerToUserPlugin;
     response.creator_plugin_hash = this._hash_code;
     response.destination_plugin_hash = message.creator_plugin_hash;
     Response content = new Response();
     content.rtype = "success";
     content.AddContent("command", "information");
     content.AddContent("username", userinfo.username);
     content.AddContent("alias", userinfo.alias);
     response.content = content;
     message.origin.Write(response);
     User requesterInfo = this.GetUser(message.origin);
     Message information = new Message();
     information.type = Message.Type.ServerToUser;
     information.creator_plugin_hash = this._hash_code;
     Information con = new Information();
     con.AddContent("username", requesterInfo.username);
     con.AddContent("alias", requesterInfo.alias);
     information.content = con;
     userinfo.connection.Write(information);
 }
Example #5
0
 private void Status(string username, Message message)
 {
     User info = this._users.Get(username);
     string stats = info.GetStatus();
     Message statusMessage = new Message();
     statusMessage.type = Message.Type.ServerToUserPlugin;
     statusMessage.creator_plugin_hash = this._hash_code;
     statusMessage.destination_plugin_hash = message.creator_plugin_hash;
     Command command = (Command)message.content;
     Response contents = new Response();
     contents.AddContent(command.ctype, stats);
     statusMessage.content = contents;
     message.origin.Write(statusMessage);
 }
Example #6
0
 private void ProcessCommand(Message message, Command command)
 {
     try
     {
         switch(command.ctype)
         {
             case "login":
                 this.Login(command.GetContent("username"), command.GetContent("password"), message);
                 break;
             case "logout":
                 this.Logout(command.GetContent("username"), message);
                 break;
             case "register":
                 this.Register(command.GetContent("username"), command.GetContent("password"), command.GetContent("alias"));
                 break;
             case "status":
                 this.Status(command.GetContent("username"), message);
                 throw new Exception("Punching out so we don't send an error.");
                 break;
             case "information":
                 this.UserInformation(command.GetContent("username"), message);
                 break;
             default:
                 throw new UnknownType("Command not valid.");
                 break;
         }
     }
     catch(IrisIMException e)
     {
         Message resp = new Message();
         resp.creator_plugin_hash = this._hash_code;
         resp.destination_plugin_hash = message.creator_plugin_hash;
         resp.type = Message.Type.ServerToUserPlugin;
         Response content = new Response();
         content.rtype = "failure";
         content.AddContent("command", command.ctype);
         content.AddContent("reason", e.Message);
         resp.content = content;
         message.origin.Write(resp);
     }
     catch(Exception e)
     {
         Message resp = new Message();
         resp.creator_plugin_hash = this._hash_code;
         resp.destination_plugin_hash = message.creator_plugin_hash;
         resp.type = Message.Type.ServerToUserPlugin;
         Response content = new Response();
         content.rtype = "failure";
         content.AddContent("command", command.ctype);
         content.AddContent("reason", e.Message);
         resp.content = content;
         message.origin.Write(resp);
         Logger.log("UserManager ProcessCommand error:", Logger.Verbosity.moderate);
         Logger.log(e.Message+"\n"+e.StackTrace, Logger.Verbosity.moderate);
     }
 }
Example #7
0
 private void Login(string username, string password, Message message)
 {
     Logger.log("attempting login.", Logger.Verbosity.moderate);
     try
     {
         UserInfo info = this._user_database.GetUser(username, password);
         User user = new User(info.username, info.alias, message.origin);
         this._users.Add(user);
         Message response = new Message();
         response.type = Message.Type.ServerToUserPlugin;
         response.creator_plugin_hash = this._hash_code;
         response.destination_plugin_hash = message.creator_plugin_hash;
         Response content = new Response();
         content.rtype = "success";
         content.AddContent("command", "login");
         response.content = content;
         message.origin.Write(response);
     }
     catch(IrisIMException e)
     {
         throw new ItemNotFound("Invalid username/password");
     }
 }