public static bool ExecuteSimpleContentRetreival(
            IWin32Window dialogOwner, ContentSourceInfo contentSourceInfo, string url, ref string title, ref string newContent)
        {
            try
            {
                // if there is progress requested then just do it on the main UI thread
                if (contentSourceInfo.UrlContentSourceRequiresProgress)
                {
                    // create the progress dialog and the async operation
                    UrlContentRetreivalWithProgressDialog progressDialog = new UrlContentRetreivalWithProgressDialog(contentSourceInfo);
                    progressDialog.CreateControl();
                    SimpleUrlContentRetreivalAsyncOperation asyncOperation = new SimpleUrlContentRetreivalAsyncOperation(progressDialog, contentSourceInfo.Instance as ContentSource, url, title);

                    // execute and retreive results
                    if (ExecuteWithProgress(dialogOwner, progressDialog, asyncOperation, contentSourceInfo))
                    {
                        title = asyncOperation.Title;
                        newContent = asyncOperation.NewContent;
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    try
                    {
                        (contentSourceInfo.Instance as ContentSource).CreateContentFromUrl(url, ref title, ref newContent);
                        return true;
                    }
                    catch (Exception ex)
                    {
                        ContentSourceManager.DisplayContentRetreivalError(dialogOwner, ex, contentSourceInfo);
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return false;
            }
        }
Esempio n. 2
0
        public static bool ExecuteSimpleContentRetreival(
            IWin32Window dialogOwner, ContentSourceInfo contentSourceInfo, string url, ref string title, ref string newContent)
        {
            try
            {
                // if there is progress requested then just do it on the main UI thread
                if (contentSourceInfo.UrlContentSourceRequiresProgress)
                {
                    // create the progress dialog and the async operation
                    UrlContentRetreivalWithProgressDialog progressDialog = new UrlContentRetreivalWithProgressDialog(contentSourceInfo);
                    progressDialog.CreateControl();
                    SimpleUrlContentRetreivalAsyncOperation asyncOperation = new SimpleUrlContentRetreivalAsyncOperation(progressDialog, contentSourceInfo.Instance as ContentSource, url, title);

                    // execute and retrieve results
                    if (ExecuteWithProgress(dialogOwner, progressDialog, asyncOperation, contentSourceInfo))
                    {
                        title      = asyncOperation.Title;
                        newContent = asyncOperation.NewContent;
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    try
                    {
                        (contentSourceInfo.Instance as ContentSource).CreateContentFromUrl(url, ref title, ref newContent);
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        ContentSourceManager.DisplayContentRetreivalError(dialogOwner, ex, contentSourceInfo);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return(false);
            }
        }
Esempio n. 3
0
        private static bool ExecuteWithProgress(
            IWin32Window dialogOwner,
            UrlContentRetreivalWithProgressDialog progressDialog,
            UrlContentRetreivalAsyncOperation asyncOperation,
            ContentSourceInfo contentSourceInfo)
        {
            try
            {
                // show the progress dialog
                using (progressDialog)
                {
                    asyncOperation.Start();
                    progressDialog.ShowProgress(dialogOwner, asyncOperation);
                }

                //  handle the result
                if (asyncOperation.Error != null)
                {
                    ContentSourceManager.DisplayContentRetreivalError(dialogOwner, asyncOperation.Error, contentSourceInfo);
                    return(false);
                }
                else if (asyncOperation.WasCancelled)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return(false);
            }
        }
        private static bool ExecuteWithProgress(
            IWin32Window dialogOwner,
            UrlContentRetreivalWithProgressDialog progressDialog,
            UrlContentRetreivalAsyncOperation asyncOperation,
            ContentSourceInfo contentSourceInfo)
        {
            try
            {
                // show the progress dialog
                using (progressDialog)
                {
                    asyncOperation.Start();
                    progressDialog.ShowProgress(dialogOwner, asyncOperation);
                }

                //  handle the result
                if (asyncOperation.Error != null)
                {
                    ContentSourceManager.DisplayContentRetreivalError(dialogOwner, asyncOperation.Error, contentSourceInfo);
                    return false;
                }
                else if (asyncOperation.WasCancelled)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception executing network operation for content source: " + ex.ToString());
                return false;
            }
        }