本文整理汇总了C#中Microsoft.ApplicationInsights.TelemetryClient.TrackDependency方法的典型用法代码示例。如果您正苦于以下问题:C# TelemetryClient.TrackDependency方法的具体用法?C# TelemetryClient.TrackDependency怎么用?C# TelemetryClient.TrackDependency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.ApplicationInsights.TelemetryClient
的用法示例。
在下文中一共展示了TelemetryClient.TrackDependency方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public ActionResult Index()
{
var sw = Stopwatch.StartNew();
var ai = new TelemetryClient();
var startTime = DateTime.UtcNow;
var newsViewModel = new List<NewsModel>();
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext == null) return View(newsViewModel);
//get user info
var spUser = clientContext.Web.CurrentUser;
clientContext.Load(spUser, user => user.LoginName);
clientContext.ExecuteQuery();
IDatabase cache = RedisHelper.Connection.GetDatabase();
var cacheKey = $"news_{spUser.LoginName}";
if (cache.KeyExists(cacheKey))
{
newsViewModel = JsonConvert.DeserializeObject<List<NewsModel>>(cache.StringGet(cacheKey));
sw.Stop();
var timespanCache = sw.Elapsed;
ViewBag.Time = $"{timespanCache.Minutes:00}m:{timespanCache.Seconds:00}s:{timespanCache.Milliseconds / 10:00}ms";
ai.TrackDependency("Redis", cacheKey, startTime, sw.Elapsed, true);
return View(newsViewModel);
}
//Get news items
Web web = clientContext.Web;
List newsList = web.GetList("sites/Portal/Lists/News");
clientContext.Load(newsList);
var items = newsList.GetItems(CamlQuery.CreateAllItemsQuery());
clientContext.Load(items,
includes =>
includes.Include(y => y["Device"], y => y["Department"], y => y.Client_Title,
y => y["NewsContent"]));
clientContext.ExecuteQuery();
//get user profile property
PeopleManager peopleManager = new PeopleManager(clientContext);
var profilePropertyNames = new[] { "Device", "SPS-Department", "Title" };
UserProfilePropertiesForUser profilePropertiesForUser = new UserProfilePropertiesForUser(
clientContext, spUser.LoginName, profilePropertyNames);
IEnumerable<string> profilePropertyValues =
peopleManager.GetUserProfilePropertiesFor(profilePropertiesForUser);
// Load the request and run it on the server.
clientContext.Load(profilePropertiesForUser);
clientContext.ExecuteQuery();
var propertyValues = profilePropertyValues as IList<string> ?? profilePropertyValues.ToList();
var devices = propertyValues.ToList()[0];
var department = propertyValues.ToList()[1];
foreach (var item in items)
{
TaxonomyFieldValueCollection col = item["Device"] as TaxonomyFieldValueCollection;
foreach (var taxItem in col)
{
if (devices.Contains(taxItem.Label))
{
int index = newsViewModel.FindIndex(i => i.Title == item.Client_Title);
if (index != 0)
{
newsViewModel.Add(new NewsModel(item.Client_Title, item["NewsContent"].ToString()));
}
}
}
}
cache.StringSet(cacheKey, JsonConvert.SerializeObject(newsViewModel), new TimeSpan(0, 0, 1, 0));
}
sw.Stop();
var timespan = sw.Elapsed;
ViewBag.Time = $"{timespan.Minutes:00}m:{timespan.Seconds:00}s:{timespan.Milliseconds / 10:00}ms";
ai.TrackDependency("SharePoint", "GetNews", startTime, sw.Elapsed, true);
return View(newsViewModel);
}
示例2: GetTips
public async Task<JsonpResult> GetTips()
{
IDatabase cache = RedisHelper.Connection.GetDatabase();
var cacheKey = "tip";
var ai = new TelemetryClient();
var startTime = DateTime.UtcNow;
var timer = System.Diagnostics.Stopwatch.StartNew();
if (cache.KeyExists(cacheKey))
{
timer.Stop();
ai.TrackDependency("Redis", "GetTip", startTime, timer.Elapsed, true);
return new JsonpResult(JsonConvert.DeserializeObject<TipsModel>(await cache.StringGetAsync(cacheKey)));
}
var tip = GetTipForCurrentUser();
await cache.StringSetAsync(cacheKey, JsonConvert.SerializeObject(tip), new TimeSpan(0, 0, 10, 0));
timer.Stop();
ai.TrackDependency("SharePoint", "GetTip", startTime, timer.Elapsed, true);
return new JsonpResult(tip);
}