Exemplo n.º 1
0
        //
        // GET: /ShoppingCart/AddToCart/5

        public async Task <IActionResult> AddToCart(int id)
        {
            // Retrieve the product from the database
            var addedProduct = this.productsRepository.GetById(id);

            // Start timer for save process telemetry
            var startTime = System.DateTime.Now;

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(_db, this.productsRepository, HttpContext);

            cart.AddToCart(addedProduct);

            await _db.SaveChangesAsync(HttpContext.RequestAborted);

            // Trace add process
            var measurements = new Dictionary <string, double>()
            {
                { "ElapsedMilliseconds", System.DateTime.Now.Subtract(startTime).TotalMilliseconds }
            };

            _telemetry.TrackEvent("Cart/Server/Add", null, measurements);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
        //
        // GET: /ShoppingCart/AddToCart/5

        public async Task <ActionResult> AddToCart(int id)
        {
            // Retrieve the product from the database
            var addedProduct = db.Products
                               .Single(product => product.ProductId == id);

            // Start timer for save process telemetry
            var startTime = DateTime.Now;

            // Add it to the shopping cart
            var cart = ShoppingCart.GetCart(db, HttpContext);

            cart.AddToCart(addedProduct);

            await db.SaveChangesAsync(CancellationToken.None);

            // Trace add process
            var measurements = new Dictionary <string, double>()
            {
                { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds }
            };

            telemetry.TrackEvent("Cart/Server/Add", null, measurements);

            // Go back to the main store page for more shopping
            return(RedirectToAction("Index"));
        }
        void SubscribeTelemetryEvents()
        {
            events
            .Of <object>()
            .Where(ev => ev.IsBrowsable())
            .Subscribe(x => {
                var ev = x as Event;

                if (ev == null)
                {
                    var eventName  = x.GetName();
                    var properties = x.GetProperties();
                    var metrics    = x.GetMetrics();

                    telemetry.TrackEvent(eventName, properties, metrics);
                }
                else
                {
                    telemetry.TrackEvent(ev.Name, ev.Properties, ev.Metrics);
                }
            });

            events
            .Of <TelemetryError> ()
            .Subscribe(err => {
                telemetry.TrackError(err);
            });
        }
        public void ProcessRequest(NewSignupRequest request)
        {
            _telemetryProvider.AddTelemetryEventProperty("IsMetro", request.IsMetro.ToString());
            _telemetryProvider.TrackEvent("RequestProcessed");

            SendNotificationEmail(request.IsMetro);
            CreateAndUploadBlob(request.IsMetro);
            UpdateDatabase(request.IsMetro);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation($"AppInsightsAzureFunctionDemo Start: {DateTime.Now}");

            var timer = System.Diagnostics.Stopwatch.StartNew();

            // Add custom data to the event
            // customEvents | where timestamp > ago(7d) | order by timestamp desc
            // https://microsoft.github.io/AzureTipsAndTricks/blog/tip195.html
            var dictionary = new Dictionary <string, string>();

            dictionary.Add("Function", "My AppInsightsAzureFunctionDemo");
            dictionary.Add("Caller", "Toni Pohl");
            dictionary.Add("Description", "This is the Azure function using App Insights description");
            _provider.TrackEvent($"Event: Start {DateTime.Now}", dictionary);

            // track a numeric value
            // customMetrics | order by timestamp desc
            _provider.TrackMetric("Metric: Ticks based on current time", DateTime.Now.Ticks);

            // track an exception
            // exceptions | order by timestamp desc
            _provider.TrackException(new Exception($"Exception: at {DateTime.Now}"));

            // track long running external service call
            // dependencies | order by timestamp desc
            _provider.TrackDependency("myDependency", "MyType", "myCall 1", DateTime.Now, timer.Elapsed, true);

            // Done
            _provider.TrackEvent($"Event: End {DateTime.Now}");

            string responseMessage = $"AppInsightsAzureFunctionDemo End: {DateTime.Now}";

            log.LogInformation(responseMessage);

            return(new OkObjectResult(responseMessage));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Index(string q)
        {
            var result = await search.Search(q);

            var count = q == "jumper" ? 0 : new Random().Next(3, 7);

            telemetryProvider.TrackEvent("Search",
                                         new Dictionary <string, string>()
            {
                { "term", q }
            }, new Dictionary <string, double>()
            {
                { "count", count }
            });

            return(View(result));
        }
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                _telemetry.TrackTrace("Order/Server/NullId");
                return(RedirectToAction("Index", new { invalidOrderSearch = Request.QueryString["id"] }));
            }

            var order = await _ordersQuery.FindOrderAsync(id.Value);

            var username = User.Identity.GetUserName();

            // If the username isn't the same as the logged in user, return as if the order does not exist
            if (order == null || !String.Equals(order.Username, username, StringComparison.Ordinal))
            {
                _telemetry.TrackTrace("Order/Server/UsernameMismatch");
                return(RedirectToAction("Index", new { invalidOrderSearch = id.ToString() }));
            }

            // Capture order review event for analysis
            var eventProperties = new Dictionary <string, string>()
            {
                { "Id", id.ToString() },
                { "Username", username }
            };
            var costSummary = new OrderCostSummary()
            {
                CartSubTotal = 0.ToString("C"),
                CartShipping = 0.ToString("C"),
                CartTax      = 0.ToString("C"),
                CartTotal    = 0.ToString("C"),
            };

            if (order.OrderDetails == null)
            {
                _telemetry.TrackEvent("Order/Server/NullDetails", eventProperties, null);
            }
            else
            {
                var eventMeasurements = new Dictionary <string, double>()
                {
                    { "LineItemCount", order.OrderDetails.Count }
                };
                _telemetry.TrackEvent("Order/Server/Details", eventProperties, eventMeasurements);

                costSummary = _shippingTaxCalc.CalculateCost(order.OrderDetails, order.PostalCode);
                //var itemsCount = order.OrderDetails.Sum(x => x.Count);
                //var subTotal = order.OrderDetails.Sum(x => x.Count * x.Product.Price);
                //var shipping = itemsCount * (decimal)6.00;
                //var tax = (subTotal + shipping) * (decimal)0.06;
                //var total = subTotal + shipping + tax;

                //costSummary.CartSubTotal = subTotal.ToString("C");
                //costSummary.CartShipping = shipping.ToString("C");
                //costSummary.CartTax = tax.ToString("C");
                //costSummary.CartTotal = total.ToString("C");
            }

            var viewModel = new OrderDetailsViewModel
            {
                OrderCostSummary = costSummary,
                Order            = order
            };

            return(View(viewModel));
        }