當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。