public XmlResult SaveByXml(EsbVerifyDistribute entity)
 {
     string message = string.Empty;
     entity.CreatedOn = DateTime.Now;
     entity.DistributeStrategy = entity.InterfaceType == 0 ? null : entity.DistributeStrategy;
     var parameter = new
     {
         ReceiverInterfaceID = entity.ReceiverInterfaceID,
         ServiceInfoID = entity.ServiceInfoID,
         MethodName = entity.MethodName,
         InterfaceType = entity.InterfaceType
     };
     if (CPQuery.From("select count(1) from Esb_VerifyDistribute where ReceiverInterfaceID=@ReceiverInterfaceID and ServiceInfoID=@ServiceInfoID and MethodName=@MethodName and InterfaceType=@InterfaceType", parameter).ExecuteScalar<int>() < 1)
     {
         if (entity.Insert() < 1)
             message = "保存数据失败!";
     }
     //返回xml数据使用XmlResult类进行包装
     return new XmlResult(message);
 }
Beispiel #2
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);
        }
Beispiel #3
0
        public JsonResult SaveValidateDistribute(EsbVerifyDistribute entity)
        {
            HttpResult hr = new HttpResult() { Result = true };

            using( ConnectionScope scope = new ConnectionScope(TransactionMode.Required) ) {
                var paramDistribute = new { ReceiverInterfaceID = entity.ReceiverInterfaceID, ServiceInfoID = entity.ServiceInfoID, MethodName = entity.MethodName, InterfaceType = entity.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) {
                    entity.VerifyDistributeID = Guid.NewGuid();
                    entity.CreatedOn = DateTime.Now;
                    entity.Insert();
                    hr.KeyValue = entity.VerifyDistributeID.ToString();
                } else {
                    hr.Result = false;
                    hr.ErrorMessage = "该接口已经订阅!";
                }
                scope.Commit();
            }
            return new JsonResult(hr);
        }