%PDF- %PDF-
Direktori : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/platform/win/ |
Current File : C:/Windows/SystemApps/Microsoft.Windows.Cortana_cw5n1h2txyewy/dss_service/node_modules/platform/win/telemetry_impl.js |
function getErrorHResult(n){return n?n.HRESULT?n.HRESULT>>>0:2147500037:0}function appendLoggingFields(n,t,i){var e,f,o;if(i&&n.beginStruct(i),t&&t instanceof Object)for(e=Object.keys(t),f=0;f<e.length;f++){var u=e[f],r=t[u],s=typeof r;switch(s){case"string":n.addString(u,r);break;case"boolean":n.addBoolean(u,r);break;case"object":if(r instanceof Error){r.HRESULT&&n.addUInt32("hr",getErrorHResult(r),diagnostics.LoggingFieldFormat.hResult);n.addString("error",r.toString());n.addString("stack",getErrorStackForLogging(r));break}default:try{o=JSON.stringify(r);n.addString(u,o,diagnostics.LoggingFieldFormat.json)}catch(h){console.warn("%s: Failed to stringify value for key [%s]",tag,u)}}}i&&n.endStruct()}function getErrorStackForLogging(n,t){var u,i,o,r;if(n&&n.cleanStack)return n.cleanStack;if((t===undefined&&(t=10),t<=0)||(u=n.stack,!u))return"";var f=u.split("\n"),e=[];for(i=1;i<f.length;i++)if(o=f[i],r=o.match(/\s*at (.*) \((?:.*\\dss_service\\)?(.*)\)/),r&&e.push("@ "+r[1]+" ("+r[2]+")"),--t==0)break;return n.cleanStack=e.join("\n"),n.cleanStack}function toWinLoggingLevelObject(n){switch(n){case 0:return Windows.Foundation.Diagnostics.LoggingLevel.verbose;case 1:return Windows.Foundation.Diagnostics.LoggingLevel.information;case 2:return Windows.Foundation.DiagnosticsLoggingLevel.warning;case 3:return Windows.Foundation.Diagnostics.LoggingLevel.error;case 4:return Windows.Foundation.Diagnostics.LoggingLevel.critical;default:throw new Error("unexpected");}}var util=require("util"),platUtils=require("platform-utils"),winrt=require("winrt-projections"),SamplingLevel=require("../platform_types.js").telemetry.SamplingLevel,LoggingLevel=require("../platform_types.js").telemetry.LoggingLevel,Provider=require("../platform_types.js").telemetry.Provider,diagnostics,tag="telemetry_impl.js",DSS_KEYWORD_TELEMETRY=35184372088833,DSS_KEYWORD_MEASURES=70368744177665,DSS_KEYWORD_CRITICAL=0x800000000001,TELEMETRY_GROUP_GUID="4f50731a-89cf-4782-b3e0-dce8c90476ba",THREAD_ID=0,DEFAULT_SAMPLING_LEVEL=SamplingLevel.low,SamplingLevelLoggingOptionsMap=[];module.exports.EventInfo=function(n,t,i){this.name=n;this.samplingLevel=t;this.loggingLevel=i||LoggingLevel.critical};module.exports.ActivityInfo=function(n,t,i){this.name=n;this.samplingLevel=t;this.loggingLevel=i||LoggingLevel.critical};module.exports.createLoggingChannel=function(n){if(!n)throw new TypeError("provider");switch(n){case Provider.proactive:return new LoggingChannel("Microsoft-Windows-Shell-CortanaProactive",TELEMETRY_GROUP_GUID);case Provider.inferences:return new LoggingChannel("Microsoft-Windows-Shell-CortanaCSI",TELEMETRY_GROUP_GUID);case Provider.notifications:return new LoggingChannel("Microsoft-Windows-Shell-CortanaNotifications",TELEMETRY_GROUP_GUID);default:throw new Error("Unsupported telemetry provider");}};var LoggingChannel=function(){function n(n,t){try{winrt.projectNamespace("Windows.Foundation");diagnostics=Windows.Foundation.Diagnostics;SamplingLevelLoggingOptionsMap.length==0&&(SamplingLevelLoggingOptionsMap[SamplingLevel.low]=new diagnostics.LoggingOptions(DSS_KEYWORD_TELEMETRY),SamplingLevelLoggingOptionsMap[SamplingLevel.medium]=new diagnostics.LoggingOptions(DSS_KEYWORD_MEASURES),SamplingLevelLoggingOptionsMap[SamplingLevel.full]=new diagnostics.LoggingOptions(DSS_KEYWORD_CRITICAL));var i=new diagnostics.LoggingChannelOptions(t);this.internalChannel=new diagnostics.LoggingChannel(n,i)}catch(r){console.warn("%s: Failed to create LoggingChannel %s",tag,n,r)}}return n.prototype.logEvent=function(n,t){var i,r;if(!n||!n.name||typeof n.name!="string")throw new TypeError("eventInfo");if(!this.internalChannel)return console.warn("%s: Failed to invoke logEvent because LoggingChannel does not exist",tag);try{i=null;t&&(i=new diagnostics.LoggingFields,appendLoggingFields(i,t));r=n.samplingLevel||DEFAULT_SAMPLING_LEVEL;this.internalChannel.logEvent(n.name,i,toWinLoggingLevelObject(n.loggingLevel),SamplingLevelLoggingOptionsMap[r])}catch(u){console.warn("%s: Failed to log event %s.",tag,n.name,u)}},n.prototype.startActivity=function(n,t){var i,r,u;if(!n||!n.name||typeof n.name!="string")throw new TypeError("activityInfo");if(!this.internalChannel)return console.warn("%s: Failed to invoke startActivity because LoggingChannel does not exist",tag),NoOpLoggingActivity;try{return i=new diagnostics.LoggingFields,i.beginStruct("wilActivity"),i.addUInt32("threadId",THREAD_ID,diagnostics.LoggingFieldFormat.threadId),i.endStruct(),t&&appendLoggingFields(i,t),r=n.samplingLevel||DEFAULT_SAMPLING_LEVEL,u=this.internalChannel.startActivity(n.name,i,toWinLoggingLevelObject(n.loggingLevel),SamplingLevelLoggingOptionsMap[r]),new LoggingActivity(u,n.name)}catch(f){return console.warn("%s: Failed to start activity %s.",tag,n.name,f),NoOpLoggingActivity}},n}(),LoggingActivity=function(){function n(n,t){if(!n)throw new TypeError("internalActivity");if(!t)throw new TypeError("name");this.internalActivity=n;this.name=t}return n.prototype.stop=function(n,t){try{var i=new diagnostics.LoggingFields;i.beginStruct("wilActivity");i.addUInt32("hresult",getErrorHResult(n),diagnostics.LoggingFieldFormat.hResult);i.addUInt32("threadId",THREAD_ID,diagnostics.LoggingFieldFormat.threadId);n&&(i.addString("message",n.toString()),i.addString("stack",getErrorStackForLogging(n)));i.endStruct();t&&appendLoggingFields(i,t);this.internalActivity.stopActivity(this.name,i)}catch(n){console.warn("%s: Failed to stop activity %s.",tag,this.name,n)}},n.prototype.logEvent=function(n,t){var i,r;if(!n||!n.name||typeof n.name!="string")throw new TypeError("eventInfo");try{i=null;t&&(i=new diagnostics.LoggingFields,appendLoggingFields(i,t));r=n.samplingLevel||DEFAULT_SAMPLING_LEVEL;this.internalActivity.logEvent(n.name,i,toWinLoggingLevelObject(n.loggingLevel),SamplingLevelLoggingOptionsMap[r])}catch(u){console.warn("%s: Failed to log event %s for activity %s.",tag,n.name,this.name,u)}},n}(),NoOpLoggingActivity={stop:function(){},logEvent:function(){}};module.exports.getErrorStackForLogging=getErrorStackForLogging