private void AddHandler(object sender, EventArgs e) { SynchronizationPoint syncPoint = new SynchronizationPoint(View.OrginalTiming, View.CorrectTiming); SynchronizationPointsValidator syncPointsValidatior = new SynchronizationPointsValidator(); if (syncPointsValidatior.CanAddPoint(syncPoint, tool.SynchronizationPoints)) { tool.SynchronizationPoints.Add(syncPoint); View.AddSynchronizationPoint(); SelectLastPoint(); UpdateViewCanSynchronize(); } else { IInfoBoxView infoBoxView = new InfoBoxView(); InfoBoxPresenter infoBoxPresenter = new InfoBoxPresenter( ViewManager, infoBoxView, Resources.MsgSyncPointOrginalTimingWrong, System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, Resources.PathAlertImage)); //Dodajemy widok do głównego widoku, żeby został wyświetlony jako widok podrzędny w stosutnku do niego. var mainView = (Subeditor.Views.Main.MainFormView)ViewManager.GetView(Resources.NameMainView); mainView.AddChildView((IHierarchicalView)infoBoxView); ViewManager.AddView(infoBoxView); ViewManager.ShowView(infoBoxView); ViewManager.RemoveView(infoBoxView); } }
private void SaveHandler(object sender, EventArgs e) { cancellationToken.Cancel = false; //Istnieje konieczność ukrycia widoku inaczej nie zniknie on gdy ma miejsce sytuacja taka jak tu, //gdy zamykamy jeden blokujący widok okna a otwieramy zaraz następny. ViewManager.HideView(View); var subtitlesPath = subtitlesManager.CurrentSubtitles.Path; if (subtitlesPath != null) { subtitlesManager.Save(); } else { ISaveFileView saveFileView = new SaveFileView(); SaveFilePresenter saveFilePresenter = new SaveFilePresenter(ViewManager, saveFileView, subtitlesManager, cancellationToken); //Dodajemy widok zapisu do głównego widoku, żeby został wyświetlony jako widok podrzędny w stosutnku do niego. var mainView = (Subeditor.Views.Main.MainFormView)ViewManager.GetView(Subeditor.Properties.Resources.NameMainView); mainView.AddChildView(saveFileView); ViewManager.AddView(saveFileView); ViewManager.ShowView(saveFileView); ViewManager.CloseView(saveFileView); ViewManager.RemoveView(saveFileView); } ViewManager.CloseView(View); }
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()); } }
/// <summary> /// Metoda wywoływana w momencie odpalenia polecenia. /// </summary> protected override void OnExecute() { bool isToolShown = (toolView != null) ? ViewManager.IsViewShown(toolView) : false; if (!isToolShown) { var mainView = (MainFormView)ViewManager.GetView(Subeditor.Properties.Resources.NameMainView); if (toolView != null) { ViewManager.CloseView(toolView); ViewManager.RemoveView(toolView); mainView.RemoveChildView((IHierarchicalView)toolView); } if (presenter != null) { presenter.ClosePresenter(); } toolView = new TimingAdjustmentToolView(); presenter = new TimingAdjustmentToolPresenter(ViewManager, toolView, manager, editor, tool); mainView.AddChildView((IHierarchicalView)toolView); ViewManager.AddView(toolView); ViewManager.ShowView(toolView); } }
/// <summary> /// Metoda wywoływana w momencie odpalenia polecenia. /// </summary> protected override void OnExecute() { IOpenFileView openFileView = new OpenFileView(); OpenFilePresenter openFilePresenter = new OpenFilePresenter(ViewManager, openFileView, subtitlesManager); ViewManager.AddView(openFileView); ViewManager.ShowView(openFileView); ViewManager.CloseView(openFileView); ViewManager.RemoveView(openFileView); }
/// <summary> /// Metoda wywoływana w momencie odpalenia polecenia. /// </summary> protected override void OnExecute() { ISaveFileView saveFileView = new SaveFileView(); SaveFilePresenter saveFilePresenter = new SaveFilePresenter(ViewManager, saveFileView, subtitlesManager); ViewManager.AddView(saveFileView); ViewManager.ShowView(saveFileView); ViewManager.CloseView(saveFileView); ViewManager.RemoveView(saveFileView); }
public void ProcessRequest(HttpContext context) { //LoadHTMLLocations(); ViewManager vm = new ViewManager(); vm.AddView("index", "~/views/index.html"); context.Response.ContentType = "text/html"; String oAuthURL = Authorization.GetAuthorizationUrl("", ""); vm.Arguments = new Dictionary <String, String>() { { "AUTH_CODE", oAuthURL } }; context.Response.Write(vm.RenderView("index")); }
private void ViewPreCloseRequestHandler(object sender, ViewPreCloseEventArgs e) { var currentSubtitles = subtitlesManager.CurrentSubtitles; if ((!currentSubtitles.IsSaved) && (!String.IsNullOrEmpty(currentSubtitles.Content))) { ViewCloseCancellationToken mainViewCloseCancellationToken = new ViewCloseCancellationToken(e.CancelViewClose); ISaveBeforeCloseView view = new SaveBeforeCloseView(); SaveBeforeClosePresenter presenter = new SaveBeforeClosePresenter(ViewManager, view, subtitlesManager, mainViewCloseCancellationToken); ViewManager.AddView(view); ViewManager.ShowView(view); //Zamyka się sam. ViewManager.RemoveView(view); e.CancelViewClose = mainViewCloseCancellationToken.Cancel; } }
/// <summary> /// Metoda wywoływana w momencie odpalenia polecenia. /// </summary> protected override void OnExecute() { var subtitlesPath = subtitlesManager.CurrentSubtitles.Path; if (subtitlesPath != null) { subtitlesManager.Save(); } else { ISaveFileView saveFileView = new SaveFileView(); SaveFilePresenter saveFilePresenter = new SaveFilePresenter(ViewManager, saveFileView, subtitlesManager); ViewManager.AddView(saveFileView); ViewManager.ShowView(saveFileView); ViewManager.CloseView(saveFileView); ViewManager.RemoveView(saveFileView); } }
public void AddView(IView view) { ViewManager.AddView(view); }
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 handleGetComments(HttpContext ctx, Notification mirror, String requestPayload) { // make new timeline item TimelineItem timelineItem = new TimelineItem(); // 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 active blogger link BlogLink bl = DAL.GetActiveBlogLinkByUserId(mirror.UserToken); try { // set up the view manager ViewManager bloggerViewManager = new ViewManager(); bloggerViewManager.AddView("bloggerPostCover", "~/views/bloggerPostingBundleCover.html"); bloggerViewManager.AddView("bloggerComment", "~/views/bloggerComment.html"); // take the top 3 recent posts PostList postList = Blogger.getPosts(Blogger.BuildService(credentials), bl); // list of html pages StringBuilder bundleCover = new StringBuilder(); // html comment pages List <HtmlComment> htmlPages = new List <HtmlComment>(); int totalCommentCount = 0; // build bundle cover - limit to constant recent_post_count init above for (int postIndex = 0; postIndex < RECENT_POST_COUNT; postIndex++) { // if the index is more than the amount of posts, just break out. if (postIndex >= postList.Items.Count) { break; } // get post Post post = postList.Items[postIndex]; // get comments for post CommentList commentList = Blogger.getComments(Blogger.BuildService(credentials), bl, post.Id); // get the count int commentCount = (commentList.Items == null) ? 0 : commentList.Items.Count; // build individual comment view if (commentCount > 0) { // go through each comment and make some pages foreach (Comment comment in commentList.Items) { // new argument list bloggerViewManager.Arguments = new Dictionary <String, String>() { { "PROFILE_URL", comment.Author.Image.Url }, { "POST_TITLE", post.Title }, { "COMMENT_CONTENT", comment.Content }, { "COMMENT_AUTHOR", comment.Author.DisplayName }, { "COMMENT_TIME", comment.Published }, { "BLOG_NAME", bl.blogName } }; // render view and add it to the html page list htmlPages.Add(new HtmlComment() { html = bloggerViewManager.RenderView("bloggerComment"), text = comment.Content, time = comment.Published }); } totalCommentCount += commentCount; } } // make new argument dictionary for view before processing. bloggerViewManager.Arguments = new Dictionary <String, String>() { { "POST_COUNT", totalCommentCount.ToString() } }; timelineItem = Mirror.insertCommentBundleTimelineCard(Mirror.BuildService(credentials), bloggerViewManager.RenderView("bloggerPostCover"), htmlPages, mirror); } catch (Exception ex) { // notify user of exception StringBuilder response = new StringBuilder(); 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 Retrieve Comments</p>\n <p>Problem with Retrieving Comments</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; } 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; } }