示例#1
0
        static void Init(Bastion bastion)
        {
            string name = ConsolePrompt(ConsoleColor.White, "Bastion name");
            string ownerName = ConsolePrompt(ConsoleColor.White, "Owner's name");

            bastion.Init(new DeclarationOfExistence
            {
                Name = "The Bastion about Bastion",
                Owner = new Identity
                {
                    Name = name,
                    Identifier = IdentifierForName(name).ToString()
                }
            });
        }
示例#2
0
        static void Main(string[] args)
        {
            var repoDir = new DirectoryInfo(args[0]);
            ConsoleWriteLine(ConsoleColor.Yellow, "Using Bastion {0}", repoDir);
            var bastion = new Bastion(repoDir);

            if (!repoDir.Exists)
            {
                Init(bastion);
            }

            string c = null;
            while (c != "0")
            {
                c = ConsolePrompt(ConsoleColor.White, "1: Post, 2: List, 3: Get, 4: Vote");

                switch (c)
                {
                    case "1": NewPost(bastion); break;
                    case "2": ListPosts(bastion); break;
                    case "3": GetPost(bastion); break;
                    case "4": PostVote(bastion); break;
                }
            }
        }
示例#3
0
 static void ListPosts(Bastion bastion)
 {
     foreach (var post in bastion.ListPosts())
     {
         ConsoleWrite(ConsoleColor.White, post.Id);
         ConsoleWrite(ConsoleColor.Green, " {0}", post.Title);
         ConsoleWriteLine(ConsoleColor.Yellow, " {0} <{1}>", post.Author.Name, post.Author.Identifier);
     }
 }
示例#4
0
 static void GetPost(Bastion bastion)
 {
     string id = ConsolePrompt(ConsoleColor.White, "ID");
     Post p = bastion.GetPost(id);
     ConsoleWriteLine(ConsoleColor.Gray, JsonConvert.SerializeObject(p, Formatting.Indented));
 }
示例#5
0
        static void PostVote(Bastion bastion)
        {
            string id = ConsolePrompt(ConsoleColor.White, "ID");
            Post p = bastion.GetPost(id);
            VoteType v = ConsolePrompt(ConsoleColor.White, "U/D") == "U" ? VoteType.Upvote : VoteType.Downvote;
            string name = ConsolePrompt(ConsoleColor.White, "Post author");
            Identity voter = new Identity
            {
                Name = name,
                Identifier = IdentifierForName(name).ToString()
            };

            bastion.Vote(p, voter, v);
        }
示例#6
0
        static void NewPost(Bastion bastion)
        {
            string title = ConsolePrompt(ConsoleColor.White, "Post title");
            string text = ConsolePrompt(ConsoleColor.White, "Post text");
            string link = ConsolePrompt(ConsoleColor.White, "Post link");
            string author = ConsolePrompt(ConsoleColor.White, "Post author");

            bastion.NewPost(new Post
            {
                Title = title,
                Text = text,
                Link = string.IsNullOrWhiteSpace(link) ? null : new Uri(link),
                Author = new Identity
                {
                    Name = author,
                    Identifier = IdentifierForName(author).ToString()
                },
                Timestamp = DateTimeOffset.UtcNow
            });
        }