//private IFeedEnclosure GetEnclosure(IFeedItem item)
        //{
        //    try
        //    {
        //        System.Diagnostics.Debug.Print("Enclosure is null={0}",item.Enclosure == null);

        //        return (IFeedEnclosure)item.Enclosure;
        //    }
        //    catch (System.Runtime.InteropServices.COMException ex)
        //    {
        //        if (ex.ErrorCode == -2147023728)
        //        {
        //            // "Element not found. (Exception from HRESULT: 0x80070490)"
        //            // ignore exception
        //            System.Diagnostics.Debug.Print("Enclosure element not found exception.");
        //            return null;
        //        }
        //        else
        //            throw;
        //    }
        //}

        private static string GetLocalPath(IFeedEnclosure encl)
        {
            try
            {
                return(encl.LocalPath);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147024735)
                {
                    System.Diagnostics.Debug.Print("Enclosure localPath is invalid.");
                    // "The specified path is invalid. (Exception from HRESULT: 0x800700A1)"
                    // ignore exception
                }
                else
                {
                    throw;
                }
            }
            catch (FileNotFoundException)
            {
                System.Diagnostics.Debug.Print("Enclosure localPath element not found exception.");
                // ignore
            }
            return(null);
        }
        internal RssItem(IFeedItem item)
        {
            title = StripHTMLTags(item.Title);
            link  = item.Link;

            try
            {
                description = StripHTMLTags(item.Description);
            }
            catch (ArgumentException)
            {
                description = "<<<Item text too long.>>>";
            }

            IFeedEnclosure enclosure = (IFeedEnclosure)item.Enclosure;

            if (enclosure != null)
            {
                string filename = GetLocalPath(enclosure);

                try
                {
                    // Let's make sure we only add pictures
                    string extension = "*" + Path.GetExtension(filename);
                    extension = extension.ToUpperInvariant();
                    if (FeedList.imageExtensions.Contains(extension))
                    {
                        // Set enclosure without checking for existence, since enclosure might
                        // not be on disk yet (BITS still getting it)
                        this.enclosure = new FileInfo(filename);
                    }
                }
                catch (ArgumentException)
                {
                    System.Diagnostics.Debug.Print("Illegal character in filename.");
                    // 'Illegal character in filename' is one possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
                catch (NotSupportedException)
                {
                    System.Diagnostics.Debug.Print("The given path's format is not supported.");
                    // 'Message="The given path's format is not supported."' is another possible exception.
                    // Ignore exception; since we'll skip rssItems with this.enclosure == null
                    // higher up in the call chain.
                }
            }
        }
Example #3
0
 private static string GetLocalPath (IFeedEnclosure encl) {
     try {
         return encl.LocalPath;
     } catch (System.Runtime.InteropServices.COMException ex) {
         if (ex.ErrorCode == -2147024735) {
             System.Diagnostics.Debug.Print("Enclosure localPath is invalid.");
             // "The specified path is invalid. (Exception from HRESULT: 0x800700A1)"
             // ignore exception
         } else
             throw;
     } catch (FileNotFoundException) {
         System.Diagnostics.Debug.Print("Enclosure localPath element not found exception.");
         // ignore
     }
     return null;
 }