示例#1
0
        public async Task <IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token)
        {
            var operation = new GetApiSessionOperation(cred);

            // construct and execute request
            var operations = new[] { operation };
            var response   = await ExecuteOperations(operations, token);

            // expecting a single operation result (more or less is a problem)
            var result = response.OperationResults.OfType <IntacctOperationResult <IntacctSession> >().SingleOrDefault();

            if (result != null)
            {
                return(result.Value);
            }

            // let's see what the result is
            var badResult = response.OperationResults.FirstOrDefault();

            if (badResult == null)
            {
                throw new Exception("Unable to initiate API session, and no results were captured.");
            }

            var authError = badResult as IntacctOperationAuthFailedResult;

            if (authError != null)
            {
                throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}");
            }

            throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}.");
        }
示例#2
0
		public async Task<IIntacctSession> InitiateApiSession(IntacctUserCredential cred, CancellationToken token)
		{
			var operation = new GetApiSessionOperation(cred);

			// construct and execute request
			var operations = new[] { operation };
			var response = await ExecuteOperations(operations, token);

			// expecting a single operation result (more or less is a problem)
			var result = response.OperationResults.OfType<IntacctOperationResult<IntacctSession>>().SingleOrDefault();
			if (result != null) return result.Value;

			// let's see what the result is
			var badResult = response.OperationResults.FirstOrDefault();
			if (badResult == null) throw new Exception("Unable to initiate API session, and no results were captured.");

			var authError = badResult as IntacctOperationAuthFailedResult;
			if (authError != null) throw new Exception($"Unable to initiate API session, authentication failed. Service error: {authError.Errors.Select(e => e.ToString()).Aggregate((curr, next) => curr + " " + next)}");

			throw new Exception($"Unable to initiate API session, unexpected result type {badResult.GetType().Name}.");
		}