public void CreateOrUpdateContext(CommandConnection item)
        {
            var isNewContext = false;

            var context = GetContext(item);

            if (context != null)
            {
                context.ContextStatistics.NumberOfConnections++;
            }
            else
            {
                isNewContext = true;
                context      = new Context
                {
                    ObjectContextId      = item.ObjectContextId,
                    Url                  = item.HttpInfo.Url,
                    AtDateTime           = item.AtDateTime,
                    ObjectContextName    = item.ObjectContextName,
                    ContextStatistics    = { NumberOfConnections = 1 },
                    ManagedThreadId      = item.ManagedThreadId,
                    HttpContextCurrentId = item.HttpInfo.HttpContextCurrentId,
                    ApplicationIdentity  = item.ApplicationIdentity
                };
                PluginContext.ProfilerData.Contexts.Add(context);

                if (item.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity))
                {
                    GuiModelData.Contexts.Add(context);
                }

                PluginContext.NotifyPluginsHost(NotificationType.Update, 1);
                UpdateAppIdentityNotificationsCount(context.ApplicationIdentity);
            }

            UpdateMultipleContextPerRequestInfo(context);
            UpdateNumberOfConnections(GetStackTrace(item));

            var trafficUrl = GetTrafficUrl(item);

            UpdateNumberOfConnections(trafficUrl);
            if (trafficUrl != null && isNewContext)
            {
                trafficUrl.NumberOfContexts++;
            }
        }
Exemple #2
0
        public void GetReleaseInfo(string url)
        {
            var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            Task.Factory.StartNew(() =>
            {
                if (!NetworkStatus.IsConnectedToInternet())
                {
                    return(null);
                }

                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("user-agent", "DNTProfiler");
                    var jsonData = webClient.DownloadString(url);
                    var gitHubProjectReleases = JsonHelper.DeserializeObject <GitHubProjectRelease[]>(jsonData);

                    var releases = new List <ReleaseInfo>();
                    foreach (var release in gitHubProjectReleases)
                    {
                        foreach (var asset in release.Assets)
                        {
                            releases.Add(new ReleaseInfo
                            {
                                ReleaseHtmlUrl     = release.HtmlUrl,
                                ReleaseTagName     = release.TagName,
                                AssetCreatedAt     = asset.CreatedAt,
                                AssetName          = asset.Name,
                                AssetSize          = asset.Size,
                                AssetDownloadCount = asset.DownloadCount
                            });
                        }
                    }

                    return(releases.OrderByDescending(releaseInfo => releaseInfo.AssetCreatedAt).ToList());
                }
            }).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    if (task.Exception != null)
                    {
                        task.Exception.Flatten().Handle(ex =>
                        {
                            new ExceptionLogger().LogExceptionToFile(ex, AppMessenger.LogFile);
                            AppMessenger.Messenger.NotifyColleagues("ShowException", ex);
                            return(true);
                        });
                    }
                    return;
                }

                var releaseInfo = task.Result;
                if (releaseInfo == null || !releaseInfo.Any())
                {
                    return;
                }

                _mainGuiModel.ReleaseInfo     = releaseInfo;
                _mainGuiModel.SelectedRelease = releaseInfo.FirstOrDefault();
                _context.NotifyPluginsHost(NotificationType.Reset, releaseInfo.Count);
            }, taskScheduler);
        }
Exemple #3
0
        public void Start(string filePath)
        {
            _context.NotifyPluginsHost(NotificationType.ShowBusyIndicator, 1);
            var isActive   = _mainGuiModel.DumperSettings.IsActive;
            var filesCount = _mainGuiModel.Files.Count;

            _mainGuiModel.DumperSettings.IsActive = false;

            var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            Task.Factory.StartNew(() =>
            {
                var itemsList = JsonHelper.DeserializeFromFile <IList <BaseInfo> >(filePath, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Objects,
                });
                return(itemsList);
            }).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    if (task.Exception != null)
                    {
                        task.Exception.Flatten().Handle(ex =>
                        {
                            new ExceptionLogger().LogExceptionToFile(ex, AppMessenger.LogFile);
                            AppMessenger.Messenger.NotifyColleagues("ShowException", ex);
                            return(true);
                        });
                    }
                    _context.NotifyPluginsHost(NotificationType.HideBusyIndicator, 1);
                    return;
                }

                try
                {
                    var itemsList = task.Result;
                    if (itemsList == null || !itemsList.Any())
                    {
                        return;
                    }

                    clearAllData();
                    _context.NotifyPluginsHost(NotificationType.ResetAll, 0);

                    var count = 0;
                    foreach (var item in itemsList)
                    {
                        var baseInfo        = item;
                        baseInfo.ReceivedId = IdGenerator.GetId();

                        switch (baseInfo.InfoType)
                        {
                        case InfoType.Command:
                            var command = (Command)baseInfo;
                            command.SetCommandStatistics();
                            _context.ProfilerData.Commands.Add(command);
                            break;

                        case InfoType.CommandConnection:
                            _context.ProfilerData.Connections.Add((CommandConnection)baseInfo);
                            break;

                        case InfoType.CommandResult:
                            _context.ProfilerData.Results.Add((CommandResult)baseInfo);
                            break;

                        case InfoType.CommandTransaction:
                            _context.ProfilerData.Transactions.Add((CommandTransaction)baseInfo);
                            break;
                        }

                        if (count++ % 100 == 0)
                        {
                            DispatcherHelper.DoEvents();
                        }
                    }
                }
                finally
                {
                    _mainGuiModel.DumperSettings.IsActive = isActive;
                    _context.NotifyPluginsHost(NotificationType.HideBusyIndicator, 1);
                    _context.NotifyPluginsHost(NotificationType.Reset, filesCount);
                }
            }, taskScheduler);
        }