Beispiel #1
0
        public LiveConnectItem(IDictionary <string, object> source)
        {
            ThrowArgumentException.IfNull(source, "source");
            ThrowArgumentException.IfOutOfRange(!source.ContainsKey("id"), "source");

            this.Properties = source;
        }
Beispiel #2
0
        public LoginCompletedEventArgs(LiveConnectSession session, object userState)
            : base(null, false, userState)
        {
            ThrowArgumentException.IfNull(session, "session");

            this.Session = session;
        }
        public LiveConnectClient(LiveConnectSession session, SynchronizationContext synchronizationContext)
        {
            ThrowArgumentException.IfNull(session, "session");

            this.Session = session;
            this.SynchronizationContext = synchronizationContext;
        }
Beispiel #4
0
        public LiveConnectSessionChangedEventArgs(LiveConnectSessionStatus newStatus, LiveConnectSession newSession)
        {
            ThrowArgumentException.IfNull(newSession, "newSession");

            this.Status  = newStatus;
            this.Session = newSession;
        }
        public LiveLoginResult(LiveConnectSessionStatus status, LiveConnectSession session)
        {
            ThrowArgumentException.IfNull(session, "session");

            this.Status  = status;
            this.Session = session;
        }
Beispiel #6
0
        public static IDictionary <string, object> Parse(string source)
        {
            ThrowArgumentException.IfNull(source, "source");

            var serializer = new JavaScriptSerializer();

            return(serializer.Deserialize <IDictionary <string, object> >(source));
        }
Beispiel #7
0
        public static string ToJsonString(this IDictionary <string, object> source)
        {
            ThrowArgumentException.IfNull(source, "source");

            var serializer = new JavaScriptSerializer();

            return(serializer.Serialize(source));
        }
        public LiveOperationResult(IDictionary <string, object> result, string rawResult)
        {
            ThrowArgumentException.IfNull(result, "result");
            ThrowArgumentException.IfNull(rawResult, "rawResult");

            this.Result    = result;
            this.RawResult = rawResult;
        }
        public IAsyncResult BeginDownload(string path, AsyncCallback asyncCallback, Action <IAsyncResult, LiveOperationProgress> progress, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");

            var address = this.CreateAddress(path);
            var method  = Methods.Get;

            return(this.BeginDownloadStream(address, method, asyncCallback, progress, userState));
        }
        public LiveOperationResult EndUpload(IAsyncResult asyncResult)
        {
            ThrowArgumentException.IfNull(asyncResult, "asyncResult");

            var ar = asyncResult as LiveConnectClientAsyncResult <LiveOperationResult>;

            ThrowArgumentException.IfOutOfRange(ar == null, "asyncResult");

            return(this.End(ar));
        }
        public static string Append(string source, string key, string value)
        {
            ThrowArgumentException.IfNull(source, "source");
            ThrowArgumentException.IfNull(key, "key");
            ThrowArgumentException.IfNull(value, "value");

            ThrowArgumentException.IfOutOfRange(string.IsNullOrEmpty(key), "key");

            return(source + (source.Contains("?") ? "&" : "?") + string.Format("{0}={1}", key, System.Web.HttpUtility.UrlEncode(value)));
        }
        public IAsyncResult BeginGet(string path, AsyncCallback asyncCallback, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ;

            var address = this.CreateAddress(path);
            var method  = Methods.Get;
            var data    = string.Empty;

            return(this.BeginUploadString(address, method, data, asyncCallback, userState));
        }
        public IAsyncResult BeginPut(string path, string body, AsyncCallback asyncCallback, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(body, "body");

            var address = this.CreateAddress(path);
            var method  = Methods.Put;
            var data    = body;

            return(this.BeginUploadString(address, method, data, asyncCallback, userState));
        }
        public void DownloadAsync(string path, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");

            var address = this.CreateAddress(path);
            var method  = Methods.Get;

            var completed       = this.DownloadCompleted;
            var progressChanged = this.DownloadProgressChanged;

            this.DownloadStreamAsync(address, method, completed, progressChanged, userState);
        }
        public static IDictionary <string, string> Parse(string source)
        {
            ThrowArgumentException.IfNull(source, "source");

            int index1 = source.IndexOf('?');

            if (index1 >= 0)
            {
                source = source.Substring(index1 + 1);
            }

            return(source.Split('&').Select(_ => _.Split('=')).Select(_ => new { Key = _[0], Vale = System.Web.HttpUtility.UrlDecode(_[1]) }).ToDictionary(_ => _.Key, _ => _.Vale));
        }
        public IAsyncResult BeginCopy(string path, string destination, AsyncCallback asyncCallback, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(destination, "destination");

            var address = this.CreateAddress(path);
            var method = Methods.Copy;
            var data = new Dictionary <string, object> {
                { "destination", destination }
            }.ToJsonString();

            return(this.BeginUploadString(address, method, data, asyncCallback, userState));
        }
        public void GetAsync(string path, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ;

            var address = this.CreateAddress(path);
            var method  = Methods.Get;
            var data    = string.Empty;

            var completed = this.GetCompleted;

            this.UploadStringAsync(address, method, data, completed, userState);
        }
        public void PostAsync(string path, IDictionary <string, object> body, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(body, "body");

            var address = this.CreateAddress(path);
            var method  = Methods.Post;
            var data    = body.ToJsonString();

            var completed = this.PostCompleted;

            this.UploadStringAsync(address, method, data, completed, userState);
        }
        public void PutAsync(string path, string body, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(body, "body");

            var address = this.CreateAddress(path);
            var method  = Methods.Put;
            var data    = body;

            var completed = this.PutCompleted;

            this.UploadStringAsync(address, method, data, completed, userState);
        }
        public void CopyAsync(string path, string destination, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(destination, "destination");

            var address = this.CreateAddress(path);
            var method = Methods.Copy;
            var data = new Dictionary <string, object> {
                { "destination", destination }
            }.ToJsonString();

            var completed = this.CopyCompleted;

            this.UploadStringAsync(address, method, data, completed, userState);
        }
        public IAsyncResult BeginUpload(string path, string fileName, Stream inputStream, bool overwriteExisting, AsyncCallback asyncCallback, Action <IAsyncResult, LiveOperationProgress> progress, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(fileName, "fileName");
            ThrowArgumentException.IfNull(inputStream, "inputStream");

            var address = this.CreateAddress(path);

            if (overwriteExisting)
            {
                address = QueryParameters.Append(address, "overwrite", "true");
            }

            var method = Methods.Post;

            return(this.BeginUploadStream(address, method, fileName, inputStream, asyncCallback, progress, userState));
        }
            public static bool TryParse(Uri uri, Uri redirectUri, out LiveConnectSession session)
            {
                ThrowArgumentException.IfNull(uri, "uri");
                ThrowArgumentException.IfNull(redirectUri, "redirectUri");

                if (uri.Scheme == LiveAuthHelper.EndPoint.Scheme && uri.Host == LiveAuthHelper.EndPoint.Host && uri.Port == LiveAuthHelper.EndPoint.Port && uri.AbsolutePath == "/error")
                {
                    var @params = QueryParameters.Parse(uri.Query.Substring(1));

                    var errorCode = @params.GetValueOrDefault(Keys.Error);
                    var message   = @params.GetValueOrDefault(Keys.ErrorDescription);

                    throw new LiveAuthException(errorCode, message);
                }

                if (uri.Scheme == redirectUri.Scheme && uri.Host == redirectUri.Host && uri.Port == redirectUri.Port && uri.AbsolutePath == redirectUri.AbsolutePath)
                {
                    var @params = QueryParameters.Parse(uri.Fragment.Substring(1));

                    if (@params.ContainsKey("error"))
                    {
                        var errorCode = @params.GetValueOrDefault(Keys.Error);
                        var message   = @params.GetValueOrDefault(Keys.ErrorDescription);

                        throw new LiveAuthException(errorCode, message);
                    }

                    var _session = new LiveConnectSession();

                    @params.InvokeIfContainsKey(Keys.AccessToken, _ => { _session.AccessToken = _; });
                    @params.InvokeIfContainsKey(Keys.AuthenticationToken, _ => { _session.AuthenticationToken = _; });
                    @params.InvokeIfContainsKey(Keys.Expires, _ => { _session.Expires = new DateTimeOffset().AddSeconds(int.Parse(_)); });
                    @params.InvokeIfContainsKey(Keys.RefreshToken, _ => { _session.RefreshToken = _; });
                    @params.InvokeIfContainsKey(Keys.Scope, _ => { _session.Scopes = _.Split(' '); });

                    session = _session;
                    return(true);
                }

                session = null;
                return(false);
            }
        public void UploadAsync(string path, string fileName, Stream inputStream, bool overwriteExisting, object userState)
        {
            ThrowArgumentException.IfNull(path, "path");
            ThrowArgumentException.IfNull(fileName, "fileName");
            ThrowArgumentException.IfNull(inputStream, "inputStream");

            var address = this.CreateAddress(path);

            if (overwriteExisting)
            {
                address = QueryParameters.Append(address, "overwrite", "true");
            }

            var method = Methods.Post;

            var completed       = this.UploadCompleted;
            var progressChanged = this.UploadProgressChanged;

            this.UploadStreamAsync(address, method, fileName, inputStream, completed, progressChanged, userState);
        }
            public static Uri Create(string clientId, string[] scopes, Uri redirectUri, string locale)
            {
                ThrowArgumentException.IfNull(clientId, "clientId");
                ThrowArgumentException.IfNull(scopes, "scopes");
                ThrowArgumentException.IfNull(redirectUri, "redirectUri");

                var uri = LiveAuthHelper.EndPoint.ToString();

                uri = QueryParameters.Append(uri, Keys.ResponseType, "token");
                uri = QueryParameters.Append(uri, Keys.ClientId, clientId);
                uri = QueryParameters.Append(uri, Keys.Scope, string.Join(" ", scopes));

                if (!string.IsNullOrEmpty(locale))
                {
                    uri = QueryParameters.Append(uri, Keys.Locale, locale);
                }

                uri = QueryParameters.Append(uri, Keys.RedirectUri, redirectUri.ToString());

                return(new Uri(uri));
            }
Beispiel #25
0
        public LiveConnectSessionChangedEventArgs(Exception error)
        {
            ThrowArgumentException.IfNull(error, "error");

            this.Error = error;
        }
Beispiel #26
0
        public LiveDownloadResult(Stream result)
        {
            ThrowArgumentException.IfNull(result, "result");

            this.Result = result;
        }
        public void CancelCopy(IAsyncResult asyncResult)
        {
            ThrowArgumentException.IfNull(asyncResult, "asyncResult");

            this.Cancel <LiveOperationResult>(asyncResult);
        }
        public void CancelDownload(IAsyncResult asyncResult)
        {
            ThrowArgumentException.IfNull(asyncResult, "asyncResult");

            this.Cancel <LiveDownloadResult>(asyncResult);
        }