ReadFromString() public static method

public static ReadFromString ( string xmlAsString ) : XmlDocument,
xmlAsString string
return XmlDocument,
Esempio n. 1
0
        internal bool Load()
        {
            if (File.Exists(FileName))
            {
                var content = File.ReadAllText(FileName);
                var root    = XMLReader.ReadFromString(content);
                root = root["entries"];
                foreach (var child in root.Children)
                {
                    var id   = child.GetString("key");
                    var list = new List <string>();
                    foreach (var item in child.Children)
                    {
                        if (item.Name == "item")
                        {
                            list.Add(item.Value);
                        }
                    }

                    _keystore[id] = list;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public void TestXMLCData()
        {
            string test    = String.Format(@"<message> <content><![CDATA[test<>me]]></content></message>");
            var    root    = XMLReader.ReadFromString(test);
            var    msg     = root["message"];
            var    content = msg.GetString("content");

            Assert.IsTrue(content.Equals("test<>me"));

            test    = String.Format(@"<message> <content><![CDATA[test<>me]<[]]></content></message>");
            root    = XMLReader.ReadFromString(test);
            msg     = root["message"];
            content = msg.GetString("content");
            Assert.IsTrue(content.Equals("test<>me]<["));

            test    = String.Format(@"<message><content>![CDATA[testme]]</content></message>");
            root    = XMLReader.ReadFromString(test);
            msg     = root["message"];
            content = msg.GetString("content");
            Assert.IsTrue(content.Equals("![CDATA[testme]]"));

            test = String.Format("<message><content><![CDATA[line1.test<>me\nline2.hello\nthirdline]]></content></message>");

            root    = XMLReader.ReadFromString(test);
            msg     = root["message"];
            content = msg.GetString("content");
            Assert.IsTrue(content.Equals("line1.test<>me\nline2.hello\nthirdline"));
        }
Esempio n. 3
0
        public void Load(string fileName)
        {
            var xml  = File.ReadAllText(fileName);
            var root = XMLReader.ReadFromString(xml);

            root = root["adventure"];

            foreach (var child in root.Children)
            {
                switch (child.Name.ToLower())
                {
                case "entry":
                {
                    var entry = new Entry(child);
                    _entries[entry.id] = entry;
                    break;
                }

                case "area":
                {
                    var area_id = child.GetString("id");
                    var area    = new Area(area_id);
                    _areas[area.id] = area;
                    break;
                }

                case "item":
                {
                    var item_id = child.GetString("id");
                    var item    = new Item(child);
                    _items[item.id] = item;
                    break;
                }
                }
            }


            foreach (var child in root.Children)
            {
                switch (child.Name.ToLower())
                {
                case "area":
                {
                    var area_id = child.GetString("id");
                    var area    = FindArea(area_id);
                    area.Load(this, child);
                    break;
                }
                }
            }

            this.Reset();
        }
Esempio n. 4
0
        public void TestXMLEmpty()
        {
            var root = XMLReader.ReadFromString("");

            Assert.True(root.ChildCount.Equals(0));
            root = XMLReader.ReadFromString("    ");
            Assert.True(root.ChildCount.Equals(0));
            root = XMLReader.ReadFromString("<!---->");
            Assert.True(root.ChildCount.Equals(0));
            root = XMLReader.ReadFromString("<!-- nsbdghfds <msg>hello</msg> fdgf -->");
            Assert.True(root.ChildCount.Equals(0));
            root = XMLReader.ReadFromString("<!-- <aa /> -->");
            Assert.True(root.ChildCount.Equals(0));
        }
Esempio n. 5
0
        public static DataNode LoadFromString(DataFormat format, string contents)
        {
            switch (format)
            {
            case DataFormat.XML: return(XMLReader.ReadFromString(contents));

            case DataFormat.JSON: return(JSONReader.ReadFromString(contents));

            default:
            {
                throw new System.Exception("Format not supported");
            }
            }
        }
Esempio n. 6
0
        public static Message FromHash(string hash)
        {
            var xml = PhantasmaMail.Store.GetFile(hash);


            if (xml != null)
            {
                var root = XMLReader.ReadFromString(xml);

                root = root.FindNode("mail");
                return(new Mail(root));
            }

            return(null);
        }
Esempio n. 7
0
        public void TestXMLComments()
        {
            var root = XMLReader.ReadFromString("<message><!--This is a comment, will be ignored--><content>Hello world!</content></message>");

            Assert.NotNull(root);

            var msg = root["message"];

            Assert.NotNull(msg);
            Assert.IsTrue("message".Equals(msg.Name));

            var content = msg.GetString("content");

            Assert.IsFalse(string.IsNullOrEmpty(content));
            Assert.IsTrue("Hello world!".Equals(content));
        }
Esempio n. 8
0
        public void TestXMLCommentsUnbalanced()
        {
            var root = XMLReader.ReadFromString("<message><!-- will <-- be ignored-->" +
                                                "<content> <!--df \" \" <!-- </ message > --> " +
                                                "Hello world!</content></message>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);
            Assert.AreEqual("message", msg.Name);
            var content = msg.GetString("content");

            Assert.IsFalse(string.IsNullOrEmpty(content));
            Assert.AreEqual("Hello world!", content.Trim());
        }
Esempio n. 9
0
        public void TestXMLAttributesIgnored()
        {
            var root = XMLReader.ReadFromString("<message content=\"Hello /> world!\"/>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);

            Assert.IsTrue("message".Equals(msg.Name));

            var content = msg.GetString("content");

            Assert.IsFalse(string.IsNullOrEmpty(content));

            Assert.IsTrue("Hello /> world!".Equals(content));
        }
Esempio n. 10
0
        public void TestXMLText()
        {
            var root = XMLReader.ReadFromString("<message attribute=\"something\">other</message>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);

            Assert.IsTrue("message".Equals(msg.Name));

            var attr = msg.GetString("attribute");

            Assert.IsTrue("something".Equals(attr));

            Assert.IsTrue("other".Equals(msg.Value));
        }
Esempio n. 11
0
        public void TestXMLReaderFull()
        {
            var root = XMLReader.ReadFromString("<?xml version=\"1.0\" encoding=\"utf-8\"?><!-- In this collection, we will keep each title \"as is\" --><videos><video><title>The Distinguished Gentleman</title><director>Jonathan Lynn</director><length>112 Minutes</length><format>DVD</format><rating>R</rating></video><video><title>Her Alibi</title><director>Bruce Beresford</director><length>94 Mins</length><format>DVD</format><rating>PG-13</rating> </video></videos>");

            Assert.NotNull(root);

            var videos = root["videos"];

            Assert.NotNull(videos);

            Assert.IsTrue("videos".Equals(videos.Name));
            Assert.IsTrue(videos.ChildCount.Equals(2));

            var content = videos.GetNode("video");

            Assert.NotNull(content);
            Assert.IsTrue(content.ChildCount.Equals(5));
        }
Esempio n. 12
0
        public void TestXMLCommentsTags()
        {
            var root = XMLReader.ReadFromString("<message><!-- will - - <- be ignored-->" +
                                                "<!--df <! - - </ m\"es\"sage > dd=\"aa\" -->" +
                                                "<content>Hello world!</content>" +
                                                "<!-- df <!- - </message> --> </message>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);

            Assert.IsTrue("message".Equals(msg.Name));
            var content = msg.GetString("content");

            Assert.IsFalse(string.IsNullOrEmpty(content));
            Assert.AreEqual("Hello world!", content);
        }
Esempio n. 13
0
        public void TestXMLReader()
        {
            var xml = "<message><content>Hello world!</content></message>";

            var root = XMLReader.ReadFromString(xml);

            Assert.NotNull(root);

            var msg = root["message"];

            Assert.NotNull(msg);

            Assert.IsTrue("message".Equals(msg.Name));

            var content = msg.GetString("content");

            Assert.IsFalse(string.IsNullOrEmpty(content));

            Assert.IsTrue("Hello world!".Equals(content));
        }
Esempio n. 14
0
        public void TestNestedStructs()
        {
            var color1 = new Color(128, 200, 64, 255);
            var color2 = new Color(230, 130, 60, 100);
            var cgroup = new ColorGroup(color1, color2);

            var root = DataNode.CreateObject("test");

            Assert.NotNull(root);

            var obj = cgroup.ToDataNode();

            Assert.IsTrue(obj.ChildCount == 2);

            root.AddNode(obj);

            Assert.IsTrue(root.ChildCount == 1);

            var xml = XMLWriter.WriteToString(root);

            Assert.IsFalse(string.IsNullOrEmpty(xml));

            root = XMLReader.ReadFromString(xml);
            Assert.NotNull(root);

            var test = root.GetNode("test");

            Assert.IsTrue("test".Equals(test.Name));

            var content = test.GetNode("colorgroup");

            Assert.NotNull(content);
            Assert.IsTrue(content.ChildCount == 2);

            var otherGroup = content.ToObject <ColorGroup>();

            Assert.IsTrue(otherGroup.foreground.Equals(cgroup.foreground));
            Assert.IsTrue(otherGroup.background.Equals(cgroup.background));
        }
Esempio n. 15
0
        public void TestXMLRoot()
        {
            var root = XMLReader.ReadFromString("<message></message>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);
            Assert.IsEmpty(msg.Value);

            root = XMLReader.ReadFromString("<message>aaa</message>");
            Assert.NotNull(root);
            msg = root["message"];
            Assert.NotNull(msg);
            Assert.AreEqual("aaa", msg.Value);

            root = XMLReader.ReadFromString("<message><!--aa--></message>");
            Assert.NotNull(root);
            msg = root["message"];
            Assert.NotNull(msg);
            Assert.IsEmpty(msg.Value);
        }
Esempio n. 16
0
        internal void Reload()
        {
            var diff = DateTime.UtcNow - lastTime;

            if (diff.TotalSeconds < 10)
            {
                return;
            }

            var lastWriteTime = File.GetLastWriteTime(path);

            if (lastWriteTime < lastTime)
            {
                return;
            }

            var contents = File.ReadAllText(path);

            switch (targetExtension)
            {
            case ".xml": content = XMLReader.ReadFromString(contents); break;

            case ".json": content = JSONReader.ReadFromString(contents); break;

            case ".csv": content = CSVReader.ReadFromString(contents); break;

            case ".yaml": content = YAMLReader.ReadFromString(contents); break;

            default: throw new TemplateException("Unsupported store extension: " + targetExtension);
            }

            if (content.Name == null)
            {
                content = content.GetNodeByIndex(0);
            }

            lastTime = DateTime.UtcNow;
        }
Esempio n. 17
0
        public void TestXMLShortTag()
        {
            var root = XMLReader.ReadFromString("<message attribute=\"something\"><go /></message>");

            Assert.NotNull(root);
            var msg = root["message"];

            Assert.NotNull(msg);

            Assert.IsTrue("message".Equals(msg.Name));

            var attr = msg.GetString("attribute");

            Assert.IsTrue("something".Equals(attr));

            Assert.IsTrue(msg.ChildCount == 2);

            var child = msg.GetNodeByIndex(1);

            Assert.IsNotNull(child);
            Assert.IsTrue("go".Equals(child.Name));
            Assert.IsTrue(string.IsNullOrEmpty(child.Value));
        }
Esempio n. 18
0
        public void TestDateTime()
        {
            var date = new DateTime(2017, 11, 29, 10, 30, 0);

            var root = DataNode.CreateObject("test");

            Assert.NotNull(root);

            root.AddField("first", date);
            root.AddField("second", date.ToString());
            root.AddField("third", "2017-11-29T10:30:00.000Z");

            Assert.IsTrue(root.ChildCount == 3);

            var xml = XMLWriter.WriteToString(root);

            Assert.IsFalse(string.IsNullOrEmpty(xml));

            root = XMLReader.ReadFromString(xml);
            Assert.NotNull(root);

            var test = root.GetNode("test");

            Assert.IsTrue("test".Equals(test.Name));

            var first = test.GetDateTime("first");

            Assert.IsTrue(first.Equals(date));

            var second = test.GetDateTime("second");

            Assert.IsTrue(second.Equals(date));

            var third = test.GetDateTime("third");

            Assert.IsTrue(third.Equals(date));
        }
Esempio n. 19
0
        public void TestStructArrays()
        {
            var red   = new Color(255, 0, 0, 255);
            var green = new Color(0, 255, 0, 255);
            var blue  = new Color(0, 0, 255, 255);
            var white = new Color(255, 255, 255, 255);
            var grey  = new Color(128, 128, 128, 255);

            var root = DataNode.CreateObject("test");

            Assert.NotNull(root);

            var colors = new Color[] { red, green, blue, white, grey };
            var temp   = colors.ToDataNode("colors");

            Assert.NotNull(temp);
            Assert.IsTrue(temp.ChildCount == 5);

            root.AddNode(temp);
            var xml = XMLWriter.WriteToString(root);

            root = XMLReader.ReadFromString(xml);

            var test = root["test"];

            temp = test["colors"];

            colors = temp.ToArray <Color>();
            Assert.IsTrue(colors.Length == 5);

            Assert.IsTrue(colors[0].Equals(red));
            Assert.IsTrue(colors[1].Equals(green));
            Assert.IsTrue(colors[2].Equals(blue));
            Assert.IsTrue(colors[3].Equals(white));
            Assert.IsTrue(colors[4].Equals(grey));
        }
Esempio n. 20
0
        public void TestStructs()
        {
            var color = new Color(128, 200, 64, 255);

            var root = DataNode.CreateObject("test");

            Assert.NotNull(root);

            var obj = color.ToDataNode();

            Assert.IsTrue(obj.ChildCount == 4);

            root.AddNode(obj);

            Assert.IsTrue(root.ChildCount == 1);

            var xml = XMLWriter.WriteToString(root);

            Assert.IsFalse(string.IsNullOrEmpty(xml));

            root = XMLReader.ReadFromString(xml);
            Assert.NotNull(root);

            var test = root.GetNode("test");

            Assert.IsTrue("test".Equals(test.Name));

            var content = test.GetNode("color");

            Assert.NotNull(content);
            Assert.IsTrue(content.ChildCount == 4);

            var otherColor = content.ToObject <Color>();

            Assert.IsTrue(otherColor.Equals(color));
        }
Esempio n. 21
0
        private static void Initialize()
        {
            resourcePath = "Resources/";
            ourAssembly  = Assembly.GetExecutingAssembly();
            pdnCulture   = CultureInfo.CurrentUICulture;

            var xml  = File.ReadAllText(resourcePath + "Strings/EN.xml");
            var root = XMLReader.ReadFromString(xml);

            root = root["root"];

            _strings = new Dictionary <string, string>();

            foreach (var entry in root.Children)
            {
                if (entry.Name == "data")
                {
                    var key   = entry.GetString("name");
                    var value = entry.GetNode("value").Value;

                    _strings[key] = System.Net.WebUtility.HtmlDecode(value);
                }
            }
        }
Esempio n. 22
0
 public override DataNode ReadStore(string content)
 {
     return(XMLReader.ReadFromString(content));
 }
Esempio n. 23
0
        public AngelFont(string path)
        {
            string xml  = File.ReadAllText(path);
            var    root = XMLReader.ReadFromString(xml);

            path = Path.GetDirectoryName(path);

            if (!"font".Equals(root.Name))
            {
                root = root.GetNode("font");
            }

            var info = root.GetNode("info");

            //name = info.ReadString("face");
            name = Path.GetFileNameWithoutExtension(path);

            info        = root.GetNode("common");
            this.height = info.GetInt32("lineHeight");
            this.baseY  = info.GetInt32("base");

            int kerning = info.GetInt32("kerning");

            var pages = root.GetNode("pages");

            foreach (var child in pages.Children)
            {
                int    id            = child.GetInt32("id");
                string imageFilename = child.GetString("file");

                imageFilename = Path.Combine(path, imageFilename);

                var bitmap = new Bitmap(Image.FromFile(imageFilename));

                this.pages.Add(id, bitmap);
            }

            var chars = root.GetNode("chars");

            foreach (var child in chars.Children)
            {
                if (!child.Name.ToLower().Equals("char"))
                {
                    continue;
                }

                var c  = new FontChar();
                int id = child.GetInt32("id");
                c.x        = child.GetInt32("x");
                c.y        = child.GetInt32("y");
                c.width    = child.GetInt32("width");
                c.height   = child.GetInt32("height");
                c.xoffset  = child.GetInt32("xoffset");
                c.yoffset  = child.GetInt32("yoffset");
                c.xadvance = child.GetInt32("xadvance") + (id != 32 ? kerning : 0);
                c.page     = child.GetInt32("page");

                // An empty bitmap which will hold the cropped image
                c.image = new Bitmap(c.width, c.height);

                var g = Graphics.FromImage(c.image);

                var page    = this.pages[c.page];
                var section = new Rectangle(c.x, c.y, c.width, c.height);

                // Draw the given area (section) of the source image
                // at location 0,0 on the empty bitmap (bmp)
                g.DrawImage(page, 0, 0, section, GraphicsUnit.Pixel);

                this.chars.Add(id, c);
            }

            lineAdvance = this.chars[(int)'H'].height;
        }
Esempio n. 24
0
        private static void Main(string[] args)
        {
            var log = new SynkServer.Core.Logger();

            var settings = ServerSettings.Parse(args);

            var server = new HTTPServer(log, settings);
            var site   = new Site(server, "public");

            var keys  = new Dictionary <string, KeyPair>();
            var lines = File.ReadAllLines(rootPath + "keys.txt");

            log.Info("Loadking keys...");
            foreach (var line in lines)
            {
                var temp = line.Split(',');
                var mail = temp[0];
                var key  = temp[1];
                keys[mail] = new KeyPair(key.HexToBytes());
            }
            log.Info($"Loaded {keys.Count} keys!");

            log.Info("Initializing mailboxes...");

            var custom_mailboxes  = new ConcurrentDictionary <string, Mailbox>();
            var default_mailboxes = new ConcurrentDictionary <string, Mailbox>();

            foreach (var entry in keys)
            {
                var mailbox = new Mailbox(entry.Value);
                default_mailboxes[entry.Key] = mailbox;

                if (string.IsNullOrEmpty(mailbox.name))
                {
                    log.Info("Registering mail: " + entry.Key);
                    mailbox.RegisterName(entry.Key);
                }
            }

            if (File.Exists(rootPath + whitelistFileName))
            {
                var xml  = File.ReadAllText(rootPath + whitelistFileName);
                var root = XMLReader.ReadFromString(xml);

                try
                {
                    root = root["users"];

                    foreach (var node in root.Children)
                    {
                        if (node.Name.Equals("whitelistuser"))
                        {
                            var user = node.ToObject <WhitelistUser>();
                            if (user != null)
                            {
                                whitelist.Add(user);
                                whitelistEmailMap[user.email]   = user;
                                whitelistWalletMap[user.wallet] = user;
                            }
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("Error loading whitelist!");
                }
            }

            Console.WriteLine("Initializing server...");

            var cache = new FileCache(log, rootPath);

            Console.CancelKeyPress += delegate {
                Console.WriteLine("Closing service.");
                server.Stop();
                Environment.Exit(0);
            };

            var templateEngine = new TemplateEngine("views");

            site.Get("/", (request) =>
            {
                return(HTTPResponse.FromString(File.ReadAllText(rootPath + "home.html")));
            });

            site.Get("/terms", (request) =>
            {
                return(File.ReadAllBytes(rootPath + "terms.html"));
            });

            site.Get("/demo", (request) =>
            {
                var currentMailbox = request.session.Get <Mailbox>("current", default_mailboxes.Values.FirstOrDefault());
                var context        = new Dictionary <string, object>();

                var mailboxList = default_mailboxes.Values.ToList();

                var customMailbox = request.session.Get <Mailbox>("custom");
                if (customMailbox != null)
                {
                    mailboxList.Add(customMailbox);
                }

                context["mailboxes"] = mailboxList;

                context["currentMailbox"] = currentMailbox.name;
                context["currentAddress"] = currentMailbox.address;

                var mails = new List <MailEntry>();

                lock (currentMailbox)
                {
                    foreach (Mail entry in currentMailbox.messages)
                    {
                        var mail = new MailEntry()
                        {
                            from    = entry.fromAddress.Split('@')[0],
                            subject = entry.subject,
                            body    = entry.body,
                            date    = "12:10 AM"
                        };

                        mails.Insert(0, mail);
                    }
                }

                context["mails"] = mails.ToArray();
                context["empty"] = mails.Count == 0;

                var flash = request.session.Get <string>("flash");
                if (flash != null)
                {
                    context["flash"] = flash;
                    request.session.Remove("flash");
                }

                return(templateEngine.Render(site, context, new string[] { "demo" }));
            });

            site.Get("/demo/inbox/{id}", (request) =>
            {
                var id = request.args["id"];
                if (default_mailboxes.ContainsKey(id))
                {
                    var mailbox = default_mailboxes[id];
                    request.session.Set("current", mailbox);
                }
                else
                if (custom_mailboxes.ContainsKey(id))
                {
                    var mailbox = custom_mailboxes[id];
                    request.session.Set("current", mailbox);
                }
                return(HTTPResponse.Redirect("/demo"));
            });

            site.Post("/demo/custom", (request) =>
            {
                var emailStr = request.args["email"];

                var privateStr = request.args["private"];
                var privateKey = privateStr.HexToBytes();

                if (privateKey.Length == 32)
                {
                    var customKeys = new KeyPair(privateKey);
                    var mailbox    = new Mailbox(customKeys);

                    if (string.IsNullOrEmpty(mailbox.name))
                    {
                        mailbox.RegisterName(emailStr);
                    }
                    else
                    if (mailbox.name != emailStr)
                    {
                        request.session.Set("flash", "Wrong mail for this address");
                        return(HTTPResponse.Redirect("/demo"));
                    }

                    request.session.Set("current", mailbox);
                    request.session.Set("custom", mailbox);

                    if (!custom_mailboxes.ContainsKey(emailStr))
                    {
                        custom_mailboxes[emailStr] = mailbox;
                        lock (mailbox)
                        {
                            mailbox.SyncMessages();
                        }
                    }
                }

                return(HTTPResponse.Redirect("/demo"));
            });

            site.Post("/demo/send", (request) =>
            {
                var to      = request.args["to"];
                var subject = request.args["subject"];
                var body    = request.args["body"];

                var script = NeoAPI.GenerateScript(Protocol.scriptHash, "getAddressFromMailbox", new object[] { to });
                var invoke = NeoAPI.TestInvokeScript(Protocol.net, script);

                var temp = (byte[])invoke.result;
                if (temp != null && temp.Length > 0)
                {
                    var currentMailbox = request.session.Get <Mailbox>("current");

                    if (currentMailbox == null || string.IsNullOrEmpty(currentMailbox.name))
                    {
                        request.session.Set("flash", "Invalid mailbox selected");
                    }
                    else
                    {
                        var msg = Mail.Create(currentMailbox, to, subject, body);

                        try
                        {
                            if (currentMailbox.SendMessage(msg))
                            {
                                request.session.Set("flash", "Your message was sent to " + to);
                            }
                        }

                        catch (Exception e)
                        {
                            request.session.Set("flash", e.Message);
                        }
                    }
                }
                else
                {
                    request.session.Set("flash", to + " is not a valid Phantasma mailbox address");
                }

                return(HTTPResponse.Redirect("/demo"));
            });


            site.Post("/signup", (request) =>
            {
                var fullName = request.GetVariable("whitelist_name");
                var email    = request.GetVariable("whitelist_email");
                var wallet   = request.GetVariable("whitelist_wallet");
                var country  = request.GetVariable("whitelist_country");

                var captcha   = request.GetVariable("whitelist_captcha");
                var signature = request.GetVariable("whitelist_signature");

                string error = null;

                if (string.IsNullOrEmpty(fullName) || fullName.Length <= 5)
                {
                    error = "Full name is invalid";
                }
                else
                if (string.IsNullOrEmpty(email) || !email.Contains("@") || !email.Contains("."))
                {
                    error = "Email is invalid";
                }
                else
                if (string.IsNullOrEmpty(wallet) || !wallet.ToLower().StartsWith("a") || !WalletHelper.IsValidWallet(wallet))
                {
                    error = "Wallet does not seems to be a valid NEO address";
                }
                else
                if (string.IsNullOrEmpty(country))
                {
                    error = "Country is invalid";
                }
                else
                if (string.IsNullOrEmpty(captcha) || !CaptchaUtils.VerifyCatcha(captcha, signature))
                {
                    error = "Captcha is invalid";
                }
                else
                if (PhantasmaSite.whitelistEmailMap.ContainsKey(email))
                {
                    error = "Email already registered";
                }
                else
                if (PhantasmaSite.whitelistWalletMap.ContainsKey(wallet))
                {
                    error = "Wallet already registered";
                }

                var root = DataNode.CreateObject("signup");
                root.AddField("result", error != null ? "fail" : "success");

                if (error != null)
                {
                    root.AddField("error", error);
                }
                else
                {
                    var user     = new WhitelistUser();
                    user.name    = fullName;
                    user.email   = email;
                    user.wallet  = wallet;
                    user.country = country;

                    PhantasmaSite.AddToWhitelist(user);
                }

                var json = JSONWriter.WriteToString(root);
                return(Encoding.UTF8.GetBytes(json));
            });

            site.Get("captcha/", (request) =>
            {
                var content = File.ReadAllText(rootPath + "captcha.html");

                string sign;
                string pic;
                CaptchaUtils.GenerateCaptcha(rootPath + "captcha.fnt", out sign, out pic);

                content = content.Replace("$SIGNATURE", sign).Replace("$CAPTCHA", pic);

                return(Encoding.UTF8.GetBytes(content));
            });

            #region EMAIL SYNC THREAD
            log.Info("Running email thread");

            var emailThread = new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;

                do
                {
                    foreach (var mailbox in default_mailboxes.Values)
                    {
                        try
                        {
                            lock (mailbox)
                            {
                                mailbox.SyncMessages();
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    foreach (var mailbox in custom_mailboxes.Values)
                    {
                        try
                        {
                            lock (mailbox)
                            {
                                mailbox.SyncMessages();
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    var delay = (int)(TimeSpan.FromSeconds(5).TotalMilliseconds);
                    Thread.Sleep(delay);
                } while (true);
            });

            emailThread.Start();
            #endregion

            server.Run();
        }