Beispiel #1
0
        public void ItSetsConfigDataAndUserPropertiesInServiceModel()
        {
            // Arrange
            DiagnosticsEventsApiModel target = new DiagnosticsEventsApiModel();

            target.SessionId = 123;

            ServicesConfig config = new ServicesConfig
            {
                DeploymentId   = "Id1",
                SolutionType   = "Sample",
                SolutionName   = "SampleSolution",
                IoTHubName     = "SampleHub",
                CloudType      = "Public",
                SubscriptionId = "12345"
            };

            // Act
            DiagnosticsEventsServiceModel model = target.ToServiceModel(config);

            // Assert
            Assert.Equal(config.DeploymentId, model.DeploymentId);
            Assert.Equal(config.SolutionType, model.SolutionType);
            Assert.Equal(target.SessionId, model.SessionId);
            Assert.Equal(config.SubscriptionId, model.UserProperties["SubscriptionId"]);
            Assert.Equal(config.SolutionName, model.UserProperties["SolutionName"]);
            Assert.Equal(config.CloudType, model.UserProperties["CloudType"]);
            Assert.Equal(config.IoTHubName, model.UserProperties["IoTHubName"]);
        }
        public async Task <bool> LogEventsAsync(DiagnosticsEventsServiceModel data)
        {
            DateTimeOffset now      = DateTimeOffset.UtcNow;
            TimeSpan       duration = now - lastPolled;

            if (userConsent == null || duration.TotalSeconds >= this.servicesConfig.UserConsentPollingIntervalSecs)
            {
                try
                {
                    userConsent = await this.diagnosticsClient.CheckUserConsentAsync();

                    lastPolled = now;
                }
                catch (Exception e)
                {
                    this.log.Error(e.Message, () => { });
                }
            }

            if (userConsent == true)
            {
                string jsonData = JsonConvert.SerializeObject(data);
                return(await this.diagnosticsClient.SendAsync(jsonData));
            }

            return(false);
        }
Beispiel #3
0
 public DiagnosticsClientTest()
 {
     this.mockHttpClient = new Mock <IHttpClient>();
     this.mockLogger     = new Mock <ILogger>();
     this.data           = new DiagnosticsEventsServiceModel
     {
         EventId      = "MockEventId",
         EventType    = "MockEvent",
         DeploymentId = "MockDeploymentId",
         SolutionType = "MockSolutionType",
         Timestamp    = DateTimeOffset.UtcNow,
     };
 }
        public DiagnosticsEventsServiceTest()
        {
            this.diagnosticsClient = new Mock <IDiagnosticsClient>();
            this.servicesConfig    = new Mock <IServicesConfig>();
            this.data = new DiagnosticsEventsServiceModel
            {
                EventId      = "MockEventId",
                EventType    = "MockEvent",
                DeploymentId = "MockDeploymentId",
                SolutionType = "MockSolutionType",
                Timestamp    = DateTimeOffset.UtcNow
            };

            this.target = new DiagnosticsEventsService(
                this.diagnosticsClient.Object,
                this.servicesConfig.Object,
                new Logger("UnitTest"));
        }
Beispiel #5
0
        public void ItSetsConfigDataInServiceModel()
        {
            // Arrange
            DiagnosticsEventsApiModel target = new DiagnosticsEventsApiModel();
            ServicesConfig            config = new ServicesConfig
            {
                DeploymentId = "Id1",
                SolutionType = "Sample"
            };

            // Act
            DiagnosticsEventsServiceModel model = target.ToServiceModel(config);

            // Assert
            Assert.Equal(config.DeploymentId, model.DeploymentId);
            Assert.Equal(config.SolutionType, model.SolutionType);

            Assert.Null(model.SessionId);
        }
Beispiel #6
0
        public async Task <bool> LogEventsAsync(DiagnosticsEventsServiceModel serviceModelData)
        {
            DateTimeOffset now      = DateTimeOffset.UtcNow;
            TimeSpan       duration = now - lastPolled;

            if (userConsent == null || duration.TotalSeconds >= this.servicesConfig.UserConsentPollingIntervalSecs)
            {
                try
                {
                    userConsent = await this.diagnosticsClient.CheckUserConsentAsync();

                    lastPolled = now;
                }
                catch (Exception e)
                {
                    this.log.Error(e.Message, () => { });
                }
            }

            if (userConsent == true)
            {
                try
                {
                    // Call out to App Insights
                    TelemetryClient telemetryClient =
                        this.telemetryClientWrapper.CreateTelemetryClient(this.servicesConfig);
                    var appInsightsModelData = AppInsightsDataModel.FromServiceModel(serviceModelData);
                    this.telemetryClientWrapper.SetSessionAndDeploymentId(telemetryClient, appInsightsModelData);
                    this.telemetryClientWrapper.TrackEvent(telemetryClient, appInsightsModelData);

                    return(true);
                }
                catch (Exception e)
                {
                    this.log.Error(e.Message, () => { });
                }
            }

            return(false);
        }