private void AuthClient_GetActiveUserCompleted(object sender, GetActiveUserCompletedEventArgs e) { // The authentication client has delivered what we need and so we can close it AuthenticationServiceClient authClient = e.UserState as AuthenticationServiceClient; authClient.CloseAsync(); if (null == e.Error) { m_userID = e.Result.ID; } }
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(); }
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(); }