예제 #1
0
        static void Main(string[] args)
        {
            string document = "SAMPLE TEXT";

            char[] CharsInDocument = document.ToCharArray();

            ConsoleColor[] colors = new ConsoleColor[CharsInDocument.Length];

            for (int i = 0; i < CharsInDocument.Length; i++)
            {
                colors[i] = ConsoleColor.White;
                if (i % 2 != 0)
                {
                    colors[i] = ConsoleColor.Green;
                }
            }

            CharsFactory CharsFactory = new CharsFactory();

            for (int i = 0; i < CharsInDocument.Length; i++)
            {
                Console.ForegroundColor = colors[i];
                Char letter = CharsFactory.GetChar(CharsInDocument[i]);
                letter.DisplayText();
            }

            Console.WriteLine("\nNumber of repeating characters: " + CharsFactory.NumberRepeatingChars);

            Console.ReadKey();
        }
예제 #2
0
        protected override GetAuthCodeRD ProcessRequest(DTO.Base.APIRequest <GetAuthCodeRP> pRequest)
        {
            //参数验证
            if (string.IsNullOrEmpty(pRequest.Parameters.Mobile))
            {
                throw new APIException("请求参数中缺少Mobile或值为空.")
                      {
                          ErrorCode = ERROR_LACK_MOBILE
                      };
            }
            //
            GetAuthCodeRD rd = new GetAuthCodeRD();

            #region 发送短信
            string msg;
            var    code = CharsFactory.Create6Char();
            var    sign = string.Empty;
            #region 根据客户名称创建签名
            //暂时先用阿拉丁,后须改为客户名称
            //sign = "阿拉丁";
            //sign = CurrentUserInfo.ClientName;

            if (string.IsNullOrEmpty(pRequest.CustomerID))
            {
                throw new APIException("请求参数中缺少CustomerId或值为空.")
                      {
                          ErrorCode = 121
                      };
            }
            var bll = new VipBLL(CurrentUserInfo);

            sign = !string.IsNullOrEmpty(bll.GetSettingValue(CurrentUserInfo.ClientID)) ? bll.GetSettingValue(CurrentUserInfo.ClientID) : "阿拉丁";


            #endregion
            if (!SMSHelper.Send(pRequest.CustomerID, pRequest.Parameters.Mobile, code, sign, out msg))
            {
                //throw new APIException("短信发送失败:" + msg) { ErrorCode = ERROR_SMS_FAILD };
                throw new APIException(msg)
                      {
                          ErrorCode = ERROR_SMS_FAILD
                      };
            }
            #endregion

            #region 保存验证码
            int ValidPeriod;
            var tempstr = System.Configuration.ConfigurationManager.AppSettings["AuthCodeValidPeriod"];
            if (string.IsNullOrEmpty(tempstr))
            {
                ValidPeriod = 30;
            }
            else
            {
                if (!int.TryParse(tempstr, out ValidPeriod))
                {
                    ValidPeriod = 30;
                }
            }
            var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo);
            codebll.DeleteByMobile(pRequest.Parameters.Mobile); //删除该手机号已有的验证码
            var codeEntity = new RegisterValidationCodeEntity()
            {
                Code        = code,
                CodeID      = Guid.NewGuid().ToString("N"),
                Mobile      = pRequest.Parameters.Mobile,
                IsValidated = 0,
                Expires     = DateTime.Now.AddMinutes(ValidPeriod)
            };
            codebll.Create(codeEntity); //以新的验证码为准
            #endregion
            return(rd);

            #region 被替换
            //GetAuthCodeRD rd = new GetAuthCodeRD();
            //VipEntity entity = null;
            //#region 验证手机号,如果不存在此手机号的用户则新增会员
            //var bll = new VipBLL(base.CurrentUserInfo);
            //var vip = bll.GetByID(pRequest.UserID);
            //entity = bll.GetByMobile(pRequest.Parameters.Mobile, pRequest.CustomerID);
            //if (vip != null)
            //{
            //    if (vip.Phone != pRequest.Parameters.Mobile)
            //    {
            //        if (entity != null)
            //        {
            //            if (vip.VIPID != entity.VIPID)
            //                throw new APIException("此手机号已注册") { ErrorCode = ERROR_MOBILE_REGISTERED };
            //            else
            //            {
            //                entity = vip;
            //            }
            //        }
            //        else
            //        {
            //            entity = vip;
            //            vip.Phone = pRequest.Parameters.Mobile;
            //            bll.Update(entity);
            //        }
            //    }
            //    else
            //        entity = vip;
            //}
            //else
            //{
            //    entity = bll.GetByMobile(pRequest.Parameters.Mobile, pRequest.CustomerID);
            //    if (entity == null)
            //    {
            //        entity = new VipEntity()
            //        {
            //            Phone = pRequest.Parameters.Mobile,
            //            VipName = pRequest.Parameters.Mobile,
            //            VIPID = Guid.NewGuid().ToString("N"),
            //            Status = 1,
            //            ClientID = pRequest.CustomerID,
            //            VipSourceId = pRequest.Parameters.VipSource.ToString()
            //        };
            //        bll.Create(entity);
            //    }
            //    else
            //    {
            //        if (string.IsNullOrEmpty(entity.VipName))
            //        {
            //            entity.VipName = pRequest.Parameters.Mobile;
            //            bll.Update(entity);
            //        }
            //    }
            //}
            //#endregion

            //#region 发送短信
            //string msg;
            //var code = CharsFactory.Create6Char();
            //var sign = string.Empty;
            //#region 根据客户名称创建签名
            ////暂时先用阿拉丁,后须改为客户名称
            //sign = "阿拉丁";
            ////sign = CurrentUserInfo.ClientName;
            //#endregion
            //if (!SMSHelper.Send(pRequest.Parameters.Mobile, code, sign, out msg))
            //{
            //    throw new APIException("短信发送失败:" + msg) { ErrorCode = ERROR_SMS_FAILD };
            //}
            //#endregion

            //#region 保存验证码
            //int ValidPeriod;
            //var tempstr = System.Configuration.ConfigurationManager.AppSettings["AuthCodeValidPeriod"];
            //if (string.IsNullOrEmpty(tempstr))
            //{
            //    ValidPeriod = 30;
            //}
            //else
            //{
            //    if (!int.TryParse(tempstr, out ValidPeriod))
            //    {
            //        ValidPeriod = 30;
            //    }
            //}
            //var codebll = new RegisterValidationCodeBLL(base.CurrentUserInfo);
            //codebll.DeleteByMobile(entity.Phone);
            //var codeEntity = new RegisterValidationCodeEntity()
            //{
            //    Code = code,
            //    CodeID = Guid.NewGuid().ToString("N"),
            //    Mobile = entity.Phone,
            //    IsValidated = 0,
            //    Expires = DateTime.Now.AddMinutes(ValidPeriod)
            //};
            //codebll.Create(codeEntity);
            //#endregion
            //return rd;
            #endregion
        }
예제 #3
0
        protected string DoSetEventSignUp(string pRequest)
        {
            //1、请求参数反序列化
            var rp = pRequest.DeserializeJSONTo <APIRequest <SetEventSignUpRP> >();

            //2、参数校验
            rp.Parameters.Validate();

            //3、构造响应数据
            var rd = new APIResponse <SetEventSignUpRD>(new SetEventSignUpRD());

            try
            {
                //4、获取当前用户登录信息

                //5、确定
                PrivateLEventSignUpBLL.SetEventSignUpOper(10, rp.Parameters.SignUpId, rp.UserID, CharsFactory.Create6Char());
            }
            catch (Exception ex)
            {
                Loggers.Exception(new ExceptionLogInfo(ex));
                throw new Exception(ex.Message, ex);
            }
            return(rd.ToJSON());
        }