Пример #1
0
            private async Task <string> CheckMaxNoOwnersAsync(IEnumerable <dynamic> dynamics, string table, IDictionary <string, object> values)
            {
                this.CalculatedMaxs.TryAdd(0, await Task.Run(() => CalculateMaxPerOwner(dynamics.ToList())).ConfigureAwait(false));
                bool calculatedIsActualMax = dynamics
                                             .Where(dyn => dyn.Codigo == CalculatedMaxs[0]) //take only calculatedMax
                                             .Select(dyn => (bool)(dyn.Maximo == 1))        //get if calculatedMax is the current DB readed max
                                             .SingleOrDefault();

                if (!calculatedIsActualMax)
                {
                    SemaphoreSlim         sphr       = new SemaphoreSlim(1, 1);
                    StringBuilder         sb         = new StringBuilder();
                    IEnumerable <dynamic> readedMaxs = dynamics.Where(dyn => dyn.Maximo == 1);
                    string         ownersClause      = "";
                    MaxCorrections corrections       = DoCorrectionsForMax(readedMaxs, CalculatedMaxs[0], table, values, ownersClause, 0);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    SetChangesToDictionaries(0, corrections, sphr).Forget().ConfigureAwait(false);
#pragma warning restore CS4014
                    sb.Append(corrections.SQL);
                    //this.CalculatedMaxs.AddOrUpdate(0, CalculatedMaxs[0], (x, y) => calculatedMax);
                    return(sb.ToString());
                }

                return("");
            }
Пример #2
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
            private async Task <string> CheckMaxOwnerCdadAsync(IEnumerable <dynamic> dynamics, string table, IDictionary <string, object> values)
            {
                SemaphoreSlim sphr = new SemaphoreSlim(1, 1);
                StringBuilder sb   = new StringBuilder("");

                Parallel.ForEach(this.OwnersCdades[CCheckType], async(x, loopState) =>
                {
                    this.CalculatedMaxs.TryAdd(x, await Task.Run(() => CalculateMaxPerOwner(dynamics.ToList())).ConfigureAwait(false));
                    IEnumerable <dynamic> onlyXOwner = dynamics
                                                       .Where(dyn => dyn.IdOwnerComunidad == x);     //take those with owner = x
                    bool calculatedIsActualMax = onlyXOwner
                                                 .Where(dyn => dyn.Codigo == this.CalculatedMaxs[x]) //take only calculatedMax
                                                 .Select(dyn => (bool)(dyn.Maximo == 1))             //get if calculatedMax is the current DB readed max
                                                 .SingleOrDefault();

                    if (!calculatedIsActualMax)
                    {
                        IEnumerable <dynamic> readedMaxs = onlyXOwner.Where(dyn => dyn.Maximo == 1);
                        string ownersClause = $" AND IdOwnerComunidad=@idCdad";
                        values.Add("idCdad", x);
                        MaxCorrections corrections = DoCorrectionsForMax(readedMaxs, this.CalculatedMaxs[0], table, values, ownersClause, x);

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                        SetChangesToDictionaries(0, corrections, sphr).Forget().ConfigureAwait(false);
#pragma warning restore CS4014
                        await sphr.WaitAsync();
                        //this.CalculatedMaxs.AddOrUpdate(x, calculatedMax, (l, i) => calculatedMax);
                        sb.Append(corrections.SQL);
                        sphr.Release();
                    }
                    loopState.Stop();
                });

                return(sb.ToString());
            }
Пример #3
0
            private async Task SetChangesToDictionaries(long id, MaxCorrections corrections, SemaphoreSlim sphr)
            {
                await sphr.WaitAsync();

                this.Changes_NewMax.AddOrUpdate(id, corrections.Changes_NewMax,
                                                (Id, max) => corrections.Changes_NewMax);
                sphr.Release();
            }