示例#1
0
        public async Task <IHttpActionResult> PostBasic(Guid telemetryKey, BasicTelemetryItem request)
        {
            if (request == null)
            {
                request = new BasicTelemetryItem();
            }

            TelemetryRootObject program = await this.work.GetMonitoredProgram(telemetryKey).ConfigureAwait(false);

            if (program == null)
            {
                throw new BadRequestException($"Program with telemetry key [{telemetryKey}] does not exist");
            }

            try
            {
                TelemetryItem item = TelemetryMapper.Map(telemetryKey, request);

                string ip = this.Request.GetClientIp();

                await this.InsertDataInternal(new[] { item }, program, ip).ConfigureAwait(false);

                return(await Task.FromResult(this.StatusCode(HttpStatusCode.OK)).ConfigureAwait(false));
            }
            catch (Exception ex)
            {
                return(await Task.FromResult(this.InternalServerError(new InvalidOperationException($"Error while inserting entry: {ex}"))).ConfigureAwait(false));
            }
        }
示例#2
0
        /// <summary>
        /// Maps the specified basic item.
        /// </summary>
        /// <param name="telemetryKey"></param>
        /// <param name="basicItem">The basic item.</param>
        /// <returns>TelemetryItem.</returns>
        public static TelemetryItem Map(Guid telemetryKey, BasicTelemetryItem basicItem)
        {
            if (!Version.TryParse(basicItem.ProgramVersion, out _))
            {
                basicItem.ProgramVersion = "0.0.0.0";
            }

            TelemetryItem item = new TelemetryItem
            {
                TelemetryKey      = telemetryKey,
                UserIdentifier    = basicItem.UserIdentifier,
                TelemetryItemType = basicItem.TelemetryItemType,
                LogMessage        = basicItem.LogMessage,
                EntryKey          = basicItem.EventName,
                Sequence          = "NotSpecified",
                Properties        = basicItem.Properties,
                Measurements      = basicItem.Metrics,
                VersionData       = new VersionData(basicItem.ProgramVersion, basicItem.ProgramVersion),
                Timestamp         = basicItem.Timestamp
            };

            if (basicItem.TelemetryItemType == TelemetryItemTypes.Exception)
            {
                item.Exceptions = new List <TelemetryItem.ExceptionInfo>();
                item.Exceptions.Add(new TelemetryItem.ExceptionInfo()
                {
                    Message = basicItem.ErrorMessage
                });
            }
            return(item);
        }
示例#3
0
        public async Task SendBasicTelemetry(Guid guid, BasicTelemetryItem telemetry)
        {
            HttpResponseMessage response = await this.HttpClient.PostAsJsonAsync($"{this.BaseUrl.TrimEnd('/')}/api/v1/telemetry/{guid.ToString()}/basic", telemetry).ConfigureAwait(false);

            var text = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            Console.WriteLine(text);
            response.EnsureSuccessStatusCode();
        }
        public void TestException()
        {
            var basicItem = new BasicTelemetryItem()
            {
                TelemetryItemType = TelemetryItemTypes.Exception,
                Timestamp         = new DateTimeOffset(1988, 02, 28, 0, 0, 0, new TimeSpan(0)),
                ErrorMessage      = "An error message"
            };
            var item = TelemetryMapper.Map(this.testTelemetryKey, basicItem);

            Assert.AreEqual(TelemetryItemTypes.Exception, item.TelemetryItemType);
            Assert.AreEqual("An error message", item.Exceptions.Single().Message);
        }
        public void TestDefault()
        {
            var basicItem = new BasicTelemetryItem();
            var item      = TelemetryMapper.Map(this.testTelemetryKey, basicItem);

            Assert.IsNotNull(item.EntryKey);
            Assert.IsNotNull(item.UserIdentifier);
            Assert.AreEqual("0.0.0.0", item.VersionData.FileVersion);
            Assert.AreEqual("0.0.0.0", item.VersionData.AssemblyVersion);
            Assert.AreNotEqual(Guid.Empty, item.Id);
            Assert.AreEqual(this.testTelemetryKey, item.TelemetryKey);
            Assert.AreEqual(TelemetryItemTypes.Event, item.TelemetryItemType);
            Assert.AreNotEqual(default(DateTimeOffset), item.Timestamp);
            Assert.IsTrue(!string.IsNullOrEmpty(basicItem.EventName));
            Assert.AreEqual(basicItem.EventName, item.EntryKey);
        }
        public void TestLogMessage()
        {
            var basicItem = new BasicTelemetryItem()
            {
                LogMessage        = "Boo",
                TelemetryItemType = TelemetryItemTypes.LogMessage,
                EventName         = "LogMsg",
                Timestamp         = new DateTimeOffset(1988, 02, 28, 0, 0, 0, new TimeSpan(0)),
                ProgramVersion    = "3.4",
                UserIdentifier    = "JimBeam"
            };
            var item = TelemetryMapper.Map(this.testTelemetryKey, basicItem);

            Assert.AreEqual(TelemetryItemTypes.LogMessage, item.TelemetryItemType);
            Assert.AreEqual("Boo", item.LogMessage);
            Assert.AreEqual(new DateTimeOffset(1988, 02, 28, 0, 0, 0, new TimeSpan(0)), item.Timestamp);
            Assert.AreEqual("JimBeam", item.UserIdentifier);
            Assert.AreEqual("3.4", item.VersionData.FileVersion);
            Assert.AreEqual("3.4", item.VersionData.AssemblyVersion);
            Assert.IsTrue(!string.IsNullOrEmpty(basicItem.EventName));
            Assert.AreEqual(basicItem.EventName, item.EntryKey);
        }
示例#7
0
        public async Task <IHttpActionResult> PostBasic(Guid telemetryKey, BasicTelemetryItem request)
        {
            if (request == null)
            {
                request = new BasicTelemetryItem();
            }

            TelemetryRootObject program = await this.work.GetMonitoredProgram(telemetryKey).ConfigureAwait(false);

            if (program == null)
            {
                throw new BadRequestException($"Program with telemetry key [{telemetryKey}] does not exist");
            }

            if (!Version.TryParse(request.ProgramVersion, out _))
            {
                request.ProgramVersion = "0.0.0.0";
            }

            TelemetryItem item = new TelemetryItem
            {
                UserIdentifier = request.UserIdentifier
                , EntryKey     = request.EventName
                , Properties   = request.Properties
                , Measurements = request.Metrics
                , VersionData  = new VersionData(request.ProgramVersion, request.ProgramVersion)
                , Timestamp    = request.Timestamp
            };


            string ip = this.Request.GetClientIp();

            await this.InsertDataInternal(new [] { item }, program, ip).ConfigureAwait(false);

            return(await Task.FromResult(this.StatusCode(HttpStatusCode.OK)).ConfigureAwait(false));
        }