public virtual GetItemsCommandResponse GetItemsCommand(GetItemsCommandRequest request)
        {
            var response = new GetItemsCommandResponse();

            try {
                // Raise Initialization Event
                var initialization = GetItemsCommandInitialization;
                if (initialization != null)
                {
                    initialization(request, response);
                }
                // Raise Execute Event
                var execute = GetItemsCommandExecute;
                if (execute != null)
                {
                    response = execute(request);
                }
                // Raise Complete Event
                var complete = GetItemsCommandComplete;
                if (complete != null)
                {
                    complete(request, response);
                }
            }
            catch (Exception exception) {
                // Raise Error Event
                var error = GetItemsCommandError;
                if (error != null)
                {
                    error(request, response, exception);
                }
            }
            return(response);
        }
Ejemplo n.º 2
0
        public override GetItemsCommandResponse OnGetItemsCommandExecute(GetItemsCommandRequest request)
        {
            var response = new GetItemsCommandResponse();

            try
            {
                response.GetItemsResponse = _apiCommands.ApiGetItems(request.GetItemsRequest);
            }
            catch (Exception ex)
            {
                response.Exception = ex;
                response.Message   = ex.Message;
            }
            return(response);
        }
 public abstract GetItemsCommandResponse OnGetItemsCommandExecute(GetItemsCommandRequest request);
Ejemplo n.º 4
0
        public SyncItems SyncProducts(int batchRecords, int skip)
        {
            var response = new SyncItems();

            _produtoRepository.ExecuteSqlCommand("TRUNCATE TABLE FoccoWebApiProduto;");

            var apiReq = new GetItemsCommandRequest()
            {
                GetItemsRequest = new GetItemsRequest()
                {
                    Skip = skip, Take = 250
                }
            };

            while (true)
            {
                var apiResp = base._foccoErpApiCommands.GetItemsCommand(apiReq);

                if (apiResp.Success && apiResp.GetItemsResponse.Rows != null)
                {
                    var rows = apiResp.GetItemsResponse.Rows.DistinctBy(x => x.ID, null);
                    foreach (var row in rows)
                    {
                        InsertProduct(row);
                        response.TotalProcessedRows += 1;
                    }

                    base._unitOfWork.Commit();

                    response.TotalRowCount = apiResp.GetItemsResponse.TotalRowCount;
                }
                //else if (!apiResp.Success)
                //    throw apiResp.Exception;
                else
                {
                    response.EndOfRecords = true;
                    break;
                }


                var controller = (response.TotalProcessedRows + apiReq.GetItemsRequest.Take) - batchRecords;

                if (controller <= 0)
                {
                    apiReq.GetItemsRequest.Skip += apiReq.GetItemsRequest.Take;
                }
                else
                {
                    if (apiReq.GetItemsRequest.Take > controller)
                    {
                        apiReq.GetItemsRequest.Skip += (apiReq.GetItemsRequest.Take - controller);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(response);
        }