示例#1
0
        /// <summary>
        /// Authenticate a user with the EJS.
        /// If authentication is successful a new Session Token
        /// is returned.
        /// </summary>
        /// <param name="userName">User Name to validate.</param>
        /// <param name="password">Password to validate.</param>
        /// <param name="sourceHostId">A uniqe string that identifies this client's host. This string is per session.</param>
        /// <returns></returns>
        public static ejsSessionToken AuthenticateUser(
            string userName, string password, Guid sourceHostId)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                ejsSessionToken newToken = _client.Authenticate(userName, password, sourceHostId);
                return(newToken);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            //	[shiniwa] We just do NOT need this. Let's do NOT translate arbitrary exceptions to ApplicationException
            //catch (Exception)
            //{
            //	throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
            //}
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Updates the record of single User in the eJournalServer
        /// </summary>
        public static void UpdateUser(ejsSessionToken sessionToken,
                                      ejsUserInfo userToUpdate, string newPassword)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.UpdateUserRecord(sessionToken, userToUpdate, newPassword);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Update a user password in the EJS.
        /// </summary>
        public static void UpdateUserPassword(
            string UserName, string OldPassword, string NewPassword)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.UpdateUserPassword(UserName, OldPassword, NewPassword);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#4
0
        /// <summary>
        /// Adds a course document to a course in the EJS
        /// </summary>
        public static void AddDocumentToCourse(ejsSessionToken sessionToken,
                                               ejsCourseDocument document, int courseId, byte[] data)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.AddDocumentToCourse(sessionToken, document, courseId, data);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#5
0
        public static ejsAssignment[] GetAllPublishedAssignments(
            ejsSessionToken sessionToken, bool IncludeNotAvailable)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                ejsAssignment[] results = _client.GetAllAssignments(sessionToken, IncludeNotAvailable);

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

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#6
0
        /// <summary>
        /// Authenticate a user with the EJS.
        /// If authentication is successful a new Session Token
        /// is returned.
        /// </summary>
        /// <param name="userName">User Name to validate.</param>
        /// <param name="password">Password to validate.</param>
        /// <param name="sourceHostId">A uniqe string that identifies this client's host. This string is per session.</param>
        /// <returns>A Token that contains the negotiated login data.</returns>
        public static ejsSessionToken AuthenticateUser(
            string userName, string password, Guid sourceHostId)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                ejsSessionToken newToken = _client.Authenticate(userName, password, sourceHostId);
                return(newToken);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#7
0
        /// <summary>
        /// Returns all the courses registered in EJS.
        /// </summary>
        public static ejsCourse[] GetAllRegisteredCourses(
            ejsService.ejsSessionToken sessionToken, bool includeDisabledCourses)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                ejsCourse[] results = _client.GetAllRegisteredCourses(sessionToken, includeDisabledCourses);
                return(results);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            //catch (Exception)
            //{
            //	throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
            //}
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#8
0
        public static void SaveAndUploadStudyMetaData(
            ejsSessionToken sessionToken, ejsStudyMetaData study, int parentAssignmentId)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.SaveStudyMetaData(sessionToken, study, parentAssignmentId);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            //catch (Exception)
            //{
            //	throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
            //}
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#9
0
        /// <summary>
        /// Update a user password in the EJS.
        /// </summary>
        public static void UpdateUserPassword(
            string UserName, string OldPassword, string NewPassword)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.UpdateUserPassword(UserName, OldPassword, NewPassword);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            //	let's do not translate arbitrary exception to AppicationException here.
            //catch (Exception)
            //{
            //	throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
            //}
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#10
0
        /// <summary>
        /// Registers a new User in the eJournalServer
        /// </summary>
        public static void AddNewUser(ejsSessionToken sessionToken, ejsUserInfo newUser,
                                      int userGroup, string password)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.RegisterNewUser(sessionToken, newUser, newUser.UserName, password, userGroup, newUser.IsAccountActive);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#11
0
        /// <summary>
        /// Invalidate a user Token in the service token pool.
        /// </summary>
        /// <param name="tokenToInvalidate">The token to invalidate.</param>
        public static void LogOutUser(
            EjsBridge.ejsService.ejsSessionToken tokenToInvalidate)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.InvalidateToken(tokenToInvalidate);
                tokenToInvalidate._isAuthenticated = false;
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._message);
            }
            catch (Exception)
            {
                //throw new ApplicationException(Properties.Resources.EX_EjsConnectionFailed);
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#12
0
        public static void HideAssignment(ejsSessionToken sessionToken, ejsAssignment assignmentToHide)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.HideAssignment(sessionToken, assignmentToHide);
            }
            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);
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#13
0
        /// <summary>
        /// Restores a single Assignment in the eJournalServer
        /// </summary>
        public static void RestoreAssignment(ejsSessionToken sessionToken, ejsAssignment assignmentToRestore)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.RestoreAssignment(sessionToken, assignmentToRestore);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#14
0
        /// <summary>
        /// Invalidate a user Token in the service token pool.
        /// </summary>
        /// <param name="tokenToInvalidate">The token to invalidate.</param>
        public static void LogOutUser(
            ejsSessionToken tokenToInvalidate)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                _client.InvalidateToken(tokenToInvalidate);
                tokenToInvalidate._isAuthenticated = false;
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                //throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#15
0
        /// <summary>
        /// Returns all the courses that a particular user has registered to.
        /// </summary>
        public static ejsCourse[] GetRegisteredCoursesForUser(
            ejsSessionToken sessionToken, bool includeDocuments)
        {
            EjsPublicServiceClient _client = null;

            try
            {
                _client = new EjsPublicServiceClient();
                _client.Endpoint.Address = new EndpointAddress(ejsBridgeManager.EjsAddress);
                ejsCourse[] results = _client.GetRegisteredCoursesForUser(sessionToken, includeDocuments);
                return(results);
            }
            catch (FaultException <ejsFailureReport> ex)
            {
                if (ex.Detail._failureCode == 7)
                {
                    sessionToken._isAuthenticated = false;
                }

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#16
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();
                }
            }
        }
示例#17
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();
                }
            }
        }
示例#18
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 string DownloadCourseDocument(
            ejsSessionToken sessionToken, string path, ejsService.ejsCourseDocument document)
        {
            EjsPublicServiceClient _client = null;

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

                byte[]       data = _client.GetCourseDocument(sessionToken, document);
                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("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#19
0
        /// <summary>
        /// Gets all the user records from the eJournalServer
        /// </summary>
        public static ejsUserInfo[] GetAllUserRecords(
            ejsSessionToken sessionToken)
        {
            EjsPublicServiceClient _client = null;

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

                //3 == regular users
                //-1 == all users
                ejsUserInfo[] results = _client.GetAllRegisteredUsers(sessionToken, -1);

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

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }
示例#20
0
        /// <summary>
        /// Gets all the current stats from the designated server.
        /// </summary>
        public static ejsServerStats GetServerStats(
            ejsSessionToken sessionToken)
        {
            EjsPublicServiceClient _client = null;

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

                ejsServerStats result = _client.GetCurrentServerStats(sessionToken);

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

                throw new ApplicationException(ex.Detail._header + "\n" + ex.Detail._originalException.Message);
            }
            catch (Exception)
            {
                sessionToken._isAuthenticated = false;
                throw new ApplicationException("EJSと接続する際に失敗しました。");
            }
            finally
            {
                if (_client != null)
                {
                    _client.Close();
                }
            }
        }