//获取当前用户发布的新闻源 private int GetPublishdNews() { SPSocialFeedManager feedManager = new SPSocialFeedManager(); SPSocialFeedOptions socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; int i = 0; try { string acountName = GetAccountName(); SPSecurity.RunWithElevatedPrivileges(delegate() { SPSocialFeed feed = feedManager.GetFeedFor(acountName, socialOptions);//.GetFeed(SPSocialFeedType.Personal, socialOptions); SPSocialThread[] threads = feed.Threads; i = threads.Length; foreach (SPSocialThread thread in threads) { if (thread.Attributes.ToString() != "None") { i = i + 1; } else { //this.Controls.Add(new LiteralControl( thread.RootPost.Text) ); } } }); } catch { } return(i); }
//获取当前用户的新闻源 private void GetAllPost() { SPSocialFeedManager feedManager = new SPSocialFeedManager(); SPSocialFeedOptions socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; SPSocialFeed feed = feedManager.GetFeed(SPSocialFeedType.Personal, socialOptions); IterateThroughFeed(feed, true); }
private int GetTotalNewsFeeds() { SPSocialFeedOptions socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; int i = 0; try { string acountName = GetAccountName(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID]) { SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(serviceContext); string accountName = GetAccountName(); UserProfile u = upm.GetUserProfile(accountName); SPSocialFeedManager feedManager = new SPSocialFeedManager(u, serviceContext); SPSocialFeed feed = feedManager.GetFeedFor(web.Url, socialOptions); SPSocialThread[] threads = feed.Threads; foreach (SPSocialThread thread in threads) { if (thread.Attributes.ToString() != "None") { string actorAccount; if (thread.Actors.Length == 2) { actorAccount = thread.Actors[1].AccountName; } else { actorAccount = thread.Actors[0].AccountName; } if (actorAccount.ToLower() == accountName.ToLower()) { i = i + 1; } } } EnumerateNewsfeeds(ref i, web, feedManager, socialOptions, accountName); } } }); } catch { } return(i); }
/// <summary> ///统计不同时间的个人用户和团队的新闻源 /// </summary> /// MaxThreadCount最大值是100,即最多只能返回100,默认值是20, /// <returns>返回一维数组,0-个人总数,1-团队总数,2-当日更新,3-本周更新</returns> private int[] GetPublishdNews() { SPSocialFeedOptions socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; int i = 0; int j = 0; int[] totalTimes = new int[4]; try { string acountName = GetAccountName(); SPSecurity.RunWithElevatedPrivileges(delegate { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { //this.Controls.Add(new LiteralControl("site:" + site.Url + "<br/>")); using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID]) { //this.Controls.Add(new LiteralControl("web:"+web.Url + "<br/>")); SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(serviceContext); string accountName = GetAccountName(); //this.Controls.Add(new LiteralControl("name:" + accountName + "<br/>")); UserProfile u = upm.GetUserProfile(accountName); SPSocialFeedManager feedManager = new SPSocialFeedManager(u, serviceContext); SPSocialFeed feed = feedManager.GetFeedFor(web.Url, socialOptions); SPSocialThread[] threads = feed.Threads; //this.Controls.Add(new LiteralControl("count:" + threads.Length + "<br/>")); foreach (SPSocialThread thread in threads) { //只统计用户发布的新闻源,thread.Attributes.ToString() == "None"表示用户关注了哪些内容,这部分没有统计 if (thread.Attributes.ToString() != "None") { string actorAccount; if (thread.Actors.Length == 1) { actorAccount = thread.Actors[0].AccountName; } else { actorAccount = thread.Actors[1].AccountName; } //string temp = ""; //for (int k = 0; k < thread.Actors.Length; k++) //{ // temp += thread.Actors[k].AccountName+" 、 "; //} //this.Controls.Add(new LiteralControl("actorlength:" + thread.Actors.Length + ";actorAccount:" + temp + "<br/>")); //当前用户 if (actorAccount.ToLower() == accountName.ToLower()) { i = i + 1; } j = j + 1; } } totalTimes[0] = i; //个人总数 //this.Controls.Add(new LiteralControl("my:" + i + "<br/>")); totalTimes[1] = j; //团队总数 //this.Controls.Add(new LiteralControl("all:" + j + "<br/>")); socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; //this.Controls.Add(new LiteralControl("Now:" + DateTime.Now + "<br/>24小时前:" + DateTime.Now.AddHours(-24) + "<br/>一天前:" + DateTime.Now.AddDays(-1))); socialOptions.NewerThan = DateTime.Now.AddHours(-32);//.Date.AddDays(-1).AddHours(8); feed = feedManager.GetFeedFor(web.Url, socialOptions); threads = feed.Threads; totalTimes[2] = threads.Length;//当日更新 socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; socialOptions.NewerThan = DateTime.Now.Date.AddDays(-6).AddHours(-8);//.AddHours(8); feed = feedManager.GetFeedFor(web.Url, socialOptions); threads = feed.Threads; totalTimes[3] = threads.Length;//本周更新 //this.Controls.Add(new LiteralControl("week:" + threads.Length + "<br/>")); } } }); } catch (Exception ex) { this.Controls.Add(new LiteralControl(ex.Message)); } return(totalTimes); }
//获取当前用户发布的新闻源 /// <summary> ///统计不同时间的用户和总的新闻源 /// </summary> /// <param name="typeID">0-个人总数,1-团队总数,2-当日更新,3-本周更新</param> /// <returns></returns> private int[] GetPublishdNews( ) { SPSocialFeedOptions socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; int i = 0; int j = 0; int[] totalTimes = new int[4]; try { string acountName = GetAccountName(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID]) { SPServiceContext serviceContext = SPServiceContext.GetContext(site); UserProfileManager upm = new UserProfileManager(serviceContext); string accountName = GetAccountName(); UserProfile u = upm.GetUserProfile(accountName); SPSocialFeedManager feedManager = new SPSocialFeedManager(u, serviceContext); //this.Controls.Add(new LiteralControl(accountName + "<br>")); //SPSocialFeed feed = feedManager.GetFeedFor(accountName, socialOptions);//.GetFeed SPSocialFeed feed = feedManager.GetFeedFor(web.Url, socialOptions);//.GetFeed(SPSocialFeedType.Personal, socialOptions); SPSocialThread[] threads = feed.Threads; foreach (SPSocialThread thread in threads) { if (thread.Attributes.ToString() != "None") { //if (thread.RootPost.Text != null) // this.Controls.Add(new LiteralControl("Text " + thread.RootPost.Text + "")); //else if (thread.RootPost.Attachment != null) // this.Controls.Add(new LiteralControl( thread.RootPost.Attachment.AttachmentKind.ToString () + "<img src='" + thread.RootPost.Attachment.Uri.ToString() + "'/><br>")); ////if (thread.RootPost.Text == "http://xqx2012/_layouts/15/studentlist/studentlist.aspx") //// Console.WriteLine(thread.RootPost.Text ); string actorAccount; if (thread.Actors.Length == 2) { actorAccount = thread.Actors[1].AccountName; } //this.Controls.Add(new LiteralControl("AccountName " + thread.Actors[1].AccountName + "<br>")); else { actorAccount = thread.Actors[0].AccountName; } //this.Controls.Add(new LiteralControl("AccountName " + thread.Actors[0].AccountName + "<br>")); //当前用户 if (actorAccount.ToLower() == accountName.ToLower()) { i = i + 1; } j = j + 1; } } totalTimes[0] = i; //个人总数 totalTimes[1] = j; //团队总数 socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; socialOptions.NewerThan = DateTime.Now.Date.AddDays(-1).AddHours(8); feed = feedManager.GetFeedFor(accountName, socialOptions); threads = feed.Threads; totalTimes[2] = threads.Length;//当日更新 socialOptions = new SPSocialFeedOptions(); socialOptions.MaxThreadCount = int.MaxValue; socialOptions.NewerThan = DateTime.Now.Date.AddDays(-7).AddHours(8); feed = feedManager.GetFeedFor(accountName, socialOptions); threads = feed.Threads; totalTimes[3] = threads.Length;//本周更新 } } }); } catch { } return(totalTimes); }
/// <summary> /// 遍历当前网站下面子网站的新闻源 /// </summary> /// <param name="totalCount"></param> /// <param name="pWeb"></param> private void EnumerateNewsfeeds(ref int totalCount, SPWeb pWeb, SPSocialFeedManager feedManager, SPSocialFeedOptions socialOptions, string accountName) { foreach (SPWeb subWeb in pWeb.Webs) { SPSocialFeed feed = feedManager.GetFeedFor(subWeb.Url, socialOptions); SPSocialThread[] threads = feed.Threads; int i = 0; foreach (SPSocialThread thread in threads) { if (thread.Attributes.ToString() != "None") { string actorAccount; if (thread.Actors.Length == 2) { actorAccount = thread.Actors[1].AccountName; } else { actorAccount = thread.Actors[0].AccountName; } if (actorAccount.ToLower() == accountName.ToLower()) { i = i + 1; } } } totalCount = totalCount + i; EnumerateNewsfeeds(ref totalCount, subWeb, feedManager, socialOptions, accountName); } }