コード例 #1
0
ファイル: EventTest.aspx.cs プロジェクト: mammerla/YamSamples
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            YammerStandaloneContext yammerContext = new YammerStandaloneContext();
            yammerContext.UserId = String.Empty;
            yammerContext.LoadAuthenticationResponseToken(String.Empty);

            Activity a = new Activity();
            a.Action = "update";
            a.Message = "test update";

            a.Actor.Name = "Mike Ammerlaan";
            a.Actor.EMail = "emailaddress";

            a.Object.Url = "https://yourserverURLhere/sites/dev/Shared%20Documents/test.docx";
            a.Object.Title = "Test Document";
            a.Object.Type = "document";

            a.Private = false;

            yammerContext.PostActivity(a);
        }
コード例 #2
0
        public void ProcessOneWayEvent(SPRemoteEventProperties properties)
        {
            YammerStandaloneContext yammerContext = new YammerStandaloneContext();
            yammerContext.UserId = String.Empty;
            yammerContext.LoadAuthenticationResponseToken(String.Empty);

            String message = string.Empty;

            if (properties == null || properties.ItemEventProperties == null)
            {
                yammerContext.PostMessage("Error: properties or item event properties was not specified.");
                return;
            }

            try
            {
                Web web;
                Microsoft.SharePoint.Client.User user;
                List list;
                ListItem li;

                using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
                 {

                    if (clientContext == null)
                    {
                        yammerContext.PostMessage("Error: could not create a client context within an event.");
                        return;
                    }

                    web = clientContext.Web;
                    clientContext.Load(web);

                    user = clientContext.Web.CurrentUser;
                    clientContext.Load(user);

                    list = web.Lists.GetById(properties.ItemEventProperties.ListId);
                    clientContext.Load(list);

                    li = list.GetItemById(properties.ItemEventProperties.ListItemId);
                    clientContext.Load(li, listItem => listItem.DisplayName);

                    clientContext.ExecuteQuery();
                 }

                Activity a = new Activity();
                a.Action = "update";
                a.Actor.Name = properties.ItemEventProperties.UserDisplayName;
                a.Actor.EMail = user.Email;

                if (properties.EventType == SPRemoteEventType.ItemUpdated || properties.EventType == SPRemoteEventType.ItemUpdating)
                {
                    a.Message = "An item was updated.";
                }
                else if (properties.EventType == SPRemoteEventType.ItemAdded || properties.EventType == SPRemoteEventType.ItemAdding)
                {
                    a.Message = "An item was added.";
                }
                else if (properties.EventType == SPRemoteEventType.ItemDeleted || properties.EventType == SPRemoteEventType.ItemDeleting)
                {
                    a.Message = "An item was deleted.";
                }

                a.Object.Url =  UrlUtilities.EnsurePathEndsWithSlash(properties.ItemEventProperties.WebUrl) + properties.ItemEventProperties.AfterUrl;
                a.Object.Title = li.DisplayName;
                a.Object.Type = "document";

                a.Private = false;

                //message += a.Actor.Name + "|" + a.Actor.EMail + "|" + a.Object.Url + "|" + a.Object.Title + "|";

                //yammerContext.PostMessage(message);

                yammerContext.PostActivity(a);
            }
            catch (Exception e)
            {
                yammerContext.PostMessage("An error occurred while posting a message." + e.Message);
            }
        }
コード例 #3
0
        public void PostActivity(Activity activity)
        {
            YammerRequest yr = this.CreateRequest();

            yr.EndPoint = YammerEndPoint.Activity;

            ActivityUpdate au = new ActivityUpdate();
            au.Activity = activity;

            yr.Method = "POST";
            yr.ContentType = "application/json";
            yr.BeginInit();

            Stream content = yr.GetRequestStream();

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ActivityUpdate), this.Settings);

            serializer.WriteObject(content, au);

            Stream responseStream = yr.GetResponseStream();

            StreamReader sr = new StreamReader(responseStream);

            String body = sr.ReadToEnd();
        }
コード例 #4
0
        private void createPost_Click(object sender, EventArgs e)
        {
            Activity a = new Activity();
            a.Actor.EMail = this.actorEmail.Text;
            a.Actor.Name = this.actorName.Text;
            a.Object.Url = this.objectUrl.Text;
            a.Object.Type = this.objectType.Text;
            a.Object.Image = this.objectImage.Text;
            a.Object.Title = this.objectTitle.Text;
            a.Action = this.action.Text;
            a.Message = this.message.Text;

            a.Users.Add(a.Actor);

            this.YammerContext.PostActivity(a);
        }