Exemplo n.º 1
0
                /// <summary>
                /// AgFx will call this method when it wants to load the new value -
                /// even though it's just the values we got off of the OAuth process.
                /// </summary>
                /// <param name="result"></param>
                public override void Execute(Action <LoadRequestResult> result)
                {
                    // Grab the values off of the LoadContext.
                    //
                    FacebookLoginLoadContext context = (FacebookLoginLoadContext)LoadContext;

                    string   access_token    = context.AccessToken;
                    DateTime expiration_time = context.Expiration;

                    // Make sure we have a token.
                    if (access_token != null)
                    {
                        // write the values into a stream and return that.
                        MemoryStream ms = new MemoryStream();
                        StreamWriter sw = new StreamWriter(ms);

                        sw.WriteLine(access_token);
                        sw.WriteLine(expiration_time);
                        sw.Flush();

                        ms.Seek(0, SeekOrigin.Begin);

                        LoadRequestResult r = new LoadRequestResult(ms);
                        result(r);
                    }
                    else
                    {
                        result(new LoadRequestResult(new UnauthorizedAccessException()));
                    }
                }
        private void ProcessResult(string str, Exception ex)
        {
            var callback = _callback;

            _callback = null;

            LoadRequestResult res;

            if (ex != null)
            {
                res = new LoadRequestResult(ex);
            }
            else
            {
                var rs = str;
                try
                {
                    // TODO: PERFORMANCE NOTE: MOVE AWAY FROM USING DOWNLOAD STRING ASYNC HERE!@!!
                    Stream s = new MemoryStream(Encoding.UTF8.GetBytes(rs));
                    res = new LoadRequestResult(s);
                }
                catch (Exception e)
                {
                    res = new LoadRequestResult(
                        new InvalidOperationException(
                            "There was a problem understanding the response from the service.", e));
                }
            }

            callback(res);
        }
Exemplo n.º 3
0
                public override void Execute(Action <LoadRequestResult> result)
                {
                    MemoryStream ms = new MemoryStream();

                    StreamWriter sw = new StreamWriter(ms);

                    sw.Write(val);
                    sw.Flush();

                    ms.Seek(0, SeekOrigin.Begin);

                    LoadRequestResult lrr = new LoadRequestResult(ms);

                    result(lrr);
                }