예제 #1
0
        /// <summary>
        /// Ôö¼Ó»º´æÏîÄ¿
        /// </summary>
        /// <param name="key">»º´æ¼üÃû</param>
        /// <param name="obj">»º´æ¶ÔÏó</param>
        /// <param name="seconds">»º´æÃëÊý</param>
        public void Insert(string key, object obj, int seconds)
        {
            Remove(key);
            CachedItem item = new CachedItem();

            item.StartTime = DateTime.Now;
            item.EndTime   = DateTime.Now.AddSeconds(seconds * Factor);
            item.CacheData = obj;
            item.CacheType = obj.GetType().ToString();
            item.CacheKey  = key;
            cacheList.Add(key, item);
        }
예제 #2
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="task">任务</param>
        public static void AddTask(TaskInfo task)
        {
            if (tasksInfo.ContainsKey(task.Class))
            {
                RemoveTask(task.Class);
            }

            Timer  timer  = new Timer(true);
            Action action = () => SingletonAddIn <IPlugin> .Instance(task.Class + "," + task.Assembly).Main(task.Parameter);

            if (task.Interval > 0)
            {
                timer.Start(action, task.Interval, task.Degree);
            }
            if (!task.HHmm.IsNullEmpty())
            {
                timer.Start(action, task.HHmm, task.Degree, task.Format);
            }
            if (!tasksInfo.ContainsKey(task.Class))
            {
                tasksInfo.Add(task.Class, timer);
            }
        }
예제 #3
0
        /// <summary>
        /// GetWsProxyType 获取目标Web服务对应的代理类型 CACHE
        /// </summary>
        /// <param name="wsUrl">目标Web服务的url</param>
        /// <param name="classname">Web服务的class名称,如果不需要指定,则传入null</param>
        /// <returns>Type</returns>
        public static Type GetWsProxyType(string wsUrl, string classname)
        {
            string @namespace = "Pub.Class.WebServiceHelper.DynamicWebCalling";

            if ((classname.IsNull()) || (classname == ""))
            {
                classname = GetWsClassName(wsUrl);
            }
            string cacheKey = wsUrl + "@" + classname;

            if (WSProxyTypeDictionary.ContainsKey(cacheKey))
            {
                return(WSProxyTypeDictionary[cacheKey]);
            }


            //获取WSDL
            WebClient                  wc     = new WebClient();
            Stream                     stream = wc.OpenRead(wsUrl + "?WSDL");
            ServiceDescription         sd     = ServiceDescription.Read(stream);
            ServiceDescriptionImporter sdi    = new ServiceDescriptionImporter();

            sdi.AddServiceDescription(sd, "", "");
            CodeNamespace cn = new CodeNamespace(@namespace);

            //生成客户端代理类代码
            CodeCompileUnit ccu = new CodeCompileUnit();

            ccu.Namespaces.Add(cn);
            sdi.Import(cn, ccu);
            CSharpCodeProvider csc = new CSharpCodeProvider();
            ICodeCompiler      icc = csc.CreateCompiler();

            //设定编译参数
            CompilerParameters cplist = new CompilerParameters();

            cplist.GenerateExecutable = false;
            cplist.GenerateInMemory   = true;
            cplist.ReferencedAssemblies.Add("System.dll");
            cplist.ReferencedAssemblies.Add("System.XML.dll");
            cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
            cplist.ReferencedAssemblies.Add("System.Data.dll");

            //编译代理类
            CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);

            if (true == cr.Errors.HasErrors)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors)
                {
                    sb.Append(ce.ToString());
                    sb.Append(System.Environment.NewLine);
                }
                throw new Exception(sb.ToString());
            }

            //生成代理实例,并调用方法
            System.Reflection.Assembly assembly = cr.CompiledAssembly;
            Type wsProxyType = assembly.GetType(@namespace + "." + classname, true, true);

            if (!WSProxyTypeDictionary.ContainsKey(cacheKey))
            {
                WSProxyTypeDictionary.Add(cacheKey, wsProxyType);
            }
            return(wsProxyType);
        }