public override async void OnAppear(params object[] args) { base.OnAppear(args); var semesters = await _courseHandler.GetStudentCurrentSemesters(); Courses = semesters.SelectMany(x => x.Courses).ToList(); if (args.Length > 0 && args[0] is Notice notice) { CurrentNotice = notice; } else if (args.Length == 1 && args[0] is PostType postType) { CurrentNotice = new Notice { PostType = postType }; } else if (args.Length == 1 && args[0] is Course course) { CurrentCourse = Courses.FirstOrDefault(x => x.Id == course.Id); CurrentNotice = new Notice { Title = "Notice for " + CurrentCourse.CourseId }; HasCourse = true; } else { CurrentNotice = new Notice(); } CurrentPost = PostTypes.FirstOrDefault(x => x == CurrentNotice.PostType); }
public string GeneratePostsContent() { StringBuilder sb = new StringBuilder(); var sortedPosts = Posts.OrderBy(x => x.PostType); PostTypes previousCategoryType = PostTypes.NA; foreach (Post currentPost in sortedPosts) { if (previousCategoryType != currentPost.PostType) { if (currentPost.PostType != PostTypes.NA) { sb.AppendLine("</ul>"); } previousCategoryType = currentPost.PostType; sb.AppendLine(string.Format("<h2>{0}</h2>", currentPost.PostType.GetTitle())); sb.AppendLine("<ul style=\"list-style-type: disc;\">"); } string currentAuthorText = currentPost.Site != null?string.Format("{0}({1})", currentPost.Author, currentPost.Site) : currentPost.Author; string currentUrl = currentPost.IsTrackBack == true?string.Format("{0}/trackback", currentPost.Url.TrimEnd('/')) : currentPost.Url; string currentLine = string.Format("<li><span style=\"font-size: 12pt;\"><a style=\"color: #{0};\" href=\"{1}\" target=\"_blank\">{2}</a></span> - <span style=\"font-size: 10pt;\"><em>{3}</em></span></li>", currentPost.PostType.Description(), currentUrl, currentPost.Title, currentAuthorText); sb.AppendLine(currentLine); } sb.AppendLine("</ul>"); return(sb.ToString()); }
//修改帖子内容 public static void AlterPost(int userId, int postId, string title, string description, ItemTypes type, PostTypes postType, float price) { string strUser = "******" + "postId=" + postId; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); Post post = new Post(postId); post.Title = title; post.UserId = userId; post.Type = type; post.PostType = postType; post.BriefDescription = description; post.Price = price; HttpContent content = new StringContent(JsonConvert.SerializeObject(post), Encoding.UTF8, "application/json"); var task = client.PutAsync(strUser, content); // Post user1 = JsonConvert.DeserializeObject<Post>(task.Result.ToString()); task.Wait(); return; }
public static int get_post_type_id(PostTypes postType) { switch (postType) { case PostTypes.Text: return(1); case PostTypes.Knowledge: return(2); case PostTypes.Node: return(3); case PostTypes.Question: return(4); case PostTypes.File: return(5); case PostTypes.User: return(6); default: return(0); } }
public TumblrPost(PostTypes postType, string url, string id, string date) { this.PostType = postType; this.Url = url; this.Id = id; this.Date = date; }
public TumblrPost(PostTypes postType, string url, string id) { this.PostType = postType; this.Url = url; this.Id = id; this.Date = string.Empty; }
/// <summary> /// The WordPressClient holds all connection infos and provides methods to call WordPress APIs. /// </summary> /// <param name="uri">URI for WordPress API endpoint, e.g. "http://demo.wp-api.org/wp-json/"</param> public WordPressClient(string uri) { if (string.IsNullOrWhiteSpace(uri)) { throw new ArgumentNullException(nameof(uri)); } if (!uri.EndsWith("/")) { uri += "/"; } _wordPressUri = uri; _httpHelper = new HttpHelper(WordPressUri); Posts = new Posts(ref _httpHelper, defaultPath); Comments = new Comments(ref _httpHelper, defaultPath); Tags = new Tags(ref _httpHelper, defaultPath); Users = new Users(ref _httpHelper, defaultPath); Media = new Media(ref _httpHelper, defaultPath); Categories = new Categories(ref _httpHelper, defaultPath); Pages = new Pages(ref _httpHelper, defaultPath); Taxonomies = new Taxonomies(ref _httpHelper, defaultPath); PostTypes = new PostTypes(ref _httpHelper, defaultPath); PostStatuses = new PostStatuses(ref _httpHelper, defaultPath); CustomRequest = new CustomRequest(ref _httpHelper); }
/// <summary> /// The WordPressClient holds all connection infos and provides methods to call WordPress APIs. /// </summary> /// <param name="httpClient">HttpClient with BaseAddress set which will be used for sending requests to the WordPress API endpoint.</param> /// <param name="defaultPath">Relative path to standard API endpoints, defaults to "wp/v2/"</param> public WordPressClient(HttpClient httpClient, string defaultPath = DEFAULT_PATH) { if (httpClient == null) { throw new ArgumentNullException(nameof(httpClient)); } string uri = httpClient.BaseAddress.ToString(); if (!uri.EndsWith("/", StringComparison.Ordinal)) { uri += "/"; } WordPressUri = uri; _defaultPath = defaultPath; _httpHelper = new HttpHelper(httpClient); Posts = new Posts(ref _httpHelper, _defaultPath); Comments = new Comments(ref _httpHelper, _defaultPath); Tags = new Tags(ref _httpHelper, _defaultPath); Users = new Users(ref _httpHelper, _defaultPath); Media = new Media(ref _httpHelper, _defaultPath); Categories = new Categories(ref _httpHelper, _defaultPath); Pages = new Pages(ref _httpHelper, _defaultPath); Taxonomies = new Taxonomies(ref _httpHelper, _defaultPath); PostTypes = new PostTypes(ref _httpHelper, _defaultPath); PostStatuses = new PostStatuses(ref _httpHelper, _defaultPath); CustomRequest = new CustomRequest(ref _httpHelper); }
private int DetermineDuplicates(PostTypes type) { return(statisticsBag.Where(url => url.PostType.Equals(type)) .GroupBy(url => url.Url) .Where(g => g.Count() > 1) .Sum(g => g.Count() - 1)); }
public virtual BOPostTypes MapEFToBO( PostTypes ef) { var bo = new BOPostTypes(); bo.SetProperties( ef.Id, ef.Type); return(bo); }
public virtual PostTypes MapBOToEF( BOPostTypes bo) { PostTypes efPostTypes = new PostTypes(); efPostTypes.SetProperties( bo.Id, bo.Type); return(efPostTypes); }
public static List <BSPost> GetPosts(PostTypes postType, PostVisibleTypes postVisibleType, FileTypes fileType, int postCount) { List <BSPost> posts = new List <BSPost>(); using (DataProcess dp = new DataProcess()) { dp.AddParameter("Type", (short)postType); if (postVisibleType != PostVisibleTypes.All) { if (fileType != FileTypes.All) { dp.AddParameter("State", (short)postVisibleType); dp.AddParameter("Show", (short)fileType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State AND [Show]=@Show ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } else { dp.AddParameter("State", (short)postVisibleType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } } else { if (fileType != FileTypes.All) { dp.AddParameter("Show", (short)fileType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [Show]=@Show ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } else { dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return(posts); }
public void MapBOToEF() { var mapper = new DALPostTypesMapper(); var bo = new BOPostTypes(); bo.SetProperties(1, "A"); PostTypes response = mapper.MapBOToEF(bo); response.Id.Should().Be(1); response.Type.Should().Be("A"); }
public void MapEFToBO() { var mapper = new DALPostTypesMapper(); PostTypes entity = new PostTypes(); entity.SetProperties(1, "A"); BOPostTypes response = mapper.MapEFToBO(entity); response.Id.Should().Be(1); response.Type.Should().Be("A"); }
public void MapEFToBOList() { var mapper = new DALPostTypesMapper(); PostTypes entity = new PostTypes(); entity.SetProperties(1, "A"); List <BOPostTypes> response = mapper.MapEFToBO(new List <PostTypes>() { entity }); response.Count.Should().Be(1); }
public IEnumerable <Post> GetPosts(PostTypes type) { try { if (type == PostTypes.NoType) { return(dBContext.Posts.OrderByDescending(x => x.Id).Take(COUNT_GET_POSTS)); } return(dBContext.Posts.OrderByDescending(x => x.Id).Where(x => x.PostTypeId == type).Take(COUNT_GET_POSTS)); } catch (Exception ex) { Logger.LogError(ex.Message, ex); return(null); } }
public async void Get() { var mock = new ServiceMockFacade <IPostTypesRepository>(); var record = new PostTypes(); mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record)); var service = new PostTypesService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.PostTypesModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLPostTypesMapperMock, mock.DALMapperMockFactory.DALPostTypesMapperMock); ApiPostTypesResponseModel response = await service.Get(default(int)); response.Should().NotBeNull(); mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>())); }
/// <summary> /// Posts data to a specified url. Note that this assumes that you have already url encoded the post data. /// </summary> /// <param name="postData">The data to post.</param> /// <param name="url">the url to post to.</param> /// <param name="postType">the type of post you are performing.</param> /// <returns>Returns the result of the post.</returns> public static string PostData(string url, string postData, PostTypes postType) { HttpWebRequest request = null; if (postType == PostTypes.Post) { Uri uri = new Uri(url); request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postData.Length; if (!String.IsNullOrEmpty(postData)) { using (Stream writeStream = request.GetRequestStream()) { UTF8Encoding encoding = new UTF8Encoding(); byte[] bytes = encoding.GetBytes(postData); writeStream.Write(bytes, 0, bytes.Length); } } } else { Uri uri = new Uri(url + "?" + postData); request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; } string result = string.Empty; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8)) { result = readStream.ReadToEnd(); } } } return(result); }
public List<BSPost> GetPosts(PostTypes postType) { return BSPost.GetPostsByColumnValue("UserID", UserID, 0, "ORDER By CreateDate DESC", postType, PostStates.All); }
public List <BSPost> GetPosts(PostTypes postType) { return(BSPost.GetPostsByColumnValue("UserID", UserID, 0, "ORDER By CreateDate DESC", postType, PostStates.All)); }
public static List<BSPost> GetPostsByTerm(int termId, string code, TermTypes termType, PostTypes postType, PostStates postState) { List<BSPost> posts = new List<BSPost>(); using (DataProcess dp = new DataProcess()) { BSTerm bsTerm = null; bsTerm = termId != 0 ? BSTerm.GetTerm(termId) : BSTerm.GetTerm(code, termType); if (bsTerm != null) { dp.AddParameter("TermID", bsTerm.TermID); if (postState != PostStates.All) { dp.AddParameter("State", (short)postState); dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [State]=@State ORDER By [CreateDate] DESC"); } else { dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [Type]=@Type ORDER By [CreateDate] DESC"); } } else return posts; if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return posts; }
public abstract byte[] Post(Uri postUri, PostEncodingTypes postEncodingType, PostTypes postType, IDictionary<string, string> parameters);
public static List <BSPost> GetPostsByColumnValue(string column, object value, int postCount, string orderBy, PostTypes postType, PostStates postState) { List <BSPost> posts = new List <BSPost>(); using (DataProcess dp = new DataProcess()) { string top = postCount > 0 ? "TOP " + postCount : String.Empty; if (!String.IsNullOrEmpty(column) && value != null) { dp.AddParameter("Type", (short)postType); dp.AddParameter(column, value); if (postState == PostStates.All) { dp.ExecuteReader(String.Format("SELECT {1} * FROM Posts WHERE [Type]=@Type AND [{0}]=@{0} {2}", column, top, orderBy)); } else { dp.AddParameter("State", (short)postState); dp.ExecuteReader(String.Format("SELECT {1} * FROM Posts WHERE [Type]=@Type AND [{0}]=@{0} AND [State]=@State {2}", column, top, orderBy)); } } else { dp.AddParameter("Type", (short)postType); if (postState == PostStates.All) { dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type {1}", top, orderBy)); } else { dp.AddParameter("State", (short)postState); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State {1}", top, orderBy)); } } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return(posts); }
public static bool add_meta_box(string id, string title, Action <PostInfo> callback, PostTypes post_type, PartOfPage context = PartOfPage.advanced, Priority priority = Priority.Default, string callback_args = null) { // http://codex.wordpress.org/Function_Reference/add_meta_box throw new MockMethodException(); }
public static List<BSPost> GetPosts(PostTypes postType, PostVisibleTypes postVisibleType, FileTypes fileType, int postCount) { List<BSPost> posts = new List<BSPost>(); using (DataProcess dp = new DataProcess()) { dp.AddParameter("Type", (short)postType); if (postVisibleType != PostVisibleTypes.All) { if (fileType != FileTypes.All) { dp.AddParameter("State", (short)postVisibleType); dp.AddParameter("Show", (short)fileType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State AND [Show]=@Show ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } else { dp.AddParameter("State", (short)postVisibleType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } } else { if (fileType != FileTypes.All) { dp.AddParameter("Show", (short)fileType); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [Show]=@Show ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } else { dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type ORDER By [CreateDate] DESC,[Title]" , postCount == 0 ? String.Empty : "TOP " + postCount)); } } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return posts; }
public static List<BSPost> GetPostsByColumnValue(string column, object value, int postCount, string orderBy, PostTypes postType, PostStates postState) { List<BSPost> posts = new List<BSPost>(); using (DataProcess dp = new DataProcess()) { string top = postCount > 0 ? "TOP " + postCount : String.Empty; if (!String.IsNullOrEmpty(column) && value != null) { dp.AddParameter("Type", (short)postType); dp.AddParameter(column, value); if (postState == PostStates.All) { dp.ExecuteReader(String.Format("SELECT {1} * FROM Posts WHERE [Type]=@Type AND [{0}]=@{0} {2}", column, top, orderBy)); } else { dp.AddParameter("State", (short)postState); dp.ExecuteReader(String.Format("SELECT {1} * FROM Posts WHERE [Type]=@Type AND [{0}]=@{0} AND [State]=@State {2}", column, top, orderBy)); } } else { dp.AddParameter("Type", (short)postType); if (postState == PostStates.All) dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type {1}", top, orderBy)); else { dp.AddParameter("State", (short)postState); dp.ExecuteReader(String.Format("SELECT {0} * FROM Posts WHERE [Type]=@Type AND [State]=@State {1}", top, orderBy)); } } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return posts; }
public byte[] Post(Uri postUri, PostEncodingTypes postEncodingType, PostTypes postType, IDictionary<string, string> parameters, Encoding encoding) { Encoding = encoding; return Post(postUri, postEncodingType, postType, parameters); }
public byte[] Post(Uri postUri, PostEncodingTypes postEncodingType, PostTypes postType) { PostType = postType; return Post(postUri, postEncodingType); }
public IEnumerable <Post> GetPosts(PostTypes type) { return(postService.GetPosts(type)); }
public abstract byte[] Post(Uri postUri, PostEncodingTypes postEncodingType, PostTypes postType);
public static List <BSPost> GetPostsByTerm(int termId, string code, TermTypes termType, PostTypes postType, PostStates postState) { List <BSPost> posts = new List <BSPost>(); using (DataProcess dp = new DataProcess()) { BSTerm bsTerm = null; bsTerm = termId != 0 ? BSTerm.GetTerm(termId) : BSTerm.GetTerm(code, termType); if (bsTerm != null) { dp.AddParameter("TermID", bsTerm.TermID); if (postState != PostStates.All) { dp.AddParameter("State", (short)postState); dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [State]=@State ORDER By [CreateDate] DESC"); } else { dp.ExecuteReader("SELECT * FROM Posts WHERE [PostID] IN (SELECT [ObjectID] FROM TermsTo WHERE [TermID]=@TermID) AND [Type]=@Type ORDER By [CreateDate] DESC"); } } else { return(posts); } if (dp.Return.Status == DataProcessState.Success) { using (IDataReader dr = dp.Return.Value as IDataReader) { while (dr != null && dr.Read()) { BSPost bsPost = new BSPost(); FillPost(dr, bsPost); posts.Add(bsPost); } } } } return(posts); }
public byte[] Post(Uri postUri, PostEncodingTypes postEncodingType, PostTypes postType, IDictionary<string, string> parameters) { Parameters = parameters; return Post(postUri, postEncodingType, postType); }
private async Task <string> ContinueExecution(object jsonContent, string apiPath, PostTypes postType) { var result = string.Empty; _httpClient = new HttpClient(); var claim = _httpContextAccessor.HttpContext.User.Claims.First(c => c.Type == ConstantString.AccessToken); string accessToken = claim.Value; if (!string.IsNullOrEmpty(accessToken)) { _httpClient.DefaultRequestHeaders.Add(ConstantString.AccessToken, accessToken); } _httpClient.DefaultRequestHeaders.Add(Headers.ClientID, Common.ClientID); _httpClient.DefaultRequestHeaders.Add(Headers.SecreteToken, Common.ClientSecretKey); _httpClient.BaseAddress = new Uri(apiPath); if (PostTypes.GET == postType) { HttpResponseMessage response = await _httpClient.GetAsync(apiPath); switch (response.StatusCode) { case HttpStatusCode.OK: result = response.Content.ReadAsStringAsync().Result; break; } response.Dispose(); } else { HttpContent content = CreateHttpContent <object>(jsonContent); HttpResponseMessage response = await _httpClient.PostAsync(apiPath, content); switch (response.StatusCode) { case HttpStatusCode.OK: result = response.Content.ReadAsStringAsync().Result; break; } content.Dispose(); response.Dispose(); } return(result); }