コード例 #1
0
ファイル: OSBLEState.cs プロジェクト: WSU-HELPLAB/OSBLE
        private void RefreshProc()
        {
            // First login
            AuthenticationServiceClient authClient = new AuthenticationServiceClient();
            string authToken = null;

            try
            {
                authToken = authClient.ValidateUser(m_user, m_pass);
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                authClient.Close();
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "Could not connect to the OSBLE server. " +
                                                           "Please contact support if this problem persists."));
                return;
            }
            authClient.Close();
            authClient = null;

            if (string.IsNullOrEmpty(authToken))
            {
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "Could not log in to OSBLE. " +
                                                           "Please check your user name and password."));
                return;
            }

            // Now get a list of courses
            OsbleServiceClient osc = new OsbleServiceClient();

            m_courses = osc.GetCourses(authToken);

            // Make sure we got some courses
            if (null == m_courses || 0 == m_courses.Length)
            {
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "No courses were found for this user."));
                return;
            }

            // Go through the courses and find out this user's role
            List <Course> canBeGraded = new List <Course>();

            foreach (Course c in m_courses)
            {
                CourseRole cr = osc.GetCourseRole(c.ID, authToken);
                if (cr.CanGrade)
                {
                    canBeGraded.Add(c);
                }
            }
            m_courses = canBeGraded.ToArray();

            // Success if we made it this far
            m_onComplete(this, new OSBLEStateEventArgs(true, string.Empty));
        }
コード例 #2
0
        public void Logout()
        {
            AuthenticationServiceClient client = new AuthenticationServiceClient();
            OperationContextScope       scope  = new OperationContextScope(client.InnerChannel);
            var prop = new HttpRequestMessageProperty();

            prop.Headers.Add(HttpRequestHeader.Cookie, ModelLocator.getInstance().SessionModel.SessionCookie);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = prop;

            try
            {
                client.Logout();
                mResponder.LogoutResult();
            }
            catch (FaultException <ONyRFaultException> ex)
            {
                mResponder.LogoutFault((ErrorCode)ex.Detail.ErrorCode);
            }
            catch (Exception)
            {
                mResponder.LogoutFault(ErrorCode.NonONyRError);
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }
        }
コード例 #3
0
        public static bool IsLoggedIn()
        {
            bool result = false;

            AuthenticationServiceClient client = new AuthenticationServiceClient();
            OperationContextScope       scope  = new OperationContextScope(client.InnerChannel);
            var prop = new HttpRequestMessageProperty();

            prop.Headers.Add(HttpRequestHeader.Cookie, ModelLocator.getInstance().SessionModel.SessionCookie);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = prop;

            result = client.IsLoggedIn();

            client.Close();

            return(result);
        }
コード例 #4
0
        public void Login(string username, string password)
        {
            bool result = false;

            AuthenticationServiceClient client = new AuthenticationServiceClient();
            OperationContextScope       scope  = new OperationContextScope(client.InnerChannel);

            try
            {
                result = client.Login(username, password, null, false);
                MessageProperties           props = OperationContext.Current.IncomingMessageProperties;
                HttpResponseMessageProperty prop  = props[HttpResponseMessageProperty.Name] as HttpResponseMessageProperty;
                string rawCookies = prop.Headers[HttpResponseHeader.SetCookie];

                if (!result)
                {
                    ONyRFaultException e = new ONyRFaultException();
                    e.ErrorCode = (int)ErrorCode.InvalidCredentialsError;
                    throw new FaultException <ONyRFaultException>(e);
                }

                mResponder.LoginResult(FormatCookie(rawCookies));
            }
            catch (FaultException <ONyRFaultException> ex)
            {
                mResponder.LoginFault((ErrorCode)ex.Detail.ErrorCode);
            }
            catch (Exception)
            {
                mResponder.LoginFault(ErrorCode.NonONyRError);
            }
            finally
            {
                if (client != null)
                {
                    client.Close();
                }
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: faturita/SSLClient
        public static void DoLogin()
        {
            UserPassCredential credential = new UserPassCredential();

            credential.userName = "******";
            credential.password = "******";

            AuthenticationServiceClient client = new AuthenticationServiceClient();

            try
            {
                ContextInformationInspector behavior = new ContextInformationInspector();
                client.Endpoint.Behaviors.Add((IEndpointBehavior)behavior);

                AuthenticatedToken token = client.LogInUserPass(credential);
                TokenManager.Instance.LoadToken(token);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
            }
        }
コード例 #6
0
        public static SaveResult Save(string userName, string password, int courseID,
                                      Workbook wb)
        {
            // What needs to be done here:
            // 1. "Export" each sheet in the workbook to a CSV
            // 2. Package all CSVs in a zip
            // 3. Upload this zip to OSBLE through the web service

            string tempSaveDir = Environment.GetFolderPath(
                Environment.SpecialFolder.LocalApplicationData);

            if (!tempSaveDir.EndsWith("\\") &&
                !tempSaveDir.EndsWith("/"))
            {
                tempSaveDir += "\\";
            }

            // For each non-empty worksheet in the workbook we need to make a CSV
            ZipFile zf         = new ZipFile();
            int     sheetCount = 0;

            foreach (Worksheet ws in wb.Worksheets)
            {
                // We only want gradebook worksheets.
                // Check for a "#" in cell A1 before making a CSV
                var currentWorkSheet = Convert.ToString(ws.Range["A1"].Value);

                if (currentWorkSheet == null) // Cell is empty
                {
                }
                else if (currentWorkSheet.Contains("#")) //Cell contains #, continue...
                {
                    // Make an in-memory CSV for the worksheet
                    string csvTemp = WorksheetToCSVString(ws);
                    if (string.IsNullOrEmpty(csvTemp))
                    {
                        continue;
                    }

                    sheetCount++;
                    zf.AddEntry(ws.Name + ".csv", Encoding.UTF8.GetBytes(csvTemp));
                }
            }

            // If we didn't get any data then we can't upload to OSBLE
            if (0 == sheetCount)
            {
                return(new SaveResult(false,
                                      string.Format(
                                          "Save attempt at {0} failed because no data could be obtained " +
                                          "from the workbook.\r\nPlease make sure you have at least 2x2 " +
                                          "cells worth of grade data in one or more worksheets.", DateTime.Now)));
            }

            // Save the zip to a memory stream
            MemoryStream ms = new MemoryStream();

            zf.Save(ms);
            zf.Dispose();
            zf = null;

            // Get the byte array from the memory stream
            byte[] data = ms.ToArray();

            AuthenticationServiceClient auth = new AuthenticationServiceClient();
            string authToken;

            try
            {
                authToken = auth.ValidateUser(userName, password);
            }
            catch (Exception)
            {
                return(new SaveResult(false,
                                      "Could not login to OSBLE. " +
                                      "You may need to reenter your user name and password."));
            }
            auth.Close();

            // Now we get the service client
            OSBLEServices.OsbleServiceClient osc = new OSBLEServices.OsbleServiceClient();
            int retVal = osc.UploadCourseGradebook(courseID, data, authToken);

            osc.Close();

            // The return value indicates the number of items in the zip that
            // FAILED to upload if >0 or generic upload failure if == -1. A
            // return value of 0 indicates success.
            if (retVal >= sheetCount || -1 == retVal)
            {
                return(new SaveResult(
                           false,
                           string.Format(
                               "Save attempt at {0} failed because the data failed to upload " +
                               "properly. This might occur because of a lapse in Internet " +
                               "connectivity, so it is recommended that you try again shortly. If " +
                               "the problem persists, please contact OSBLE support.", DateTime.Now)));
            }
            else if (retVal > 0)
            {
                // This means that some sheets failed but some succeeded. We'll still
                // issue an error message in this case.
                return(new SaveResult(
                           false,
                           string.Format(
                               "Save attempt at {0} only uploaded some of the worksheets in the " +
                               "workbook. It is recommended that you try again and/or check the " +
                               "gradebook status online at PLUS.OSBLE.org.", DateTime.Now)));
            }

            return(new SaveResult(true, null));
        }