%PDF- %PDF-
Direktori : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/proactive/lib/ |
Current File : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/proactive/lib/orchestrator.js |
function Orchestrator(n,t){if(!(this instanceof Orchestrator))return new Orchestrator(n,t);if(!n)throw new TypeError("lazyLoader");return events.EventEmitter.call(this),this._loader=n,this._experienceServices=t||{},this}function invokeExperienceServices(n,t){function f(n,t,i,r){function u(n){return f.stop(n),r()}console.log("%s: Invoking experience service [%s]",tag,n);var f=telemetryInstance.startActivity(telemetryEvents.InvokeExperienceServiceActivity,{name:n});if(!t.isInitialized)try{t.init()}catch(e){return u(e)}t.update(i,u)}var i=[],r,u;for(r in this._experienceServices)u=this._experienceServices[r],u?i.push(f.bind(this,r,u,n.Answers)):console.warn("%s: Experience service [%s] is invalid.",tag,r);return i.length>0?(console.log("%s: Invoking [%d] experience services",tag,i.length),_module.async.parallel(i,t)):(console.warn("%s: No experience services to invoke",tag),t())}function processFetchResults(n){var i,t,r;if(!n)throw new Error("Fetch did not return any results.");if(!n.Answers||!Array.isArray(n.Answers))throw new Error("Fetch did not return a valid answers segment.");for(i=[],t=0;t<n.Answers.length;t++)r=n.Answers[t],r instanceof Object?i.push(r):console.warn("%s: Answer at index %d failed validation, excluding from response.",tag,t);if(i.length===0)throw new Error("Zero valid answers.");n.Answers=i}var dss_utils=require("dss-utils"),util=require("util"),events=require("events"),_module={};dss_utils.definePropertiesForLazyLoad(_module,require,{stream:"stream",async:"async",cortanaPlat:"cortana-platform"});var tag="proactive/orchestrator.js",telemetry=require("proactive-telemetry"),telemetryInstance=telemetry.getProactiveTelemetryInstance(),telemetryEvents=telemetry.Events.Orchestrator;util.inherits(Orchestrator,events.EventEmitter);exports.Orchestrator=Orchestrator;Orchestrator.prototype.refreshAnswers=function(n){function i(t,i){return r.stop(t),n(t,i)}if(typeof n!="function")throw new TypeError("cb");console.log("%s: Refreshing answers.",tag);var t=this,r=telemetryInstance.startActivity(telemetryEvents.RefreshAnswersActivity);if(!t._loader.isInitialized)try{t._loader.init()}catch(u){return i(u)}t._loader.getAnswers(function(u,f){if(u)return i(u);try{processFetchResults(f)}catch(u){return i(u)}return invokeExperienceServices.call(t,f,function(){r.stop();t.emit("done")}),n(null,f)})}