public void ProcessStubContext()
        {
            var ctx = new Mock <HttpContextBase>();
            var app = new ExpressApplication();

            Assert.IsFalse(app.Process(ctx.Object));
        }
Example #2
0
 public JsonResult ChangeStatus(long id, ExpressStatus status)
 {
     ExpressApplication.ChangeExpressStatus(id, status);
     return(Json(new Result {
         success = true, msg = "操作成功"
     }));
 }
 public JsonResult DeleteExpress(long id)
 {
     ExpressApplication.DeleteExpress(id);
     return(Json(new Result {
         success = true, msg = "删除成功"
     }, JsonRequestBehavior.AllowGet));
 }
Example #4
0
 public JsonResult DeleteExpress(long id)
 {
     ExpressApplication.DeleteExpress(id);
     return(Json(new Result {
         success = true, msg = "删除成功"
     }));
 }
 public JsonResult ClearData(long id)
 {
     ExpressApplication.ClearData(id);
     return(Json(new Result {
         success = true, msg = "清除成功"
     }, JsonRequestBehavior.AllowGet));
 }
Example #6
0
 public JsonResult ClearData(long id)
 {
     ExpressApplication.ClearData(id);
     return(Json(new Result {
         success = true, msg = "清除成功"
     }));
 }
Example #7
0
        private static void Main(string[] args)
        {
            var options = (from arg in args
                           where arg.StartsWith("--")
                           let pair = arg.Substring(2).Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries)
                                      where pair.Length == 2
                                      let key = pair[0].Trim()
                                                let val = pair[1].Trim()
                                                          select new KeyValuePair <string, string>(key, val))
                          .ToDictionary(x => x.Key, x => x.Value, StringComparer.InvariantCultureIgnoreCase);

            var app = new ExpressApplication();

            Func <double, double> square = x => x * x;

            app.Get("", req => req.Text("Hi!"))
            .Get(
                "text/{x}/{y}",
                req => req.Text(
                    string.Format("x={0}, y={1}",
                                  req.RouteData.Values["x"],
                                  req.RouteData.Values["y"]))
                )
            .Get(
                "json/{x}/{y}",
                req => req.Json(
                    new
            {
                x = req.RouteData.Values["x"],
                y = req.RouteData.Values["y"]
            })
                )
            .Get("math/square/{x}", square)
            .WebService <MathService>("math.svc");

            var port = options.Get("port", 1111);
            var mode = options.Get("mode", "tcp");

            var settings = new HttpServerSettings {
                Port = port
            };

            switch (mode.ToLowerInvariant())
            {
            case "http":
                settings.Mode = HttpServerMode.HttpListener;
                break;

            default:
                settings.Mode = HttpServerMode.TcpListener;
                break;
            }

            using (new HttpServer(app, settings))
            {
                Console.WriteLine("Listening port {0}. Press enter to stop the server.", port);
                Console.ReadLine();
            }
        }
Example #8
0
        public object GetGiftExpressInfo(long orderId)
        {
            CheckUserLogin();
            var order = GiftsOrderApplication.GetOrder(orderId, CurrentUser.Id);


            List <object> TracesList = new List <object>();

            //取订单物流信息
            if (!string.IsNullOrWhiteSpace(order.ShipOrderNumber))
            {
                var expressData = ExpressApplication.GetExpressData(order.ExpressCompanyName, order.ShipOrderNumber);
                if (expressData.Success)
                {
                    expressData.ExpressDataItems = expressData.ExpressDataItems.OrderByDescending(item => item.Time);//按时间逆序排列
                    foreach (var item in expressData.ExpressDataItems)
                    {
                        var traces = new
                        {
                            acceptStation = item.Content,
                            acceptTime    = item.Time.ToString("yyyy-MM-dd HH:mm:ss")
                        };
                        TracesList.Add(traces);
                    }
                }
            }
            var data = new
            {
                LogisticsData = new
                {
                    success = TracesList.Count > 0,
                    traces  = TracesList
                },
                ExpressCompanyName = order.ExpressCompanyName,
                ShipOrderNumber    = order.ShipOrderNumber,
                ShipTo             = order.ShipTo,
                CellPhone          = order.CellPhone,
                Address            = order.RegionFullName + order.Address
            };

            //var expressData = ExpressApplication.GetExpressData(order.ExpressCompanyName, order.ShipOrderNumber);
            //if (expressData == null)
            //{
            //    return Json(ErrorResult<dynamic>("没有物流记录!",data:new { ExpressNum = order.ShipOrderNumber, ExpressCompanyName = order.ExpressCompanyName, Comment = "" }));
            //}
            //if (expressData.Success)
            //    expressData.ExpressDataItems = expressData.ExpressDataItems.OrderByDescending(item => item.Time);//按时间逆序排列
            //var json = new
            //{
            //    Success = expressData.Success,
            //    Msg = expressData.Message,
            //    Data = expressData.ExpressDataItems.Select(item => new
            //    {
            //        time = item.Time.ToString("yyyy-MM-dd HH:mm:ss"),
            //        content = item.Content
            //    })
            //};
            return(Json(data));
        }
Example #9
0
 public static ExpressApplication EnableCors(this ExpressApplication app, string url)
 {
     return(app.Options(url, req =>
     {
         // TODO config CORS headers
         // http://enable-cors.org/server_expressjs.html
         req.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", "*");
         req.HttpContext.Response.AddHeader("Access-Control-Allow-Headers", "X-Requested-With");
     }));
 }
Example #10
0
 public JsonResult Express(ExpressCompany model)
 {
     if (model.Id > 0)
     {
         ExpressApplication.UpdateExpressCode(model);
     }
     else
     {
         ExpressApplication.AddExpress(model);
     }
     return(Json(new Result {
         success = true
     }));
 }
        public void Get(string path)
        {
            var app = new ExpressApplication();

            app.Get <string, string>("{name}", name => name);

            using (new HttpServer(app, _settings))
                using (var client = _createClient())
                {
                    var json       = client.DownloadString(path);
                    var serializer = new JavaScriptSerializer();
                    var d          = serializer.DeserializeObject(json) as IDictionary <string, object>;
                    Assert.AreEqual(path, d["d"]);
                }
        }
        public void Get(string path)
        {
            var app = new ExpressApplication();

            app.Get<string, string>("{name}", name => name);

            using (new HttpServer(app, _settings))
            using (var client = _createClient())
            {
                var json = client.DownloadString(path);
                var serializer = new JavaScriptSerializer();
                var d = serializer.DeserializeObject(json) as IDictionary<string,object>;
                Assert.AreEqual(path, d["d"]);
            }
        }
        public void GetText()
        {
            var app = new ExpressApplication();
            app.Get("test", req => req.Text("test"));

            var request = new Mock<HttpRequestBaseImpl> {CallBase = true};
            request.Setup(x => x.Url).Returns(new Uri("http://localhost/test"));

            var response = new Mock<HttpResponseBase>();

            var ctx = new Mock<HttpContextBase>();
            ctx.Setup(x => x.Request).Returns(request.Object);
            ctx.Setup(x => x.Response).Returns(response.Object);

            Assert.IsTrue(app.Process(ctx.Object));
        }
        public void Post()
        {
            var app = new ExpressApplication();
            app.Post("test", req =>
            {
                var reader = new StreamReader(req.HttpContext.Request.InputStream);
                var s = reader.ReadToEnd();
                req.HttpContext.Response.StatusCode = 200;
                req.HttpContext.Response.Write(s);
            });

            using (new HttpServer(app, _settings))
            using (var client = _createClient())
            {
                var body = Enumerable.Range(0, 1000).Select(i => "abcd").Aggregate("", (acc, val) => acc + val);
                var res = client.UploadData("test", "POST", Encoding.UTF8.GetBytes(body));
                Assert.AreEqual(body, Encoding.UTF8.GetString(res));
            }
        }
        public void Post()
        {
            var app = new ExpressApplication();

            app.Post("test", req =>
            {
                var reader = new StreamReader(req.HttpContext.Request.InputStream);
                var s      = reader.ReadToEnd();
                req.HttpContext.Response.StatusCode = 200;
                req.HttpContext.Response.Write(s);
            });

            using (new HttpServer(app, _settings))
                using (var client = _createClient())
                {
                    var body = Enumerable.Range(0, 1000).Select(i => "abcd").Aggregate("", (acc, val) => acc + val);
                    var res  = client.UploadData("test", "POST", Encoding.UTF8.GetBytes(body));
                    Assert.AreEqual(body, Encoding.UTF8.GetString(res));
                }
        }
        public void GetText()
        {
            var app = new ExpressApplication();

            app.Get("test", req => req.Text("test"));

            var request = new Mock <HttpRequestBaseImpl> {
                CallBase = true
            };

            request.Setup(x => x.Url).Returns(new Uri("http://localhost/test"));

            var response = new Mock <HttpResponseBase>();

            var ctx = new Mock <HttpContextBase>();

            ctx.Setup(x => x.Request).Returns(request.Object);
            ctx.Setup(x => x.Response).Returns(response.Object);

            Assert.IsTrue(app.Process(ctx.Object));
        }
Example #17
0
    static Server()
    {
        string dbUrl = Node.Process.Arguments[2];

        if (String.IsNullOrEmpty(dbUrl))
        {
            Debug.WriteLine("Usage: node cellar.server.js <database url>");
            Debug.WriteLine("Format of database url:");
            Debug.WriteLine("  mongodb://user:password@host:port/database");
            Debug.WriteLine(String.Empty);
            return;
        }

        CellarApplication cellarApplication = new CellarApplication();

        cellarApplication.Initialize(dbUrl, delegate(Exception initializationError) {
            if (initializationError != null)
            {
                Debug.WriteLine(initializationError.ToString());
                return;
            }

            Debug.WriteLine("Starting web application on port 8080...");
            string path = (string)Script.Literal("__dirname");

            ExpressApplication app = Express.Application();
            app.Use(Express.Static(path + "\\Content"));
            app.Get("/wines/:id", delegate(ExpressServerRequest request, ExpressServerResponse response) {
                WinesController controller = cellarApplication.CreateWinesController();
                controller.LookupWine(request, response);
            })
            .Get("/wines", delegate(ExpressServerRequest request, ExpressServerResponse response) {
                WinesController controller = cellarApplication.CreateWinesController();
                controller.QueryWines(request, response);
            });

            app.Listen(8080);
        });
    }
Example #18
0
        public JsonResult Save(string elements, string name, int width, int height, string backimage)//前台返回的的元素点的X、Y与宽、高的比例
        {
            elements = elements.Replace("\"[", "[").Replace("]\"", "]");
            var expressElements = Newtonsoft.Json.JsonConvert.DeserializeObject <IEnumerable <ExpressElement> >(elements);

            ExpressCompany express = new ExpressCompany();

            express.Name            = name;
            express.Height          = height;
            express.Width           = width;
            express.BackGroundImage = backimage;
            express.Elements        = expressElements.Select(e => new ExpressElement
            {
                a           = e.a,
                b           = e.b,
                ElementType = (ExpressElementType)e.name,
            }).ToList();
            ExpressApplication.UpdateExpressAndElement(express);
            return(Json(new Result {
                success = true
            }));
        }
Example #19
0
        public JsonResult GetConfig(string name)
        {
            var template     = ExpressApplication.GetExpress(name);
            var elementTypes = Enum.GetValues(typeof(ExpressElementType));
            var allElements  = new List <Element>();

            foreach (var item in elementTypes)
            {
                Element el = new Element()
                {
                    key   = ((int)item).ToString(),
                    value = ((ExpressElementType)item).ToDescription()
                };
                allElements.Add(el);
            }
            ExpressTemplateConfig config = new ExpressTemplateConfig()
            {
                width  = template.Width,
                height = template.Height,
                data   = allElements.ToArray(),
            };

            if (template.Elements != null)
            {
                int i = 0;
                foreach (var element in template.Elements)
                {
                    var item = config.data.FirstOrDefault(t => t.key == ((int)element.ElementType).ToString());
                    item.a        = element.a;
                    item.b        = element.b;
                    item.selected = true;
                    i++;
                }
                config.selectedCount = i;
            }
            return(Json(config));
        }
 public void ProcessStubContext()
 {
     var ctx = new Mock<HttpContextBase>();
     var app = new ExpressApplication();
     Assert.IsFalse(app.Process(ctx.Object));
 }
Example #21
0
        public static ExpressApplication Nest(this ExpressApplication app, string prefix, ExpressApplication nested)
        {
            var url = prefix.EndsWith("/") ? prefix + "{*}" : prefix + "/{*}";

            return(app.All(url, req => nested.Process(req.HttpContext)));
        }
Example #22
0
        public ActionResult Management()
        {
            var result = ExpressApplication.GetAllExpress();

            return(View(result));
        }
Example #23
0
        public ActionResult Edit(string name)
        {
            var template = ExpressApplication.GetExpress(name);

            return(View(template));
        }
Example #24
0
 public static ExpressApplication Nest(this ExpressApplication app, string prefix, ExpressApplication nested)
 {
     var url = prefix.EndsWith("/") ? prefix + "{*}" : prefix + "/{*}";
     return app.All(url, req => nested.Process(req.HttpContext));
 }
Example #25
0
 public static ExpressApplication EnableCors(this ExpressApplication app)
 {
     return(app.EnableCors("{*}"));
 }
        /// <summary>
        /// 获取所有快递公司名称
        /// </summary>
        /// <returns></returns>
        public string GetAllExpress()
        {
            var listData = ExpressApplication.GetAllExpress().Select(i => i.Name);

            return(String.Join(",", listData));
        }