Click here to Skip to main content
15,894,630 members
Home / Discussions / C#
   

C#

 
GeneralRe: creating a schedule similar to sunbirt/outlook .... Pin
mrkeivan18-Apr-10 9:04
mrkeivan18-Apr-10 9:04 
QuestionHow to merg two datatable Pin
linqabc18-Apr-10 4:12
linqabc18-Apr-10 4:12 
AnswerRe: How to merg two datatable Pin
Abhinav S18-Apr-10 4:28
Abhinav S18-Apr-10 4:28 
QuestionVB.Net solution to C# Pin
mehrdadc4818-Apr-10 3:24
mehrdadc4818-Apr-10 3:24 
AnswerRe: VB.Net solution to C# Pin
Abhinav S18-Apr-10 3:42
Abhinav S18-Apr-10 3:42 
AnswerRe: VB.Net solution to C# Pin
Brij18-Apr-10 6:24
mentorBrij18-Apr-10 6:24 
AnswerRe: VB.Net solution to C# Pin
Dave Doknjas18-Apr-10 10:18
Dave Doknjas18-Apr-10 10:18 
QuestionOptimising part of a code thats bulky Pin
malcomhfc18-Apr-10 1:21
malcomhfc18-Apr-10 1:21 
Hi there. I'm continuing to learn c# but moved on to the .net 4 compact framework. I have this piece of code i am using in a project. All though it does what i want it too, it feels to clunky and no need for multiple methods. I just don't know how to optimize it.

I am trying to get it to do everything in the responsehandler, without the need for 3 of the same methods. It means my code wont be clunky and unoptimized and i believe all the feeds with display at once and not at different times.

/* removed, no need for it here i think */ but fyi its using system.xml and system.servicemodel.syndication --typo

namespace NewsTap
{
    public partial class NewsFeed : PhoneApplicationPage
    {
        object _selectedItem;
        public NewsFeed()
        {

            InitializeComponent();
            SupportedOrientations = SupportedPageOrientation.Portrait;
            Loaded += new RoutedEventHandler(MainPage_Loaded);

            PageTransitionList.Completed += new EventHandler(PageTransitionList_Completed);

            // Set the data context of the listbox control to the sample data
            //DataContext = new MainViewModel();

            string bbc = "http://www.pchelpforum.com/external.php";
            string dailyMail = "http://www.dailymail.co.uk/home/index.rss";
            string guardian = "http://www.guardian.co.uk/tv-and-radio/rss";

            //bbc request
            HttpWebRequest bbcRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(bbc));
            bbcRequest.BeginGetResponse(new AsyncCallback(ResponseHandler), bbcRequest);

            //daily mail request
            HttpWebRequest DailyMailRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(dailyMail));
            DailyMailRequest.BeginGetResponse(new AsyncCallback(ResponseHandlerdaily), DailyMailRequest);
            // Guardian request
            HttpWebRequest GuardianRequest = (HttpWebRequest)HttpWebRequest.Create(new Uri(guardian));
            GuardianRequest.BeginGetResponse(new AsyncCallback(ResponseHandlerguardian), GuardianRequest);
            //Custom request -- coming soon

        }
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Reset page transition
            ResetPageTransitionList.Begin();
            
            
        }

        #region getting feed
        private void ListBbc_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Capture selected item data
            _selectedItem = (sender as ListBox).SelectedItem;

            // Start page transition animation
            PageTransitionList.Begin();
        }

        private void ListDailyMail_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Capture selected item data
            _selectedItem = (sender as ListBox).SelectedItem;

            // Start page transition animation
            PageTransitionList.Begin();
        }

        private void ListGuardian_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Capture selected item data
            _selectedItem = (sender as ListBox).SelectedItem;

            // Start page transition animation
            PageTransitionList.Begin();
        }
        // no need to touch this i believe!!
        private void PageTransitionList_Completed(object sender, EventArgs e)
        {
            // Set datacontext of details page to selected listbox item
            NavigationService.Navigate(new Uri("/DetailsPage.xaml", UriKind.Relative));
            FrameworkElement root = Application.Current.RootVisual as FrameworkElement;
            root.DataContext = _selectedItem;
        }

        private void ResponseHandler(IAsyncResult asyncResult)
        {
            HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                XmlReader reader = XmlReader.Create(response.GetResponseStream());
                SyndicationFeed newFeed = SyndicationFeed.Load(reader);
                ListBbc.Dispatcher.BeginInvoke(delegate
                    
                {
                    ListBbc.ItemsSource = newFeed.Items;



                });

            }
        }
        private void ResponseHandlerdaily(IAsyncResult asyncResult)
        {
            HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                XmlReader reader = XmlReader.Create(response.GetResponseStream());
                SyndicationFeed newFeed = SyndicationFeed.Load(reader);
                ListDailyMail.Dispatcher.BeginInvoke(delegate
                {
                    ListDailyMail.ItemsSource = newFeed.Items;

                });

            }
        }
        private void ResponseHandlerguardian(IAsyncResult asyncResult)
        {
            HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                XmlReader reader = XmlReader.Create(response.GetResponseStream());
                SyndicationFeed newFeed = SyndicationFeed.Load(reader);
                ListGuardian.Dispatcher.BeginInvoke(delegate
                {
                    ListGuardian.ItemsSource = newFeed.Items;

                });

            }
        }
        #endregion
    }
}


Any help would be great. Thanks in advance to any repliers,

malcomhfc
AnswerRe: Optimising part of a code thats bulky Pin
Gideon Engelberth18-Apr-10 16:34
Gideon Engelberth18-Apr-10 16:34 
GeneralRe: Optimising part of a code thats bulky Pin
malcomhfc21-Apr-10 10:42
malcomhfc21-Apr-10 10:42 
QuestionprogressBar with percents display [modified] Pin
igalep13218-Apr-10 0:55
igalep13218-Apr-10 0:55 
AnswerRe: progressBar with percents display [modified] Pin
Luc Pattyn18-Apr-10 1:11
sitebuilderLuc Pattyn18-Apr-10 1:11 
GeneralRe: progressBar with percents display [modified] Pin
igalep13218-Apr-10 1:21
igalep13218-Apr-10 1:21 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 3:58
Som Shekhar18-Apr-10 3:58 
GeneralRe: progressBar with percents display Pin
igalep13218-Apr-10 4:00
igalep13218-Apr-10 4:00 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 4:04
Som Shekhar18-Apr-10 4:04 
GeneralRe: progressBar with percents display Pin
igalep13218-Apr-10 4:08
igalep13218-Apr-10 4:08 
GeneralRe: progressBar with percents display Pin
Som Shekhar18-Apr-10 4:13
Som Shekhar18-Apr-10 4:13 
AnswerRe: progressBar with percents display Pin
igalep13218-Apr-10 11:48
igalep13218-Apr-10 11:48 
QuestionMessage Removed Pin
17-Apr-10 21:19
Nadia Monalisa17-Apr-10 21:19 
AnswerRe: Do I need to uninstall Visual Studio 2008 in order to install VS 2010 Professional ? Pin
OriginalGriff17-Apr-10 21:30
mveOriginalGriff17-Apr-10 21:30 
GeneralRe: Do I need to uninstall Visual Studio 2008 in order to install VS 2010 Professional ? Pin
Nadia Monalisa17-Apr-10 21:40
Nadia Monalisa17-Apr-10 21:40 
QuestionWill my .NET 2.0 Control work in .NET 4.0 application ? Pin
Nadia Monalisa17-Apr-10 21:14
Nadia Monalisa17-Apr-10 21:14 
AnswerRe: Will my .NET 2.0 Control work in .NET 4.0 application ? Pin
Abhinav S17-Apr-10 23:19
Abhinav S17-Apr-10 23:19 
QuestionSelect Area Pin
Frozzeg17-Apr-10 10:44
Frozzeg17-Apr-10 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.