Exemplo n.º 1
0
 private void Visit(GrafVertex vertex)
 {
     if (vertex.VertexType != VertexType.White)
     {
         throw new Exception("Wrong algorithm work!");
     }
     vertex.VertexType = VertexType.Gray;
     foreach (var nextVertex in vertex.NextVertexes)
     {
         if (nextVertex.VertexType == VertexType.Gray)
         {
             ThrowCycleError(nextVertex.Description.Type);
         }
         else if (nextVertex.VertexType == VertexType.Black)
         {
             continue;
         }
         else
         {
             Visit(nextVertex);
         }
     }
     vertex.VertexType = VertexType.Black;
     WhiteSet.Remove(vertex);
     Result.Push(vertex);
 }
Exemplo n.º 2
0
 public MiddlewareDescription[] CalcResult()
 {
     while (WhiteSet.Count > 0)
     {
         var vertex = WhiteSet.First();
         Visit(vertex);
     }
     return(Result.Select(v => v.Description).Reverse().ToArray());
 }
Exemplo n.º 3
0
 public Graf(IEnumerable <MiddlewareDescription> descriptions)
 {
     foreach (var item in descriptions)
     {
         GrafVertex vertex = new GrafVertex {
             Description = item, VertexType = VertexType.White
         };
         WhiteSet.Add(vertex);
     }
     CreateGraf();
 }
Exemplo n.º 4
0
        private void CreateGraf()
        {
            foreach (var vertex in WhiteSet)
            {
                vertex.NextVertexes.AddRange(WhiteSet.Where(v => vertex.Description.MustBeAfter.Contains(v.Description.Type)));

                foreach (var typeBefore in vertex.Description.MustBeBefore)
                {
                    var vertexBefore = WhiteSet.FirstOrDefault(v => v.Description.Type == typeBefore);
                    vertexBefore?.NextVertexes.Add(vertex);
                }
            }
        }