Ejemplo n.º 1
0
        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);
        }
 /// <summary>
 /// 更新分发策略
 /// </summary>
 /// <param name="distributeStrategy">分发策略</param>
 /// <param name="context">上下文</param>
 public void UpdateDistributeStrategy(EsbDistributeStrategy distributeStrategy)
 {
     //TODO:新增分发策略。使用Map的保存策略。接受分发策略、校验、分发、通知信息。分别保存。
 }
 /// <summary>
 /// 新增分发策略
 /// </summary>
 /// <param name="distributeStrategy">分发策略</param>
 /// <param name="context">上下文</param>
 /// <returns>分发策略Guid</returns>
 public Guid CreateDistributeStrategy(EsbDistributeStrategy distributeStrategy)
 {
     //TODO:新增分发策略。使用Map的保存策略。接受分发策略、校验、分发、通知信息。分别保存。
     return Guid.NewGuid();
 }
 /// <summary>
 /// 检查分发策略是否重复
 /// </summary>
 /// <param name="entity">分发策略</param>
 /// <param name="context">上下文</param>
 /// <returns>同一主数据类型只允许设置一条策略</returns>
 public bool CheckRepeated(EsbDistributeStrategy entity)
 {
     return false;
 }
Ejemplo n.º 5
0
        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);
        }