コード例 #1
0
        public void addSubscriptionFromURL(string podcastRss, bool importingFromExternalService = false)
        {
            if (String.IsNullOrEmpty(podcastRss))
            {
#if DEBUG
                podcastRss = "http://192.168.0.6:8000/feed.rss";
#else
                Debug.WriteLine("ERROR: Empty URL.");
                PodcastSubscriptionFailedWithMessage("Empty podcast address.");
                return;
#endif
            }

            if (podcastRss.StartsWith("http://") == false)
            {
                podcastRss = podcastRss.Insert(0, "http://");
            }

            Uri podcastRssUri;
            try
            {
                podcastRssUri = new Uri(podcastRss);
            }
            catch (UriFormatException)
            {
                Debug.WriteLine("ERROR: Cannot add podcast from that URL.");
                SubscriptionManagerArgs args = new SubscriptionManagerArgs();
                args.message = "Malformed URL";
                OnPodcastChannelAddFinishedWithError(this, args);
                return;
            }

            AddSubscriptionOptions options = new AddSubscriptionOptions();
            options.rssUrl = podcastRss;
            options.isImportingFromExternalService = importingFromExternalService;

            if (importingFromExternalService)
            {
                m_activeExternalImportsCount++;
            }

            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadPodcastRSSCompleted);
            wc.DownloadStringAsync(podcastRssUri, options);

            if (!importingFromExternalService)
            {
                OnPodcastChannelAddStarted(this, null);
            }

            Debug.WriteLine("Fetching podcast from URL: " + podcastRss.ToString());
        }
コード例 #2
0
        public void addSubscriptionFromURLWithCredentials(string podcastRss, NetworkCredential nc)
        {
            if (String.IsNullOrEmpty(podcastRss))
            {
#if DEBUG
                podcastRss = "http://192.168.0.6:8000/feed.rss";
#else
                Debug.WriteLine("ERROR: Empty URL.");
                PodcastSubscriptionFailedWithMessage("Empty podcast address.");
                return;
#endif
            }

            if (podcastRss.StartsWith("http://") == false)
            {
                podcastRss = podcastRss.Insert(0, "http://");
            }

            Uri podcastRssUri;
            try
            {
                podcastRssUri = new Uri(podcastRss);
            }
            catch (UriFormatException)
            {
                Debug.WriteLine("ERROR: Cannot add podcast from that URL.");
                SubscriptionManagerArgs args = new SubscriptionManagerArgs();
                args.message = "Malformed URL";
                OnPodcastChannelAddFinishedWithError(this, args);
                return;
            }

            AddSubscriptionOptions options = new AddSubscriptionOptions();
            options.rssUrl   = podcastRss;
            options.username = nc.UserName;
            options.password = nc.Password;

            WebClient wc = new WebClient();
            wc.Credentials              = nc;
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadPodcastRSSCompleted);
            wc.DownloadStringAsync(podcastRssUri, options);

            OnPodcastChannelAddStarted(this, null);

            Debug.WriteLine("Fetching podcast from URL: " + podcastRss.ToString());
        }
コード例 #3
0
        public void addSubscriptionFromURLWithCredentials(string podcastRss, NetworkCredential nc)
        {
            if (String.IsNullOrEmpty(podcastRss))
            {
#if DEBUG
                podcastRss = "http://192.168.0.6:8000/feed.rss";
#else
                Debug.WriteLine("ERROR: Empty URL.");
                PodcastSubscriptionFailedWithMessage("Empty podcast address.");
                return; 
#endif
            }

            if (podcastRss.StartsWith("http://") == false)
            {
                podcastRss = podcastRss.Insert(0, "http://");
            }

            Uri podcastRssUri;
            try
            {
                podcastRssUri = new Uri(podcastRss);
            }
            catch (UriFormatException)
            {
                Debug.WriteLine("ERROR: Cannot add podcast from that URL.");
                SubscriptionManagerArgs args = new SubscriptionManagerArgs();
                args.message = "Malformed URL";
                OnPodcastChannelAddFinishedWithError(this, args);
                return;
            }

            AddSubscriptionOptions options = new AddSubscriptionOptions();
            options.rssUrl = podcastRss;
            options.username = nc.UserName;
            options.password = nc.Password;

            WebClient wc = new WebClient();
            wc.Credentials = nc;
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadPodcastRSSCompleted);
            wc.DownloadStringAsync(podcastRssUri, options);

            OnPodcastChannelAddStarted(this, null);

            Debug.WriteLine("Fetching podcast from URL: " + podcastRss.ToString());
        }
コード例 #4
0
        public void addSubscriptionFromURL(string podcastRss, bool importingFromExternalService = false)
        {

            if (String.IsNullOrEmpty(podcastRss))
            {
#if DEBUG
                podcastRss = "http://192.168.0.6:8000/feed.rss";
#else
                Debug.WriteLine("ERROR: Empty URL.");
                PodcastSubscriptionFailedWithMessage("Empty podcast address.");
                return; 
#endif
            }

            if (podcastRss.StartsWith("http://") == false)
            {
                podcastRss = podcastRss.Insert(0, "http://");
            }

            Uri podcastRssUri;
            try
            {
                podcastRssUri = new Uri(podcastRss);
            }
            catch (UriFormatException)
            {
                Debug.WriteLine("ERROR: Cannot add podcast from that URL.");
                SubscriptionManagerArgs args = new SubscriptionManagerArgs();
                args.message = "Malformed URL";
                OnPodcastChannelAddFinishedWithError(this, args);
                return;
            }

            AddSubscriptionOptions options = new AddSubscriptionOptions();
            options.rssUrl = podcastRss;
            options.isImportingFromExternalService = importingFromExternalService;

            if (importingFromExternalService)
            {
                m_activeExternalImportsCount++;
            }

            WebClient wc = new WebClient();
            wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadPodcastRSSCompleted);
            wc.DownloadStringAsync(podcastRssUri, options);

            if (!importingFromExternalService)
            {
                OnPodcastChannelAddStarted(this, null);
            }

            Debug.WriteLine("Fetching podcast from URL: " + podcastRss.ToString());
        }
コード例 #5
0
        async private void wc_DownloadPodcastRSSCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null ||
                e.Cancelled)
            {
                try
                {
                    string foo = e.Result;
                }
                catch (WebException ex)
                {
                    if (needsAuthentication(ex))
                    {
                        if (MessageBox.Show("Subscribing to this podcast requires authentication. Do you want to give username and password to continue?",
                                            "Attention",
                                            MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            SubscriptionManagerArgs authArgs = new SubscriptionManagerArgs();
                            authArgs.podcastFeedRSSUri = ex.Response.ResponseUri;
                            OnPodcastChannelRequiresAuthentication(this, authArgs);
                            return;
                        }
                    }
                }

                PodcastSubscriptionFailedWithMessage("Could not fetch the podcast feed.");
                return;
            }

            string podcastRss = e.Result;
            PodcastSubscriptionModel podcastModel = PodcastFactory.podcastModelFromRSS(podcastRss);

            if (podcastModel == null)
            {
                PodcastSubscriptionFailedWithMessage("Podcast feed is invalid.");
                return;
            }

            AddSubscriptionOptions options = e.UserState as AddSubscriptionOptions;
            string rssUrl = options.rssUrl;
            bool   importingFromExternalService = options.isImportingFromExternalService;
            bool   isPodcastInDB = false;

            using (var db = new PodcastSqlModel())
            {
                isPodcastInDB = db.isPodcastInDB(rssUrl);
            }

            if (isPodcastInDB)
            {
                if (!importingFromExternalService)
                {
                    PodcastSubscriptionFailedWithMessage("You have already subscribed to that podcast.");
                }

                if (importingFromExternalService)
                {
                    m_activeExternalImportsCount--;
                    if (m_activeExternalImportsCount <= 0)
                    {
                        if (OnExternalServiceImportFinished != null)
                        {
                            OnExternalServiceImportFinished(this, null);
                        }
                    }
                }
                return;
            }

            podcastModel.CachedPodcastRSSFeed     = podcastRss;
            podcastModel.PodcastLogoLocalLocation = localLogoFileName(podcastModel);
            podcastModel.PodcastRSSUrl            = rssUrl;

            if (String.IsNullOrEmpty(options.username) == false)
            {
                podcastModel.Username = options.username;
            }

            if (String.IsNullOrEmpty(options.password) == false)
            {
                podcastModel.Password = options.password;
            }

            using (var db = new PodcastSqlModel())
            {
                db.addSubscription(podcastModel);
            }

            await podcastModel.fetchChannelLogo();

            SubscriptionManagerArgs addArgs = new SubscriptionManagerArgs();

            addArgs.subscription = podcastModel;
            addArgs.isImportingFromExternalService = importingFromExternalService;

            OnPodcastChannelAddFinished(this, addArgs);
            OnPodcastChannelAdded(podcastModel);
        }