/// <summary>
        /// Adds a record to the Course Registrations database in the E Journal Server.
        /// </summary>
        internal static int RegisterUserToCourse(SqlConnection dBconnection,
                                                 ejsSessionToken sessionToken, ejsCourse Course)
        {
            SqlCommand command = new SqlCommand();

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "RegisterUserToCourse";

                command.Parameters.Add("CourseId", System.Data.SqlDbType.Int).Value              = Course.Id;
                command.Parameters.Add("UserId", System.Data.SqlDbType.UniqueIdentifier).Value   = sessionToken.UserId;
                command.Parameters.Add("RegistrationDate", System.Data.SqlDbType.DateTime).Value = DateTime.Now;

                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;
                return(resultCode);
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 2
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();
                }
            }
        }
Ejemplo n.º 3
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();
                }
            }
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 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></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();
                }
            }
        }
Ejemplo n.º 7
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();
                }
            }
        }
Ejemplo n.º 8
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();
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Deletes the record of a user in the EJS
        /// </summary>
        internal static int DeleteUserData(SqlConnection dBconnection,
                                           ejsSessionToken sessionToken, ejsUserInfo userInfo)
        {
            SqlCommand command = new SqlCommand();

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "DeleteUser";

                command.Parameters.Add("OperatorId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;
                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value     = new Guid(userInfo.Id);

                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;
                return(resultCode);
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 10
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();
                }
            }
        }
Ejemplo n.º 11
0
        internal static int UpdateCourseRecord(SqlConnection dBconnection,
                                               ejsSessionToken sessionToken, ejsCourse course)
        {
            SqlCommand command = new SqlCommand();

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "UpdateCourseRecord";

                command.Parameters.Add("UserId", System.Data.SqlDbType.UniqueIdentifier).Value   = sessionToken.UserId;
                command.Parameters.Add("CourseId", System.Data.SqlDbType.Int).Value              = course.Id;
                command.Parameters.Add("Name", System.Data.SqlDbType.NVarChar, 150).Value        = course.Name;
                command.Parameters.Add("Description", System.Data.SqlDbType.NVarChar, 500).Value = course.Description;
                command.Parameters.Add("Owner", System.Data.SqlDbType.NVarChar, 200).Value       = course.Owner;
                command.Parameters.Add("IsActive", System.Data.SqlDbType.Bit).Value              = course.IsActive;


                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;
                return(resultCode);
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 12
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();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Pushes the given study into the EJS database.
        /// </summary>
        internal static void SaveStudyMetaData(SqlConnection dBconnection,
                                               ejsSessionToken sessionToken, ejsStudyMetaData study, int parentAssignmentId)
        {
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "UploadAndSaveStudyMetaData";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;
                command.Parameters.Add("Title", SqlDbType.NVarChar, 50).Value      = study.Title;
                command.Parameters.Add("Description", System.Data.SqlDbType.NVarChar, 500).Value = study.Description;
                command.Parameters.Add("ParentAssignmentId", SqlDbType.Int).Value                = parentAssignmentId;
                command.Parameters.Add("CreationDate", System.Data.SqlDbType.DateTime).Value     = study.CreationDate;
                command.Parameters.Add("LastModifiedDate", System.Data.SqlDbType.DateTime).Value = study.LastModifiedDate;
                command.Parameters.Add("IsAvailable", System.Data.SqlDbType.Bit).Value           = 1;
                command.Parameters.Add("CommentCount", SqlDbType.Int).Value = study.CommentCount;

                command.ExecuteNonQuery();
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 14
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();
                }
            }
        }
Ejemplo n.º 15
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();
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates a Course Document record in the EJS
        /// </summary>
        internal static void UpdateCourseDocument(SqlConnection dBconnection,
                                                  ejsSessionToken Token, ejsCourseDocument document)
        {
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "UpdateCourseDocument";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value                 = Token.UserId;
                command.Parameters.Add("Title", System.Data.SqlDbType.NVarChar, 150).Value         = document.Name;
                command.Parameters.Add("Description", System.Data.SqlDbType.NVarChar, 500).Value   = document.Description;
                command.Parameters.Add("DocumentId", System.Data.SqlDbType.UniqueIdentifier).Value = document.DocumentId;
                command.Parameters.Add("IsAvailable", System.Data.SqlDbType.Bit).Value             = document.IsAvailable;
                command.Parameters.Add("CourseId", SqlDbType.Int).Value = document.CourseId;

                command.ExecuteNonQuery();
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Deletes a Course Document from the EJS
        /// </summary>
        internal static int DeleteCourseDocument(SqlConnection dBconnection,
                                                 ejsSessionToken Token, ejsCourseDocument document)
        {
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "DeleteCourseDocument";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value     = Token.UserId;
                command.Parameters.Add("DocumentId", SqlDbType.UniqueIdentifier).Value = document.DocumentId;

                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;
                return(resultCode);
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Get a list of all the users assignments.
        /// </summary>
        internal static void GetAllAssignments(SqlConnection dBconnection, bool IncludeNotAvailable,
                                               ejsSessionToken sessionToken, ref List <ejsAssignment> result)
        {
            result.Clear();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "GetAllAssignmentsForUser";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;
                command.Parameters.Add("IncludeNotAvailable", SqlDbType.Bit).Value = IncludeNotAvailable;

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ejsAssignment assign = new ejsAssignment();
                        assign.EJSDatabaseId = reader.GetInt32(0);
                        assign.Title         = reader.GetString(1);
                        assign.Description   = reader.GetString(2);
                        assign.StudyCount    = reader.GetInt32(3);
                        assign.IsAvailable   = reader.GetBoolean(9);                       //Added 080829
                        //assign.OwnerUserId = sessionToken.UserId; //Removed 080318, replaced with the next line.
                        assign.OwnerUserId           = new Guid(reader.GetGuid(14).ToString());
                        assign.OriginalOwnerDbId     = reader.GetInt32(4);
                        assign.AssignmentContentType = reader.GetInt32(5);
                        assign.CreationDate          = reader.GetDateTime(6);
                        assign.LastModifiedDate      = reader.GetDateTime(7);
                        assign.Version      = reader.GetInt32(8);
                        assign.DataSize     = reader.GetInt64(10);
                        assign.CommentCount = reader.GetInt32(11);
                        assign.IsManagedByEJournalServer = true;
                        assign.OwnerName            = reader.GetString(13);
                        assign.CourseId             = reader.GetInt32(12);
                        assign.ExternalAssignmentId = new Guid(reader.GetGuid(15).ToString());                       //Added 080318
                        assign.ParentAssignmentId   = new Guid(reader.GetGuid(16).ToString());                       //Added 080318
                        result.Add(assign);
                    }
                }
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Download a copy of a document stored in a course in the database.
        /// </summary>
        internal static byte[] GetCourseDocument(SqlConnection dBconnection,
                                                 ejsSessionToken sessionToken, ejsCourseDocument document)
        {
            SqlCommand    command = null;
            SqlDataReader reader  = null;

            try
            {
                byte[] result = new byte[document.ByteSize];

                int          bufferSize = (int)document.ByteSize;
                byte[]       outbyte    = new byte[bufferSize];
                MemoryStream ms         = new MemoryStream(bufferSize);
                BinaryWriter bw         = new BinaryWriter(ms);
                long         startIndex = 0;
                long         retval;

                command = new SqlCommand("SELECT Data FROM CourseDocuments WHERE DocumentId = @Id", dBconnection);
                command.Parameters.Add("@Id", SqlDbType.UniqueIdentifier).Value = document.DocumentId;
                command.CommandTimeout = 60;

                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

                while (reader.Read())
                {
                    retval = reader.GetBytes(0, startIndex, outbyte, 0, bufferSize);

                    while (retval == bufferSize)
                    {
                        bw.Write(outbyte);
                        bw.Flush();

                        startIndex += bufferSize;
                        retval      = reader.GetBytes(0, startIndex, outbyte, 0, bufferSize);
                    }

                    bw.Write(outbyte, 0, (int)retval);
                    bw.Flush();
                    bw.Close();

                    ms.Close();
                    ms.Dispose();
                }

                result = ms.GetBuffer();
                return(result);
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Validates the provided credentials against the Ejs Database.
        /// </summary>
        /// <param name="dBconnection">Connection to use when communicating with the EJS Database.</param>
        /// <param name="userName">User Name part of the credentials.</param>
        /// <param name="password">Password part of the credentials.</param>
        /// <param name="token">A Token that will be updated with the user Id (Guid) from the database.</param>
        /// <returns>0 on success, 1 on failure to authenticate</returns>
        internal static int AuthenticateUserCredentials(SqlConnection dBconnection,
                                                        string userName, string password, ref ejsSessionToken token)
        {
            /*TODO: Maybe rename this to LogIn or something similar...*/

            SqlCommand command = new SqlCommand();

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "ValidateUserNamePassword";

                command.Parameters.Add("UserName", SqlDbType.VarChar, 50);
                command.Parameters.Add("Password", SqlDbType.VarChar, 512);
                command.Parameters[0].Value = userName;
                command.Parameters[1].Value = password;

                SqlParameter pmId = new SqlParameter("Id", SqlDbType.VarChar, 38);
                pmId.Direction = ParameterDirection.Output;
                command.Parameters.Insert(2, pmId);

                SqlParameter pmFirstName = new SqlParameter("FirstName", SqlDbType.VarChar, 100);
                pmFirstName.Direction = ParameterDirection.Output;
                command.Parameters.Insert(3, pmFirstName);

                SqlParameter pmLastName = new SqlParameter("LastName", SqlDbType.VarChar, 100);
                pmLastName.Direction = ParameterDirection.Output;
                command.Parameters.Insert(4, pmLastName);

                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;

                if (resultCode == 0)
                {
                    token = new ejsSessionToken(
                        token.Id, token.SourceHostId, new Guid((string)pmId.Value), DateTime.Now,
                        DateTime.Now.AddHours(12), true, (string)pmFirstName.Value, (string)pmLastName.Value);
                    return(0);
                }
                else
                {
                    return(1);
                }
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 21
0
        public CourseRegistrationsWindow(ejsUserInfo user,
                                         ejsSessionToken userToken, ejsManagerStage parentStage)
        {
            InitializeComponent();

            this._currentUserToken = userToken;
            this._currentUserInfo  = user;
            this._parentStage      = parentStage;

            this.BuildCourseLists();

            this._l_CurrentUserName.Content = user.LastName + ", " + user.FirstName;
        }
Ejemplo n.º 22
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();
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Gets all the studies asc. with the given assignment.
        /// </summary>
        internal static void GetStudiesForAssignment(SqlConnection dBconnection, ejsSessionToken sessionToken,
                                                     ejsAssignment assignment, ref List <ejsStudyMetaData> result)
        {
            result.Clear();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "GetStudiesForAssignment";

                command.Parameters.Add("UserId", SqlDbType.Int).Value       = assignment.OriginalOwnerDbId;
                command.Parameters.Add("AssignmentId", SqlDbType.Int).Value = assignment.EJSDatabaseId;

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ejsStudyMetaData study = new ejsStudyMetaData();
                        study.Title              = reader.GetString(1);
                        study.Description        = reader.GetString(2);
                        study.ParentAssignmentId = reader.GetInt32(4);
                        study.CreationDate       = reader.GetDateTime(5);
                        study.LastModifiedDate   = reader.GetDateTime(6);
                        study.IsAvailable        = reader.GetBoolean(7);
                        study.CommentCount       = reader.GetInt32(8);
                        result.Add(study);
                    }
                }
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Returns a list of ALL the courses currentlty registered in the server.
        /// </summary>
        internal static void GetAllRegisteredCourses(SqlConnection dBconnection,
                                                     ejsSessionToken sessionToken, bool includeDisabledCourses, ref List <ejsCourse> result)
        {
            result.Clear();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "GetAllRegisteredCourses";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;
                command.Parameters.Add("IncludeNotAvailable", SqlDbType.Bit).Value = 1;

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ejsCourse course = new ejsCourse();
                        course.Id           = reader.GetInt32(0);
                        course.Name         = reader.GetString(1);
                        course.Description  = reader.GetString(2);
                        course.Owner        = reader.GetString(3);
                        course.CreationDate = reader.GetDateTime(4);
                        course.IsActive     = reader.GetBoolean(5);
                        result.Add(course);
                    }
                }
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Updates the record for a user in the EJS
        /// </summary>
        /// <param name="operatorId">ID of the person performing the update</param>
        /// <param name="password">Send 'NoChange' for no update.</param>
        internal static int UpdateUserData(SqlConnection dBconnection,
                                           ejsSessionToken sessionToken, ejsUserInfo userInfo, string password)
        {
            SqlCommand command = new SqlCommand();

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "UpdateUser";

                command.Parameters.Add("OperatorId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;
                command.Parameters.Add("UserName", SqlDbType.VarChar, 50).Value        = userInfo.UserName;
                command.Parameters.Add("FirstName", SqlDbType.NVarChar, 100).Value     = userInfo.FirstName;
                command.Parameters.Add("LastName", SqlDbType.NVarChar, 100).Value      = userInfo.LastName;
                command.Parameters.Add("IsAccountActive", SqlDbType.Bit).Value         = userInfo.IsAccountActive;
                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value     = new Guid(userInfo.Id);
                command.Parameters.Add("Email", SqlDbType.VarChar, 128).Value          = userInfo.Email;
                command.Parameters.Add("NewUserGroupId", SqlDbType.Int).Value          = userInfo.UserGroupId;

                if (password != "")
                {
                    command.Parameters.Add("Password", SqlDbType.VarChar, 512).Value = password;
                }
                else
                {
                    command.Parameters.Add("Password", SqlDbType.VarChar, 512).Value = "NoChange";
                }

                SqlParameter returnValue = new SqlParameter("@RETURN_VALUE", SqlDbType.Int);
                returnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(returnValue);

                command.ExecuteNonQuery();
                int resultCode = (int)returnValue.Value;
                return(resultCode);
            }
            finally
            {
                command.Dispose();
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Returns all the courses that a particular user has registered to.
        /// </summary>
        internal static void GetRegisteredCoursesForUser(SqlConnection dBconnection,
                                                         ejsSessionToken sessionToken, ref List <ejsCourse> courseList)
        {
            courseList.Clear();
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "GetRegisteredCoursesForUser";

                command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier);
                command.Parameters[0].Value = sessionToken.UserId;

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ejsCourse course = new ejsCourse();
                        course.Id           = reader.GetInt32(0);
                        course.Name         = reader.GetString(1);
                        course.Description  = reader.GetString(2);
                        course.Owner        = reader.GetString(3);
                        course.CreationDate = reader.GetDateTime(4);
                        courseList.Add(course);
                    }
                }
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 27
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();
                }
            }
        }
Ejemplo n.º 28
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();
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Pulls all the CourseRegistrations records out of the EJS
        /// </summary>
        internal static void GetAllCourseRegistrations(SqlConnection dBconnection,
                                                       ejsSessionToken sessionToken, ref List <ejsCourseRegistration> result)
        {
            SqlCommand    command = new SqlCommand();
            SqlDataReader reader  = null;

            command.CommandTimeout = 60;

            try
            {
                command.Connection  = dBconnection;
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = "GetAllCourseRegistrations";

                //command.Parameters.Add("UserId", SqlDbType.UniqueIdentifier).Value = sessionToken.UserId;

                reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ejsCourseRegistration reg = new ejsCourseRegistration();
                        reg.CourseId     = reader.GetInt32(0);
                        reg.UserId       = reader.GetGuid(1).ToString();
                        reg.RegisterDate = reader.GetDateTime(2);
                        result.Add(reg);
                    }
                }
            }
            finally
            {
                command.Dispose();
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }
        }
Ejemplo n.º 30
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();
                }
            }
        }