Пример #1
0
        /// <summary>
        /// Preprocess the head of request with statistic ip accessing
        /// it's used in situation of inserting user operation log into database
        /// </summary>
        /// <param name="request"></param>
        /// <param name="flag">true, do ip statisticing</param>
        /// <param name="login">true -> check if uid info in the token is null or empty</param>
        /// <returns>key error or token error in left value, or else request head in right value</returns>
        public static Either <Response, Request_Head> Preprocess2Either(this Request request, bool flag = false, bool login = false)
        {
            Util.Set_Context();

            var head_Mb = request.GetHead();

            if (!head_Mb.HasValue)
            {
                return(Constructor.Create_KeyErr_Response().ToLeft <Response, Request_Head>());
            }

            //if (Token.VerifyBlack(head_Mb.Value.Token))
            //    return Constructor.Create_BlackErr_Response().ToLeft<Response, Request_Head>();

            // validate the token
            var validation_Mb = head_Mb.Select <bool, Response>(
                h => Token.Verify(h.Token, h.Cookie, login),
                // check verify result: true -> no significant return value; false -> token error response for return value
                (h, boolean) => boolean ? null : Constructor.Create_TokErr_Response());


            // statistic ip accessing
            head_Mb.Where(_ => !validation_Mb.HasValue && flag)  // filter to make sure the token verification is passed, if not passed, ip statisticing will not be processed
            .DoWhen(_ => !VisitorStatisticHandler.AuthorizeIp() && new Random().Next(0, 4) % 3 == 0,
                    _ => Thread.Sleep(new Random().Next(2000, 6000)))
            .DoWhen(h => h.Cookie != null && h.Cookie.Length > 0,
                    h => VisitorStatisticHandler.counter.AddCookie(h.Cookie, Util.Get_RemoteIp()));

            return(validation_Mb.HasValue ? validation_Mb.Value.ToLeft <Response, Request_Head>() : head_Mb.Value.ToRight <Response, Request_Head>());
        }
Пример #2
0
        /// <summary>
        /// Preprocess the head of request with statistic ip accessing
        /// </summary>
        /// <param name="request"></param>
        /// <param name="flag">true, do ip statisticing</param>
        /// <returns>Encryption key error or token error response, or else null response</returns>
        public static Maybe <Response> Preprocess2Maybe(this Request request, bool flag = false, bool login = false)
        {
            Util.Set_Context();   // switch content type of response. It is maybe required by ios client

            var head_Mb = request.GetHead();

            if (!head_Mb.HasValue)
            {
                return(Constructor.Create_KeyErr_Response().ToMaybe());
            }

            //if (Token.VerifyBlack(head_Mb.Value.Token))
            //    return Constructor.Create_BlackErr_Response().ToMaybe();

            // validate the token
            var validation_Mb = head_Mb.Select <bool, Response>(
                h => Token.Verify(h.Token, h.Cookie, login),
                // check verify result: true -> no significant return value; false -> token error response for return value
                (h, boolean) => boolean ? null : Constructor.Create_TokErr_Response());


            // statistic ip accessing
            head_Mb.Where(_ => !validation_Mb.HasValue && flag)  // filter to make sure the token verification is passed
            //.Where(_ => flag)    // this flag marks whether do ip statisticing
            .DoWhen(_ => !VisitorStatisticHandler.AuthorizeIp() && new Random().Next(0, 4) % 3 == 0,
                    _ => Thread.Sleep(new Random().Next(2000, 6000)))
            .DoWhen(h => h.Cookie != null && h.Cookie.Length > 0,
                    h => VisitorStatisticHandler.counter.AddCookie(h.Cookie, Util.Get_RemoteIp()));

            return(validation_Mb.HasValue ? validation_Mb.Value : null);
        }
Пример #3
0
 public static Maybe <Resp_Company_List> CompanyList_Query(this Company company) =>
 company.ToMaybe()
 .DoWhen(_ => !VisitorStatisticHandler.AuthorizeIp(),                // ip checking to provent from catching info illegelly
         q => q.Pg_Index(1).Pg_Size(10).Input_Cutoff())
 .DoWhen(q => !string.IsNullOrEmpty(q.oc_name),
         q => q.Input(Regex.Replace(q.oc_name, @"[\\%#.]", "", RegexOptions.Compiled)))
 .Do(q => DataAccess.SearchHistory_Insert(q, q.u_id.ToInt() > 0))                   // Insert Search history table      /* Using Do Operation if it can do */
 .Where(q => q.pg_index < ConfigurationManager.AppSettings["query_pg_limit"].ToInt())
 .ShiftWhenOrElse(q => q.v == 1,
                  q => NextGen_Company_Search(q),
                  q => Req_Ext.PrevGen_Company_Search(q))
 .Do(q => q.oc_list.ForEach(u => u.oc_reg_capital = Util.InvestMoneyHandle(u.oc_reg_capital)));