예제 #1
0
        void DependecyReport_Click(object sender, RoutedEventArgs e)
        {
            var dependencyReport = new DependencyReport(fileNames);
            var reportCreator    = dependencyReport.Run(list);
            var previewViewModel = new PreviewViewModel(dependencyReport.ReportSettings, reportCreator.Pages);

            viewer.SetBinding(previewViewModel);
            ActivateReportTab();
        }
예제 #2
0
        internal static int Poll(IUsageOpts opts)
        {
            var report = new DependencyReport();

            Poll(opts, report);
            var outFile = Path.GetFullPath("report.json");

            WriteToJson(report, outFile);
            Log.Info($"Report is in '{outFile}'.");
            return(0);
        }
예제 #3
0
        internal static void Poll(IUsageOpts opts, DependencyReport report)
        {
            var workDir = Path.GetFullPath(opts.WorkDir);
            var files   = GetAssemblyFiles(workDir).ToArray();

            Log.Info($"Found {files.Length} file(s) in '{workDir}'!");
            using (var resolv = new DefaultAssemblyResolver())
            {
                resolv.AddSearchDirectory(workDir);
                var rparam = new ReaderParameters {
                    AssemblyResolver = resolv
                };
                var nativeInsp  = new NativeInspector(opts.Assemblies);
                var managedInsp = new ManagedInspector(opts.Assemblies);
                foreach (var file in files)
                {
                    Poll(file, rparam, report, nativeInsp, managedInsp);
                }
            }
        }
예제 #4
0
        internal static int Invert(InvertOptions opts)
        {
            var report = new DependencyReport();

            Usager.Poll(opts, report);
            Log.Info($"{report.Files.Count} file(s) read for metadata.");
            var tempDir = Path.GetFullPath(opts.TempDir);

            Directory.CreateDirectory(tempDir);
            Log.Info($"Temporary directory is '{tempDir}'.");
            var reportFile = Path.Combine(tempDir, "report.json");

            Usager.WriteToJson(report, reportFile);
            Log.Info($"Report is in '{reportFile}'.");
            var outDir = Path.GetFullPath(opts.OutputDir);

            Directory.CreateDirectory(outDir);
            Log.Info($"Output directory is '{outDir}'.");
            var generated = GenerateNamespaces(report);
            var files     = generated.GroupBy(g => g.Key).ToArray();

            Log.Info($"Generating {files.Length} package(s)...");
            var newLine   = Environment.NewLine + Environment.NewLine;
            var names     = report.ManagedRefs.Keys.Concat(report.NativeRefs.Keys).Distinct().ToArray();
            var toCompile = new List <string>();

            foreach (var file in files)
            {
                var key = file.Key;
                var meta = CreateMetadata(key, names.First(n => Compare(n, key)));
                var nsps = new object[] { meta }.Concat(file.Select(f => f.Value)).ToArray();
                var code     = string.Join(newLine, nsps.Select(n => n.ToString()));
                var filePath = Path.Combine(tempDir, key);
                Log.Info($"'{ToRelativePath(tempDir, filePath)}' [{nsps.Length} namespace(s)]");
                File.WriteAllText(filePath, code, Encoding.UTF8);
                toCompile.Add(filePath);
            }
            IFileCopier copier  = new FileCopier();
            var         workDir = Path.GetFullPath(opts.WorkDir);

            copier.CopyFolder(workDir, outDir);
            Log.Info($"Compiling {toCompile.Count} package(s)...");
            var toInject = new List <string>();

            foreach (var package in toCompile)
            {
                var bytes = (new FileInfo(package)).Length;
                Log.Info($"'{ToRelativePath(tempDir, package)}' [{bytes} bytes]");
                var name = Path.GetFileNameWithoutExtension(package);
                var ass  = CreateAssembly(tempDir, name, new[] { package });
                if (ass == null)
                {
                    Log.Error("Sorry, I could not compile everything ;-(");
                    return(-1);
                }
                Log.Info($"  --> '{ass.FullName}'");
                toInject.Add(copier.CopyFile(ass.Location, outDir));
            }
            var oneFileOrMore = report.Files.Count >= 1 && files.Length >= 1;

            if (oneFileOrMore)
            {
                Log.Info($"Ensuring dependencies in '{outDir}'...");
                Log.InfoFormat(" added '{0}'!", CopyTypeRef <IVessel>(outDir));
                Log.InfoFormat(" added '{0}'!", CopyTypeRef <DefaultVessel>(outDir));
                Log.InfoFormat(" added '{0}'!", CopyTypeRef <MoqContainer>(outDir));
                Log.InfoFormat(" added '{0}'!", CopyTypeRef <AutofacContainer>(outDir));
            }
            if (oneFileOrMore)
            {
                Log.Info($"Processing {report.Files.Count} file(s)...");
                ProcessMarkedFiles(workDir, report, toInject, outDir);
            }
            Log.Info("Done.");
            return(0);
        }