Esempio n. 1
0
        /// <summary>
        /// Actual sub site creation and modification logic. Calls Core component methods to make things work
        /// </summary>
        /// <param name="hostWeb"></param>
        /// <param name="url"></param>
        /// <param name="template"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="feedType"></param>
        /// <param name="yammerGroupName"></param>
        /// <returns></returns>
        public void CreateSubSite(Web hostWeb, string url, string template,
                                  string title, string description, string feedType, string yammerGroupName)
        {
            // Create new sub site
            Web newWeb = hostWeb.CreateSite(title, url, description, template, 1033);

            // Set theme for the site
            newWeb.SetThemeToSubWeb(hostWeb, "Orange");

            //Remove the out of the box "NewsFeed" web part
            newWeb.DeleteWebPart("SitePages", "Site feed", "home.aspx");

            // Let's first get the details on the Yammer network using the access token
            WebPartEntity wpYammer;
            YammerUser    user = YammerUtility.GetYammerUser(ConfigurationManager.AppSettings["YammerAccessToken"]);

            // Notice that in general we do not recommend of matching Yammer group for each site to avoid "group pollution" in Yammer
            if (feedType == "Group")
            {
                // Get Yammer Group - Creates if does not exist. Let's create these as public by default.
                YammerGroup group =
                    YammerUtility.CreateYammerGroup(yammerGroupName, false, ConfigurationManager.AppSettings["YammerAccessToken"]);
                // Get Yammer web part
                wpYammer = YammerUtility.GetYammerGroupDiscussionPart(user.network_name, group.id, false, false);
            }
            else
            {
                // Get OpenGrap object for using that as the discussion feed
                wpYammer = YammerUtility.GetYammerOpenGraphDiscussionPart(user.network_name, Request["SPHostUrl"] + "/" + txtUrl.Text,
                                                                          false, false, "SharePoint Site Feed - " + title);
            }
            // Add Yammer web part to the page
            newWeb.AddWebPartToWikiPage("SitePages", wpYammer, "home.aspx", 2, 1, false);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns Yammer Group if group exists. If the group does not exist, returns null.
        /// </summary>
        /// <param name="groupId">Group Id to search for</param>
        /// <param name="accessToken">accessToken will have all the required permissions to update or retrieve data to Yammer on behalf of the user</param>
        /// <returns>Returns Yammer Group is group exists. If group does not exists, returns null.</returns>
        public static YammerGroup GetYammerGroupById(int groupId, string accessToken)
        {
            YammerGroup yamGroup = null;
            var         groups   = GetYammerGroups(accessToken);

            foreach (var item in groups)
            {
                if (item.id == groupId)
                {
                    yamGroup = item;
                }
            }
            return(yamGroup);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns Yammer Group if group exists. If the group does not exist, returns null.
        /// </summary>
        /// <param name="groupName">Group name to search for</param>
        /// <param name="accessToken">accessToken will have all the required permissions to update or retrieve data to Yammer on behalf of the user</param>
        /// <returns>Returns Yammer Group is group exists. If group does not exists, returns null.</returns>
        public static YammerGroup GetYammerGroupByName(string groupName, string accessToken)
        {
            YammerGroup yamGroup = null;
            var         groups   = GetYammerGroups(accessToken);

            foreach (var item in groups)
            {
                if (item.full_name.Equals(groupName, StringComparison.CurrentCultureIgnoreCase))
                {
                    yamGroup = item;
                }
            }
            return(yamGroup);
        }
Esempio n. 4
0
        /// <summary>
        /// Can be used to create Yammer group to the Yammer network
        /// </summary>
        /// <param name="groupName">Creates yammer group with given name</param>
        /// <param name="isPrivate">Sets yammer groups as private if the value is true. Otherwise sets as public group</param>
        /// <param name="accessToken">accessToken will have all the required permissions to update or retrieve data to Yammer on behalf of the user</param>
        /// <returns>Returns YammerGroup created</returns>
        public static YammerGroup CreateYammerGroup(string groupName, bool isPrivate, string accessToken)
        {
            //Get reference existing group if exists
            YammerGroup yamGroup = GetYammerGroupByName(groupName, accessToken);

            if (yamGroup == null)
            {
                //Create yammer group
                string url = $"https://www.yammer.com/api/v1/groups.json?name={groupName}&private={isPrivate.ToString().ToLower()}";
                PostYammerJson(url, accessToken);
                yamGroup = GetYammerGroupByName(groupName, accessToken);
            }
            return(yamGroup);
        }
Esempio n. 5
0
        private YammerGroup GetYammerGroup(JToken group)
        {
            var yammerGroup = new YammerGroup();

            yammerGroup.Id          = Convert.ToInt32(group["id"]);
            yammerGroup.Email       = group["email"].ToString();
            yammerGroup.FullName    = group["full_name"].ToString();
            yammerGroup.Name        = group["name"].ToString();
            yammerGroup.NetworkId   = Convert.ToInt32(group["network_id"]);
            yammerGroup.Description = group["description"].ToString();
            yammerGroup.Privacy     = group["privacy"].ToString();
            yammerGroup.Url         = group["web_url"].ToString();
            yammerGroup.CreatedAt   = (DateTime)group["created_at"];
            yammerGroup.CreatorId   = Convert.ToInt32(group["creator_id"]);
            yammerGroup.Members     = Convert.ToInt32(group["stats"]["members"]);
            return(yammerGroup);
        }
Esempio n. 6
0
 static void Main(string[] args)
 {
     // Simple tester console to ensure that token works as expected. Details on getting token from here - https://developer.yammer.com/authentication
     string      accessToken = "GetYourOwnAccessTokenFromYammer";
     YammerGroup group       = YammerUtility.GetYammerGroupByName("fuu", accessToken);
 }
 /// <summary>
 /// Updates an existing group
 /// </summary>
 /// <param name="instance">the instance</param>
 /// <param name="group">The group to update</param>
 /// <returns></returns>
 public static IYammerGroupsUpdate Update(this IYammerGroups instance, YammerGroup group)
 {
     instance.Root.Method = WebMethod.Put;
     instance.Root.Parameters.Id = group.Id;
     return new YammerGroupsUpdate(instance.Root);
 }