/// <summary> /// 客户采用异步调用 /// </summary> /// <returns></returns> public ActResult <string> Upload() { var result = new ActResult <string>(); try { HttpPostedFile file = HttpContext.Current.Request.Files[0]; string root = HttpContext.Current.Server.MapPath("~/App_Data"); var relative = string.Format("{0}\\{1}", ConfigurationManager.AppSettings["AccountDoc"], Guid.NewGuid().ToString("N")); string path = string.Format("{0}\\{1}", root, relative); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path += "\\" + file.FileName; file.SaveAs(path); result.Message = "上传成功"; result.Tag = string.Format("{0}\\{1}", relative, file.FileName); } catch (Exception ex) { result.Message = ex.Message; } return(result); }
public ActResult <string> Create(Account account) { var result = new ActResult <string>(); try { //检查登录名和手机号码是否重复 if (accountDao.GetAccountByLoginName(account.Name) != null) { result.Message = "该用户名已存在!"; } else if (accountDao.GetAccountByPhone(account.Phone) != null) { result.Message = "该手机号码已存在!"; } else { accountDao.Create(account); result.Message = "创建成功!"; } } catch (Exception ex) { result.Message = ex.Message; } return(result); }
public void GenericErrorResult_EmptyAssertReturnsAssertionRoot() { var input = ActResult.ThrewException <int>(new Exception()); var underTest = new Acted <int>(input); var result = underTest.Assert(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(AssertionRoot)); }
public void GenericOkResult_AssertionCallbackIsCalled() { var input = ActResult.Ok(1); var underTest = new Acted <int>(input); bool called = false; underTest.Assert(r => called = true); Assert.IsTrue(called); }
public void GenericErrorResult_AssertionCallbackIsCalled() { var input = ActResult.ThrewException <int>(new Exception()); var underTest = new Acted <int>(input); bool called = false; underTest.Assert(r => called = true); Assert.IsTrue(called); }
public void OkResult_EmptyAssertReturnsAssertionRoot() { var input = ActResult.Ok(); var underTest = new Acted(input); var result = underTest.Assert(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(AssertionRoot)); }
static void Hnd(ActResult ar) { if (ar.Exception != null) { Console.WriteLine(ar.Exception); } else { Console.WriteLine("{0}\t{1}", Encoding.Unicode.GetString(ar.ResultData), DateTime.Now); //Console.WriteLine("{0}\t{1}", BitConverter.ToInt32(ar.ResultData, 0), DateTime.Now); } }
public IActResult LoginOut(string accountId, string ip) { var result = new ActResult(); LFFK.DataManager.Delete <AuthLoginDO>().Where(p => p.UserId == accountId).Execute(); LFFK.DataManager.Insert <LoginlogDO>(new LoginlogDO() { LoginIP = ip, LoginTime = DateTime.Now, LoginType = "LoginOut", UserId = accountId, }); return(result); }
public void GenericErrorResult_ThrewExceptionDoesNotThrowException() { var result = ActResult.ThrewException <int>(new Exception()); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.ThrewException(); } catch (Exception ex) { exception = ex; } Assert.IsNull(exception); }
public void GenericOkResult_IsSuccessDoesNotThrowException() { var result = ActResult.Ok(0); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.IsSuccess(); } catch (Exception ex) { exception = ex; } Assert.IsNull(exception); }
public void OkResult_ThrewExceptionThrowsException() { var result = ActResult.Ok(); var underTest = new AssertionRoot(result); Exception exception = null; try { underTest.ThrewException(); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void GenericErrorResultWithWrongExceptionType_ThrewExceptionThrowsException() { var result = ActResult.ThrewException <int>(new IOException()); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.ThrewException <InvalidOperationException>(); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void ErrorResult_IsSuccessThrowsExceptionWithMessage() { const string message = "Should work"; var result = ActResult.ThrewException(new Exception()); var underTest = new AssertionRoot(result); Exception exception = null; try { underTest.IsSuccess(message); } catch (Exception ex) { exception = ex; } Assert.IsTrue(exception.Message.Contains(message)); }
public void GenericErrorResult_IsSuccessThrowsException() { var result = ActResult.ThrewException <int>(new Exception()); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.IsSuccess(); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void GenericErrorResult_ValidateThrowsException() { var result = ActResult.ThrewException <int>(new IOException()); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.Validate(r => Assert.AreEqual(1, r)); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void GenericOkResult_ValidationCallbackThrowsException() { var result = ActResult.Ok(1); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.Validate(r => Assert.AreEqual(2, r)); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void GenericOkResult_ValidationCallbackDoesNotThrowException() { const int one = 1; var result = ActResult.Ok(one); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.Validate(r => Assert.AreEqual(one, r)); } catch (Exception ex) { exception = ex; } Assert.IsNull(exception); }
public IActResult Login(string accountId, string password, string ip, string token) { var result = new ActResult(); var authUser = LFFK.DataManager.TableQuery <UserDO>().Select().From().Where(p => p.UserId == accountId).Execute(); if (authUser != null) { if (authUser.ReTryTimes > 5) { result = new ActResult("密码输入错误次数已超过5次,当前账号被锁定,请联系网站管理员!"); } else { if (authUser.Password.Equals(password, StringComparison.OrdinalIgnoreCase) && authUser.State == 1) { LFFK.DataManager.DataProvider.ExecuteNonQuery(System.Data.CommandType.Text, String.Format(DAConstants.Sql_Insert_AuthLogin, accountId, ip, DateHelper.ConvertToString(DateTime.Now, DateType.Second), token, DateHelper.ConvertToString(DateTime.Now.AddDays(5), DateType.Second))); LFFK.DataManager.DataProvider.ExecuteNonQuery(System.Data.CommandType.Text, String.Format(DAConstants.Sql_Update_RetryTimes0, accountId)); LFFK.DataManager.Insert <LoginlogDO>(new LoginlogDO() { LoginIP = ip, LoginTime = DateTime.Now, LoginType = "LoginIn", UserId = accountId, }); return(result); } else { LFFK.DataManager.DataProvider.ExecuteNonQuery(System.Data.CommandType.Text, String.Format(DAConstants.Sql_Update_RetryTimes, accountId)); result = new ActResult(String.Format("用户密码不正确;输入错误密码多于5次用户账号将被锁定,您还有{0}次机会;谢谢!", (4 - authUser.ReTryTimes))); } } } else { result = new ActResult("密码错误或账号不存在"); } return(result); }
public void ErrorResultWithWrongExceptionType_ThrewExceptionThrowsExceptionWithMessage() { const string message = "Should throw InvalidOperation"; var result = ActResult.ThrewException(new IOException()); var underTest = new AssertionRoot(result); Exception exception = null; try { underTest.ThrewException <InvalidOperationException>(message); } catch (Exception ex) { exception = ex; } Assert.IsNotNull(exception); Assert.IsInstanceOfType(exception, typeof(AssertFailedException)); }
public void GenericOkResult_ThrewExceptionThrowsExceptionWithMessage() { const string message = "Should not work"; var result = ActResult.Ok(0); var underTest = new AssertionRoot <int>(result); Exception exception = null; try { underTest.ThrewException(message); } catch (Exception ex) { exception = ex; } Assert.IsTrue(exception.Message.Contains(message)); }
public IActResult Register(string accountId, long mobileNo, string password, int authCode, int userType) { var result = new ActResult(); var authUser = LFFK.DataManager.TableQuery <UserDO>().Select().From().Where(p => p.UserId == accountId).Execute(); if (authUser != null) { result = new ActResult("账号已存在"); } else { var authCodeOld = LFFK.DataManager.TableQuery <AuthCodeDO>().Select().From().Where(p => p.MobileNo == mobileNo).Execute(); if (authCodeOld != null && authCodeOld.AuthCode == authCode) { var insResult = LFFK.DataManager.Insert <UserDO>(new UserDO() { UserId = accountId, MobileNo = mobileNo, Password = password, ReTryTimes = 0, State = 1, UserType = userType, CreateTime = DateTime.Now, UserName = accountId.ToString(), }); if (insResult.IsSucceed) { result = new ActResult(); } else { result = new ActResult("注册失败:" + insResult.ErrorMsg); } } else { result = new ActResult("验证码输入错误"); } } return(result); }
static void Main(string[] args) { DCClient client = DCClient.Instance("TESTACT", "global"); Random r = new Random(); while (true) { //string read = Console.ReadLine(); Thread.Sleep(r.Next(1000)); for (int i = 0; i < 10; i++) { try { string requet = string.Format("{0}+{1}", r.Next(10, 1000), r.Next(100, 1000)); ActResult ar = client.Act("Add?TESTACT", "TESTSRV", Encoding.Unicode.GetBytes(requet), 2); Console.WriteLine("{0}\t{1}", Encoding.Unicode.GetString(ar.ResultData), DateTime.Now); } catch (Exception e) { Console.WriteLine(e.Message); } } } }
private static void issueResponse(HttpListenerRequest request, HttpListenerResponse response, ActResult rst) { if (rst.Exception != null) { rst.ResultData = PackOrb.PackRespose( new HttpHeadInfo { StatusCode = BizUtils.Rest.HttpStatusCode.ServerSideError }, new ListDictionary { { "respnum", -1 }, { "respmsg", rst.Exception }, } ); DCLogger.LogError("issueResponse get a biz srv error:{0}", rst.Exception.Message); } // 设置回应头部内容,长度,编码 int httpHeadInfoLength = BitConverter.ToInt32(rst.ResultData, 0); HttpHeadInfo httpHeadInfo = HttpHeadInfo.FromBytes(rst.ResultData, 4, httpHeadInfoLength); int rawBytesIndex = httpHeadInfoLength + 4; response.ContentLength64 = rst.ResultData.LongLength - rawBytesIndex; response.ContentType = httpHeadInfo.ContentType; response.StatusCode = (int)httpHeadInfo.StatusCode; // 输出回应内容 try { using (BinaryWriter writer = new BinaryWriter(response.OutputStream)) { writer.Write(rst.ResultData, rawBytesIndex, (int)response.ContentLength64); } } catch (Exception ex) { DCLogger.LogError(ex.Message); } if (response.ContentType.Equals(HttpContentType.Json)) { if (response.ContentLength64 > logTxtLen) { if (response.StatusCode == (int)BizUtils.Rest.HttpStatusCode.Succeed) { DCLogger.LogTrace(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, logTxtLen) + "..." ) ); } else { DCLogger.LogWarn(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, logTxtLen) + "..." ) ); } } else { if (response.StatusCode == (int)BizUtils.Rest.HttpStatusCode.Succeed) { DCLogger.LogTrace(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, (int)response.ContentLength64) ) ); } else { DCLogger.LogWarn(string.Format( "{0}<--{1}:::{2}", request.RemoteEndPoint, request.RawUrl, Global.Encoding.GetString(rst.ResultData, rawBytesIndex, (int)response.ContentLength64) ) ); } } } }
public IActResult SaveDeliverReturn(string accountId, int deliverId, string remarks) { IActResult result = new ActResult(); var mfDO = LFFK.DataManager.TableQuery <UserDO>().Select().From().Where(p => p.UserId == accountId).Execute(); if (mfDO != null && mfDO.UserType == 2 && mfDO.TargetId > 0) { var deliverDO = LFFK.DataManager.TableQuery <P_DeliverDO>().Select().From().Where(p => p.DeliverId == deliverId && p.CarPartsId == mfDO.TargetId).Execute(); if (deliverDO == null || deliverDO.State != 1) { result = new ActResult("发货单不存在!"); } else { if (deliverDO.DeliverReturnId > 0) { result = new ActResult("已退货,不能重复操作!"); } else { #region 新增 var deliverReturnDO = new P_DeliverReturnDO() { Amount = deliverDO.Amount, CarPartsId = mfDO.TargetId, CreateTime = DateTime.Now, CreateUser = accountId, DeliverReturnDate = DateTime.Now, DeliverId = deliverDO.DeliverId, DeliverReturnId = 0, PartsName = deliverDO.PartsName, Price = deliverDO.Price, PurchaseId = deliverDO.PurchaseId, Quantity = deliverDO.Quantity, Remark = remarks, State = 1 }; deliverDO.UpdateTime = DateTime.Now; deliverDO.UpdateUser = accountId; var updateColumns = ExpressionBuilder.AssembleColumns <P_DeliverDO>( p => p.DeliverReturnId, p => p.UpdateTime, p => p.UpdateUser ); using (var tran = new TransactionScope()) { try { var resultSave = LFFK.DataManager.Insert <P_DeliverReturnDO>(deliverReturnDO); if (resultSave.IsSucceed) { var deliverReturnId = Convert.ToInt32(resultSave.IdentityRowNo); deliverDO.DeliverReturnId = deliverReturnId; resultSave = LFFK.DataManager.Update(deliverDO, updateColumns); } if (resultSave.IsSucceed) { tran.Complete(); } result = resultSave; } catch (Exception ex) { LFFK.LogManager.Error(ex); result = new ActResult(ex.Message); } } #endregion } } } else { result = new ActResult("当前用户无权限"); } return(result); }
public IActResult InquiryToPurchase(string accountId, int quoteId) { IActResult result = new ActResult(); var mfDO = LFFK.DataManager.TableQuery <UserDO>().Select().From().Where(p => p.UserId == accountId).Execute(); if (mfDO != null && mfDO.UserType == 1 && mfDO.TargetId > 0) { var quoteDO = LFFK.DataManager.TableQuery <P_QuotationDO>().Select().From().Where(p => p.QuotationId == quoteId).Execute(); if (quoteDO == null || quoteDO.State != 1) { result = new ActResult("报价单不存在!"); } else { if (quoteDO.PurchaseId > 0) { result = new ActResult("已转采购单,不能重复操作!"); } else if (quoteDO.InquiryId > 0) { var inquiryDO = LFFK.DataManager.TableQuery <F_InquiryDO>().Select().From().Where(p => p.InquiryId == quoteDO.InquiryId).Execute(); if (inquiryDO == null || inquiryDO.State != 1) { result = new ActResult("报价单不存在!"); } else { quoteDO.UpdateTime = DateTime.Now; quoteDO.UpdateUser = accountId; quoteDO.PurchaseId = 0; var updateQuoteColumns = ExpressionBuilder.AssembleColumns <P_QuotationDO>( p => p.PurchaseId, p => p.UpdateTime, p => p.UpdateUser ); inquiryDO.UpdateTime = DateTime.Now; inquiryDO.UpdateUser = accountId; inquiryDO.PurchaseId = 0; inquiryDO.State = 2; var updateInquiryColumns = ExpressionBuilder.AssembleColumns <F_InquiryDO>( p => p.PurchaseId, p => p.State, p => p.UpdateTime, p => p.UpdateUser ); var purchaseDo = new F_PurchaseDO() { PurchaseId = 0, Amount = quoteDO.Amount, CreateTime = DateTime.Now, CreateUser = accountId, InquiryId = inquiryDO.InquiryId, MaintainFactoryId = inquiryDO.MaintainFactoryId, CarPartsId = quoteDO.CarPartsId, PartsName = quoteDO.PartsName, Price = quoteDO.Price, PurchaseDate = DateTime.Now, Quantity = quoteDO.Quantity, QuotationId = quoteDO.QuotationId, Remark = quoteDO.Remark, State = 1 }; using (var tran = new TransactionScope()) { try { var resultSave = LFFK.DataManager.Insert <F_PurchaseDO>(purchaseDo); if (resultSave.IsSucceed) { var purchaseId = Convert.ToInt32(resultSave.IdentityRowNo); quoteDO.PurchaseId = purchaseId; inquiryDO.PurchaseId = purchaseId; resultSave = LFFK.DataManager.Update(quoteDO, updateQuoteColumns); if (resultSave.IsSucceed) { resultSave = LFFK.DataManager.Update(inquiryDO, updateInquiryColumns); } } if (resultSave.IsSucceed) { tran.Complete(); } result = resultSave; } catch (Exception ex) { LFFK.LogManager.Error(ex); result = new ActResult(ex.Message); } } } } } } else { result = new ActResult("当前用户无权限"); } return(result); }