aslaken

Unexpected end of file while reading rss feed

Discussion created by aslaken on Aug 6, 2012
Latest reply on Aug 7, 2012 by aslaken
Hi,

I'm reading an rss feed every 10th second, but on some occations I receive a Unexpexted end of file, although I'm 100% certain that the rss is valid. I'm using the sample code for ArcGIS API for WPF 2.4.

Does anyone have an idea of what the problem is, and how I can resolve it? The code is included below:

private void Fetch_Click(object sender, RoutedEventArgs e)
        {
            if (FeedLocationTextBox.Text != String.Empty)
            {
                LoadRSS(FeedLocationTextBox.Text.Trim());
                DispatcherTimer UpdateTimer = new System.Windows.Threading.DispatcherTimer();
                UpdateTimer.Interval = new TimeSpan(0, 0, 0, 0, 60000);
                UpdateTimer.Tick += (evtsender, args) =>
                {
                    LoadRSS(FeedLocationTextBox.Text.Trim());
                };
                UpdateTimer.Start();
            }
        }

        protected void LoadRSS(string uri)
        {
            WebClient wc = new WebClient();
            wc.OpenReadCompleted += wc_OpenReadCompleted;
            Uri feedUri = new Uri(uri, UriKind.Absolute);
            wc.OpenReadAsync(feedUri);
        }

        private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {

            if (e.Error != null)
            {
                FeedLocationTextBox.Text = "Error in Reading Feed. Try Again later!!";
                return;
            }

            // Optional, use LINQ to query GeoRSS feed.
            //UseLinq(e.Result); return;

            using (Stream s = e.Result)
            {
                SyndicationFeed feed;
                List<SyndicationItem> feedItems = new List<SyndicationItem>();

                GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
                graphicsLayer.ClearGraphics();

                using (XmlReader reader = XmlReader.Create(s))
                {
                    feed = SyndicationFeed.Load(reader);
                    foreach (SyndicationItem feedItem in feed.Items)
                    {
                        SyndicationElementExtensionCollection ec = feedItem.ElementExtensions;

                        string x = "";
                        string y = "";
                        string magnitude = feedItem.Title.Text;

                        foreach (SyndicationElementExtension ee in ec)
                        {
                            XmlReader xr = ee.GetReader();
                            switch (ee.OuterName)
                            {
                                case ("lat"):
                                    {
                                        y = xr.ReadElementContentAsString();
                                        break;
                                    }
                                case ("long"):
                                    {
                                        x = xr.ReadElementContentAsString();
                                        break;
                                    }
                            }
                        }

                        if (!string.IsNullOrEmpty(x))
                        {
                            Graphic graphic = new Graphic()
                            {
                              Geometry = new MapPoint(Convert.ToDouble(x, System.Globalization.CultureInfo.InvariantCulture),
                          Convert.ToDouble(y, System.Globalization.CultureInfo.InvariantCulture),
                                                      new SpatialReference(4326)),
                                Symbol = LayoutRoot.Resources["QuakePictureSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
                            };

                            graphic.Attributes.Add("MAGNITUDE", magnitude);

                            graphicsLayer.Graphics.Add(graphic);
                        }
                    }
                }



Thanks.

Outcomes