private void RequestUserInformation(HtmlTextWriter output)
        {
            HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(UrlUtilities.EnsurePathEndsWithSlash(GetFormattedContextUrl()) + "_api/SP.Microfeed.MicrofeedManager/");

            hwr.Method = "GET";
            hwr.Accept = "application/json";

            if (Configuration.AuthModeToMy == SharePointProxyAuthMode.Impersonate)
            {
                hwr.UseDefaultCredentials = true;
            }

            WebResponse wresp = null;

            try
            {
                wresp = hwr.GetResponse();
            }
            catch (WebException exception)
            {
                // todo: better error handling.
                throw exception;
            }
            catch (Microsoft.SharePoint.Client.ServerUnauthorizedAccessException exception)
            {
                // todo: better error handling.
                throw exception;
            }

            Stream sharePointResponseStream = wresp.GetResponseStream();

            StreamReader reader = new StreamReader(sharePointResponseStream);

            StringBuilder sb   = new StringBuilder();
            String        line = reader.ReadLine();

            sb.AppendLine("var userInfo = " + line.Substring(1));

            while (!reader.EndOfStream)
            {
                sb.AppendLine(line);
                line = reader.ReadLine();
            }

            sb.Append("};");

            String outputA = sb.ToString().Replace("\r", "").Replace("\n", "");

            output.Write(outputA);
        }
        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);
            }
        }