示例#1
0
 public WebClient(Uri uri, Uri referrer, string ip, String userAgent, WebSession manager = null)
 {
     this.Uri             = uri;
     this.UserHostAddress = ip;
     this.UrlReferrer     = referrer;
     this.UserAgent       = userAgent;
     this.Session         = manager ?? WebSession.Instance();
     this.InnerHeaders    = UMC.Data.JSON.Deserialize <Hashtable>(this.Session.Header) ?? new Hashtable();
     this.IsCashier       = UMC.Security.Principal.Current.IsInRole(UMC.Security.Membership.UserRole);
     this.IsApp           = CheckApp(userAgent);
 }
示例#2
0
 public WebClient(Uri uri, Uri referrer, string ip, String userAgent, WebSession manager = null)
 {
     this.Uri             = uri;
     this.UserHostAddress = ip;
     this.UrlReferrer     = referrer;
     this.UserAgent       = userAgent;
     this.Session         = manager ?? WebSession.Instance();
     this.InnerHeaders    = UMC.Data.JSON.Deserialize <Hashtable>(this.Session.Header) ?? new Hashtable();
     if (this.InnerHeaders.Contains("Click"))
     {
         this.UIEvent = Data.JSON.Deserialize <UIClick>(this.InnerHeaders["Click"] as string);
     }
     this.IsCashier = UMC.Security.Principal.Current.IsInRole(UMC.Security.Membership.UserRole);
     this.IsApp     = CheckApp(userAgent, uri.Query);//.Contains("&_v=Debug");
 }
示例#3
0
        void Process(NameValueCollection nvs,
                     Uri Url, Net.NetContext context, string model, string cmd, Action <Uri> redirec)
        {
            NameValueCollection QueryString = new NameValueCollection();

            var SessionKey = String.Empty;
            var paths      = new System.Collections.Generic.List <string>(Url.AbsolutePath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));

            if (paths.Count > 0)
            {
                paths.RemoveAt(0);
            }
            if (paths.Count > 0)
            {
                SessionKey = paths[0];
                paths.RemoveAt(0);
            }

            if (String.IsNullOrEmpty(model))
            {
                if (Url.Segments.Length > 4)
                {
                    if (paths.Count > 0)
                    {
                        if (paths[paths.Count - 1].IndexOf('.') > -1)
                        {
                            paths.RemoveAt(paths.Count - 1);
                        }
                    }

                    if (paths.Count > 1)
                    {
                        model = paths[0];
                        cmd   = paths[1];
                    }
                    if (paths.Count > 2)
                    {
                        QueryString.Add(null, paths[2]);
                    }
                }
            }
            string start = nvs.Get("_start");

            for (var i = 0; i < nvs.Count; i++)
            {
                var key   = System.Web.HttpUtility.UrlDecode(nvs.GetKey(i));
                var value = nvs.Get(i);
                if (String.IsNullOrEmpty(key))
                {
                    if (String.IsNullOrEmpty(value) == false)
                    {
                        QueryString.Add(null, value);
                    }
                }
                else if (!key.StartsWith("_"))
                {
                    QueryString.Add(key, value);
                }
            }
            var jsonp = QueryString.Get("jsonp");

            QueryString.Remove("jsonp");
            WebSession session = null;
            var        writer  = new System.IO.StreamWriter(context.OutputStream);

            context.ContentType = "text/javascript;charset=utf-8";
            if (String.IsNullOrEmpty(cmd) == false && cmd.EndsWith(".html"))
            {
                context.ContentType = "text/html";
            }

            if (String.IsNullOrEmpty(SessionKey) == false)
            {
                context.Cookies[Membership.SessionCookieName] = SessionKey;
            }
            try
            {
                switch (model)
                {
                case "System":
                    switch (cmd)
                    {
                    case "Icon":
                    case "TimeSpan":
                    case "Start":
                    case "Setup":
                    case "Log":
                    case "Mapping":
                        session = new SysSession();
                        break;

                    default:
                        Authorization(context);
                        break;
                    }
                    break;

                default:
                    Authorization(context);
                    break;
                }
            }
            catch (Data.Sql.DbException exp)
            {
                if (exp.DbCommand == null)
                {
                    session = new SysSession();
                    model   = "System";
                    cmd     = "Start";
                }
                else
                {
                    throw exp;
                }
            }
            var client = new WebClient(Url, context.UrlReferrer, context.UserHostAddress, context.UserAgent, session);

            client.InputStream = context.InputStream;
            if (String.IsNullOrEmpty(jsonp) == false && jsonp.StartsWith("app"))
            {
                client.IsApp = true;
            }
            client.XHRTime = Utility.IntParse(context.Headers["umc-request-time"], 0) + 1;
            if (String.IsNullOrEmpty(start) == false)
            {
                client.Start(start);
            }
            else if (String.IsNullOrEmpty(model))
            {
                client.SendDialog(QueryString);
            }
            else if (String.IsNullOrEmpty(cmd))
            {
                if (model.StartsWith("[") == false)
                {
                    throw new Exception("Command is empty");
                }
            }
            else
            {
                client.Command(model, cmd, QueryString);
            }

            if (String.IsNullOrEmpty(model) == false && model.StartsWith("[") && String.IsNullOrEmpty(cmd))
            {
                client.JSONP(model, jsonp, writer);
            }
            else
            {
                if (String.IsNullOrEmpty(jsonp) == false)
                {
                    writer.Write(jsonp);
                    writer.Write('(');
                }
                client.WriteTo(writer, redirec);
                if (String.IsNullOrEmpty(jsonp) == false)
                {
                    writer.Write(")");
                }
            }
            writer.Flush();
        }
示例#4
0
 public WebClient(Uri uri, Uri referrer, string ip, WebSession manager = null)
     : this(uri, referrer, ip, "", manager)
 {
 }