Ejemplo n.º 1
0
        public void PostEvent(TelemetryEvent telemetryEvent)
        {
            CodeContract.RequiresArgumentNotNull <TelemetryEvent>(telemetryEvent, "telemetryEvent");
            if (!TelemetrySession.IsOptedIn)
            {
                return;
            }
            FaultEvent faultEvent = telemetryEvent as FaultEvent;

            if (faultEvent == null)
            {
                throw new InvalidOperationException("WatsonSession channel must have FaultEvent posted");
            }
            int num = FaultEventWatsonSamplePercent;

            faultEvent.ReservedProperties["DataModel.Fault.WatsonSamplePercentDefault"] = FaultEventWatsonSamplePercent;
            if (FaultEvent.WatsonSamplePercent.HasValue)
            {
                num = FaultEvent.WatsonSamplePercent.Value;
                faultEvent.ReservedProperties["DataModel.Fault.WatsonSamplePercentOverride"] = FaultEvent.WatsonSamplePercent.Value;
            }
            if (!faultEvent.IsIncludedInWatsonSample.HasValue)
            {
                faultEvent.UserOptInToWatson = FaultEvent.FaultEventWatsonOptIn.Unspecified;
                if (num > 0)
                {
                    faultEvent.IsIncludedInWatsonSample = (Random.Next(100) < num);
                }
                else
                {
                    faultEvent.IsIncludedInWatsonSample = false;
                }
            }
            else
            {
                if (faultEvent.IsIncludedInWatsonSample == true)
                {
                    faultEvent.UserOptInToWatson = FaultEvent.FaultEventWatsonOptIn.PropertyOptIn;
                }
                else
                {
                    faultEvent.UserOptInToWatson = FaultEvent.FaultEventWatsonOptIn.PropertyOptOut;
                }
                faultEvent.Properties["VS.Fault.WatsonOptIn"] = faultEvent.UserOptInToWatson.ToString();
            }
            WatsonReport watsonReport = new WatsonReport(faultEvent, TelemetrySession);
            int          num2         = FaultEventMaximumWatsonReportsPerSession;

            faultEvent.ReservedProperties["DataModel.Fault.MaxReportsPerSessionDefault"] = FaultEventMaximumWatsonReportsPerSession;
            if (FaultEvent.MaximumWatsonReportsPerSession.HasValue)
            {
                num2 = FaultEvent.MaximumWatsonReportsPerSession.Value;
                faultEvent.ReservedProperties["DataModel.Fault.MaxReportsPerSessionOverride"] = FaultEventMaximumWatsonReportsPerSession;
            }
            if (num == 0 && num2 == 0)
            {
                faultEvent.IsIncludedInWatsonSample = false;
            }
            int minSecondsBetweenReports = FaultEventMinimumSecondsBetweenWatsonReports;

            faultEvent.ReservedProperties["DataModel.Fault.MinSecondsBetweenReportsDefault"] = FaultEventMinimumSecondsBetweenWatsonReports;
            if (FaultEvent.MinimumSecondsBetweenWatsonReports.HasValue)
            {
                minSecondsBetweenReports = FaultEvent.MinimumSecondsBetweenWatsonReports.Value;
                faultEvent.ReservedProperties["DataModel.Fault.MinSecondsBetweenReportsOverride"] = FaultEvent.MinimumSecondsBetweenWatsonReports;
            }
            watsonReport.PostWatsonReport(num2, minSecondsBetweenReports);
        }