Ejemplo n.º 1
0
        public sealed override void DoTest(Blog blog, IBlogClient blogClient, ITestResults results)
        {
            BlogPost blogPost = new BlogPost();
            bool?    publish  = null;

            PreparePost(blogPost, ref publish);

            string token = BlogUtil.ShortGuid;

            blogPost.Title = token + ":" + blogPost.Title;

            string      etag;
            XmlDocument remotePost;
            string      postId = blogClient.NewPost(blog.BlogId, blogPost, null, publish ?? true, out etag, out remotePost);

            try
            {
                RetryUntilTimeout(TimeoutDuration, delegate
                {
                    using (HttpWebResponse response = HttpRequestHelper.SendRequest(blog.HomepageUrl))
                    {
                        using (Stream stream = response.GetResponseStream())
                        {
                            string html = Encoding.ASCII.GetString(StreamHelper.AsBytes(stream));

                            if (html.Contains(token))
                            {
                                HandleResult(html, results);
                                return(true);
                            }

                            Thread.Sleep(1000);
                            return(false);
                        }
                    }
                });
            }
            catch (TimeoutException te)
            {
                if (!HandleTimeout(te, results))
                {
                    throw;
                }
            }

            if (postId != null && CleanUpPosts)
            {
                blogClient.DeletePost(blog.BlogId, postId, false);
            }
        }
        public void ShowCaptcha()
        {
            HttpWebResponse response = HttpRequestHelper.SendRequest(_imageUrl);
            Image           image;

            using (Stream s = response.GetResponseStream())
            {
                image = Bitmap.FromStream(new MemoryStream(StreamHelper.AsBytes(s)));
            }

            using (image)
            {
                using (GDataCaptchaForm form = new GDataCaptchaForm())
                {
                    form.SetImage(image);
                    _dialogResult = form.ShowDialog(_owner);
                    if (_dialogResult == DialogResult.OK)
                    {
                        _reply = form.Reply;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void DoAfterPublishUploadWork(IFileUploadContext uploadContext)
        {
            FileAttachSettings attachSettings = new FileAttachSettings(uploadContext.Settings);

            if (attachSettings.AttachmentFileName == null)
            {
                CalculateUploadVariables(uploadContext.FormatFileName(uploadContext.PreferredFileName), attachSettings);
            }

            string listGuid = SharepointBlogIdToListGuid(uploadContext.BlogId);

            if (listGuid != null)
            {
                SharePointListsService listsServicesharePointLists = new SharePointListsService(attachSettings.UploadServiceUrl);
                listsServicesharePointLists.Credentials = GetHttpCredentials();

                //The AddAttachment() call will throw an error if the attachment already exists, so we need to delete
                //the attachment first (if it exists).  To delete the attachment, we must construct the attachment URL
                //that is typically generated internally by the server.
                //Sample URL: http://sharepoint/sites/writer/b2/blog/Lists/Posts/Attachments/13/Sunset_thumb1.jpg
                string attachDeleteUrl = String.Format(CultureInfo.InvariantCulture, "{0}{1}/Lists/Posts/Attachments/{2}/{3}", attachSettings.BaseUrl, attachSettings.BlogUrlPart, uploadContext.PostId, attachSettings.AttachmentFileName);
                try
                {
                    listsServicesharePointLists.DeleteAttachment(listGuid, uploadContext.PostId, attachDeleteUrl);
                }
                catch (Exception) {}

                //Add the attachment
                using (Stream fileContents = uploadContext.GetContents())
                    listsServicesharePointLists.AddAttachment(listGuid, uploadContext.PostId, attachSettings.AttachmentFileName, Convert.ToBase64String(StreamHelper.AsBytes(fileContents)));

                uploadContext.Settings.SetString(uploadContext.PostId, FILE_ALREADY_UPLOADED);

                return;
            }
            throw new BlogClientFileUploadNotSupportedException();
        }