Пример #1
0
        /// <summary>
        /// Sets a user's status to "withdrawn" for the current course
        /// </summary>
        /// <param name="user"></param>
        public void WithdrawUserFromCourse(UserProfile user)
        {
            var cu = (from c in db.CourseUsers
                      where c.AbstractCourseID == ActiveCourseUser.AbstractCourseID &&
                      c.UserProfileID == user.ID
                      select c).FirstOrDefault();

            if (cu != null)
            {
                if (cu.AbstractRole.GetType() == typeof(CommunityRole))
                {
                    RemoveUserFromCourse(user);
                }
                cu.AbstractRoleID  = (int)CourseRole.CourseRoles.Withdrawn;
                db.Entry(cu).State = EntityState.Modified;
            }
            db.SaveChanges();
        }
Пример #2
0
        /// <summary>
        /// Sends a document that resides on OSBLE to the Annotate server.
        /// If the document already exists on annotate's servers, this function will not resubmit
        /// unless forceUpload is set to TRUE.
        /// </summary>
        /// <param name="assignmentID">The assignment that the document belongs to</param>
        /// <param name="authorTeamID">The document's author</param>
        /// <param name="forceUpload">If set to TRUE, will force a document upload to annotate's servers</param>
        /// <returns></returns>
        public AnnotateResult UploadDocument(int assignmentID, int authorTeamID, bool forceUpload = false)
        {
            bool           needsUpload = true;
            AnnotateResult result      = new AnnotateResult();

            result.Result = ResultCode.ERROR;

            //By default, we only upload documents to annotate if they haven't been uploaded
            //already.  This can be overridden by setting forceUpload = true.
            if (forceUpload == false)
            {
                //check for existing document
                using (OSBLEContext db = new OSBLEContext())
                {
                    string docString = GetAnnotateDocumentName(assignmentID, authorTeamID);
                    AnnotateDocumentReference code = (from c in db.AnnotateDocumentReferences
                                                      where c.OsbleDocumentCode.CompareTo(docString) == 0
                                                      select c
                                                      ).FirstOrDefault();
                    if (code == null)
                    {
                        needsUpload = true;
                    }
                    else
                    {
                        needsUpload         = false;
                        result.Result       = ResultCode.OK;
                        result.DocumentDate = code.AnnotateDocumentDate;
                        result.DocumentCode = code.AnnotateDocumentCode;
                    }
                }
            }

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

                //Submit document to annotate
#if DEBUG
                //string documentUrl = "http://osble.org/content/icershort.pdf";
                string documentUrl = "https://plus.osble.org/FileHandler/GetAnnotateDocument?assignmentID={0}&authorTeamID={1}&apiKey={2}";
                documentUrl = string.Format(documentUrl, assignmentID, authorTeamID, ApiKey);
#else
                string documentUrl = "https://plus.osble.org/FileHandler/GetAnnotateDocument?assignmentID={0}&authorTeamID={1}&apiKey={2}";
                documentUrl = string.Format(documentUrl, assignmentID, authorTeamID, ApiKey);
#endif

                string apiKey = GenerateAnnotateKey("uploadDocument.php", ApiUser, epoch);
                //TODO: this was changed when helplab.org went down.
                //string uploadString = "http://helplab.org/annotate/php/uploadDocument.php?" +
                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,
                                             HttpUtility.UrlEncode(documentUrl)
                                             );
                try
                {
                    sendResult = client.DownloadString(uploadString);
                    //WriteLog("UploadDocument: " + sendResult);
                }
                catch (Exception ex)
                {
                    result.RawMessage = ex.Message;
                    result.Result     = ResultCode.ERROR;
                    return(result);
                }
                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;

                    //add DB entry into OSBLE so that we know something's been sent
                    using (OSBLEContext db = new OSBLEContext())
                    {
                        string docString = GetAnnotateDocumentName(assignmentID, authorTeamID);
                        AnnotateDocumentReference code = (from c in db.AnnotateDocumentReferences
                                                          where c.OsbleDocumentCode.CompareTo(docString) == 0
                                                          select c
                                                          ).FirstOrDefault();
                        if (code == null)
                        {
                            code = new AnnotateDocumentReference();
                            db.AnnotateDocumentReferences.Add(code);
                        }
                        else
                        {
                            db.Entry(code).State = EntityState.Modified;
                        }
                        code.AnnotateDocumentCode = result.DocumentCode;
                        code.AnnotateDocumentDate = result.DocumentDate;
                        code.OsbleDocumentCode    = docString;
                        db.SaveChanges();
                    }
                }
            }
            return(result);
        }