Beispiel #1
0
        /// <summary>
        /// Handles the POST request.
        /// </summary>
        /// <returns>
        /// The POST request.
        /// </returns>
        /// <param name='ctx'>
        /// Context.
        /// </param>
        public static string HandlePOSTRequest(HttpListenerContext ctx, SessionIdentity si)
        {
            if (!string.IsNullOrEmpty(ctx.Request.Headers [RESTKeys.RESTHandlerRequest]))
            {
                // This is where the string specified in the REQUEST header is matched against the
                // POST REST API mappings
                Dictionary <string, string> Headers  = UtilitiesManager.Instance.GetHeaders(ctx);
                Dictionary <string, string> PostData = UtilitiesManager.Instance.GetPOSTData(ctx);

                if (!RESTCallbackManager.Instance.POSTCallbacks.ContainsKey(ctx.Request.Headers [RESTKeys.RESTHandlerRequest]))
                {
                    ctx.Response.StatusCode = 404;
                    return(HttpResponse.NewResponse().AddErrorCode(GuruMeditation.ErrorCode.RESTHandlerRequestNotFound).ToJSON());
                }

                HttpResponse ret = RESTCallbackManager.Instance.POSTCallbacks [ctx.Request.Headers [RESTKeys.RESTHandlerRequest]]
                                       (Headers, si, PostData);

                ctx.Response.ContentType = "application/json; charset=utf-8";
                return(ret.ToJSON());
            }
            else
            {
                nMVCLogger.Instance.Error("POST requests must include the API_V1_REQUEST kv pair to indicate a route");
                ctx.Response.StatusCode = 500;
                return("BAD REQUEST");
            }
        }
Beispiel #2
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="routerID"></param>
            /// <param name="sessionID"></param>
            /// <param name="data"></param>
            /// <param name="offset"></param>
            /// <param name="count"></param>
            /// <exception cref="Exception"></exception>
            public static void SendMessage(RouterIdentity routerID, SessionIdentity sessionID, byte[] data, int offset, int count)
            {
                CheckRouter();
                INetwork netwrok = Network.Get(GetRouter(routerID));

                netwrok.Send(sessionID, data, offset, count);
            }
Beispiel #3
0
        /// <summary>
        /// Handles the GET request.
        /// </summary>
        /// <returns>
        /// The GET request.
        /// </returns>
        /// <param name='ctx'>
        /// Context.
        /// </param>
        public static object HandleGETRequest(HttpListenerContext ctx)
        {
            if (!string.IsNullOrEmpty(ctx.Request.Headers [RESTKeys.RESTHandlerRequest]))
            {
                if (!RESTCallbackManager.Instance.GETCallbacks.ContainsKey(ctx.Request.Headers [RESTKeys.RESTHandlerRequest]))
                {
                    ctx.Response.StatusCode = 404;
                    return(HttpResponse.NewResponse().AddErrorCode(GuruMeditation.ErrorCode.RESTHandlerRequestNotFound).ToJSON());
                }

                // Is a REST API request
                SessionIdentity             si      = CustomSessionIdentity.GetSessionIdentity(ctx);
                Dictionary <string, string> Headers = UtilitiesManager.Instance.GetHeaders(ctx);

                // This is where the string specified in the REQUEST header is matched against the
                // GET REST API mappings
                HttpResponse ret = RESTCallbackManager.Instance.GETCallbacks [ctx.Request.Headers [RESTKeys.RESTHandlerRequest]] (Headers, si);
                ctx.Response.ContentType = "application/json; charset=utf-8";
                if (ret.ErrorCode.Count() > 0)
                {
                    ctx.Response.StatusCode = 500;
                }
                return(ret.ToJSON());
            }

            else
            {
                // Not a REST API Request
                string route = RouterManager.Instance.FindRoute(ctx.Request.Url).FirstOrDefault();

                if (!string.IsNullOrEmpty(route) && ContentManager.Instance.content.ContainsKey(route))
                {
                    var item = ContentManager.Instance.content[route];
                    ctx.Response.ContentType     = item.ContentType.MediaType;
                    ctx.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    return(item);
                }
                else if (!string.IsNullOrEmpty(route) && RESTCallbackManager.Instance.GETCallbacks.ContainsKey(route))
                {
                    SessionIdentity             si      = CustomSessionIdentity.GetSessionIdentity(ctx);
                    Dictionary <string, string> Headers = UtilitiesManager.Instance.GetHeaders(ctx);

                    // This is where the string specified in the REQUEST header is matched against the
                    // GET REST API mappings
                    HttpResponse ret = RESTCallbackManager.Instance.GETCallbacks [route] (Headers, si);
                    //ctx.Response.ContentType = "application/json; charset=utf-8";
                    if (ret.ErrorCode.Count() > 0)
                    {
                        ctx.Response.StatusCode = 500;
                    }
                    ctx.Response.Redirect("/");
                    return("");
                }
                else
                {
                    ctx.Response.StatusCode = 404;
                    return("NOT FOUND");
                }
            }
        }
Beispiel #4
0
        private void OnMessageInternal(FixMessage msg)
        {
            var field = msg.Header[Tags.MsgType] as FixField <char>;

            switch (field.Value)
            {
            case '0':
                var hb = new FixMessage(ID, '0');
                hb.Header.Add(52, DateTime.UtcNow.ToString(FixSettings.DateTimeFormat));
                SendAsync(hb);
                break;

            case '1':
                var testAck = new FixMessage(ID, '0');
                testAck.Header.Add(52, DateTime.UtcNow.ToString(FixSettings.DateTimeFormat));
                testAck.Add(msg[Tags.TestReqID]);
                SendAsync(testAck);
                break;

            case '2':
                throw new NotImplementedException();

            case '3':
                break;

            case '4':
                throw new NotImplementedException();

            case '5':
                _transport.DisconnectAsync();
                break;

            case 'A':
                ID       = new SessionIdentity(msg.Header[Tags.BeginString].AsString(), msg.Header[Tags.SenderCompID].AsString(), msg.Header[Tags.TargetCompID].AsString());
                RevertID = new SessionIdentity(msg.Header[Tags.BeginString].AsString(), msg.Header[Tags.TargetCompID].AsString(), msg.Header[Tags.SenderCompID].AsString());
                //HeartbeatInterval = msg[Tag]

                var logon = new FixMessage(RevertID, 'A');
                logon.Header.Add(52, DateTime.UtcNow.ToString(FixSettings.DateTimeFormat));
                logon.Add(98, "0");
                logon.Add(108, "30");
                SendAsync(logon);
                break;

            default:
                // non session level message
                _application.OnMessage(msg);
                break;
            }
        }
Beispiel #5
0
        public void ToString()
        {
            var sessionId = new SessionIdentity("FIX.4.2", "EXECUTOR", "CLIENT1");
            var target    = new FixMessage(sessionId, 'A');

            target.Header.Add(34, "1");
            target.Header.Add(52, "20200925-11:05:13.797");
            target.Add(98, "0");
            target.Add(108, "30");

            var str = target.ToString();

            Assert.AreEqual("8=FIX.4.2\u00019=70\u000135=A\u000149=EXECUTOR\u000156=CLIENT1\u000134=1\u000152=20200925-11:05:13.797\u000198=0\u0001108=30\u000110=096\u0001", str);
        }
Beispiel #6
0
        public ActionResult Finish(Guid id)
        {
            var view = Global.Client.GetView <RegistrationView>(new RegistrationId(id));
            var reg  = view.Value;


            if (reg.Completed && !reg.HasProblems)
            {
                var log = SessionIdentity.Create(reg.UserDisplayName, reg.UserId, reg.UserToken, reg.SecurityId);
                // auto-login!
                return(Global.Forms.HandleLogin(log, false, Url.Action("welcome", "account")));
            }

            throw new InvalidOperationException("Invalid reg");
        }
Beispiel #7
0
        public ActionResult Index(string username, string password, bool?isRemember)
        {
            var getItem = _db.Setting.All.Count(x => (x.ItemKey == "LoginName" && x.ItemValue == username) || (x.ItemKey == "LoginPassword" && x.ItemValue == password));

            if (getItem == 2)
            {
                var newSession = new SessionIdentity();
                newSession.Username = username;
                // Creating Session
                SessionManager.CurrentSession = newSession;
                if (isRemember == true)
                {
                    Response.Cookies["HPUsername"].Expires = DateTime.UtcNow.AddDays(30);
                    Response.Cookies["HPPassword"].Expires = DateTime.UtcNow.AddDays(30);
                    Response.Cookies["HPUsername"].Value   = UtilManager.ConvertToBase64(username);
                    Response.Cookies["HPUsername"].Path    = "/";
                    Response.Cookies["HPPassword"].Value   = UtilManager.ConvertToBase64(password);
                    Response.Cookies["HPPassword"].Path    = "/";
                }
                return(Redirect("/Group"));
            }
            ModelState.AddModelError("Username", "Bilgiler Doğrulanamadı");
            return(View());
        }
Beispiel #8
0
 public InitiatorSession(IApplication application, SessionIdentity id) : base(application)
 {
     ID = id;
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="de.netcrave.nMVC.Models.DomainObjectRepository`1"/> class.
 /// </summary>
 /// <param name="si">Si.</param>
 public DomainObjectRepository(SessionIdentity si)
 {
     this.si     = si;
     _innerArray = new ArrayList();
 }
Beispiel #10
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="routerID"></param>
            /// <param name="sessionID"></param>
            /// <param name="message"></param>
            public static void SendMessage(RouterIdentity routerID, SessionIdentity sessionID, string message)
            {
                var data = Utf8.GetBytes(message);

                SendMessage(routerID, sessionID, data, 0, data.Length);
            }
Beispiel #11
0
        protected override void ApplicationStartup(Nancy.TinyIoc.TinyIoCContainer container, Nancy.Bootstrapper.IPipelines pipelines)
        {
            string gzipflag = System.Configuration.ConfigurationManager.AppSettings["EnableGzip"] ?? "1";

            if (gzipflag == "1")
            {
                AddGZip(pipelines);
            }

            pipelines.BeforeRequest += ctx =>
            {
                bool   valid = false;
                string msg   = string.Empty;
                try
                {
                    //LogUtil.WriteLog(ctx.Request.Url.ToString());
                    //放过登录入口
                    string         url      = ctx.Request.Path;
                    IList <string> freePass = new List <string>();//免除通行证
                    freePass.Add("/Auth/");
                    freePass.Add("/Exhibition/");
                    freePass.Add("/SignBook/");
                    freePass.Add("/DialogMessages/");
                    freePass.Add("/Article/ArticleCommon");
                    for (int i = 0; i < freePass.Count; i++)
                    {
                        if (url.Contains(freePass[i]))
                        {
                            return(null);
                        }
                    }
                    string appkey = ctx.Request.Headers["mars_appkey"].FirstOrDefault();

                    //LogUtil.WriteLog(appkey==null ? "NULL" : appkey);
                    //LogUtil.WriteLog(AppServerDataInitializer.AppClients.Count > 0 ? AppServerDataInitializer.AppClients[appkey].AppKey : "");

                    if (appkey != null && AppServerDataInitializer.AppClients.ContainsKey(appkey))
                    {
                        string token     = ctx.Request.Headers["mars_token"].FirstOrDefault();
                        string sessionid = ctx.Request.Headers["mars_sid"].FirstOrDefault();
                        string tick      = ctx.Request.Headers["mars_tick"].FirstOrDefault();
                        string version   = ctx.Request.Headers["mars_version"].FirstOrDefault();
                        string method    = ctx.Request.Method.ToLower();
                        if (!string.IsNullOrEmpty(token))
                        {
                            SessionIdentity si = SessionCenter.GetIdentity(sessionid);

                            if (si != null)
                            {
                                string data   = method == "get" ? ctx.Request.Query.data : ctx.Request.Form.data;
                                string token1 = GetSign(data, tick, appkey, sessionid, version, AppServerDataInitializer.AppClients[appkey].AppSecrect);

                                StringBuilder sblog = new StringBuilder();

                                sblog.AppendFormat(",Path:{0}", ctx.Request.Url.Path);
                                sblog.AppendFormat(",Method:{0}", method);
                                sblog.AppendFormat(",Data:", data);
                                sblog.AppendFormat(",Tick:{0}", tick);
                                sblog.AppendFormat(",AppKey:{0}", appkey);
                                sblog.AppendFormat(",SessionID:{0}", sessionid);
                                sblog.AppendFormat(",Version:{0}", version);
                                sblog.AppendFormat(",AppSecrect:{0}", AppServerDataInitializer.AppClients[appkey].AppSecrect);
                                sblog.AppendFormat(",Token:{0}", token1);
                                sblog.AppendFormat(",TokenFromClient:{0}", token);

                                LogUtil.WriteLog(sblog.ToString());

                                if (token == token1)
                                {
                                    si.Version = version;
                                    si.AppKey  = appkey;
                                    MarsUserIdentity identity = new MarsUserIdentity();
                                    identity.SessionID = si.SessionID;
                                    ctx.CurrentUser    = identity;
                                    valid = true;
                                }
                                else
                                {
                                    msg = "请求密钥错误!";
                                }
                            }
                            else
                            {
                                msg = "非法会话ID,请退出系统重新登录";
                            }
                        }
                        else
                        {
                            msg = "缺少会话密钥";
                        }
                    }
                    else
                    {
                        msg = "非法AppKey";
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    LogUtil.WriteLog(ex);
                }
                if (!valid)
                {
                    var res = new Response();
                    res.ContentType = "application/json; charset=utf-8";
                    res.Contents    = s =>
                    {
                        byte[] bs = Encoding.UTF8.GetBytes(JsonObj <JsonMessageBase> .ToJson(new JsonMessageBase()
                        {
                            Status = 0, Msg = msg
                        }));
                        s.Write(bs, 0, bs.Length);
                    };
                    return(res);
                }
                return(null);
            };

            base.ApplicationStartup(container, pipelines);
        }