Пример #1
0
        private WriterEditingManifest SafeDownloadEditingManifest()
        {
            WriterEditingManifest editingManifest = null;

            try
            {
                // create a blog client
                IBlogClient blogClient = CreateBlogClient();

                // can we get one based on cached download info
                IBlogCredentialsAccessor credentialsToUse = (IncludeInsecureOperations || blogClient.IsSecure) ? _context.Credentials : null;
                if (_context.ManifestDownloadInfo != null)
                {
                    string manifestUrl = _context.ManifestDownloadInfo.SourceUrl;
                    if (UseManifestCache)
                    {
                        editingManifest = WriterEditingManifest.FromDownloadInfo(_context.ManifestDownloadInfo, blogClient, credentialsToUse, true);
                    }
                    else
                    {
                        editingManifest = WriterEditingManifest.FromUrl(new Uri(manifestUrl), blogClient, credentialsToUse, true);
                    }
                }

                // if we don't have one yet then probe for one
                if (editingManifest == null)
                {
                    editingManifest = WriterEditingManifest.FromHomepage(_homepageAccessor, new Uri(_context.HomepageUrl), blogClient, credentialsToUse);
                }
            }
            catch (Exception ex)
            {
                ReportException("attempting to download editing manifest", ex);
            }

            // return whatever we found
            return(editingManifest);
        }
        private BlogEditingTemplateFiles SafeGetTemplates(IProgressHost progress)
        {
            WriterEditingManifest    editingManifest = null;
            BlogEditingTemplateFiles templateFiles   = new BlogEditingTemplateFiles();

            try
            {
                // if we have a manifest url then try to get our manifest
                if (_manifestDownloadInfo != null)
                {
                    // try to get the editing manifest
                    string manifestUrl = _manifestDownloadInfo.SourceUrl;
                    editingManifest = WriterEditingManifest.FromUrl(
                        new Uri(manifestUrl),
                        _blogClient,
                        _credentials,
                        true);

                    // progress
                    CheckCancelRequested(progress);
                    progress.UpdateProgress(20, 100);
                }

                // if we have no editing manifest then probe (if allowed)
                if ((editingManifest == null) && _probeForManifest)
                {
                    editingManifest = WriterEditingManifest.FromHomepage(
                        new LazyHomepageDownloader(_blogHomepageUrl, new HttpRequestHandler(_blogClient.SendAuthenticatedHttpRequest)),
                        new Uri(_blogHomepageUrl),
                        _blogClient,
                        _credentials);
                }

                // progress
                CheckCancelRequested(progress);
                progress.UpdateProgress(40, 100);

                // if we got one then return templates from it as-appropriate
                if (editingManifest != null)
                {
                    if (editingManifest.WebLayoutUrl != null)
                    {
                        string webLayoutTemplate = DownloadManifestTemplate(new ProgressTick(progress, 10, 100), editingManifest.WebLayoutUrl);
                        if (BlogEditingTemplate.ValidateTemplate(webLayoutTemplate))
                        {
                            // download supporting files
                            string templateFile = DownloadTemplateFiles(webLayoutTemplate, _blogHomepageUrl, new ProgressTick(progress, 20, 100));

                            // return the template
                            templateFiles.FramedTemplate = new BlogEditingTemplateFile(BlogEditingTemplateType.Framed, templateFile);
                        }
                        else
                        {
                            Trace.WriteLine("Invalid webLayoutTemplate specified in manifest");
                        }
                    }

                    if (editingManifest.WebPreviewUrl != null)
                    {
                        string webPreviewTemplate = DownloadManifestTemplate(new ProgressTick(progress, 10, 100), editingManifest.WebPreviewUrl);
                        if (BlogEditingTemplate.ValidateTemplate(webPreviewTemplate))
                        {
                            // download supporting files
                            string templateFile = DownloadTemplateFiles(webPreviewTemplate, _blogHomepageUrl, new ProgressTick(progress, 20, 100));

                            // return the template
                            templateFiles.WebPageTemplate = new BlogEditingTemplateFile(BlogEditingTemplateType.Webpage, templateFile);
                        }
                        else
                        {
                            Trace.WriteLine("Invalid webPreviewTemplate specified in manifest");
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
                progress.UpdateProgress(100, 100);
            }

            return(templateFiles);
        }