/*************************************************************
        *
        * async Task<Feed> FetchTastyTradeFeed
        *
        *************************************************************/

        private async Task <Feed> FetchTastyTradeFeed()
        {
            Feed feed = new Feed();

            XElement root;

            try
            {
                root = await LoadXDocumentAsync("https://feeds.tastytrade.com/podcast.rss");
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("Failed to access tastytrade podcasts. {0}", e.Message));
                return(feed);
            }

            XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

            var items = (from el in root.Descendants("item")
                         select el
                         ).ToList();

            foreach (var el in items)
            {
                string movie = el.Element("guid").Value;
                if (!(movie.EndsWith(".mov") || movie.EndsWith(".mp4")))
                {
                    continue;
                }

                /* discovered the hard way that the image is not always defined
                 * ------------------------------------------------------------ */

                string image  = null;
                var    ximage = el.Element(itunes + "image");
                if (ximage != null)
                {
                    image = ximage.Attribute("href").Value;
                }

                FeedItem fi = new FeedItem(el.Element("title").Value,
                                           el.Element(itunes + "subtitle").Value,
                                           image,
                                           el.Element("guid").Value,
                                           DateTime.Parse(el.Element("pubDate").Value));
                feed.Add(fi);
            }

            return(feed);
        }
 /* public Aquarium(int t)
  * {
  *
  *   temper = t;
  *   //light = l;
  *
  * }
  * /* public void StartGame()
  * {
  *   Random rnd=new Random();
  *   creator = new CreatorFish();
  *   IStrategy s;
  *   for (int i = 0; i < fish.Length; i++)
  *   {
  *       Dweller f = creator.Create(rnd, s);
  *       fish[i] = f;
  *       f.Draw();
  *   }
  *   creator = new CreatorSnail();
  *   IStrategy s1;
  *   for (int i = 0; i < snail.Length; i++)
  *   {
  *       Dweller sn = creator.Create(rnd, s1);
  *   }
  *
  *
  *
  * }*/
 public void CreateFood(int x, int y)
 {
     Feed.Add(new Eat(x, y));
 }
Exemple #3
0
        private void LoadData(String Filename)
        {
            String CurLine;                                         // 存讀取器抓到的字串
            int    Section = 0;                                     // 設定變數存狀態,預設為0

            String[] Piecewise;                                     // 存字串陣列

            StreamReader TaskCSV = new StreamReader(Filename);      // 用資料流讀取器抓資料

            //-------讀檔,要做檢查跳出的判斷式-------//
            while ((CurLine = TaskCSV.ReadLine()) != null)
            {
                int fileEnd = 0;
                if (CurLine.ToUpper().Contains("DATA_TIME"))        // 先將字串矩陣轉大寫,在檢查裡面是否包含特定字串
                //if (CurLine.ToUpper().Contains("NUM1"))        // 先將字串矩陣轉大寫,在檢查裡面是否包含特定字串
                {
                    Section = 1;                                    // Section = 1,這行要跳過
                }
                else if (CurLine.ToUpper().Contains("0"))
                {
                    Section = 2;                                   // Section = 2,數值資料的部分
                }

                switch (Section)
                {
                case 1:
                    Piecewise    = CurLine.Trim().Split(',');
                    ItemsNumbers = Piecewise.Length;
                    break;

                case 2:
                    Piecewise = CurLine.Trim().Split(',');
                    //------判斷是否讀到空字串了------------//
                    if (Piecewise[0] == "" || Piecewise[0] == string.Empty || Piecewise[0] == null)
                    {
                        fileEnd = 1;
                        break;
                    }
                    else     //解析字串內容並存進矩陣
                    {
                        for (int j = 0; j < ItemsNumbers; j++)
                        {
                            //------把各項數值放進對應的List裡------//
                            if (j == 0)
                            {
                                Index.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 1)
                            {
                                DataTime.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 5)
                            {
                                Gap.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 6)
                            {
                                Feed.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 7)
                            {
                                Hipwr.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 8)
                            {
                                WaterR.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            //else if (j == 9) Label3.Add(Convert.ToDouble(Piecewise[j]));
                            else if (j == 10)
                            {
                                Label4.Add(Convert.ToDouble(Piecewise[j]));
                            }
                            else if (j == 11)
                            {
                                Label5.Add(Convert.ToDouble(Piecewise[j]));
                            }

                            /*
                             * if (j == 0) Gap.Add(Convert.ToDouble(Piecewise[j]));
                             * else if (j == 1) Feed.Add(Convert.ToDouble(Piecewise[j]));
                             * else if (j == 2) Hipwr.Add(Convert.ToDouble(Piecewise[j]));
                             * else if (j == 3) WaterR.Add(Convert.ToDouble(Piecewise[j]));
                             * else if (j == 4) Label5.Add(Convert.ToDouble(Piecewise[j]));
                             */
                        }
                    }
                    break;
                }
                if (fileEnd == 1)
                {
                    break;
                }
            }
        }
        /*************************************************************
        *
        * async Task<Feed> FetchTastyTradeFeed
        *
        *************************************************************/

        private async Task<Feed> FetchTastyTradeFeed ()
        {
            Feed feed = new Feed ();

            XElement root;

            try
            {
                root = await LoadXDocumentAsync ("https://feeds.tastytrade.com/podcast.rss");
            }
            catch (Exception e)
            {
                MessageBox.Show (string.Format ("Failed to access tastytrade podcasts. {0}", e.Message));
                return feed;
            }

            XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

            var items = (from el in root.Descendants ("item")
                         select el
                         ).ToList ();

            foreach (var el in items)
            {
                string movie = el.Element ("guid").Value;
                if (! (movie.EndsWith (".mov") || movie.EndsWith (".mp4")) )
                {
                    continue;
                }

                /* discovered the hard way that the image is not always defined
                 * ------------------------------------------------------------ */

                string image = null;
                var ximage = el.Element (itunes + "image");
                if (ximage != null)
                {
                    image = ximage.Attribute ("href").Value;
                }

                FeedItem fi = new FeedItem (el.Element ("title").Value,
                                              el.Element (itunes + "subtitle").Value,
                                              image,
                                              el.Element ("guid").Value,
                                              DateTime.Parse (el.Element ("pubDate").Value));
                feed.Add (fi);
            }

            return feed;
        }