コード例 #1
0
        /// <summary>
        /// 动态创建同步的实现类
        /// </summary>
        private static List <T> GetSynchroClsInstance <T>(Assembly assembly, Type type, SynOperationType operType)
        {
            List <T> types = null;

            if (assembly != null)
            {
                CreateSynchroClsInstance <T>(assembly, type);

                types = new List <T>();

                if (clsSynchroType != null && clsSynchroType.Count > 0)
                {
                    foreach (var item in clsSynchroType)
                    {
                        if (item != null)
                        {
                            if (item.BaseType != null)
                            {
                                if (item.BaseType == type || item.BaseType.BaseType == type)
                                {
                                    T x = (T)Activator.CreateInstance(item);

                                    if (x != null)
                                    {
                                        if (x.GetType() != null)
                                        {
                                            if (x.GetType().GetProperty("OperType") != null)
                                            {
                                                if (x.GetType().GetProperty("OperType").GetValue(x, null) != null)
                                                {
                                                    if (operType.ToString() == x.GetType().GetProperty("OperType").GetValue(x, null).ToString())
                                                    {
                                                        types.Add(x);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(types);
        }
コード例 #2
0
ファイル: InvokeWebApi.cs プロジェクト: abbottCheer/K3Cloud
        /// <summary>
        /// 根据操作类型确定调用动态方法的名称
        /// </summary>
        /// <param name="type"></param>
        /// <param name="operateType"></param>
        /// <returns></returns>
        public static string GetMethodName(Type type, SynOperationType operateType)
        {
            MethodInfo[] methods = DynamicInvoke.GetMethods(type);

            if (methods != null && methods.Length > 0)
            {
                foreach (var method in methods)
                {
                    if (method != null)
                    {
                        if (method.Name.ToUpper().Contains(operateType.ToString().ToUpper()))
                        {
                            return(method.Name);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: InvokeWebApi.cs プロジェクト: abbottCheer/K3Cloud
        /// <summary>
        /// 根据操作类型确定动态调用方法的参数类型和个数
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="operateType"></param>
        /// <param name="dataType"></param>
        /// <param name="formId"></param>
        /// <param name="json"></param>
        /// <param name="numbers"></param>
        /// <param name="pkIds"></param>
        /// <returns></returns>
        public static object[] GetAgrs(Context ctx, SynOperationType operateType, SynchroDataType dataType, string formId, string json, IEnumerable <string> numbers = null, IEnumerable <int> pkIds = null)
        {
            if (!string.IsNullOrWhiteSpace(operateType.ToString()))
            {
                switch (operateType)
                {
                case SynOperationType.SAVE:
                    return(new object[] { ctx, dataType, formId, json });

                case SynOperationType.DELETE:
                case SynOperationType.AUDIT:
                case SynOperationType.UNAUDIT:
                case SynOperationType.SUBMIT:
                    return(new object[] { ctx, dataType, formId, numbers, pkIds });

                case SynOperationType.ALLOT:
                    return(new object[] { ctx, dataType, formId, pkIds });
                }
            }
            return(null);
        }
コード例 #4
0
        public virtual HttpResponseResult ExecuteOperate(SynOperationType operateType, List <string> numbers = null, List <int> pkIds = null, string json = null)
        {
            HttpResponseResult result = null;

            if ((numbers != null && numbers.Count > 0) || (pkIds != null && pkIds.Count > 0) || !string.IsNullOrWhiteSpace(json))
            {
                HttpClient httpClient = new HttpClient();
                httpClient.Url = "http://localhost/K3Cloud/Services/SynchroServiceBus.asmx/ExecuteOperate";
                Dictionary <string, string> dict = new Dictionary <string, string>();

                dict.Add("ctx", HttpUtility.UrlEncode(JsonConvert.SerializeObject(this.K3CloudContext), Encoding.UTF8));
                dict.Add("dataType", HttpUtility.UrlEncode(this.DataType.ToString(), Encoding.UTF8));
                dict.Add("operateType", HttpUtility.UrlEncode(operateType.ToString(), Encoding.UTF8));
                dict.Add("formId", HttpUtility.UrlEncode(this.FormKey, Encoding.UTF8));
                dict.Add("numbers", numbers == null ? null : HttpUtility.UrlEncode(JsonConvert.SerializeObject(numbers.ToArray()), Encoding.UTF8));
                dict.Add("pkIds", pkIds == null ? null : HttpUtility.UrlEncode(JsonConvert.SerializeObject(pkIds.ToArray()), Encoding.UTF8));
                dict.Add("json", HttpUtility.UrlEncode(json, Encoding.UTF8));

                StringBuilder sb = new StringBuilder();

                foreach (var item in dict)
                {
                    sb.AppendFormat("&{0}={1}", item.Key, item.Value);
                }

                httpClient.Content = sb.ToString();
                string ret = httpClient.PostData();

                result = JsonConvert.DeserializeObject <HttpResponseResult>(ret);

                if (result != null)
                {
                    SynchroDataLog(this.K3CloudContext, result, this.DataType, operateType);
                }
            }

            return(result);
        }
コード例 #5
0
 /// <summary>
 /// 更新同步后的操作(提交、审核)日志的提示信息
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="result"></param>
 /// <param name="dataType"></param>
 /// <param name="operateType"></param>
 public virtual void SynchroDataLog(Context ctx, HttpResponseResult result, SynchroDataType dataType, SynOperationType operateType)
 {
     if (result != null)
     {
         if (result.SuccessEntityNos != null && result.SuccessEntityNos.Count > 0)
         {
             string msg = string.Format("单据编码【{0}】{1}成功!", string.Join(",", result.SuccessEntityNos.Select(o => o.ToString())), operateType.ToString());
             result.Message = msg;
             LogUtils.WriteSynchroLog(ctx, dataType, msg);
         }
     }
     else
     {
         LogUtils.WriteSynchroLog(ctx, dataType, "" + dataType + "" + operateType + " 失败!");
     }
 }