private void handleReply(HttpContext ctx, Notification mirror, String requestPayload)
        {
            // create new string builder to hold the response
            StringBuilder response = new StringBuilder();

            // access the credential state
            IAuthorizationState credentialState = DAL.RetrieveCredentialsByRequestIdAndUserToken(mirror.UserToken, mirror.VerifyToken);

            // get auth code from the verify token
            String authCode = DAL.RetrieveAuthCodeByRequestId(mirror.VerifyToken);

            // we can reuse the access token
            IAuthenticator credentials = Authorization.GetAuthenticatorFromState(credentialState);

            // get the speakable text
            TimelineItem timelineItem = Mirror.getTimelineItem(Mirror.BuildService(credentials), mirror.ItemId);

            // get the new title and in reply to
            String newTitle  = timelineItem.Text;
            String inReplyTo = timelineItem.InReplyTo;

            // remove the extra timline card
            Mirror.DeleteTimelineItem(Mirror.BuildService(credentials), timelineItem.Id);

            // get active blogger link
            BlogLink bl = DAL.GetActiveBlogLinkByUserId(mirror.UserToken);

            // we need to determine if this came from our post toolbox or not
            PostToolbox postToolbox = DAL.GetPostToolbox(bl.userId);

            if (postToolbox.itemId == inReplyTo)
            // it's a new post request from the toolbox
            {
                // new posting
                String newPostText = newTitle;

                // post manager
                PostManager pm = new PostManager();

                // create blogger post instance
                Post postInsertRequest = new Post();

                try
                {
                    // append brand
                    newPostText += "<code><br />Posted From Glass</code>";

                    // use post insert request to handle items
                    postInsertRequest = Blogger.insertPost(Blogger.BuildService(credentials), bl, newPostText);

                    // create the response that will go to glass
                    ViewManager bloggerViewHandler = new ViewManager();
                    bloggerViewHandler.AddView("bloggerText", "~/views/bloggerTextPost.html");
                    bloggerViewHandler.Arguments = new Dictionary <String, String>()
                    {
                        { "BLOG_NAME", bl.blogName },
                        { "BLOG_TEXT", newPostText }
                    };
                    timelineItem = Mirror.insertTimelineItem(Mirror.BuildService(credentials), bloggerViewHandler.RenderView("bloggerText"));
                }
                catch (Exception ex)
                {
                    // notify user of exception
                    DAL.InsertAccessLog(mirror.VerifyToken, mirror.UserToken, ex.ToString());
                    response.Append("<article>\n  <section>\n    <div class=\"text-auto-size\" style=\"\">\n      <p class=\"red\">Unable to Insert Text Post</p>\n      <p>Problem with Inserting Text Post</p>\n    </div>\n  </section>\n  <footer>\n    <div>please share again later</div>\n  </footer>\n</article>\n");
                    timelineItem = Mirror.insertTimelineItem(Mirror.BuildService(credentials), response.ToString(), true);
                }

                // submit to post_manager
                pm.postImageLocation = "TEXT_ONLY";
                pm.postImageWebURI   = "TEXT_ONLY";
                pm.postImageContent  = "TEXT_ONLY";
                pm.blogLinkId        = bl.blogId;
                pm.postTitle         = DAL.scrubApos(postInsertRequest.Title);
                pm.postId            = postInsertRequest.Id;
                pm.postContent       = DAL.scrubApos(newPostText);
                pm.userId            = mirror.UserToken;
                pm.eTagId            = timelineItem.ETag;
                pm.itemId            = timelineItem.Id;

                // insert post manager
                DAL.InsertPostManager(pm);
            }
            else
            // it's a title request
            {
                // create blogger post instance
                Post postPatchRequest = new Post();

                try
                {
                    // the inreply to is the specific post we are dealing with
                    PostManager pm = DAL.GetPostManager(mirror, inReplyTo);

                    if (pm.itemId != "-1")
                    {
                        // use post insert request to handle items
                        postPatchRequest = Blogger.updatePostTitle(Blogger.BuildService(credentials), bl, pm, newTitle);
                        // set post manager title to new title
                        pm.postTitle = DAL.scrubApos(newTitle);
                        pm.itemId    = inReplyTo;
                        // update the post manager database
                        DAL.UpdatePostManagerTitle(pm);
                    }
                }
                catch (Exception ex)
                {
                    // notify user of exception
                    DAL.InsertAccessLog(mirror.VerifyToken, mirror.UserToken, ex.ToString());
                    response.Append("<article>\n  <section>\n    <div class=\"text-auto-size\" style=\"\">\n      <p class=\"red\">Unable to Update</p>\n      <p>Problem with Updating Title Text</p>\n    </div>\n  </section>\n  <footer>\n    <div>please share again later</div>\n  </footer>\n</article>\n");
                    timelineItem = Mirror.insertTimelineItem(Mirror.BuildService(credentials), response.ToString(), true);
                }
            }

            return;
        }
        private void handleShare(HttpContext ctx, Notification mirror, String requestPayload)
        {
            try
            {
                // access the credential state
                IAuthorizationState credentialState = DAL.RetrieveCredentialsByRequestIdAndUserToken(mirror.UserToken, mirror.VerifyToken);

                // get auth code from the verify token
                String authCode = DAL.RetrieveAuthCodeByRequestId(mirror.VerifyToken);

                // we can reuse the access token
                IAuthenticator credentials = Authorization.GetAuthenticatorFromState(credentialState);

                // is there an attachment?
                Attachment attachment = Mirror.getTimelineItem(Mirror.BuildService(credentials), mirror.ItemId).Attachments[0];

                // only do this if post doesn't exsist
                Stream fileStream = Mirror.DownloadAttachment(Mirror.BuildService(credentials), attachment);

                // create a new image and save it to the server
                PostManager pm = makeImage(fileStream, mirror);

                // create an image payload for re-creation
                String imagePayload = "data:image/jpeg;base64," + makeImageBase64(pm.postImageLocation);

                // create the response that will go to blogger
                ViewManager bloggerViewHandler = new ViewManager();
                bloggerViewHandler.AddView("bloggerImage", "~/views/bloggerImageView.html");
                bloggerViewHandler.Arguments = new Dictionary <String, String>()
                {
                    { "IMAGE_WEB_URI", pm.postImageWebURI }
                };
                String bloggerResponse = bloggerViewHandler.RenderView("bloggerImage");

                // get active blogger link
                BlogLink bl = DAL.GetActiveBlogLinkByUserId(mirror.UserToken);

                // create blogger post instance
                Post postInsertRequest = new Post();

                // create timeline post instance
                TimelineItem timelineItem = new TimelineItem();

                try
                {
                    // use post insert request to handle items
                    postInsertRequest = Blogger.insertPost(Blogger.BuildService(credentials), bl, bloggerResponse);
                    ViewManager timlineViewHandler = new ViewManager();
                    timlineViewHandler.AddView("timelineImage", "~/views/insertTimelinePhotoOverlay.html");
                    timlineViewHandler.Arguments = new Dictionary <String, String>()
                    {
                        { "IMAGE_WEB_URI", pm.postImageWebURI },
                        { "BLOG_NAME", bl.blogName }
                    };
                    timelineItem = Mirror.insertTimelineItem(Mirror.BuildService(credentials), timlineViewHandler.RenderView("timelineImage"));
                }
                catch (Exception ex)
                {
                    DAL.InsertAccessLog(mirror.VerifyToken, mirror.UserToken, ex.ToString());
                    postInsertRequest.Title = "FAILED";
                    postInsertRequest.Id    = "FAILED";
                    postInsertRequest.Url   = "FAILED";

                    String errorTitle      = "Unable to Post";
                    String errorDesc       = "This blog has exceeded its posting limit for the day";
                    String errorAdditional = "please share again tomorrow";

                    ViewManager errorInsertTimeline = new ViewManager();
                    errorInsertTimeline.AddView("timelineError", "~/views/timelineErrorView.html");
                    errorInsertTimeline.Arguments = new Dictionary <String, String>()
                    {
                        { "ERROR_TITLE", errorTitle },
                        { "ERROR_DESC", errorDesc },
                        { "ERROR_ADDITIONAL", errorAdditional },
                    };

                    timelineItem = Mirror.insertTimelineItem(Mirror.BuildService(credentials), errorInsertTimeline.RenderView("timelineError"), true);
                }

                // submit to post_manager
                pm.postImageContent = imagePayload;
                pm.blogLinkId       = bl.blogId;
                pm.postTitle        = postInsertRequest.Title;
                pm.postId           = postInsertRequest.Id;
                pm.postContent      = bloggerResponse;
                pm.userId           = mirror.UserToken;
                pm.eTagId           = timelineItem.ETag;
                pm.itemId           = timelineItem.Id;

                // insert post manager
                DAL.InsertPostManager(pm);

                return;
            }
            catch (Exception ex)
            {
                String additionalData = "";
                additionalData += "|Function: handleShare()";
                additionalData += "|Exception: " + ex.ToString();
                additionalData += "|Request Payload: " + requestPayload;
                DAL.InsertAccessLog(mirror.VerifyToken, mirror.UserToken, additionalData);
                return;
            }
        }