예제 #1
0
        public void Execute()
        {
            var walker = _directoryWalkerFactory.New(x =>
            {
                x.Directory(_directory);

                x.FileRule(y =>
                {
                    y.Extension("csproj");

                    y.Execute(filePath =>
                    {
                        try
                        {
                            var filePathUri = new Uri(filePath);

                            var project = new Project(filePath);

                            var items = project.Items.Where(item =>
                                                            item.ItemType == "Reference" &&
                                                            item.Metadata.Any(md =>
                                                                              md.Name == "HintPath" && md.UnevaluatedValue.Contains("packages")
                                                                              )
                                                            ).ToList();

                            items.ForEach(item =>
                            {
                                var hintPathMetadata = item.Metadata.First(md => md.Name == "HintPath");

                                var oldHintPath = hintPathMetadata.UnevaluatedValue;

                                var oldHintPathParts = oldHintPath.Split(
                                    new[] { "packages" },
                                    StringSplitOptions.RemoveEmptyEntries);

                                var newHintPath    = _newPath + oldHintPathParts[1];
                                var newHintPathUri = new Uri(newHintPath);

                                var newRelativeHintPathUri = filePathUri.MakeRelativeUri(newHintPathUri);

                                hintPathMetadata.UnevaluatedValue = newRelativeHintPathUri.ToString();

                                _traceWriter.Output(string.Format("Switch: {0} to {1}", oldHintPath, hintPathMetadata.UnevaluatedValue));
                            });

                            project.Save();
                        }
                        catch (InvalidProjectFileException)
                        {
                            _traceWriter.Output(string.Format("Skipping: {0}", filePath));
                        }
                    });
                });
            });

            walker.Execute();
        }
예제 #2
0
        public void Execute()
        {
            var graph = new DataAccess.Graphing.Graph();
            var nodes = new List <INode>();

            var walker = _directoryWalkerFactory.New(x =>
            {
                x.Directory(_directory);

                _excludes.ToList().ForEach(x.Exclude);

                x.FileRule(y =>
                {
                    y.Extension("sln");
                    y.Execute(filePath =>
                    {
                        Solution solution;
                        Solution.TryParse(_directory, filePath, out solution);

                        nodes.Add(solution);
                    });
                });

                x.FileRule(y =>
                {
                    y.Extension("csproj");
                    y.Execute(filePath =>
                    {
                        Project project;
                        Project.TryParse(_directory, filePath, out project);

                        nodes.Add(project);
                    });
                });
            });

            walker.TraceAction(_traceWriter.Output);
            walker.Execute();

            _traceWriter.Output("Adding nodes to graph...");
            nodes.ForEach(n => graph.AddNode(n));

            _traceWriter.Output("Computing edge weights");
            graph.ComputeWeights();

            _traceWriter.Output("Saving to database...");
            _graphDatabase.Save(graph);
        }
예제 #3
0
        public void Execute()
        {
            var walker = _directoryWalkerFactory.New(x =>
            {
                x.Directory(_directory);

                _excludes.ToList().ForEach(x.Exclude);

                x.FileRule(y =>
                {
                    y.Extension("csproj");

                    y.Execute(filePath =>
                    {
                        try
                        {
                            var project = new Project(filePath);

                            if (!TryRemoveReference(project, _isProject, _itemName, _itemPath))
                            {
                                return;
                            }

                            _traceWriter.Output(string.Format("Saving project: {0}", filePath));
                            project.Save();
                        }
                        catch (InvalidProjectFileException)
                        {
                            _traceWriter.Output(string.Format("Skipping: {0}", filePath));
                        }
                    });
                });
            });

            walker.Execute();
        }
예제 #4
0
        public void Execute()
        {
            var walker = _directoryWalkerFactory.New(x =>
            {
                x.Directory(_directory);

                _excludes.ToList().ForEach(x.Exclude);

                x.FileRule(y =>
                {
                    y.Extension("csproj");

                    y.Execute(filePath =>
                    {
                        try
                        {
                            var filePathUri    = new Uri(filePath);
                            var newHintPathUri = new Uri(_packagePath);

                            var newRelativeHintPathUri = filePathUri.MakeRelativeUri(newHintPathUri);

                            var project = new Project(filePath);

                            if (!TryRemoveReference(project, _isProject, _itemName, _itemPath))
                            {
                                return;
                            }

                            _traceWriter.Output(string.Format("Working on: {0}", filePath));

                            _traceWriter.Output(string.Format("Adding reference: {0}, {1}", _itemName, newRelativeHintPathUri));
                            AddAssemblyReference(project, _itemName, newRelativeHintPathUri);

                            _traceWriter.Output("Updating packages.config");
                            UpdatePackagesConfig(project, _packageName, _packageVersion);

                            AddPackagesConfigItem(project);

                            _traceWriter.Output("Saving...");
                            project.Save();
                        }
                        catch (InvalidProjectFileException)
                        {
                            _traceWriter.Output(string.Format("Skipping: {0}", filePath));
                        }
                    });
                });
            });

            walker.Execute();
        }
예제 #5
0
        public void Execute()
        {
            var walker = _directoryWalkerFactory.New(x =>
            {
                x.Directory(_settings.Directory);
                _settings.Excludes.ToList().ForEach(x.Exclude);

                x.FileRule(y =>
                {
                    y.Extension("csproj");

                    y.Execute(filePath =>
                    {
                        try
                        {
                            var frameworks = new[] { "v3.5", "v4.0", "v4.5" };

                            var project = new Project(filePath);

                            var targetFrameworkVersion = project.Properties.FirstOrDefault(p => p.Name == "TargetFrameworkVersion");

                            if (targetFrameworkVersion == null || !frameworks.Contains(targetFrameworkVersion.UnevaluatedValue))
                            {
                                return;
                            }

                            targetFrameworkVersion.UnevaluatedValue = _settings.TargetFramework;

                            project.Save();
                        }
                        catch (InvalidProjectFileException)
                        {
                            _traceWriter.Output(string.Format("Skipping: {0}", filePath));
                        }
                    });
                });
            });

            walker.Execute();
        }
예제 #6
0
 public void Execute()
 {
     _traceWriter.Output(_message);
     _traceWriter.Output(_arguments);
 }
예제 #7
0
        public void Execute()
        {
            _traceWriter.Output("Loading graph from database...");

            var graph = _graphDatabase.Load();

            _traceWriter.Output("Transforming nodes...");

            var nodes = graph.Nodes.Where(x => x.NodeTypeID == NodeTypes.Solution || x.NodeTypeID == NodeTypes.Project).ToList();

            var gexfNodes = nodes
                            .Select(x =>
                                    new nodecontent
            {
                id    = x.NodeID.ToString(),
                label = x.Name,
                Items = new object[]
                {
                    new attvaluescontent
                    {
                        attvalue = new[]
                        {
                            new attvalue
                            {
                                @for  = "0",
                                value = Enum.GetName(typeof(NodeTypes), x.NodeTypeID)
                            }
                        }
                    }
                }
            }).ToArray();

            _traceWriter.Output("Transforming edges...");

            var gexfEdges =
                nodes.SelectMany(
                    x => x.Out
                    .Where(y => y.To.NodeTypeID == NodeTypes.Solution || y.To.NodeTypeID == NodeTypes.Project)
                    .Select(
                        r =>
                        new edgecontent
            {
                id              = r.RelationID.ToString(),
                source          = r.FromNodeID.ToString(),
                target          = r.ToNodeID.ToString(),
                weight          = (float)r.Weight,
                weightSpecified = true
            })).ToArray();

            _traceWriter.Output("Constructing gexf format");

            var gexf = new gexfcontent
            {
                meta = new metacontent
                {
                    lastmodifieddate = DateTime.UtcNow,
                    Items            = new[]
                    {
                        _creator,
                        _description
                    },
                    ItemsElementName = new[]
                    {
                        ItemsChoiceType1.creator,
                        ItemsChoiceType1.description,
                    }
                },
                graph = new graphcontent
                {
                    mode            = modetype.@static,
                    defaultedgetype = defaultedgetypetype.directed,
                    Items           = new object[]
                    {
                        new attributescontent
                        {
                            @class    = classtype.node,
                            attribute = new[]
                            {
                                new attributecontent()
                                {
                                    id    = "0",
                                    title = "NodeType",
                                    type  = attrtypetype.@string
                                }
                            }
                        },
                        new nodescontent {
                            node = gexfNodes
                        },
                        new edgescontent {
                            edge = gexfEdges
                        }
                    }
                }
            };

            _traceWriter.Output("Writing to gexf file...");

            var writer = new XmlSerializer(typeof(gexfcontent));

            using (var file = File.Create("repository.gexf"))
            {
                writer.Serialize(file, gexf);
                file.Close();
            }
        }