Example #1
0
        /// <summary>
        ///     Job执行代理请求
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public ReturnMessage <bool> ProxyDoByJob(Proxy proxy)
        {
            if (proxy == null)
            {
                throw new ProxyServiceException("proxy is null");
            }
            var  proxyType     = proxy.ProxyType;
            Type proxyBaseType = ProxyHelper.GetType(proxyType);

            if (string.IsNullOrEmpty(proxy.ProxyJsonString))
            {
                throw new ProxyServiceException("proxy.ProxyJsonString is empty");
            }
            ProxyBase proxyBase =
                ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString,
                                                          proxyBaseType, proxyType.UseDataMemberTransData) as
                ProxyBase;

            if (proxyBase == null)
            {
                throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not a proxy base object",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            string[] arrTypeName = proxy.ProxyType.FullName.Split('.');
            string   requestCode = arrTypeName[arrTypeName.Length - 1];
            string   requestName = requestCode;
            string   bpFullName  = string.Join(".",
                                               new List <string>(arrTypeName).GetRange(0, arrTypeName.Length - 2).ToArray());

            bpFullName += "." + requestCode.Substring(0, requestCode.Length - 5);
            RequestSubmit rs = new RequestSubmit();

            //参数applicaiton表示应用模块的代号.
            rs.Application = 3000;
            //参数priority表示调度执行的优先级,1表示最高优先级
            rs.Priority = 1;
            //参数bpfullname表示服务的全名,包括命名空间
            rs.BPFullName = bpFullName;
            //表示需要调度执行的应用,及调度具体执行的应用
            rs.BPAgentObj = proxyBase;
            //表示请求执行的应用代码,即具体的服务名称
            rs.RequestCode = requestCode;
            //在表示请求执行的服务名称,即在请求监控中看到的进程名称
            rs.RequestName = requestName;
            //任何语言都可以的描述
            rs.RequestDescription = requestName;
            // 是否成功执行不能重新执行
            rs.IsSuccessCanNotReStart = true;
            //表示任务执行的时限,以秒为单位,即指定秒后开始进行调度执行
            rs.SchedulerProject = new PatternRunOnce().PatternInstant();
            //参数表示 提交到job进程里,可以保证在设定时间进行应用程序的执行
            rs.Submit();
            ReturnMessage <bool> ret = new ReturnMessage <bool>();

            ret.IsSuccess = true;
            ret.Result    = true;
            return(ret);
        }
Example #2
0
        /// <summary>
        ///     执行请求
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public ReturnMessage <string> ProxyDo(Proxy proxy)
        {
            if (proxy == null)
            {
                throw new ProxyServiceException("proxy is null");
            }
            var  proxyType     = proxy.ProxyType;
            Type proxyBaseType = ProxyHelper.GetType(proxyType);

            if (string.IsNullOrEmpty(proxy.ProxyJsonString))
            {
                throw new ProxyServiceException("proxy.ProxyJsonString is empty");
            }
            if (proxyType.OutMaxExpandDepth <= 0)
            {
                proxyType.OutMaxExpandDepth = ProxyJsonHelper.DefaultOutMaxWritingDepth;
            }
            if (proxyType.OutMaxExpandDepth > ProxyJsonHelper.MaxOutMaxWritingDepth)
            {
                throw new ProxyServiceException(string.Format("outMaxExpandDepth is max value is {0}",
                                                              ProxyJsonHelper.MaxOutMaxWritingDepth));
            }
            ProxyBase proxyBase =
                ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString,
                                                          proxyBaseType, proxyType.UseDataMemberTransData) as
                ProxyBase;

            if (proxyBase == null)
            {
                throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            MethodInfo methodInfo = proxyBase.GetType().GetMethod("Do", new Type[] {});

            if (methodInfo == null)
            {
                throw new ProxyServiceException(string.Format("no find Do() method in proxyType:{0},{1}",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            object result = methodInfo.Invoke(proxyBase, null);
            ReturnMessage <string> ret = new ReturnMessage <string>();

            ret.IsSuccess = true;
            ret.Result    = result == null
                ? string.Empty
                : ProxyJsonHelper.ProxyResultToJsonString(result, proxyType.UseDataMemberTransData,
                                                          proxyType.OutMaxExpandDepth);
            return(ret);
        }
Example #3
0
        /// <summary>
        ///     重新加载代理对象
        /// </summary>
        /// <param name="proxy"></param>
        /// <returns></returns>
        public ReturnMessage <Proxy> ReLoadProxy(Proxy proxy)
        {
            if (proxy == null)
            {
                throw new ProxyServiceException("proxy is null");
            }
            if (proxy.ProxyType == null)
            {
                throw new ProxyServiceException("proxy.ProxyType is null");
            }
            if (string.IsNullOrEmpty(proxy.ProxyJsonString))
            {
                throw new ProxyServiceException("proxy.ProxyJsonString is empty");
            }
            ProxyType proxyType = proxy.ProxyType;

            if (proxyType.InMaxExpandDepth <= 0)
            {
                proxyType.InMaxExpandDepth = ProxyJsonHelper.DefaultInMaxWritingDepth;
            }
            if (proxyType.InMaxExpandDepth > ProxyJsonHelper.MaxInMaxWritingDepth)
            {
                throw new ProxyServiceException(string.Format("inMaxExpandDepth max value is {0}",
                                                              ProxyJsonHelper.MaxInMaxWritingDepth));
            }
            Type loadType = ProxyHelper.GetType(proxyType);

            if (loadType == null)
            {
                throw new ProxyServiceException(string.Format("proxyType {0},{1} is not exist", proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            ProxyBase proxyBase =
                ProxyJsonHelper.ProxyObjectFromJsonString(proxy.ProxyJsonString,
                                                          loadType, proxyType.UseDataMemberTransData) as
                ProxyBase;

            if (proxyBase == null)
            {
                throw new ProxyServiceException(string.Format("proxyType:{0},{1} is not proxy base object",
                                                              proxyType.FullName,
                                                              proxyType.AssemblyName));
            }
            ReturnMessage <Proxy> ret = new ReturnMessage <Proxy>();

            proxy.ProxyJsonString = ProxyJsonHelper.ProxyObjectToJsonString(proxyBase, true,
                                                                            proxyType.UseDataMemberTransData,
                                                                            proxyType.InMaxExpandDepth);
            ret.Result = proxy;
            return(ret);
        }