/// <summary> /// Gets the post. /// </summary> /// <param name="postid">The postid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns>System.Object.</returns> /// <exception cref="BlogSystemException">error getting post</exception> object IMetaWeblog.GetPost(string postid, string username, string password) { ValidateUser(username, password); try { TraceUtility.LogInformation("Get post invoked for {0}", postid); var blogPost = this.metaweblogTable.GetById(ApplicationConstants.BlogKey, postid); var blog = TableBlogEntity.GetBlogPost(blogPost); if (null == blog) { return(null); } return (new { description = blog.Body, title = blog.Title, dateCreated = blog.PostedDate, wp_slug = string.Empty, categories = string.IsNullOrWhiteSpace(blogPost.CategoriesCsv) ? new[] { string.Empty } : blogPost.CategoriesCsv.ToCollection().ToArray(), postid = blog.BlogId }); } catch (Exception exception) { TraceUtility.LogError(exception); throw new BlogSystemException("error getting post"); } }
/// <summary> /// Gets the blog post. /// </summary> /// <param name="postId">The post identifier.</param> /// <returns>BlogPost.</returns> public BlogPost GetBlogPost(string postId) { var activeTable = this.blogContext.CustomOperation(); var query = (from record in activeTable.CreateQuery <DynamicTableEntity>() where record.PartitionKey == ApplicationConstants.BlogKey && record.Properties["IsDeleted"].BooleanValue == false && record.Properties["FormattedUri"].StringValue.Equals( postId, StringComparison.OrdinalIgnoreCase) select record).Take(this.pageSize); var result = query.AsTableQuery().ExecuteSegmented(null, this.blogContext.TableRequestOptions); if (!result.Any()) { return(null); } return (TableBlogEntity.GetBlogPost( result.Select(element => element.ConvertDynamicEntityToEntity <TableBlogEntity>()).FirstOrDefault())); }
/// <summary> /// Updates the post. /// </summary> /// <param name="postid">The postid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="post">The post.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> /// <exception cref="BlogSystemException">Can not update blog post</exception> /// <exception cref="RahulRai.Websites.Utilities.Common.Exceptions.BlogSystemException">Can not update blog post</exception> bool IMetaWeblog.UpdatePost(string postid, string username, string password, dynamic post, bool publish) { ValidateUser(username, password); ClearCache(); var postTitle = post["title"]; TraceUtility.LogInformation("Update post invoked for {0} ID {1}", postTitle, postid); var description = post["description"]; var categories = (null == post["categories"] || null == post["categories"] as string[]) ? string.Empty : (post["categories"] as string[]).ToCsv(); var blogPost = new BlogPost { Body = description, IsDeleted = false, Title = postTitle, PostedDate = DateTime.UtcNow, CategoriesCsv = categories, IsDraft = !publish, BlogId = postid ////Persist post id }; try { var tablePost = new TableBlogEntity(blogPost); this.metaweblogTable.InsertOrReplace(tablePost); var result = this.metaweblogTable.SaveAll(); if (!result.All(element => element.IsSuccess)) { TraceUtility.LogWarning("Could not update post id {0}", postid); throw new BlogSystemException("Can not update blog post"); } } catch (BlogSystemException) { throw; } catch (Exception exception) { TraceUtility.LogError(exception); throw new BlogSystemException("update failed"); } try { ////Update search document. If categories are removed, remove all indexes. if (publish) { this.searchService.UpsertDataToIndex( new BlogSearch { BlogId = blogPost.BlogId, SearchTags = string.IsNullOrWhiteSpace(blogPost.CategoriesCsv) ? new[] { string.Empty } : blogPost.CategoriesCsv.ToCollection().ToArray(), Title = blogPost.Title }); } } catch (Exception exception) { TraceUtility.LogError(exception); throw new BlogSystemException("indexing failed"); } return(true); }
/// <summary> /// Adds the post. /// </summary> /// <param name="blogid">The blogid.</param> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <param name="post">The post.</param> /// <param name="publish">if set to <c>true</c> [publish].</param> /// <returns>System.String.</returns> /// <exception cref="BlogSystemException">Can not save blog post</exception> /// <exception cref="RahulRai.Websites.Utilities.Common.Exceptions.BlogSystemException">Can not save blog post</exception> string IMetaWeblog.AddPost(string blogid, string username, string password, dynamic post, bool publish) { ValidateUser(username, password); ClearCache(); var postTitle = post["title"]; TraceUtility.LogInformation("Add Post invoked for title {0}", postTitle); var description = post["description"]; var categories = (null == post["categories"] || null == post["categories"] as string[]) ? string.Empty : (post["categories"] as string[]).ToCsv(); var blogPost = new BlogPost { Body = description, IsDeleted = false, Title = postTitle, CategoriesCsv = categories, PostedDate = DateTime.UtcNow, IsDraft = !publish }; try { var tablePost = new TableBlogEntity(blogPost); this.metaweblogTable.InsertOrReplace(tablePost); var result = this.metaweblogTable.SaveAll(); if (!result.All(element => element.IsSuccess)) { TraceUtility.LogWarning("Could not save blog post with title {0}", postTitle); throw new BlogSystemException("Can not save blog post"); } //// Add message in blog queue. this.azureQueueService.AddMessageToQueue(blogPost.BlogId); } catch (BlogSystemException) { //// Already logged. Throw. throw; } catch (Exception exception) { TraceUtility.LogError(exception); throw new BlogSystemException("operation failed"); } try { ////Create search document if search terms exist. if (string.IsNullOrWhiteSpace(categories) || !publish) { return(blogPost.BlogId); } this.searchService.UpsertDataToIndex( new BlogSearch { BlogId = blogPost.BlogId, SearchTags = blogPost.CategoriesCsv.ToCollection().ToArray(), Title = blogPost.Title }); TraceUtility.LogInformation("Blog post has been indexed. Title {0}", postTitle); return(blogPost.BlogId); } catch (Exception exception) { TraceUtility.LogError(exception, "Blog indexing failed title {0}. Message {1}", postTitle); throw new BlogSystemException("failed indexing"); } }