Пример #1
0
        public LayoutControl(LayoutAnalyzerPackage package)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            InitializeComponent();

            package.TextManagerEventSink.ColorsChanged += () => ResetColors(package);
            ResetColors(package);


            DataContextChanged += (sender, args) =>
            {
                if (args.NewValue is not Layout layout)
                {
                    tree.ItemsSource = null;
                    return;
                }

                tree.ItemContainerGenerator.StatusChanged += OnGeneratorStatusChanged;
                tree.ItemsSource = new[] { layout };
Пример #2
0
        public LayoutWindow(LayoutAnalyzerPackage package)
        {
            Caption = Title;
            LayoutControl content = new(package);

            Content = content;

            string frameworkDirectory = package.HostRunner.TargetFramework switch
            {
                TargetFramework.NetFramework => "net472",
                TargetFramework.NetCore => "netcoreapp3.1",
                TargetFramework.Net5Plus => "net5.0",
                _ => throw new ArgumentException("")
            };
            string projectAssemblyPath = $@"C:\Users\stefa\source\repos\LayoutAnalyzer\devsko.LayoutAnalyzer.TestProject\bin\{(package.HostRunner.IsDebug ? "Debug" : "Release")}\{frameworkDirectory}\devsko.LayoutAnalyzer.TestProject.dll";

            content.Unloaded += (sender, args) =>
                                _cancel.Cancel();

            content.Loaded += (sender, args) =>
            {
                _cancel             = CancellationTokenSource.CreateLinkedTokenSource(VsShellUtilities.ShutdownToken);
                content.DataContext = null;

                package.JoinableTaskFactory.RunAsync(async() =>
                {
                    try
                    {
                        await AnalyzeAsync("System.IO.Pipelines.Pipe, System.IO.Pipelines", TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                        await AnalyzeAsync(typeof(int).AssemblyQualifiedName, TimeSpan.Zero).ConfigureAwait(false);
                        await AnalyzeAsync(typeof(int).AssemblyQualifiedName, TimeSpan.Zero).ConfigureAwait(false);
                        await AnalyzeAsync(typeof(int).AssemblyQualifiedName, TimeSpan.FromSeconds(65)).ConfigureAwait(false);

                        await AnalyzeAsync("devsko.LayoutAnalyzer.TestProject.Explicit, devsko.LayoutAnalyzer.TestProject", TimeSpan.FromSeconds(5)).ConfigureAwait(false);

                        await AnalyzeAsync("x,y", TimeSpan.Zero).ConfigureAwait(false);

                        //await AnalyzeAsync("devsko.LayoutAnalyzer.TestProject.S1, devsko.LayoutAnalyzer.TestProject").ConfigureAwait(false);
                    }
                    catch (TaskCanceledException)
                    { }

                    async Task AnalyzeAsync(string typeName, TimeSpan delayAfter)
                    {
                        try
                        {
                            Layout layout = await package.HostRunner.AnalyzeAsync(projectAssemblyPath + '|' + typeName, _cancel.Token).ConfigureAwait(false);
                            if (layout is not null)
                            {
                                await package.OutWriter.WriteLineAsync($"Layout from HOST ({package.HostRunner.Id}) took {layout.ElapsedTime}").ConfigureAwait(false);
                            }

                            await package.JoinableTaskFactory.SwitchToMainThreadAsync();
                            content.DataContext = layout;

                            await Task.Delay(delayAfter, _cancel.Token).ConfigureAwait(false);
                        }
                        catch (TaskCanceledException)
                        {
                            await package.OutWriter.WriteLineAsync("Analysis canceled");
                            throw;
                        }
                        catch (Exception ex)
                        {
                            content.DataContext = null;
                            await package.OutWriter.WriteLineAsync("Unexpected error: " + ex.ToStringDemystified()).ConfigureAwait(false);
                        }
                    }
                });
            };
        }
    }