当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ServiceCallback.default方法代码示例

本文整理汇总了TypeScript中ms-rest.ServiceCallback.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServiceCallback.default方法的具体用法?TypeScript ServiceCallback.default怎么用?TypeScript ServiceCallback.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ms-rest.ServiceCallback的用法示例。


在下文中一共展示了ServiceCallback.default方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: callback

        return this.client.pipeline(httpRequest, (err, response, responseBody) => {
            if (err) {
                return callback(err, null, null, null);
            }

            var statusCode = response.statusCode;
            if (statusCode !== 202) {
                var error: any = new Error(responseBody);
                error.statusCode = response.statusCode;
                error.request = msRest.stripRequest(httpRequest);
                error.response = msRest.stripResponse(response);
                if (responseBody === '') responseBody = null;
                var parsedErrorResponse;
                try {
                    parsedErrorResponse = JSON.parse(responseBody);
                    if (parsedErrorResponse) {
                        if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
                        if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
                        if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
                    }
                } catch (defaultError) {
                    error.message = util.format('Error "%s" occurred in deserializing the responseBody ' +
                        '- "%s" for the default response.', defaultError.message, responseBody);
                    return callback(error, null, null, null);
                }
                return callback(error, null, null, null);
            }
            // Create Result
            var result = null;
            if (responseBody === '') responseBody = null;
            // Deserialize Response
            if (statusCode === 202) {
                var parsedResponse = null;
                try {
                    parsedResponse = JSON.parse(responseBody);
                    result = JSON.parse(responseBody);
                    if (parsedResponse !== null && parsedResponse !== undefined) {
                        var resultMapper = new this.client.models['ImportModel']().mapper();
                        result = this.client.deserialize(resultMapper, parsedResponse, 'result');
                    }
                } catch (error) {
                    var deserializationError: any = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
                    deserializationError.request = msRest.stripRequest(httpRequest);
                    deserializationError.response = msRest.stripResponse(response);
                    return callback(deserializationError, null, null, null);
                }
            }

            return callback(null, result, httpRequest, response);
        });
开发者ID:Microsoft,项目名称:PowerBI-Node,代码行数:50,代码来源:imports.ts

示例2: uploadFile

    public uploadFile(collectionName: string, workspaceId: string, filePath: string, options: any, callback?: ServiceCallback<models.ImportModel>): void {
        if (!callback && typeof options === 'function') {
            callback = options;
            options = null;
        }
        if (!callback) {
            throw new Error('callback cannot be null.');
        }

        var datasetDisplayName = (options && options.datasetDisplayName !== undefined) ? options.datasetDisplayName : undefined;
        var nameConflict = (options && options.nameConflict !== undefined) ? options.nameConflict : undefined;
        // Validate
        try {
            if (collectionName === null || collectionName === undefined || typeof collectionName.valueOf() !== 'string') {
                throw new Error('collectionName cannot be null or undefined and it must be of type string.');
            }
            if (workspaceId === null || workspaceId === undefined || typeof workspaceId.valueOf() !== 'string') {
                throw new Error('workspaceId cannot be null or undefined and it must be of type string.');
            }
            if (datasetDisplayName !== null && datasetDisplayName !== undefined && typeof datasetDisplayName.valueOf() !== 'string') {
                throw new Error('datasetDisplayName must be of type string.');
            }
            if (nameConflict !== null && nameConflict !== undefined && typeof nameConflict.valueOf() !== 'string') {
                throw new Error('nameConflict must be of type string.');
            }
            if (filePath === null || filePath === undefined) {
                throw new Error('filePath cannot be null or undefined.');
            }
        } catch (error) {
            return callback(error, null, null, null);
        }

        // Construct URL
        var requestUrl = this.client['baseUri'] + '//v1.0/collections/{collectionName}/workspaces/{workspaceId}/imports';
        requestUrl = requestUrl.replace('{collectionName}', encodeURIComponent(collectionName));
        requestUrl = requestUrl.replace('{workspaceId}', encodeURIComponent(workspaceId));

        var queryParameters = [];
        if (datasetDisplayName !== null && datasetDisplayName !== undefined) {
            queryParameters.push('datasetDisplayName=' + encodeURIComponent(datasetDisplayName));
        }
        if (nameConflict !== null && nameConflict !== undefined) {
            queryParameters.push('nameConflict=' + encodeURIComponent(nameConflict));
        }
        if (queryParameters.length > 0) {
            requestUrl += '?' + queryParameters.join('&');
        }
        // trim all duplicate forward slashes in the url
        var regex = /([^:]\/)\/+/gi;
        requestUrl = requestUrl.replace(regex, '$1');

        var formData = {
            file: fs.createReadStream(filePath)
        };

        // Create HTTP transport objects
        var httpRequest = WebResource.post(requestUrl);
        httpRequest['url'] = requestUrl;
        httpRequest['method'] = 'POST';
        httpRequest['formData'] = formData;
        httpRequest['headers'] = {};

        // Set Headers
        if (options) {
            for (var headerName in options.customHeaders) {
                if (options.customHeaders.hasOwnProperty(headerName)) {
                    httpRequest.withHeader(headerName, options.customHeaders[headerName]);
                }
            }
        }

        // Send Request
        return this.client.pipeline(httpRequest, (err, response, responseBody) => {
            if (err) {
                return callback(err, null, null, null);
            }

            var statusCode = response.statusCode;
            if (statusCode !== 202) {
                var error: any = new Error(responseBody);
                error.statusCode = response.statusCode;
                error.request = msRest.stripRequest(httpRequest);
                error.response = msRest.stripResponse(response);
                if (responseBody === '') responseBody = null;
                var parsedErrorResponse;
                try {
                    parsedErrorResponse = JSON.parse(responseBody);
                    if (parsedErrorResponse) {
                        if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
                        if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
                        if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
                    }
                } catch (defaultError) {
                    error.message = util.format('Error "%s" occurred in deserializing the responseBody ' +
                        '- "%s" for the default response.', defaultError.message, responseBody);
                    return callback(error, null, null, null);
                }
                return callback(error, null, null, null);
            }
            // Create Result
//.........这里部分代码省略.........
开发者ID:Microsoft,项目名称:PowerBI-Node,代码行数:101,代码来源:imports.ts


注:本文中的ms-rest.ServiceCallback.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。