Пример #1
0
        private async Task Twin_DeviceDesiredPropertyUpdateRecoveryAsync(
            Client.TransportType transport,
            string faultType,
            string reason,
            int delayInSec,
            string proxyAddress = null)
        {
            TestDeviceCallbackHandler testDeviceCallbackHandler = null;
            var registryManager = RegistryManager.CreateFromConnectionString(Configuration.IoTHub.ConnectionString);

            using var cts = new CancellationTokenSource(FaultInjection.RecoveryTimeMilliseconds);

            var propName = Guid.NewGuid().ToString();
            var props    = new TwinCollection();

            // Configure the callback and start accepting twin changes.
            Func <DeviceClient, TestDevice, Task> initOperation = async(deviceClient, testDevice) =>
            {
                testDeviceCallbackHandler = new TestDeviceCallbackHandler(deviceClient, Logger);
                await testDeviceCallbackHandler.SetTwinPropertyUpdateCallbackHandlerAsync(propName).ConfigureAwait(false);
            };

            // Change the twin from the service side and verify the device received it.
            Func <DeviceClient, TestDevice, Task> testOperation = async(deviceClient, testDevice) =>
            {
                var propValue = Guid.NewGuid().ToString();
                testDeviceCallbackHandler.ExpectedTwinPropertyValue = propValue;

                Logger.Trace($"{nameof(Twin_DeviceDesiredPropertyUpdateRecoveryAsync)}: name={propName}, value={propValue}");

                Task serviceSendTask  = RegistryManagerUpdateDesiredPropertyAsync(testDevice.Id, propName, propValue);
                Task twinReceivedTask = testDeviceCallbackHandler.WaitForTwinCallbackAsync(cts.Token);

                var tasks = new List <Task>()
                {
                    serviceSendTask, twinReceivedTask
                };
                while (tasks.Count > 0)
                {
                    Task completedTask = await Task.WhenAny(tasks).ConfigureAwait(false);

                    completedTask.GetAwaiter().GetResult();
                    tasks.Remove(completedTask);
                }
            };

            await FaultInjection
            .TestErrorInjectionAsync(
                s_devicePrefix,
                TestDeviceType.Sasl,
                transport,
                proxyAddress,
                faultType,
                reason,
                delayInSec,
                FaultInjection.DefaultDurationInSec,
                initOperation,
                testOperation,
                () => { return(Task.FromResult(false)); },
                Logger)
            .ConfigureAwait(false);
        }
Пример #2
0
        // Token: 0x060002D5 RID: 725 RVA: 0x00012C14 File Offset: 0x00010E14
        protected override void OnWriteBodyContents(XmlDictionaryWriter dictionaryXml)
        {
            bool error = true;
            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent           = true;
            xmlWriterSettings.IndentChars      = "  ";
            xmlWriterSettings.ConformanceLevel = ConformanceLevel.Document;
            XmlWriter xmlWriter  = XmlWriter.Create(dictionaryXml, new XmlWriterSettings());
            string    callerInfo = "LegacyBodyWriter.OnWriteBodyContents";

            if (!this.parseSuccess)
            {
                ExTraceGlobals.FrameworkTracer.TraceError <string>((long)this.GetHashCode(), "[OnWriteBodyContents()] 'Validation failed. Provider \"{0}\"'", base.GetType().AssemblyQualifiedName);
                Common.GenerateErrorResponse(xmlWriter, "http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006", "600", Strings.InvalidRequest.ToString(), this.debugData, this.requestData, base.GetType().AssemblyQualifiedName);
            }
            else
            {
                IStandardBudget standardBudget = null;
                try
                {
                    FaultInjection.GenerateFault((FaultInjection.LIDs) 2917543229U);
                    standardBudget = StandardBudget.Acquire(this.requestData.User.Identity.GetSecurityIdentifier(), BudgetType.Ews, Common.GetSessionSettingsForCallerScope());
                    HttpContext.Current.Items["StartBudget"] = standardBudget.ToString();
                    standardBudget.CheckOverBudget();
                    standardBudget.StartConnection(callerInfo);
                    standardBudget.StartLocal(callerInfo, default(TimeSpan));
                    string text;
                    error = this.GenerateResponse(xmlWriter, standardBudget, out text);
                    HttpContext.Current.Items["EndBudget"] = standardBudget.ToString();
                    if (!string.IsNullOrEmpty(text))
                    {
                        HttpContext.Current.Response.Redirect(text, false);
                    }
                }
                catch (OverBudgetException)
                {
                    this.TraceExceptionAndGenerateErrorResponse(xmlWriter, Strings.ServerBusy.ToString(), "[OnWriteBodyContents()] 'Account has exceeded budget.");
                }
                catch (NonUniqueRecipientException ex)
                {
                    this.TraceExceptionAndGenerateErrorResponse(xmlWriter, Strings.ADUnavailable.ToString(), "[OnWriteBodyContents()] " + ex.Message);
                }
                catch (ADTransientException ex2)
                {
                    this.TraceExceptionAndGenerateErrorResponse(xmlWriter, Strings.ADUnavailable.ToString(), "[OnWriteBodyContents()] " + ex2.Message);
                }
                finally
                {
                    if (standardBudget != null)
                    {
                        try
                        {
                            FaultInjection.GenerateFault((FaultInjection.LIDs) 4081462589U);
                            standardBudget.Dispose();
                        }
                        catch (ADTransientException arg)
                        {
                            ExTraceGlobals.FrameworkTracer.TraceError <ADTransientException>((long)this.GetHashCode(), "[OnWriteBodyContents()] Got ADTransientException {0} while disposing budget.", arg);
                        }
                        standardBudget = null;
                    }
                }
            }
            PerformanceCounters.UpdateTotalRequests(error);
            RequestDetailsLoggerBase <RequestDetailsLogger> .Current.ActivityScope.Action = "POX";
        }
Пример #3
0
        // Token: 0x06001B4C RID: 6988 RVA: 0x00067418 File Offset: 0x00065618
        protected override bool InternalExecute()
        {
            if (this.datapoints == null || this.datapoints.Length == 0)
            {
                return(true);
            }
            InstrumentationSettings instrumentationSettings = this.GetInstrumentationSettings();

            if (!instrumentationSettings.IsInstrumentationEnabled())
            {
                return(true);
            }
            UserContext userContext          = this.GetUserContext();
            Stopwatch   stopwatch            = Stopwatch.StartNew();
            Datapoint   chunkHeaderDatapoint = this.GetChunkHeaderDatapoint(this.datapoints[0].Time);
            int         num;
            IDictionary <DatapointConsumer, LogDatapoint.ClientLogEventList> dictionary = this.TriageAndConvertDatapoints(userContext, chunkHeaderDatapoint, instrumentationSettings, out num);
            long elapsedMilliseconds      = stopwatch.ElapsedMilliseconds;
            IList <ClientLogEvent> events = dictionary[DatapointConsumer.Watson].Events;

            if (events.Count > 0 && instrumentationSettings.IsClientWatsonEnabled)
            {
                this.clientWatsonHandler.ReportWatsonEvents(userContext, events, chunkHeaderDatapoint, this.datapoints);
            }
            FaultInjection.GenerateFault((FaultInjection.LIDs) 3804638525U);
            stopwatch.Restart();
            this.analyticsLogger(dictionary[DatapointConsumer.Analytics].Events);
            this.diagnosticsLogger(dictionary[DatapointConsumer.Diagnostics].Events);
            long elapsedMilliseconds2 = stopwatch.ElapsedMilliseconds;
            long num2 = 0L;
            long num3 = 0L;
            int  num4 = 0;

            if (this.isOwa && dictionary[DatapointConsumer.Inference].Events.Count > 0)
            {
                stopwatch.Restart();
                IActivityLogger activityLogger = this.GetActivityLogger();
                if (activityLogger != null)
                {
                    IList <Activity> list = this.CreateInferenceActivities(dictionary[DatapointConsumer.Inference].Events);
                    num2 = stopwatch.ElapsedMilliseconds;
                    num3 = 0L;
                    if (list.Count > 0)
                    {
                        num4 = list.Count;
                        stopwatch.Restart();
                        this.WriteInferenceActivities(list, activityLogger);
                        num3 = stopwatch.ElapsedMilliseconds;
                    }
                }
            }
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.CreateDatapointEventsElapsed, elapsedMilliseconds);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.TotalDatapointSize, num);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.AnalyticsDatapointCount, dictionary[DatapointConsumer.Analytics].Events.Count);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.AnalyticsDatapointSize, dictionary[DatapointConsumer.Analytics].DatapointTotalSize);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.InferenceDatapointCount, dictionary[DatapointConsumer.Inference].Events.Count);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.InferenceDatapointSize, dictionary[DatapointConsumer.Inference].DatapointTotalSize);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.DiagnosticsDatapointCount, dictionary[DatapointConsumer.Diagnostics].Events.Count);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.DiagnosticsDatapointSize, dictionary[DatapointConsumer.Diagnostics].DatapointTotalSize);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.WatsonDatapointCount, dictionary[DatapointConsumer.Watson].Events.Count);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.WatsonDatapointSize, dictionary[DatapointConsumer.Watson].DatapointTotalSize);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.DatapointsToLoggerElapsed, elapsedMilliseconds2);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.InferenceActivitiesToMailboxCount, num4);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.CreateInferenceActivitiesElapsed, num2);
            base.CallContext.ProtocolLog.Set(LogDatapointMetadata.InferenceActivitiesToMailboxElapsed, num3);
            return(true);
        }