public JsonResult SavePipe(EsbReceiverInterface pipe) { HttpResult hr = new HttpResult() { Result = true }; using (ConnectionScope scope = new ConnectionScope(TransactionMode.Required)){ if (pipe.ReceiverInterfaceID == Guid.Empty){ if (EntityCommon.IsExistData("Esb_ReceiverInterface", "ServiceName", pipe.ServiceName)){ hr.Result = false; hr.ErrorMessage = "英文名称不允许重复,请重新录入英文名称!"; return new JsonResult(hr); } pipe.ReceiverInterfaceID = Guid.NewGuid(); pipe.Status = 1; pipe.CreatedOn = DateTime.Now; pipe.Insert(); //自动生成策略 EsbDistributeStrategy esbDistributeStrategyEntity = new EsbDistributeStrategy(); esbDistributeStrategyEntity.DistributeStrategyID = Guid.NewGuid(); esbDistributeStrategyEntity.ReceiverInterfaceID = pipe.ReceiverInterfaceID; esbDistributeStrategyEntity.CreatedOn = DateTime.Now; esbDistributeStrategyEntity.Status = 1; esbDistributeStrategyEntity.Insert(); } else{ pipe.ModifiedOn = DateTime.Now; pipe.Update(); } hr.KeyValue = pipe.ReceiverInterfaceID.ToString(); scope.Commit(); } return new JsonResult(hr); }
public JsonResult CreateStrategy(string mapList) { HttpResult hr = new HttpResult() { Result = true }; XElement root = XElement.Parse(mapList); var mapConfig = new { ServiceInfoID = root.Element("SvcID").Value, MapItems = ( from map in root.Elements("mapItem") select new { ReceiveInterface = map.Element("ReceiveInterface").Value, InterfaceType = map.Element("InterfaceType").Value, MehtodName = map.Element("MethodName").Value, DistributeStrategy = map.Element("DistributeStrategy").Value } ).ToList() }; using( ConnectionScope scope = new ConnectionScope(TransactionMode.Required) ) { foreach( var map in mapConfig.MapItems ) { var param = new { ServiceName = map.ReceiveInterface }; var esbReceiveInterface = CPQuery.From("select top 1 * from esb_ReceiverInterface where ServiceName = @ServiceName", param).ToSingle<EsbReceiverInterface>(); if( esbReceiveInterface == null ) { esbReceiveInterface = new EsbReceiverInterface(); esbReceiveInterface.ReceiverInterfaceID = Guid.NewGuid(); esbReceiveInterface.ServiceName = map.ReceiveInterface; esbReceiveInterface.DisplayName = map.ReceiveInterface; esbReceiveInterface.Status = 1; esbReceiveInterface.CreatedOn = DateTime.Now; esbReceiveInterface.Insert(); } var paramOperation = new { ServiceInfoID = mapConfig.ServiceInfoID, OperationName = map.MehtodName }; var esbOperation = CPQuery.From("select top 1 * from esb_Operation where ServiceInfoID = @ServiceInfoID and OperationName = @OperationName", paramOperation).ToSingle<EsbOperation>(); if( esbOperation == null ) { hr.Result = false; hr.ErrorMessage = string.Format("方法:{0}不存在!", map.MehtodName); return new JsonResult(hr); } var paramStrategy = new { ReceiverInterfaceID = esbReceiveInterface.ReceiverInterfaceID }; var esbDistributeStrategy = CPQuery.From("select top 1 * from dbo.esb_DistributeStrategy where ReceiverInterfaceID = @ReceiverInterfaceID", paramStrategy).ToSingle<EsbDistributeStrategy>(); if( esbDistributeStrategy == null ) { esbDistributeStrategy = new EsbDistributeStrategy(); esbDistributeStrategy.DistributeStrategyID = Guid.NewGuid(); esbDistributeStrategy.ReceiverInterfaceID = esbReceiveInterface.ReceiverInterfaceID; esbDistributeStrategy.CreatedOn = DateTime.Now; esbDistributeStrategy.Status = 1; esbDistributeStrategy.Insert(); } var paramDistribute = new { ReceiverInterfaceID = esbReceiveInterface.ReceiverInterfaceID, ServiceInfoID = mapConfig.ServiceInfoID, MethodName = map.MehtodName, InterfaceType = map.InterfaceType }; var esbVerifyDistribute = CPQuery.From("select top 1* from esb_VerifyDistribute where ReceiverInterfaceID = @ReceiverInterfaceID and ServiceInfoID = @ServiceInfoID and MethodName = @MethodName and InterfaceType = @InterfaceType", paramDistribute).ToSingle<EsbVerifyDistribute>(); if( esbVerifyDistribute == null ) { esbVerifyDistribute = new EsbVerifyDistribute(); esbVerifyDistribute.ReceiverInterfaceID = esbReceiveInterface.ReceiverInterfaceID; esbVerifyDistribute.ServiceInfoID = new Guid(mapConfig.ServiceInfoID); esbVerifyDistribute.MethodName = map.MehtodName; esbVerifyDistribute.InterfaceType = Convert.ToByte(map.InterfaceType); esbVerifyDistribute.DistributeStrategy = string.IsNullOrEmpty(map.DistributeStrategy) ? null : (byte?)Convert.ToByte(map.DistributeStrategy); esbVerifyDistribute.CreatedOn = DateTime.Now; esbVerifyDistribute.Insert(); } else { esbVerifyDistribute.ModifiedOn = DateTime.Now; esbVerifyDistribute.DistributeStrategy = string.IsNullOrEmpty(map.DistributeStrategy) ? null : (byte?)Convert.ToByte(map.DistributeStrategy); esbVerifyDistribute.Update(); } } scope.Commit(); } return new JsonResult(hr); }