Пример #1
0
        public void CreateAccount()
        {
            AnnotateResult result    = new AnnotateResult();
            string         webResult = "";
            long           epoch     = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            WebClient      client    = new WebClient();

            string apiKey = annotateApi.GenerateAnnotateKey("createAccount.php", username, epoch);

            string createString = AnnotateURL + "/annotate/php/createAccount.php?" +
                                  "api-user={0}" +          //Annotate admin user name (see web config)
                                  "&api-requesttime={1}" +  //UNIX timestamp
                                  "&api-annotateuser={2}" + //the current user (reviewer)
                                  "&api-auth={3}" +         //Annotate admin auth key
                                  "&licensed=0 " +
                                  "&firstname={4}" +        //User's first name
                                  "&lastname={5}";          //User's last name

            createString = string.Format(createString,
                                         ApiUser,
                                         epoch,
                                         username,
                                         apiKey,
                                         first,
                                         last
                                         );
            webResult = client.DownloadString(createString);

            //downgrade user to unlicensed if not OSBLE admin
            if (OsbleUserAdmin == false)
            {
                apiKey = annotateApi.GenerateAnnotateKey("updateAccount.php", username, epoch);

                string updateString = AnnotateURL + "/annotate/php/updateAccount.php?" +
                                      "api-user={0}" +          //Annotate admin user name (see web config)
                                      "&api-requesttime={1}" +  //UNIX timestamp
                                      "&api-annotateuser={2}" + //the current user (reviewer)
                                      "&api-auth={3}" +         //Annotate admin auth key
                                      "&licensed=0 ";
                updateString = string.Format(updateString,
                                             ApiUser,
                                             epoch,
                                             username,
                                             apiKey
                                             );
                try
                {
                    webResult         = client.DownloadString(updateString);
                    result.RawMessage = webResult;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            result.RawMessage = webResult;

            Assert.AreEqual(webResult.Substring(0, 2), "OK");
        }
        public ActionResult Grade(int assignmentID, int authorTeamID, bool resubmission = false)
        {
            WebClient      client     = new WebClient();
            Assignment     assignment = db.Assignments.Find(assignmentID);
            AssignmentTeam at         = GetAssignmentTeam(assignment, ActiveCourseUser);
            ReviewTeam     reviewTeam = null;

            if (at != null)
            {
                reviewTeam = (from rt in assignment.ReviewTeams
                              where rt.ReviewTeamID == at.TeamID
                              &&
                              rt.AuthorTeamID == authorTeamID
                              select rt).FirstOrDefault();
            }

            //Send off to Annotate if we have exactly one deliverable and that deliverable is a PDF document
            if (assignment.Deliverables.Count == 1 && assignment.Deliverables[0].DeliverableType == DeliverableType.PDF)
            {
                AnnotateApi api = new AnnotateApi(ConfigurationManager.AppSettings["AnnotateUserName"], ConfigurationManager.AppSettings["AnnotateApiKey"]);

                AnnotateResult uploadResult = api.UploadDocument((int)assignment.ID, authorTeamID, resubmission);
                if (uploadResult.Result == ResultCode.OK)
                {
                    AnnotateResult createResult = api.CreateAccount(CurrentUser);
                    if (createResult.Result == ResultCode.OK)
                    {
                        //instructors get to see everyone, regardless of CR settings
                        CriticalReviewSettings settings = new CriticalReviewSettings();
                        settings.AnonymizeComments = false;
                        api.SetDocumentAnonymity(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate, settings);
                        api.GiveAccessToDocument(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                        //log the user in to annotate
                        string loginString = api.GetAnnotateLoginUrl(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                        //load the annotate url for the view
                        ViewBag.AnnotateUrl = loginString;
                    }
                }
            }
            else
            {
                return(RedirectToRoute(new { controller = "Home", action = "Index", area = "" }));
            }

            return(View("Review"));
        }
        /// <summary>
        /// Loads a PDF for critical review
        /// </summary>
        /// <param name="assignmentID"></param>
        /// <param name="authorTeamID"></param>
        /// <returns></returns>
        public ActionResult Review(int assignmentID, int authorTeamID)
        {
            WebClient      client       = new WebClient();
            Assignment     CRassignment = db.Assignments.Find(assignmentID);
            AssignmentTeam at           = GetAssignmentTeam(CRassignment, ActiveCourseUser);
            ReviewTeam     reviewTeam   = null;

            if (at != null)
            {
                reviewTeam = (from rt in CRassignment.ReviewTeams
                              where rt.ReviewTeamID == at.TeamID
                              &&
                              rt.AuthorTeamID == authorTeamID
                              select rt).FirstOrDefault();
            }
            bool canAccessReview = false;

            //Determine whether or not the current user can access the document
            if (CRassignment.Type == AssignmentTypes.CriticalReview)
            {
                //is the user a reviewer?
                if (reviewTeam != null)
                {
                    canAccessReview = true;
                }

                //or, is the user an instructor?
                else if (ActiveCourseUser.AbstractRole.CanGrade)
                {
                    canAccessReview = true;
                }

                //or, has the review been published and the current user is the author of the docment?
                else if (CRassignment.IsCriticalReviewPublished == true)
                {
                    reviewTeam = (from rt in CRassignment.ReviewTeams
                                  where rt.AuthorTeamID == authorTeamID
                                  select rt
                                  ).FirstOrDefault();
                    if (reviewTeam != null)
                    {
                        TeamMember tm = reviewTeam.AuthorTeam.TeamMembers.Where(t => t.CourseUserID == ActiveCourseUser.ID).FirstOrDefault();
                        if (tm != null)
                        {
                            canAccessReview = true;
                        }
                    }
                }
            }

            if (canAccessReview)
            {
                //Send off to Annotate if we have exactly one deliverable and that deliverable is a PDF document
                if (CRassignment.PreceedingAssignment.Deliverables.Count == 1 && CRassignment.PreceedingAssignment.Deliverables[0].DeliverableType == DeliverableType.PDF)
                {
                    AnnotateApi    api          = new AnnotateApi(ConfigurationManager.AppSettings["AnnotateUserName"], ConfigurationManager.AppSettings["AnnotateApiKey"]);
                    AnnotateResult uploadResult = api.UploadDocument((int)CRassignment.PrecededingAssignmentID, authorTeamID);
                    if (uploadResult.Result == ResultCode.OK)
                    {
                        AnnotateResult createResult = api.CreateAccount(CurrentUser);
                        if (createResult.Result == ResultCode.OK)
                        {
                            //instructors get to see everyone, regardless of CR settings
                            CriticalReviewSettings settings = CRassignment.CriticalReviewSettings;
                            if (ActiveCourseUser.AbstractRoleID == (int)CourseRole.CourseRoles.Instructor)
                            {
                                settings.AnonymizeComments = false;
                            }

                            api.SetDocumentAnonymity(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate, settings);
                            api.GiveAccessToDocument(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                            //log the user in to annotate
                            string loginString = api.GetAnnotateLoginUrl(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                            //load the annotate url for the view
                            ViewBag.AnnotateUrl = loginString;
                        }
                    }
                }
                else
                {
                    return(RedirectToRoute(new { controller = "Home", action = "Index", area = "" }));
                }
            }
            return(View());
        }
        /// <summary>
        /// Loads a PDF for critical review
        /// </summary>
        /// <param name="assignmentID"></param>
        /// <param name="authorTeamID"></param>
        /// <returns></returns>
        public ActionResult ReviewGradedDocument(int assignmentID, int authorTeamID, int anonReview = 0)
        {
            WebClient      client       = new WebClient();
            Assignment     CRassignment = db.Assignments.Find(assignmentID);
            AssignmentTeam at           = GetAssignmentTeam(CRassignment, ActiveCourseUser);

            bool canAccessReview = false;

            //Determine whether or not the current user can access the document
            //is the author of the docment?
            TeamMember tm = at.Team.TeamMembers.Where(tms => tms.CourseUserID == ActiveCourseUser.ID).FirstOrDefault();

            if (tm != null)
            {
                canAccessReview = true;
            }

            if (canAccessReview)
            {
                //Send off to Annotate if we have exactly one deliverable and that deliverable is a PDF document
                if (true)
                {
                    AnnotateApi    api          = new AnnotateApi(ConfigurationManager.AppSettings["AnnotateUserName"], ConfigurationManager.AppSettings["AnnotateApiKey"]);
                    AnnotateResult uploadResult = api.UploadDocument((int)assignmentID, authorTeamID);
                    if (uploadResult.Result == ResultCode.OK)
                    {
                        AnnotateResult createResult = api.CreateAccount(CurrentUser);
                        if (createResult.Result == ResultCode.OK)
                        {
                            //instructors get to see everyone, regardless of CR settings
                            CriticalReviewSettings settings = CRassignment.CriticalReviewSettings;
                            if (ActiveCourseUser.AbstractRoleID == (int)CourseRole.CourseRoles.Instructor)
                            {
                                settings.AnonymizeComments = false;
                            }

                            if (settings == null)
                            {
                                settings            = new CriticalReviewSettings();
                                settings.Assignment = CRassignment;
                            }

                            if (anonReview == 1)
                            {
                                settings.AnonymizeComments = true;
                            }

                            api.SetDocumentAnonymity(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate, settings);
                            api.GiveAccessToDocument(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                            //log the user in to annotate
                            string loginString = api.GetAnnotateLoginUrl(CurrentUser, uploadResult.DocumentCode, uploadResult.DocumentDate);

                            //load the annotate url for the view
                            ViewBag.AnnotateUrl = loginString;
                        }
                    }
                }
                else
                {
                    return(RedirectToRoute(new { controller = "Home", action = "Index", area = "" }));
                }
            }
            return(View("Review"));
        }
Пример #5
0
        public void UploadDocument()
        {
            AnnotateResult result = new AnnotateResult();

            result.Result = ResultCode.ERROR;

            long      epoch      = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
            WebClient client     = new WebClient();
            string    sendResult = "";

            //Submit document to annotate

            const string documentUrl = "http://osble.org/content/icershort.pdf";

            string apiKey = annotateApi.GenerateAnnotateKey("uploadDocument.php", ApiUser, epoch);

            string uploadString = AnnotateURL + "/annotate/php/uploadDocument.php?" +
                                  "api-user={0}" +           //Annotate admin user name (see web config)
                                  "&api-requesttime={1}" +   //UNIX timestamp
                                  "&api-annotateuser={2}" +  //the current user (reviewer)
                                  "&api-auth={3}" +          //Annotate admin auth key
                                  "&url={4}";                //URL of the document to upload

            uploadString = string.Format(uploadString,
                                         ApiUser,
                                         epoch,
                                         ApiUser,
                                         apiKey,
                                         System.Web.HttpUtility.UrlEncode(documentUrl)
                                         );

            try
            {
                sendResult = client.DownloadString(uploadString);
            }
            catch (Exception ex)
            {
                result.RawMessage = ex.Message;
                result.Result     = ResultCode.ERROR;
            }
            string documentCode = "";
            string documentDate = "";

            result.RawMessage = sendResult;
            if (sendResult.Substring(0, 2) == "OK")
            {
                result.Result = ResultCode.OK;
                string[] pieces = sendResult.Split(' ');
                documentDate        = pieces[1];
                documentCode        = pieces[2];
                result.DocumentCode = documentCode;
                result.DocumentDate = documentDate;
                string temp = "";
                for (int i = 0; i < pieces.Length; i++)
                {
                    if (i > 2)
                    {
                        temp = temp + "\n " + pieces[i];
                    }
                }
            }

            Assert.AreEqual(ResultCode.OK, result.Result);
        }