• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript ms-rest.ServiceCallback类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript msgpack-lite.createCodec函数代码示例发布时间:2022-05-25
下一篇:
TypeScript ms.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap