Ejemplo n.º 1
0
        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            if (Filter != null && !Filter.ShouldTrace(eventCache, source, eventType, id, format, args, null, null))
            {
                return;
            }

            var client = new SmtpClient(Settings.Default.SmtpServer)
                {
                    Credentials = new NetworkCredential(Settings.Default.SmtpUsername, Settings.Default.SmtpPassword),
                    EnableSsl = true
                };
            var body = string.Format(format, args);
            var firstLine = new StringReader(body).ReadLine();
            if (firstLine.Length > 100)
            {
                firstLine = firstLine.Substring(0, 97).Trim() + "...";
            }
            var msg = new MailMessage
                {
                    From = new MailAddress(Settings.Default.NotificationFrom, "FitBot"),
                    To = {Settings.Default.NotificationTo},
                    Subject = $"{eventType} - {firstLine}",
                    Body = body
                };
            client.Send(msg);
        }
Ejemplo n.º 2
0
        public virtual async Task<ActionResult> GetTypeahead(string q)
        {
            // Query the search service
            var results = await SearchService.Search(new SearchFilter()
            {
                SearchTerm = q, /* For typeahead we want wildcard matching */
                IncludePrerelease = true,
                Take = 5
            });

            // Return the results formatted as JSON
            return Json(results.Data.AsEnumerable().Select(p => {
                var summary = p.Summary ?? p.Description;
                // Truncate to a single line
                summary = new StringReader(summary).ReadLine();
                if (summary.Length > 350)
                {
                    summary = summary.Substring(0, 350) + "...";
                }
                return new {
                    Key = p.Key,
                    Id = p.PackageRegistration.Id,
                    Title = p.Title,
                    Version = p.NormalizedVersion,
                    Summary = summary
                };
            }), JsonRequestBehavior.AllowGet);
        }