System.Collections.Generic.List.Add(pixivIllust)

Here are the examples of the csharp api System.Collections.Generic.List.Add(pixivIllust) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : Login.cs
with MIT License
from FirmianaMarsili

private async Task listview_load(int per_page, string mode, int page = 1, List<pixivIllust> illustbeforeList = null)
        {

            if (Login.instance == null)
            {
                return;
            }
            CancellationTokenSource CancelTokenSource = new CancellationTokenSource();
            JObject jd = null;
            try
            {
                jd = await Login.instance.pixivAPI.rankingAsync("all", mode, page, per_page,
                    null, CancelTokenSource);
            }
            catch (Exception ex)
            {
                throw;
            }
            if (illustbeforeList == null)
            {
                illustbeforeList = new List<pixivIllust>();
            }
            foreach (JObject response in jd.Value<JArray>("response"))//actually will be only one
            {
                foreach (JObject works in response.Value<JArray>("works"))
                {//TODO: try to put it in a task
                    JObject work = works.Value<JObject>("work");

                    if (work["id"].Type == JTokenType.Null) continue;
                    pixivIllust illust_before = new pixivIllust();
                    illust_before.illustID = (string)work["id"];
                    illust_before.replacedleName = (string)work["replacedle"];
                    illust_before.authorID = (string)work["user"]["id"];
                    illust_before.authorName = (string)work["user"]["name"];
                    illust_before.FavNum = (int)works["rank"];

                    if (work["stats"].Type != JTokenType.Null && work["stats"].HasValues)
                        illust_before.Scores = (int)work["stats"]["score"];

                    illust_before.ageLimit = false;
                    if (!work["age_limit"].ToString().Equals("all-age")) illust_before.ageLimit = true;

                    //TODO:set Type

                    illust_before.MediumURL = new List<string>();
                    illust_before.MediumURL.Add((string)work["image_urls"]["px_480mw"]);
                    illust_before.isSetComplete = true;

                    illustbeforeList.Add(illust_before);
                }
            }
            if (page < (int)jd["pagination"]["pages"])
            {
                //if (Profile._mahuaApi != null)
                //{
                //    Profile._mahuaApi.SendPrivateMessage(Profile.ExceptionSender).Text(mode + "     " + page).Done();
                //}                
                await listview_load(50, mode, page + 1, illustbeforeList);
            }
            else
            {
                List<pixivIllust> illust_ = new List<pixivIllust>();
                foreach (var item in illustbeforeList)
                {
                    CancelTokenSource = new CancellationTokenSource();
                    var task = Login.instance.pixivAPI.illust_workAsync(item.illustID, CancelTokenSource);
                    JObject returns = null;
                    try
                    {
                        returns = await task;//run first item's detail                
                    }
                    catch (Exception ex)
                    {
                        returns = null;
                    }
                    if (returns != null)
                    {
                        pixivIllust tmpillust = fromJsonSetIllust_detail(returns);
                        illust_.Add(tmpillust);
                    }
                }
                illustbeforeList = illust_;
                foreach (var items in illustbeforeList)
                {
                    bool flag = false;
                    if (Profile.limitCount == 0)
                    {
                        flag = !Profile.black.Contains((int)items.Type);
                    }
                    else
                    {
                        flag = Profile.path[mode].Count <= Profile.limitCount && !Profile.black.Contains((int)items.Type);
                    }
                    if (flag)
                    {
                        CancelTokenSource = new CancellationTokenSource();
                        List<string> url = null;
                        if (Profile.DownloadOriginalURL)
                        {
                            url = items.OriginalURL;
                        }
                        else
                        {
                            url = items.MediumURL;
                        }
                        foreach (var item in url)
                        {
                            var task_imagedownload = Login.instance.pixivAPI.DownloadFileAsync(string.Format("{0}{1}", Profile.ImagePath, mode), item, null, CancelTokenSource);
                            string imagepath = null;
                            try
                            {
                                imagepath = await task_imagedownload;
                            }
                            catch (Exception)
                            {
                                imagepath = null;
                                //throw;
                            }

                            if (imagepath != null)
                            {                                
                                try
                                {
                                    if (Profile.imageLength != 0)
                                    {
                                        System.Drawing.Image img = System.Drawing.Image.FromFile(imagepath);
                                        System.Drawing.Image bmp = new System.Drawing.Bitmap(img);
                                        img.Dispose();
                                        var memory = Zip(bmp, ImageFormat.Jpeg, Profile.imageLength);
                                        bmp.Dispose();
                                        if (File.Exists(imagepath))
                                        {
                                            File.Delete(imagepath);
                                        }
                                        MemoryStream m = new MemoryStream();
                                        FileStream fs = new FileStream(imagepath, FileMode.OpenOrCreate);
                                        BinaryWriter w = new BinaryWriter(fs);
                                        w.Write(memory.ToArray());
                                        fs.Close();
                                        memory.Close();
                                    }                                                                     
                                    Profile.path[mode].Add(imagepath);
                                    Profile.path[mode] = Shuffle(Profile.path[mode]);                             
                                }
                                catch (Exception ex)
                                {
                                    //Console.WriteLine(ex.ToString());
                                    //throw;
                                }

                            }
                        }
                    }                  
                }
            }


        }