Example #1
0
        /// <summary>
        /// Download the specified Course Document to the given path if possible. If not,
        /// choose a new location and return it to the caller.
        /// </summary>
        public static int SaveAndUploadNewAssignment(
            ejsSessionToken sessionToken, string path, ejsService.ejsAssignment assignment)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);

                FileStream   fs       = new FileStream(path, FileMode.Open, FileAccess.Read);
                BinaryReader br       = new BinaryReader(fs);
                long         fileSize = fs.Length;
                byte[]       data     = br.ReadBytes((int)fs.Length);
                br.Close();
                fs.Close();
                fs.Dispose();

                assignment.DataSize = data.Length;

                int NewID = _client.SaveAndUploadAssignment(sessionToken, assignment, data);

                //	 let's do not throw ApplicationException here.
                //if (NewID == -1)
                //	throw new ApplicationException(Properties.Resources.EX_AsgUploadFailed);

                return(NewID);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                //throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
                throw;
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Download a single assignment with all connected assignment comments
        /// from the eJournalServer.
        /// </summary>
        public static string DownloadCommentsMergedAssignment(
            ejsSessionToken sessionToken, string path,
            ejsService.ejsAssignment assignment, ejsService.ejsAssignment[] assignmentsToMerge)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);

                byte[]       data = _client.GetCommentsMergedAssignment(sessionToken, assignment, assignmentsToMerge);
                FileStream   fs   = new FileStream(path, FileMode.Create, FileAccess.Write);
                BinaryWriter br   = new BinaryWriter(fs);
                br.Write(data);
                br.Flush();
                br.Close();
                fs.Close();

                return(path);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                //throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
                throw;
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }