コード例 #1
0
        public void SignIn(string group, string username, string password)
        {
            try
            {
                if (string.IsNullOrEmpty(username))
                {
                    throw new Exception("Username is blank");
                }

                if (string.IsNullOrEmpty(password))
                {
                    throw new Exception("Password is blank");
                }

                sessionState.Student = null;
                sessionState.Session = null;

                DebugLog.Info("SignIn {0}...", username);
                navigator.Reveal <ProgressIndicatorViewModel>().Then((vm, onRevealed, onRevealError) =>
                {
                    ProgressIndicatorViewModel progressIndicatorViewModel = vm.ResultAs <ProgressIndicatorViewModel>();
                    ProgressIndicatorViewModel.ProgressInfo busyIndicator = progressIndicatorViewModel.Begin("Signing in...");
                    // TODO rgtaylor 2015-12-10 Replace hardcoded 'domain'
                    authenticator.SignIn(group, username, password)
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Signed in {0}", username);
                        sessionState.Student = prevResult.ResultAs <Student>();
                        sessionService.Start(sessionState.Student.SessionGuid).Start(onCompleted, onError);
                    })
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Session started");
                        sessionState.Session = prevResult.ResultAs <Session>();
                        courseSettingsService.LoadSettings(sessionState.Student.Id).Start(onCompleted, onError);
                    })
                    .Then((prevResult, onCompleted, onError) =>
                    {
                        DebugLog.Info("Settings loaded");
                        sessionState.CourseSettings = prevResult.ResultAs <CourseSettings>();
                        navigator.Transition(this, typeof(MainMenuViewModel));
                        onCompleted(true);
                    }).Catch((Exception e) =>
                    {
                        navigator.Reveal <AlertViewModel>(alert =>
                        {
                            alert.Title           = "Unable to sign in";
                            alert.Message         = e.Message;
                            alert.Error           = e;
                            alert.AlertDismissed += ((int index) => DebugLog.Info("Button {0} pressed", index));
                        });
                    }).Finally(() =>
                    {
                        busyIndicator.Dispose();
                    }).Start();

                    onRevealed(true);
                }).Start();
            }
            catch (Exception e)
            {
                navigator.Reveal <AlertViewModel>(alert =>
                {
                    alert.Title   = "Unable to sign in";
                    alert.Message = e.Message;
                    alert.Error   = e;
                }).Start();
            }
        }
コード例 #2
0
 public void Remove(ProgressInfo indicator)
 {
     indicators.Remove(indicator);
     OnActivitiesChanged();
     DebugLog.Info(GetActivities());
 }
コード例 #3
0
        /// <summary>
        /// Post one or more MIME parts to a URI
        /// </summary>
        /// <param name="uri">The URI of the web service to receive the Http post message</param>
        /// <param name="retries">Number of times to retry post if there is an error</param>
        /// <param name="mimeParts">MIME encoded payload</param>
        /// <param name="callback">Method called on failure or success that is passed an AsyncResult whose Result property is set to HttpResult</param>
        /// <returns>WebRequest IAsyncResult object</returns>
        public IAsyncResult Post(Uri uri, int retries, List <MimePart> mimeParts, AsyncCallback callback)
        {
#if (SILVERLIGHT || WPF || TOOL)
            WebRequest webRequest = WebRequest.Create(uri);
#else
            WebRequest webRequest = new UnityWebRequest(uri);
#endif
            webRequest.Method = "POST";
            IAsyncResult asyncResult = webRequest.BeginGetRequestStream((asynchronousResult) =>
            {
                WebRequest request = (WebRequest)asynchronousResult.AsyncState;

                if (mimeParts.Count > 1)
                {
                    CreateMultiPartRequest(request, asynchronousResult, mimeParts);
                }
                else
                {
                    CreateSinglePartRequest(request, asynchronousResult, mimeParts[0]);
                }

                // Start the asynchronous operation to get the response
                request.BeginGetResponse((responseResult) =>
                {
                    bool retry            = false;
                    HttpResult httpResult = null;
                    try
                    {
                        HttpWebResponse response = ((WebRequest)responseResult.AsyncState).EndGetResponse(responseResult) as HttpWebResponse;
                        // Response stream is released when HttpResult is released
                        httpResult = new HttpResult(response.GetResponseStream(), response.StatusCode, response.StatusDescription, response.ContentType);
                    }
                    catch (WebException we)
                    {
                        DebugLog.Error("WebException -> {0} '{1}' failed", webRequest.Method, uri.ToString());
                        DebugLog.Error(we.Message);
                        if (retries > 0 && we.Status != WebExceptionStatus.RequestCanceled)
                        {
                            DebugLog.Info("Retry {0} '{1}'", webRequest.Method, uri.ToString());
                            Post(uri, --retries, mimeParts, callback);
                            retry = true;
                        }
                        else
                        {
                            httpResult = new HttpResult(we);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugLog.Error("HTTP {0} '{1}' failed: {2}", webRequest.Method, uri.ToString(), e.Message);
                        httpResult = new HttpResult(e);
                    }
                    finally
                    {
                        if (!retry && callback != null)
                        {
                            callback(new AsyncResult <HttpResult>(httpResult));
                        }
                    }
                },
                                         request);
            },
                                                                        webRequest);

            return(asyncResult);
        }
コード例 #4
0
 public void Add(ProgressInfo indicator)
 {
     indicators.Insert(0, indicator);
     OnActivitiesChanged();
     DebugLog.Info(GetActivities());
 }
コード例 #5
0
 private void OnEnabledChanged()
 {
     DebugLog.Info("RepositoryLogger: {0} Enabled={1}", DataDirectory, Enabled);
 }
コード例 #6
0
 private void CalibrationCallbackFunction(EyeTrackingController.EyeTrackingController.CalibrationPointStruct calibrationPoint)
 {
     DebugLog.Info("SMI Eye Tracker: CalibrationCallback - Number = {0} Position = ({1}, {2})", calibrationPoint.number, calibrationPoint.positionX, calibrationPoint.positionY);
 }
コード例 #7
0
        public override void Calibrate(CalibrationResultHandler callback)
        {
            IsCalibrated = false;
            string message = "Not calibrated";
            Dictionary <string, object> calibrationProperties = new Dictionary <string, object>();

            try {
                int ret = 0;

                int targetSize = 20;

                EyeTrackingController.EyeTrackingController.CalibrationStruct m_CalibrationData = new EyeTrackingController.EyeTrackingController.CalibrationStruct();
                m_CalibrationData.displayDevice   = (int)DisplayDevice.Primary;
                m_CalibrationData.autoAccept      = 1;
                m_CalibrationData.method          = (int)CalibrationPoints;
                m_CalibrationData.visualization   = 1;
                m_CalibrationData.speed           = 0;
                m_CalibrationData.targetShape     = 2;
                m_CalibrationData.backgroundColor = 230;
                m_CalibrationData.foregroundColor = 250;
                m_CalibrationData.targetSize      = targetSize;
                m_CalibrationData.targetFilename  = "";

                DebugLog.Info("SMI Eye Tracker: Setup calibration");
                ret = ETDevice.iV_SetupCalibration(ref m_CalibrationData);
                if (ret != 1)
                {
                    throw new Exception("Calibration setup returned an error: " + GetErrorMessage(ret));
                }

                DebugLog.Info("SMI Eye Tracker: Start calibration");
                ret = ETDevice.iV_Calibrate();
                if (ret != 1)
                {
                    throw new Exception("Calibration returned an error: " + GetErrorMessage(ret));
                }

                DebugLog.Info("SMI Eye Tracker: Start validation");
                ret = ETDevice.iV_Validate();
                if (ret != 1)
                {
                    throw new Exception("Validation returned an error: " + GetErrorMessage(ret));
                }

                DebugLog.Info("SMI Eye Tracker: Get accuracy data");
                EyeTrackingController.EyeTrackingController.AccuracyStruct accuracyData = new EyeTrackingController.EyeTrackingController.AccuracyStruct();
                ret = ETDevice.iV_GetAccuracy(ref accuracyData, 1);
                if (ret != 1)
                {
                    throw new Exception("GetAccuracy returned an error: " + GetErrorMessage(ret));
                }

                DebugLog.Info("SMI Eye Tracker: Calibration and validation complete");
                IsCalibrated = true;

                message = string.Format("Successfully calibrated SMI eye tracker.\nLeft Eye Deviation = ({0}, {1})\nRight Eye Deviation = ({2}, {3})",
                                        accuracyData.deviationXLeft,
                                        accuracyData.deviationYLeft,
                                        accuracyData.deviationXRight,
                                        accuracyData.deviationYRight);

                calibrationProperties["deviationXLeft"]  = accuracyData.deviationXLeft;
                calibrationProperties["deviationYLeft"]  = accuracyData.deviationYLeft;
                calibrationProperties["deviationXRight"] = accuracyData.deviationXRight;
                calibrationProperties["deviationYRight"] = accuracyData.deviationYRight;
            }
            catch (Exception e)
            {
                message = string.Format("Unable to calibrate SMI server ({0}:{1}). {2}", ServerRecvAddress, ServerRecvPort, e.Message);
            }

            if (callback != null)
            {
                callback(IsCalibrated, message, calibrationProperties);
            }
        }
コード例 #8
0
        /// <summary>
        /// Map status code to enum. Unfortunately, Unity 3D's WWW class returns the wrong status code
        /// if there is more than one. Only the first code is recorded in www.responseHeaders.
        /// </summary>
        void ParseStatusCode(WWW www)
        {
            Contract.PropertyNotNull("ResponseHeadersProperty", ResponseHeadersProperty);

            string rawHeaders = null;

            try
            {
                rawHeaders = ResponseHeadersProperty.GetValue(www, null) as String;
                /// In this example (see raw headers below), www.responseHeaders["STATUS"] returns "HTTP/1.1 100 Continue"
                ///                HTTP/1.1 100 Continue
                ///
                ///                HTTP/1.1 200 OK
                ///
                ///                Content-Type: application/xml; charset=UTF-8
                ///
                ///                Date: Thu, 11 Dec 2014 05:04:56 GMT
                ///
                ///                    Accept-Ranges: bytes
                ///
                ///                    Server: Development/1.0
                ///
                ///                    Cache-Control: no-cache
                ///
                ///                    Expires: Fri, 01 Jan 1990 00:00:00 GMT
                ///
                ///                    Content-Length: 3905
            }
            catch (Exception e)
            {
                DebugLog.Warning("Unable to access private WWW response headers. {0}", e.Message);

                // Fallback to use public headers
                www.responseHeaders.TryGetValue("STATUS", out rawHeaders);
            }

            if (string.IsNullOrEmpty(rawHeaders))
            {
                StatusCode        = HttpStatusCode.InternalServerError;
                StatusDescription = "HTTP status code is missing";
                return;
            }

            Regex           statusRegex = new Regex(httpStatusCodeRegexPattern, RegexOptions.None);
            MatchCollection matches     = statusRegex.Matches(rawHeaders);

            // Get the last HTTP status in the raw headers that matches the regex
            if (matches.Count > 0 && matches[matches.Count - 1].Success)
            {
                int status = 500;
                int.TryParse(matches[matches.Count - 1].Groups["code"].Value, out status);
                SetStatusCode(status);

                StatusDescription = matches[0].Groups["reason"].Value;
            }
            else
            {
                StatusCode        = HttpStatusCode.InternalServerError;
                StatusDescription = String.Format("Unable to parse status: {0}", rawHeaders);
            }
        }