Beispiel #1
0
        public void InitializeObjectReaderRegistry()
        {
            ObjectReaderRegistry = new ObjectReaderRegistry();
            var user     = new UserObjectReader();
            var post     = new PostObjectReader();
            var category = new CategoryObjectReader();
            var review   = new ReviewObjectReader();

            user.ReviewObjectReader   = review;
            post.ReviewObjectReader   = review;
            post.CategoryObjectReader = category;
            category.PostObjectReader = post;
            review.PostObjectReader   = post;
            review.UserObjectReader   = user;

            ObjectReaderRegistry.Reg("users", user);
            ObjectReaderRegistry.Reg("reviews", review);
            ObjectReaderRegistry.Reg("posts", review);
            ObjectReaderRegistry.Reg("categories", category);
        }
Beispiel #2
0
        public void Execute()
        {
            var command = "";

            while (command != "q")
            {
                Console.WriteLine();
                Console.WriteLine("Enter command (q => exit, h => help)");
                Console.Write("> ");
                command = Console.ReadLine(); // retreive:users
                if (command == "h")
                {
                    PrintActions();
                    continue;
                }
                else if (command == "q")
                {
                    break;
                }
                if (!Client.CommandExists(command))
                {
                    continue;
                }

                var actionHandler = ActionRegistry.Get(command);

                if (actionHandler == null)
                {
                    Console.WriteLine("Unsupported");
                    continue;
                }

                var template     = ReadTemplate(command);
                var link         = Client.GetLink(command);
                var resolvedLink = Helpers.UriParser.ParseLinkObject(link, template);
                var linkUri      = Client.GetUri(resolvedLink);

                Request request;
                if (actionHandler.HasBody)
                {
                    var objectReader = ObjectReaderRegistry.Get(command);
                    if (objectReader == null)
                    {
                        Console.WriteLine("Unsupported");
                        continue;
                    }
                    request = new Request(linkUri, objectReader.ReadFromConsole(true));
                }
                else
                {
                    request = new Request(linkUri);
                }

                try
                {
                    var response = actionHandler.Execute(request);
                    PrintResponse(response);
                }
                catch
                {
                    // Ignored
                }
            }
        }