Exemple #1
0
    void LoadFinish(LoaderItem loader)
    {
        //return;//不使用相同url同一返回出力,因为可能有postdata请求
        #region  相同的请求 统一执行回调

        if (loader.currentLoaderTask == null)
        {
            return;
        }

        List <LoaderTask> tasks = taskList.FindAll((LoaderTask t) =>
        {
            LoaderTask tk = loader.currentLoaderTask;
            return(t.url == tk.url &&
                   t.type == tk.type &&
                   t.postdata == tk.postdata);
        });

        if (tasks != null && tasks.Count > 0)
        {
            int length = tasks.Count;
            for (int i = 0; i < length; i++)
            {
                LoaderTask lt = tasks[i];
                lt.SetResponseData(loader.reponseData);
                taskList.Remove(tasks[i]);
            }
        }
        #endregion
    }
Exemple #2
0
    void Update()
    {
        if (taskList.Count == 0)
        {
            return;
        }

        while (true)
        {
            LoaderItem loader = GetIdleLoaderItem();
            if (loader == null)
            {//没有空闲loader
                break;
            }

            int taskindex = GetLoaderTaskIndex();
            if (taskindex < 0)
            {//没有需要轮询的请求
                return;
            }

            LoaderTask lt = taskList[taskindex];
            taskList.RemoveAt(taskindex);
            loader.InsertTask(lt);
        }
    }
Exemple #3
0
    LoaderItem GetIdleLoaderItem()
    {
        LoaderItem loader = loaderitemList.Find((LoaderItem li) =>
        {
            return(li.isIdle);
        });

        return(loader);
    }
Exemple #4
0
    public LoaderContianer(int synchronize = 1)
    {
        if (synchronize < 1)
        {
            synchronize = 1;
        }

        taskList       = new List <LoaderTask>();
        loaderitemList = new List <LoaderItem>();
        for (int i = 0; i < synchronize; i++)
        {
            LoaderItem item = new LoaderItem();
            item.AddListenerIdle(LoadFinish);
            loaderitemList.Add(item);
        }

        timer = new NativeTimer(Update, 0.3f);
        timer.Start();
    }
Exemple #5
0
    public void DeleteTask(LoaderTask task)
    {
        if (taskList.Contains(task))
        {
            taskList.Remove(task);
        }
        else
        {
            LoaderItem item = loaderitemList.Find((LoaderItem _loader) =>
            {
                return(!_loader.isIdle &&
                       _loader.currentLoaderTask == task);
            });

            if (item != null)
            {
                item.Dispose();
            }
        }
    }
Exemple #6
0
    void LoadFinish(LoaderItem loader)
    {
        #region  相同的请求 统一执行回调

        List <LoaderTask> tasks = taskList.FindAll((LoaderTask t) =>
        {
            LoaderTask tk = loader.currentLoaderTask;
            return(t.url == tk.url &&
                   t.type == tk.type);
        });

        if (tasks != null)
        {
            for (int i = 0; i < tasks.Count; i++)
            {
                LoaderTask lt = tasks[i];
                lt.SetResponseData(loader.reponseData);
                taskList.Remove(tasks[i]);
            }
        }
        #endregion
    }
 protected override void OnInitialized()
 {
     LoaderItem = LoaderItemFactory.CreateRandomItem();
 }