Example #1
1
        public static void StreamReadAsync(
            Stream stream,
            byte[] buffer,
            int offset,
            int count,
            SynchronizationContextWrapper syncContext,
            Action<int, Exception> callback)
        {
            Exception error = null;
            int length = 0;
            try
            {
                stream.BeginRead(buffer, offset, count,
                    delegate(IAsyncResult ar)
                    {
                        try
                        {
                            length = stream.EndRead(ar);
                        }
                        catch (Exception e)
                        {
                            error = e;
                        }

                        callback(length, error);
                    },
                    null);
            }
            catch (Exception e)
            {
                error = e;
                callback(length, error);
            }
        }
Example #2
0
        public static void StreamReadAsync(
            Stream stream,
            byte[] buffer,
            int offset,
            int count,
            SynchronizationContextWrapper syncContext,
            Action <int, Exception> callback)
        {
            Exception error  = null;
            int       length = 0;

            try
            {
                stream.BeginRead(buffer, offset, count,
                                 delegate(IAsyncResult ar)
                {
                    try
                    {
                        length = stream.EndRead(ar);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }

                    callback(length, error);
                },
                                 null);
            }
            catch (Exception e)
            {
                error = e;
                callback(length, error);
            }
        }
Example #3
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");

            this.authClient = new LiveAuthClientCore(clientId, refreshTokenHandler, this);
            this.syncContext = SynchronizationContextWrapper.Current;
        }
Example #4
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");

            this.authClient  = new LiveAuthClientCore(clientId, refreshTokenHandler, this);
            this.syncContext = SynchronizationContextWrapper.Current;
        }
Example #5
0
        /// <summary>
        /// Ensures that only one async operation is active at any time.
        /// </summary>
        private void PrepareForAsync()
        {
            Debug.Assert(
                this.asyncInProgress == 0 || this.asyncInProgress == 1,
                "Unexpected value for 'asyncInProgress' field.");

            if (this.asyncInProgress > 0)
            {
                throw new LiveAuthException(
                          AuthErrorCodes.ClientError,
                          ResourceHelper.GetString("AsyncOperationInProgress"));
            }

            Interlocked.Increment(ref this.asyncInProgress);

            this.syncContext = SynchronizationContextWrapper.Current;
        }
        /// <summary>
        /// Creates a new LiveConnectClient instance.
        /// </summary>
        /// <param name="session">the session object that contains the authentication information.</param>
        public LiveConnectClient(LiveConnectSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            this.Session = session;
            this.syncContext = SynchronizationContextWrapper.Current;

#if DEBUG
            this.ApiEndpoint =
                string.IsNullOrEmpty(LiveConnectClient.ApiEndpointOverride)
                ? LiveConnectClient.DefaultApiEndpoint
                : LiveConnectClient.ApiEndpointOverride;
#else
            this.ApiEndpoint = LiveConnectClient.DefaultApiEndpoint;
#endif
        }
Example #7
0
        /// <summary>
        /// Creates a new LiveConnectClient instance.
        /// </summary>
        /// <param name="session">the session object that contains the authentication information.</param>
        public LiveConnectClient(LiveConnectSession session)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }

            this.Session     = session;
            this.syncContext = SynchronizationContextWrapper.Current;

#if DEBUG
            this.ApiEndpoint =
                string.IsNullOrEmpty(LiveConnectClient.ApiEndpointOverride)
                ? LiveConnectClient.DefaultApiEndpoint
                : LiveConnectClient.ApiEndpointOverride;
#else
            this.ApiEndpoint = LiveConnectClient.DefaultApiEndpoint;
#endif
        }
Example #8
0
        public static void StreamReadAsync(
            Stream stream,
            byte[] buffer,
            int offset,
            int count,
            SynchronizationContextWrapper syncContext,
            Action <int, Exception> callback)
        {
            Debug.Assert(syncContext != null);

            stream.BeginRead(
                buffer,
                offset,
                count,
                delegate(IAsyncResult ar)
            {
                if (ar.IsCompleted)
                {
                    int bytesRead   = 0;
                    Exception error = null;

                    try
                    {
                        bytesRead = stream.EndRead(ar);
                    }
                    catch (IOException ioe)
                    {
                        error = ioe;
                    }
                    finally
                    {
                        syncContext.Post(() => callback(bytesRead, error));
                    }
                }
            },
                null);
        }
        public static void StreamReadAsync(
            Stream stream, 
            byte[] buffer, 
            int offset, 
            int count, 
            SynchronizationContextWrapper syncContext, 
            Action<int, Exception> callback)
        {
            Debug.Assert(syncContext != null);

            stream.BeginRead(
                buffer,
                offset,
                count,
                delegate(IAsyncResult ar)
                {
                    if (ar.IsCompleted)
                    {
                        int bytesRead = 0;
                        Exception error = null;

                        try
                        {
                            bytesRead = stream.EndRead(ar);
                        }
                        catch (IOException ioe)
                        {
                            error = ioe;
                        }
                        finally
                        {
                            syncContext.Post(() => callback(bytesRead, error));
                        }
                    }
                },
                null);
        }
        /// <summary>
        /// Ensures that only one async operation is active at any time.
        /// </summary>
        private void PrepareForAsync()
        {
            Debug.Assert(
                this.asyncInProgress == 0 || this.asyncInProgress == 1, 
                "Unexpected value for 'asyncInProgress' field.");

            if (this.asyncInProgress > 0)
            {
                throw new LiveAuthException(
                    AuthErrorCodes.ClientError, 
                    ResourceHelper.GetString("AsyncOperationInProgress"));
            }

            Interlocked.Increment(ref this.asyncInProgress);

            this.syncContext = SynchronizationContextWrapper.Current;
        }