Example #1
0
File: main.cs Project: blucz/tood
        static void _HandleRoot(Manos.Http.IHttpTransaction tx)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            tx.Response.StatusCode = 200;
            StringBuilder sb = new StringBuilder();

            _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("name", "Brian Luczkiewicz", DateTime.UtcNow.Ticks));
            _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("email", "*****@*****.**", DateTime.UtcNow.Ticks));

            int count;

            if (!_conn.TryGet("brian", new Cassandra.ColumnPath("users", "visitcount"), out count))
            {
                count = 0;
            }

            count += 1;
            _conn.Insert("brian", new Cassandra.ColumnParent("users"), new Cassandra.Column("visitcount", count, DateTime.UtcNow.Ticks));

            var name  = _conn.Get("brian", new Cassandra.ColumnPath("users", "name"));
            var email = _conn.Get("brian", new Cassandra.ColumnPath("users", "email"));

            sb.AppendLine("Name: " + name.Column.Value.ToString());
            sb.AppendLine("Email: " + email.Column.Value.ToString());
            sb.AppendLine("Visit Count: " + count);

            tx.Response.End(sb.ToString());
            tx.Response.Complete(tx.OnResponseFinished);
            sw.Stop();
            Console.WriteLine("services request in " + sw.ElapsedMilliseconds + "ms");
        }
Example #2
0
File: main.cs Project: blucz/tood
        private static void HandleStaticFile(Manos.Http.IHttpTransaction tx)
        {
            string fn = tx.Request.Path;

            while (fn.StartsWith("/"))
            {
                fn = fn.Substring(1);
            }
            string path = __staticdir;

            foreach (var part in fn.Split('/'))
            {
                if (part == "..")
                {
                    tx.Response.StatusCode = 404;
                    tx.Response.End("Not Found");
                    tx.Response.Complete(tx.OnResponseFinished);
                    return;
                }
                path = Path.Combine(path, part);
            }
            ThreadPool.QueueUserWorkItem(_ => {
                try {
                    var bytes = File.ReadAllBytes(path);
                    Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => {
                        tx.Response.StatusCode = 200;
                        tx.Response.Headers.SetHeader("Content-Type", _GetContentTypeFromExtension(Path.GetExtension(path)));
                        tx.Response.Headers.ContentLength = bytes.Length;
                        tx.Response.Write(bytes);
                        tx.Response.End();
                        tx.Response.Complete(tx.OnResponseFinished);
                    });
                } catch (FileNotFoundException) {
                    Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => {
                        tx.Response.StatusCode = 404;
                        tx.Response.End("Not Found");
                        tx.Response.Complete(tx.OnResponseFinished);
                    });
                } catch (Exception e) {
                    Console.WriteLine("Exception serving static file: " + e);
                    Manos.Threading.Boundary.Instance.ExecuteOnTargetLoop(() => {
                        tx.Response.StatusCode = 500;
                        tx.Response.End("Internal Server Error");
                        tx.Response.Complete(tx.OnResponseFinished);
                    });
                }
            });
        }
Example #3
0
File: main.cs Project: blucz/tood
 static void HandleRequest(Manos.Http.IHttpTransaction tx)
 {
     Console.WriteLine("request path " + tx.Request.Path);
     if (tx.Request.Path == "" || tx.Request.Path == "/")
     {
         tx.Request.Path = "/index.html";
         HandleRequest(tx);
     }
     else if (tx.Request.Path.StartsWith("/a/"))
     {
         HandleApi(tx);
     }
     else if (tx.Request.Path.StartsWith("/"))
     {
         HandleStaticFile(tx);
     }
     else
     {
         tx.Response.StatusCode = 404;
         tx.Response.End();
         tx.Response.Complete(tx.OnResponseFinished);
     }
 }
Example #4
0
File: main.cs Project: blucz/tood
 private static void HandleApi(Manos.Http.IHttpTransaction tx)
 {
     tx.Response.StatusCode = 404;
     tx.Response.End();
     tx.Response.Complete(tx.OnResponseFinished);
 }