Exemplo n.º 1
0
        private void AuthClient_ValidateUserCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            if (null != e.Error || string.IsNullOrEmpty(e.Result))
            {
                m_authToken  = null;
                m_isLoggedIn = false;

                OnLoginFailure(this, new OSBLEStateEventArgs(false,
                                                             "Could not login. Please recheck your user name and password."));

                //new OSBLEStateEventArgs(false, e.Error.Message));

                return;
            }

            // This means that they're logged in
            m_isLoggedIn = true;

            // Store the authentication token
            m_authToken = e.Result;

            // We're done with the authentication client
            (e.UserState as AuthenticationServiceClient).CloseAsync();

            // Create the OSBLE client
            m_osbleClient = new OsbleServiceClient();//m_bind, new System.ServiceModel.EndpointAddress(OSBLEServiceLink));

            // Make sure we setup all callbacks here
            m_osbleClient.GetCoursesCompleted += new EventHandler <GetCoursesCompletedEventArgs>(OsbleClient_GetCoursesCompleted);
            m_osbleClient.GetAssignmentSubmissionCompleted += this.OsbleClient_GetAssignmentSubmissionCompleted;

            // Get the list of courses
            m_osbleClient.GetCoursesAsync(m_authToken, m_osbleClient);
        }
Exemplo n.º 2
0
        private void AuthForSaveCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            object[] args = e.UserState as object[];
            AuthenticationServiceClient authClient = args[0] as AuthenticationServiceClient;
            EventHandler onSaveComplete            = args[1] as EventHandler;

            byte[] zippedData       = args[2] as byte[];
            int    originalAuthorID = (int)args[3];

            // If we failed then there's not much we can do
            if (null != e.Error || e.Cancelled)
            {
                // Invoke the completion delegate and return
                onSaveComplete(this, new SaveEventArgs(false));
                return;
            }

            string authToken = e.Result;

            m_lastAuthToken = authToken;

            // Build the OSBLE service client
            m_osbleClient = new OsbleServiceClient();
            m_osbleClient.OpenCompleted += delegate(object sender2, System.ComponentModel.AsyncCompletedEventArgs e2)
            {
                // How we save depends on the assignment type
                if (AssignmentTypes.CriticalReview == m_a.Type)
                {
                    // For critical reviews we use SubmitReviewAsync. According to the OSBLE team, when you call this
                    // you give it a zip file that contains a single file that is the review document. Recall that when
                    // we retrieve the files for a review assignment it's a zip of zips, and each file to review is
                    // within its own "child" zip under the main "parent" zip. This is NOT something we have to deal
                    // with here. We just submit the review file and we're done.
                    m_osbleClient.SubmitReviewCompleted += new EventHandler <SubmitReviewCompletedEventArgs>(OSBLESubmitReviewCompleted);
                    m_osbleClient.SubmitReviewAsync(originalAuthorID, m_a.ID, zippedData, authToken,
                                                    new object[] { m_osbleClient, onSaveComplete });
                }
                else
                {
                    // It's assumed that the assignment type is "Basic" if we come here
                    // For basic assignments we just use the SubmitAssignmentAsync method
                    m_osbleClient.SubmitAssignmentCompleted += this.OSBLESubmitAssignmentCompleted;
                    m_osbleClient.SubmitAssignmentAsync(m_a.ID, zippedData, authToken, new object[] { m_osbleClient, onSaveComplete });
                }
            };
            m_osbleClient.OpenAsync();

            // We're done with the authentication client
            authClient.CloseAsync();
        }
Exemplo n.º 3
0
        private void ValidateForSaveCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            // Error check
            if (e.Cancelled)
            {
                return;
            }
            if (null != e.Error)
            {
                OnError(this, new OSBLEStateEventArgs(false, e.Error.Message));
                return;
            }

            // The authentication token is stored in the result
            m_authToken = e.Result;

            // Build the OSBLE client
            //m_osbleClient = new OsbleServiceClient(m_bind,
            //    new System.ServiceModel.EndpointAddress(OSBLEServiceLink));
            m_osbleClient = new OsbleServiceClient();
            m_osbleClient.SubmitAssignmentCompleted += this.OsbleClient_SubmitAssignmentCompleted;

            // We built an object array for the user state to keep track of the authentication client
            // (which we have to close at the end) and the save data
            object[] objs = e.UserState as object[];

            // The authentication client is the first object in the array
            AuthenticationServiceClient auth = objs[0] as AuthenticationServiceClient;

            // The assignment data is the second object in the array. Note that this is the uncompressed data
            // and we need to put it in a zip before submitting.
            byte[] assignmentData = objs[1] as byte[];

            // Create a memory stream to save the zip file to
            MemoryStream ms = new MemoryStream();

            // Create the zip output stream with the maximum level of compression
            ZipOutputStream zos = new ZipOutputStream(ms);

            zos.SetLevel(9);

            // Create the entry for this file
            ZipEntry newEntry = new ZipEntry(ZipEntry.CleanName(GetDeliverableFileName(m_currentAssignment)));

            newEntry.DateTime = DateTime.Now;
            zos.PutNextEntry(newEntry);
            zos.Write(assignmentData, 0, assignmentData.Length);
            zos.CloseEntry();

            // Flush the zip file
            zos.Flush();

            // Get a reference to the compressed data
            byte[] compressed = ms.ToArray();

            // Close the zip file
            zos.Close();

            // We will reuse the array for our next async call, this time with the OSBLE client as the
            // first object
            objs[0] = m_osbleClient;

            // Submit
            m_osbleClient.SubmitAssignmentAsync(m_currentAssignment.ID, ms.ToArray(), m_authToken);

            // Free memory
            zos.Dispose();
            ms.Dispose();

            // "Always close the client" says the documentation
            auth.CloseAsync();
        }
Exemplo n.º 4
0
        private void AuthForLoadCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            object[] args = e.UserState as object[];
            AuthenticationServiceClient authClient = args[0] as AuthenticationServiceClient;

            // If we failed then there's not much we can do
            if (null != e.Error || e.Cancelled)
            {
                m_gettingFiles = false;

                // Invoke the completion delegate
                (args[1] as EventHandler)(this, new RelevantAssignmentEventArgs(m_files));

                return;
            }

            string authToken = e.Result;

            m_lastAuthToken = authToken;

            // The last thing we do with the authentication client is get the active user
            authClient.GetActiveUserCompleted += new EventHandler <GetActiveUserCompletedEventArgs>(AuthClient_GetActiveUserCompleted);
            authClient.GetActiveUserAsync(authToken, authClient);

            OsbleServiceClient osc = new OsbleServiceClient();

            // What we query for depends on the assignment type
            args[0] = osc;
            if (AssignmentTypes.CriticalReview == m_a.Type)
            {
                // We need to use "GetReviewItems"
                osc.GetReviewItemsCompleted += new EventHandler <GetReviewItemsCompletedEventArgs>(GetReviewItemsCompleted);
                try
                {
                    osc.GetReviewItemsAsync(m_a.ID, authToken, args);
                }
                catch (Exception)
                { }
            }
            else if (AssignmentTypes.CriticalReviewDiscussion == m_a.Type)
            {
                // We need to use "GetMergedReviewDocument"
                osc.GetMergedReviewDocumentCompleted += new EventHandler <GetMergedReviewDocumentCompletedEventArgs>(GetMergedReviewDocumentCompleted);
                try
                {
                    osc.GetMergedReviewDocumentAsync(m_a.ID, authToken, args);
                }
                catch (Exception)
                { }
            }
            else
            {
                // We need to use "GetAssignmentSubmission"
                osc.GetAssignmentSubmissionCompleted += new EventHandler <GetAssignmentSubmissionCompletedEventArgs>(GetAssignmentSubmissionCompleted);
                try
                {
                    osc.GetAssignmentSubmissionAsync(m_a.ID, authToken, args);
                }
                catch (Exception) { }
            }
        }