public NetSuiteReadWriteResult Get(RecordRef recordRef)
        {
            Task <ReadResponse> getAsyncResult = null;

            recordRef.type          = RecordType;
            recordRef.typeSpecified = true;

            NetSuiteHelper.TryRun(() =>
            {
                using (var proxy = NetSuiteHelper.GetProxy())
                {
                    getAsyncResult = proxy.getAsync(recordRef);
                    var result     = getAsyncResult.Result;
                    return(result.status.isSuccessSpecified && result.status.isSuccess);
                }
            },
                                  (message) =>
            {
                LogMessage?.Invoke(message);
            });

            //TODO record
            return(new NetSuiteReadWriteResult(result.status, RecordType,
                                               NetSuiteOperationType.Get, null, null));
        }
        public IEnumerable <NetSuiteReadWriteResult> Get(RecordRef[] recordRefs)
        {
            foreach (var recordRef in recordRefs)
            {
                recordRef.type          = RecordType;
                recordRef.typeSpecified = true;
            }
            Task <ReadResponseList> getAsyncResults = null;


            NetSuiteHelper.TryRun(() =>
            {
                using (var proxy = NetSuiteHelper.GetProxy())
                {
                    getAsyncResults = proxy.getListAsync(recordRefs);
                    var result      = getAsyncResults.Result;
                    return(result.status.isSuccessSpecified && result.status.isSuccess);
                }
            },
                                  (message) =>
            {
                LogMessage?.Invoke(message);
            });

            //TODO record
            yield return(new NetSuiteReadWriteResult(result.status, RecordType,
                                                     NetSuiteOperationType.Get, null, null));
        }
        /// <summary>
        /// Invokes NetSuite's asyncAddList(..) method.
        /// </summary>
        /// <param name="records">The records to be added.</param>
        /// <returns>The filter criteria for the retrieved data.</returns>
        public virtual WriteResponseList AsyncAddList(Record[] recordsList)
        {
            WriteResponseList        result     = null;
            Task <WriteResponseList> resultTask = null;

            NetSuiteHelper.TryRun(() =>
            {
                using (var proxy = NetSuiteHelper.GetProxy())
                {
                    resultTask = proxy.addListAsync(recordsList);
                    result     = resultTask.Result;
                    return(result.status.isSuccessSpecified && result.status.isSuccess);
                }
            },
                                  (message) =>
            {
                LogMessage?.Invoke(message);
            });

            return(result);
        }
        /// <summary>
        /// Adds object to the NetSuite.
        /// </summary>
        /// <param name="entity">Object to add</param>
        public virtual NetSuiteReadWriteResult Add(Record entity)
        {
            Task <WriteResponse> resultTask = null;

            NetSuiteHelper.TryRun(() =>
            {
                using (var proxy = NetSuiteHelper.GetProxy())
                {
                    resultTask = proxy.addAsync(entity);
                    var result = resultTask.Result;
                    return(result.status.isSuccessSpecified && result.status.isSuccess);
                }
            },
                                  (message) =>
            {
                LogMessage?.Invoke(message);
            });

            return(new NetSuiteReadWriteResult(result.status, RecordType,
                                               NetSuiteOperationType.Add, entity, result.writeResponse[0].baseRef));
        }
        /// <summary>
        /// Gets a list of records for one or more NetSuite WEB service call
        /// </summary>
        /// <param name="recordsList">Array of <see cref="RecordRef"/> objects</param>
        /// <returns>Array of the <see cref="NetSuiteReadWriteResult"/> objects</returns>
        public virtual NetSuiteReadWriteResult[] GetList(RecordRef[] recordsList)
        {
            if (recordsList == null)
            {
                return(null);
            }

            if (recordsList.Length == 0)
            {
                return(new NetSuiteReadWriteResult[0]);
            }

            NetSuiteReadWriteResult[] resultArray = new NetSuiteReadWriteResult[recordsList.Length];

            var maxGetListRecordsCount = NetSuiteHelper.MaxGetListRecordsCount;

            for (int index = 0; index *maxGetListRecordsCount < recordsList.Length; index++)
            {
                int startIndex    = index * maxGetListRecordsCount;
                int elementsCount = (startIndex + maxGetListRecordsCount) > recordsList.Length ?
                                    (recordsList.Length - startIndex) : maxGetListRecordsCount;

                RecordRef[] getList = new RecordRef[elementsCount];
                Array.Copy(recordsList, startIndex, getList, 0, elementsCount);
                Task <ReadResponseList> responseArrayTask = NetSuiteHelper.GetProxy().getListAsync(getList);

                for (int jIndex = 0; jIndex < responseArrayTask.Result.readResponse.Length; jIndex++)
                {
                    resultArray[startIndex + jIndex] = new NetSuiteReadWriteResult(
                        responseArrayTask.Result.readResponse[jIndex].status, getList[jIndex].type, NetSuiteOperationType.Get,
                        responseArrayTask.Result.readResponse[jIndex].record, null);
                }
            }

            return(resultArray);
        }