private void GetAssignmentSubmissionCompleted(object sender, GetAssignmentSubmissionCompletedEventArgs e)
        {
            object[]           args         = e.UserState as object[];
            OsbleServiceClient client       = args[0] as OsbleServiceClient;
            EventHandler       onCompletion = args[1] as EventHandler;

            if (null == e.Error && !e.Cancelled)
            {
                AddFromZip(e.Result);
            }

            // Close the OSBLE client
            client.CloseAsync();

            m_gettingFiles = false;

            onCompletion(this, new RelevantAssignmentEventArgs(m_files));
        }
Exemple #2
0
        private void OsbleClient_GetAssignmentSubmissionCompleted(object sender,
                                                                  GetAssignmentSubmissionCompletedEventArgs e)
        {
            if (e.Cancelled || null != e.Error)
            {
                m_currentAssignment = null;

                OnDownloadComplete(this, new OSBLEStateEventArgs(false,
                                                                 "Could not download the specified assignment file"));

                return;
            }

            // If there hasn't been any submission for this assignment yet then it may be 0 bytes in size
            if (0 == e.Result.Length)
            {
                OnDownloadComplete(this, new OSBLEStateEventArgs(true,
                                                                 "Assignment has yet to be submitted. You may save your work to OSBLE to submit " +
                                                                 "the first version for this assignment.", null));
                return;
            }

            // Make a memory stream for the byte array
            System.IO.MemoryStream ms = new System.IO.MemoryStream(e.Result);

            // Create the zip file
            ICSharpCode.SharpZipLib.Zip.ZipFile zf = new ICSharpCode.SharpZipLib.Zip.ZipFile(ms);

            // If there are 0 files in the zip, then let the user know that nothing has been submitted
            if (0 == zf.Count)
            {
                OnDownloadComplete(this, new OSBLEStateEventArgs(true,
                                                                 "Assignment has yet to be submitted. You may save your work to OSBLE to submit " +
                                                                 "the first version for this assignment.", null));
                return;
            }

            // Go through the files within the zip looking for the .cpml
            foreach (ICSharpCode.SharpZipLib.Zip.ZipEntry ze in zf)
            {
                if (ze.Name.ToLower().EndsWith(".cpml"))
                {
                    // We need a stream that is seekable and the Zip streams don't guarantee this. Thus
                    // we'll read the whole thing into a memory stream.
                    MemoryStream msUncompressed;
                    using (Stream tempStream = zf.GetInputStream(ze))
                    {
                        msUncompressed = new MemoryStream();
                        tempStream.CopyTo(msUncompressed);
                    }

                    OnDownloadComplete(this, new OSBLEStateEventArgs(true, null, msUncompressed));
                    return;
                }
            }

            // This means we didn't find a .cpml in the zip
            m_currentAssignment = null;
            OnDownloadComplete(this, new OSBLEStateEventArgs(false,
                                                             "Could not download the specified assignment file"));
        }