Exemplo n.º 1
0
 public static void ForEach <T>(this ExecutingProcess executingProcess, List <T> collection,
                                Func <T, string> elementInfo, Action <T> action, string?status = null)
 {
     if (executingProcess == null)
     {
         collection.ProgressForeach(elementInfo, action);
     }
     else
     {
         executingProcess.ForEachNonTransactional(collection, elementInfo, item => {
             using (Transaction tr = Transaction.ForceNew())
             {
                 action(item);
                 tr.Commit();
             }
         }, status);
     }
 }
Exemplo n.º 2
0
        public static void SynchronizeProgressForeachNonTransactional <K, N, O>(this ExecutingProcess ep,
                                                                                Dictionary <K, N> newDictionary,
                                                                                Dictionary <K, O> oldDictionary,
                                                                                Action <K, N> createNew,
                                                                                Action <K, O> removeOld,
                                                                                Action <K, N, O> merge)
            where O : class
            where N : class
            where K : notnull
        {
            if (ep == null)
            {
                Synchronizer.SynchronizeProgressForeach(newDictionary, oldDictionary, createNew, removeOld, merge, transactional: false);
            }
            else
            {
                HashSet <K> keys = new HashSet <K>();
                keys.UnionWith(oldDictionary.Keys);
                keys.UnionWith(newDictionary.Keys);
                ep.ForEachNonTransactional(keys.ToList(), key => key.ToString() !, key =>
                {
                    var oldVal = oldDictionary.TryGetC(key);
                    var newVal = newDictionary.TryGetC(key);

                    if (oldVal == null)
                    {
                        createNew?.Invoke(key, newVal !);
                    }
                    else if (newVal == null)
                    {
                        removeOld?.Invoke(key, oldVal);
                    }
                    else
                    {
                        merge?.Invoke(key, newVal, oldVal);
                    }
                });
            }
        }