コード例 #1
0
        /// <summary>
        /// Indicates that all the members of the enumerable must happen after the single predecessor
        /// </summary>
        /// <param name="followers">The followers.</param>
        /// <param name="predecessor">The predecessor.</param>
        /// <returns>the predecessor</returns>
        public static OrderedProcess <T> After <T>(this IEnumerable <OrderedProcess <T> > followers,
                                                   OrderedProcess <T> predecessor)
        {
            predecessor.Before(followers);

            return(predecessor);
        }
コード例 #2
0
        /// <summary>
        /// Indicates that all members of the enumerable must happen before the single follower
        /// </summary>
        /// <param name="predecessors">The predecessors.</param>
        /// <param name="follower">The follower.</param>
        /// <returns>the followers</returns>
        public static OrderedProcess <T> Before <T>(this IEnumerable <OrderedProcess <T> > predecessors,
                                                    OrderedProcess <T> follower)
        {
            follower.After(predecessors);

            return(follower);
        }
コード例 #3
0
 internal static void CheckGraph(Resource <T> a, OrderedProcess <T> b)
 {
     if (a.Graph != b.Graph)
     {
         throw new ArgumentException(
                   $"Resource {a} is not associated with the same graph as process {b}");
     }
 }
コード例 #4
0
ファイル: Resource.cs プロジェクト: dustinlacewell/TopoSort
        /// <summary>
        /// Indicates that this resource is used by the given process
        /// </summary>
        /// <param name="process">The process.</param>
        /// <returns></returns>
        public void UsedBy(OrderedProcess <T> process)
        {
            DependencyGraph <T> .CheckGraph(this, process);

            if (_users.Add(process))
            {
                process.Requires(this);
            }
        }
コード例 #5
0
        /// <summary>
        /// Indicates that this process should execute after another
        /// </summary>
        /// <param value="predecessor">The predecessor.</param>
        /// <returns>returns this process</returns>
        public OrderedProcess <T> After(OrderedProcess <T> predecessor)
        {
            DependencyGraph <T> .CheckGraph(this, predecessor);

            if (_predecessors.Add(predecessor))
            {
                predecessor.Before(this);
            }

            return(predecessor);
        }
コード例 #6
0
        /// <summary>
        /// Indicates that this process should execute before another
        /// </summary>
        /// <param value="follower">The ancestor.</param>
        /// <returns>returns this process</returns>
        public OrderedProcess <T> Before(OrderedProcess <T> follower)
        {
            DependencyGraph <T> .CheckGraph(this, follower);

            if (_followers.Add(follower))
            {
                follower.After(this);
            }

            return(follower);
        }
コード例 #7
0
        public bool Equals(OrderedProcess <T> x, OrderedProcess <T> y)
        {
            if (x == null && y == null)
            {
                return(true);
            }

            if (x == null || y == null)
            {
                return(false);
            }

            return(Comparer.Equals(x.Value, y.Value));
        }
コード例 #8
0
        public static void InitializeMaps <TType>(DependencyGraph <TType> graph,
                                                  IEnumerable <TType> items,
                                                  Dictionary <Type, HashSet <Type> > typeMap,
                                                  Dictionary <Type, HashSet <OrderedProcess <TType> > > processMap)
        {
            foreach (var item in items)
            {
                var process = new OrderedProcess <TType>(graph, item);

                var type = item.GetType();
                var deps = GetDependencies(type);

                UpdateTypeMap(typeMap, type, deps);
                UpdateProcessMap(processMap, type, process);
            }
        }
コード例 #9
0
 public static void UpdateProcessMap <TType>(Dictionary <Type, HashSet <OrderedProcess <TType> > > processMap,
                                             Type type,
                                             OrderedProcess <TType> process)
 {
     if (processMap.ContainsKey(type))
     {
         var set = processMap[type];
         set.Add(process);
     }
     else
     {
         processMap[type] = new HashSet <OrderedProcess <TType> > {
             process
         };
     }
 }
コード例 #10
0
 public int GetHashCode(OrderedProcess <T> obj)
 {
     return(obj.Value.GetHashCode());
 }
コード例 #11
0
 internal bool Add(OrderedProcess <T> orderedProcess)
 {
     return(_processes.Add(orderedProcess));
 }