예제 #1
0
 public void Dispose()
 {
     _tran?.Commit();
     _tran?.Dispose();
     _original.Dispose();
     _demander.Dispose();
 }
 private async Task DispatchInternalAsync(IEnumerable <CommandBase> commands, HashSet <string> usedChannels)
 {
     foreach (var commandBase in commands)
     {
         if (!(commandBase is ITracingOnly))
         {
             if (!usedChannels.Contains(commandBase.ChannelId))
             {
                 usedChannels.Add(commandBase.ChannelId);
             }
             var r1 = _mx.GetRunner(commandBase);
             ChannelTransaction tran = null;
             try
             {
                 var r = r1.RunInternalAsync(commandBase);
                 if (r != null)
                 {
                     tran = _transactionManager.GetCommandTransaction(commandBase.ChannelId, commandBase, false);
                     await r;
                     commandBase.IsExecuted = true;
                     tran.Commit();
                 }
             }
             catch (Exception e)
             {
                 throw new TectureCommandRunException(commandBase, e);
             }
             finally
             {
                 tran?.Dispose();
             }
         }
     }
 }
        private async Task RunCommandsAsync(IEnumerable <CommandBase> commands, HashSet <string> usedChannels,
                                            CancellationToken token = default)
        {
            foreach (var commandBase in commands)
            {
                if (!(commandBase is ITracingOnly))
                {
                    if (!usedChannels.Contains(commandBase.ChannelId))
                    {
                        usedChannels.Add(commandBase.ChannelId);
                    }
                    var r1 = _mx.GetRunner(commandBase);
                    ChannelTransaction tran = null;
                    Stopwatch          sw   = null;
                    if (_traceCollector != null && _traceCollector.Profiling)
                    {
                        sw = new Stopwatch();
                        sw.Start();
                    }

                    try
                    {
                        var r = r1.RunInternalAsync(commandBase, token);
                        if (r != null)
                        {
                            tran = _transactionManager.GetCommandTransaction(commandBase.ChannelId, commandBase, true);
                            await r;
                            commandBase.IsExecuted = true;
                            tran.Commit();
                        }
                    }
                    catch (Exception e)
                    {
                        commandBase.Exception = e;
                        throw new TectureCommandRunException(commandBase, e);
                    }
                    finally
                    {
                        tran?.Dispose();
                        if (_traceCollector != null && _traceCollector.Profiling)
                        {
                            sw.Stop();
                            commandBase.TimeTaken = sw.Elapsed;
                        }
                    }
                }
            }
        }