Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["Uniques"] == null)
            {
                return;
            }

            context.Response.ContentType = "text/plain";
            context.Response.Cache.SetCacheability(HttpCacheability.Public);
            context.Response.BufferOutput = false;

            string[] items = context.Request.QueryString["Uniques"].Split(",".ToCharArray());

            for (int i = 0; i < items.Length; i++)
            {
                SingleManager.GetInstance().AddDownloader(items[i], context);
            }

            while (context.Response.IsClientConnected == true)
            {
                context.Response.Write("{\"Command\":\"Connected\"}" + Environment.NewLine);
                context.Response.Flush();

                Thread.Sleep(60000);
            }
        }
Ejemplo n.º 2
0
        public Entity Execute(string uniques, Entity entity, int second)
        {
            try
            {
                string[] items = uniques.Split(",".ToCharArray());

                for (int i = 0; i < items.Length; i++)
                {
                    SingleManager.GetInstance().AddCommand(items[i], entity);
                }

                DateTime start = DateTime.Now;

                while (true)
                {
                    Thread.Sleep(10);

                    if ((DateTime.Now - start).TotalMilliseconds >= 1000 * second)
                    {
                        throw new TimeoutException();
                    }

                    for (int i = 0; i < items.Length; i++)
                    {
                        Entity result = SingleManager.GetInstance().GetResult(items[i]);
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                }
            }
            catch (TimeoutException)
            {
                return(Helper.GetEntity(false, "失败!请再试一次"));
            }
            catch (KeyNotFoundException)
            {
                return(Helper.GetEntity(false, "失败!网络已断开,请关闭系统并检查网络"));
            }
            catch (ConnectionLostException)
            {
                return(Helper.GetEntity(false, "失败!网络已断开,请关闭系统并检查网络"));
            }
            catch (Exception exception)
            {
                return(Helper.GetEntity(false, exception.Message));
            }
        }
Ejemplo n.º 3
0
 public void Update(string unique, Entity entity)
 {
     SingleManager.GetInstance().Update(unique, entity);
 }