public ModulesGraph LoadState()
        {
            int[][]  jaggedArray;
            Module[] symbolTable;

            // Load
            using (var ctx = new DependencyGraphContext(_connectionString))
            {
                jaggedArray = new int[ctx.ModuleVertices.Count()][];
                for (int i = 0; i < jaggedArray.Length; i++)
                {
                    var   json           = ctx.ModuleVertices.Find(i).AdjacencyListJson;
                    int[] adjencencyList = JsonConvert.DeserializeObject <int[]>(json);
                    jaggedArray[i] = adjencencyList;
                }

                symbolTable = ctx.Modules
                              .ToList()
                              .Select(s => new Module(s.Name, s.Version, s.Description, s.ModuleId)).ToArray();
            }

            var g  = new Digraph(new Memento <int[][]>(jaggedArray));
            var dg = new ModulesGraph(new Memento <Module[]>(symbolTable), g);

            return(dg);
        }
Пример #2
0
        public void CollectDependencies(List <string> solutionPaths)
        {
            var graph     = new ModulesGraph();
            var collector = new ModuleCollector();

            foreach (var solutionPath in solutionPaths)
            {
                try
                {
                    _logger.Log($"Geting modules for {Path.GetFileName(solutionPath)}...");

                    var modules = collector.GetModulesBySolution(solutionPath);
                    foreach (var v in modules)
                    {
                        graph.AddModule(v);
                        foreach (var w in v.References)
                        {
                            graph.AddDependency(v, w);
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log($"Failed to get modules for {Path.GetFileName(solutionPath)} solution - {ex.Message}", ex);
                }
            }

            if (solutionPaths.Any())
            {
                _logger.Log("Saving graph...");
                var repository = new ModulesGraphRepository(_connectionString);
                repository.SaveState(graph);
                _logger.Log("Done.");
            }
        }
        public void SaveState(ModulesGraph dg)
        {
            Module[] symbolTable = dg.CreateMemento().State;
            int[][]  jaggedArray = dg.Digraph.CreateMemento().State;

            // Save
            using (var ctx = new DependencyGraphContext(_connectionString))
            {
                ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE Module;");
                ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE ModulesGraph;");

                foreach (var module in symbolTable)
                {
                    ctx.Modules.Add(new SqlStorage.Module {
                        ModuleId = module.Id.Value, Name = module.Name, Version = module.Version, Description = module.Description
                    });
                }

                for (int i = 0; i < jaggedArray.Length; i++)
                {
                    var json = JsonConvert.SerializeObject(jaggedArray[i]);
                    ctx.ModuleVertices.Add(new ModuleVertex {
                        VertexId = i, AdjacencyListJson = json
                    });
                }
                ctx.SaveChanges();
            }
        }