Esempio n. 1
0
        internal void BulkOperation <T>(List <T> pocos, string contract, IDataDomain domain, string collection)
        {
            try
            {
                if (pocos.Count == 0)
                {
                    return;                   //throw new Exception("There are no items to page in list.");
                }
                if (pocos.Count > 5 && pocos.Count > ProcConstants.TakeCount)
                {
                    LoggerDomainEvent.Raise(LogStatus.Create("[Batch Process]: Handling " + pocos.Count + " records in batches.", true));
                    BatchRequest(pocos, contract, domain);
                }
                else
                {
                    HandleResponse(domain.Save(pocos, contract), contract);
                }

                LoggerDomainEvent.Raise(LogStatus.Create("[Batch Process]: Saving " + collection + " - success.", true));
            }
            catch (Exception ex)
            {
                LoggerDomainEvent.Raise(LogStatus.Create("UowBase:BulkOperation(): " + ex.Message, false));
                throw new ArgumentException("UowBase:BulkOperation(): " + ex.Message);
            }
        }
Esempio n. 2
0
        public void BatchRequest <T>(List <T> pocos, string contract, IDataDomain domain)
        {
            try
            {
                var take  = ProcConstants.TakeCount;
                var count = 0;
                var pages = pocos.Pages(take);
                for (var i = 0; i <= pages; i++)
                {
                    try
                    {
                        if (count == pocos.Count)
                        {
                            break;
                        }
                        var savePatients = pocos.Batch(take).ToList()[i];

                        var enumerable = savePatients as IList <T> ?? savePatients.ToList();
                        FormatPatientDataStatusResponse(savePatients.ToList(), "saving");
                        HandleResponse(domain.Save(enumerable, contract), contract);

                        count = count + enumerable.Count();
                        LoggerDomainEvent.Raise(LogStatus.Create("Patients saved:" + count, true));
                    }
                    catch (Exception ex)
                    {
                        LoggerDomainEvent.Raise(LogStatus.Create("Failure to save batch [" + i + "]:" + count + " " + ex.Message, false));
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerDomainEvent.Raise(LogStatus.Create("UowBase:BatchRequest(): " + ex.Message, false));
                throw new ArgumentException("UowBase:BatchRequest(): " + ex.Message);
            }
        }