private void enableToolboxCard(HttpContext ctx, IAuthenticator authInterface) { try { // set authorization from session; this.authorizationCode = ctx.Session["CODE"].ToString(); // get the user id String userId = DAL.RetrieveUserIdByAuthCode(this.authorizationCode); // get the view code for the new timeline card ViewManager vm = new ViewManager(); // add view vm.AddView("timelineCardToolbox", "~/views/toolboxTimelineCardCover.html"); // insert timeline card while rendering new view TimelineItem toolboxCard = Mirror.insertToolboxTimelineCard(Mirror.BuildService(authInterface), vm.RenderView("timelineCardToolbox")); // make timeline toolbox card with new item PostToolbox pt = new PostToolbox() { userId = userId, itemId = toolboxCard.Id, isActive = true }; // insert it into the database DAL.InsertPostToolbox(pt.userId, pt.itemId, pt.isActive); } catch (Exception ex) { String requestId = DAL.RetrieveRequestIdByAuthCode(this.authorizationCode); DAL.InsertAccessLog(requestId, userId, ex.ToString()); } }
private void disableToolboxCard(HttpContext ctx, IAuthenticator authInterface) { try { // set authorization from session; this.authorizationCode = ctx.Session["CODE"].ToString(); // get the user id String userId = DAL.RetrieveUserIdByAuthCode(this.authorizationCode); // get card from post toolbox PostToolbox pt = DAL.GetPostToolbox(userId); // remove the timeline card on disable Mirror.DeleteTimelineItem(Mirror.BuildService(authInterface), pt.itemId); // disable credentials in the database (can use insert, it will update) DAL.InsertPostToolbox(userId, pt.itemId, false); } catch (Exception ex) { String requestId = DAL.RetrieveRequestIdByAuthCode(this.authorizationCode); DAL.InsertAccessLog(requestId, userId, ex.ToString()); } }
private void handleBlogs(HttpContext ctx, IAuthenticator authInterface) { StringBuilder sb = new StringBuilder(); StringBuilder postToolboxResponse = new StringBuilder(); this.authorizationCode = ctx.Session["CODE"].ToString(); String userId = DAL.RetrieveUserIdByAuthCode(this.authorizationCode); BlogList blogList = Blogger.getBlogs(Blogger.BuildService(authInterface), userId); BlogLink blogLink = DAL.GetActiveBlogLinkByUserId(userId); //<--- this code is used to handle the add-on's tab --> PostToolbox postToolbox = DAL.GetPostToolbox(userId); postToolboxResponse.Append("<table class='table'>"); postToolboxResponse.Append("<thead>"); postToolboxResponse.Append("<th>Feature</th>"); postToolboxResponse.Append("<th>Preview</th>"); postToolboxResponse.Append("<th>Description</th>"); postToolboxResponse.Append("<th>Action</th>"); postToolboxResponse.Append("</thead>"); postToolboxResponse.Append("<tbody>"); postToolboxResponse.Append("<tr>"); postToolboxResponse.Append("<td>Toolcard</td>"); postToolboxResponse.Append("<td><a href='img/toolcard.png' target='_blank'><img src='img/toolcard.png' class='img-polaroid' style='height:150px;width:300px;'/></a></td>"); postToolboxResponse.Append("<td style='width:50%'><p>The toolcard is a pinnable item that allows the glass user to extend the functionalilty of the glassware service. Additional options include blog-by-voice and comment retrieval.</p></td>"); if (postToolbox.isActive) { postToolboxResponse.Append("<td>"); postToolboxResponse.Append("<input type='hidden' name='operation' value='disableToolboxCard' />"); postToolboxResponse.Append("<button type='submit' class='btn btn-danger'><i class='icon-remove-sign'></i> Disable</button>"); postToolboxResponse.Append("</td>"); } else { postToolboxResponse.Append("<td>"); postToolboxResponse.Append("<input type='hidden' name='operation' value='enableToolboxCard' />"); postToolboxResponse.Append("<button type='submit' class='btn btn-success'><i class='icon-ok-sign'></i> Enable</button>"); postToolboxResponse.Append("</td>"); } postToolboxResponse.Append("</tr>"); postToolboxResponse.Append("</tbody>"); postToolboxResponse.Append("</table>"); //<--- end add-on tab --> if (blogList.Items.Count > 0) { sb.Append("<table class='table table-striped'>"); sb.Append("<thead>"); sb.Append("<th>Blog</th>"); sb.Append("<th>Default</th>"); sb.Append("</thead>"); sb.Append("<tbody>"); foreach (Blog blog in blogList.Items) { String isHighlight = (blogLink.blogId == blog.Id) ? "success" : ""; sb.Append("<tr class='" + isHighlight + "'>"); sb.Append("<td>" + blog.Name + "</td>"); if (blogLink.blogId == blog.Id) { sb.Append("<td><input value='" + blog.Id + "|" + blog.Name + "' type='radio' name='blog_selection' checked='checked' /></td>"); } else { sb.Append("<td><input value='" + blog.Id + "|" + blog.Name + "' type='radio' name='blog_selection' /></td>"); } sb.Append("</tr>"); } sb.Append("<tr>"); sb.Append("<td></td>"); sb.Append("<td><button type='submit' class='btn btn-block'><i class='icon-retweet'></i> Synchronize Glass</button></td>"); sb.Append("</tr>"); sb.Append("</tbody>"); sb.Append("</table>"); } else { sb.Append("<h3>No Blogger Blogs found for this account!</h3>"); } vm.Arguments = new Dictionary <String, String>() { { "BLOGS", sb.ToString() }, { "BUTTON_OPERATION", postToolboxResponse.ToString() } }; // wright file ctx.Response.Write(vm.RenderView("main")); }
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; }