示例#1
0
        async public Task Delete(List <Criteria> criterias)
        {
            List <CfopToUsageMap> entities = await this.List(criterias, 0, 0);

            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entities.ForEach(e =>
            {
                batch.Post(HttpMethod.Delete, $"/{SL_TABLE_NAME}('{e.RecId}')", "");
            });

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao excluir registros de '{entities[0].EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else if (response.internalResponses.Count(m => m.success == false) != 0)
            {
                var    error   = response.internalResponses[response.internalResponses.Count() - 1];
                string message = $"Erro ao excluir registros de '{entities[0].EntityName}': {error.errorCode}-{error.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
示例#2
0
        async public Task Update(List <AccountIncomingInvoice> entities)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entities.ForEach(e =>
            {
                var json = toJson(e);
                batch.Post(HttpMethod.Patch, $"/{SL_SERVICE_NAME}('{e.RecId}')", json);
            });

            var response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"{entities[0].EntityName}: Erro ao atualizar lista de títulos a receber, {response.errorCode} {response.errorMessage}";
                throw new OperationCanceledException(message);
            }
            else if (response.internalResponses.Count(m => m.success == false) != 0)
            {
                var qtTotal   = ((IBatchProvider)batch).Items.Count();
                var qtSuccess = response.internalResponses.Count(m => m.success == true);
                var qtError   = response.internalResponses.Count(m => m.success == false);

                string message = $"Erro ao atualizar lista de títulos a receber. {qtTotal} registros, {qtSuccess} sucessos, {qtError} erros: {response.errorCode} {response.errorMessage}";
                throw new OperationCanceledException(message);
            }
        }
示例#3
0
        async public Task Update(List <CfopToUsageMap> entities)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entities.ForEach(e =>
            {
                string record = toJson(e);
                batch.Post(HttpMethod.Put, $"/{SL_TABLE_NAME}('{e.RecId}')", record);
            });

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao atualizar registro de '{entities[0].EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else if (response.internalResponses.Count(m => m.success == false) != 0)
            {
                var    error   = response.internalResponses[response.internalResponses.Count() - 1];
                string message = $"Erro ao atualizar registro de '{entities[0].EntityName}': {error.errorCode}-{error.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
示例#4
0
        async public Task Insert(Invoice entity)
        {
            try
            {
                IBatchProducer batch  = _serviceLayerConnector.CreateBatch();
                string         record = toJson(entity);
                batch.Post(HttpMethod.Post, "/Drafts", record);
                ServiceLayerResponse response = await _serviceLayerConnector.Post("Drafts", record, true, true);

                var resp1 = response.success;
                if (!response.success)
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonError();
                    string query      = Global.BuildQuery($"U_VSITINVOICE('{idEntidade}')");
                    response = await _serviceLayerConnector.Patch(query, cad, true);
                }

                if (resp1)
                {
                    Invoice savedInvoice = JsonConvert.DeserializeObject <Invoice>(response.data);
                    var     idInvoice    = entity.RecId;
                    var     cad          = toJsonSucess(savedInvoice.DocEntry.Value, entity.FRT_VAL, entity.TRN_FAT);
                    string  query        = Global.BuildQuery($"U_VSITINVOICE('{idInvoice}')");
                    response = await _serviceLayerConnector.Patch(query, cad, true);
                }
            }
            catch (Exception e)
            {
            }
        }
示例#5
0
        async public Task Insert(List <Model.Connector.POSMonitorDetail> entities)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entities.ForEach(e =>
            {
                string record = toJson(e);
                batch.Post(HttpMethod.Post, "/U_VSPOSMONITORDET", record);
            });

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entities[0].EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else if (response.internalResponses.Count(m => m.success == false) != 0)
            {
                var    error   = response.internalResponses[response.internalResponses.Count() - 1];
                string message = $"Erro ao enviar transação de '{entities[0].EntityName}': {error.errorCode}-{error.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
示例#6
0
        async public Task Insert(JournalEntry entity)
        {
            IBatchProducer batch  = _serviceLayerConnector.CreateBatch();
            string         record = toJson(entity);

            batch.Post(HttpMethod.Post, "/JournalEntries", record);
            ServiceLayerResponse response = await _serviceLayerConnector.Post("JournalEntries", record, true, true);

            var resp1 = response.success;

            if (!response.success)
            {
                var    idEntidade = entity.RecId;
                var    cad        = toJsonError();
                string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }

            if (resp1)
            {
                //Invoice savedInvoice = JsonConvert.DeserializeObject<JournalEntry>(response.data);
                var    idInvoice = entity.RecId;
                var    cad       = toJsonSucess();
                string query     = Global.BuildQuery($"U_VSITINVOICE('{idInvoice}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }
        }
示例#7
0
        async public Task create()
        {
            if (custom)
            {
                bool exists = await this.tableExists();

                IBatchProducer batch = _serviceLayerConnector.CreateBatch();

                if (!exists)
                {
                    string table = tablePayload();

                    ServiceLayerResponse response = await _serviceLayerConnector.Post("UserTablesMD", table, true);

                    if (!response.success)
                    {
                        // TODO: REGISTRAR LOG DE TABELA NÃO CRIADA
                        System.Console.WriteLine($"Erro ao criar a tabela '{this.name}': {response.errorCode}-{response.errorMessage}");
                    }
                }
            }

            foreach (var c in columns)
            {
                string newColumn = columnPayload(c);
                ServiceLayerResponse response = await _serviceLayerConnector.Post("UserFieldsMD", newColumn, true);

                if (!response.success && response.errorCode != FIELD_ALREADY_EXISTS)
                {
                    // TODO: REGISTRAR LOG DE CAMPOS NÃO CRIADOS
                    System.Console.WriteLine($"Erro ao criar o campo '{c.name}': {response.errorCode}-{response.errorMessage}");
                }
            }

            if (custom)
            {
                foreach (var i in indexes)
                {
                    string newIndex = indexPayload(i);

                    ServiceLayerResponse response = await _serviceLayerConnector.Post("UserKeysMD", newIndex, true);

                    if (!response.success)
                    {
                        // TODO: REGISTRAR LOG DE INDICES NÃO CRIADOS
                        System.Console.WriteLine($"Erro ao criar o índice '{i.name}': {response.errorCode}-{response.errorMessage}");
                    }
                }
            }

            System.Console.WriteLine("OK");
        }
示例#8
0
        public async Task <ServiceLayerResponse> Post(IBatchProducer batch, bool returnContent = false)
        {
            MultipartContent multipart = new MultipartContent("mixed");

            StringBuilder messageBuilder  = new StringBuilder(512);
            string        messageTemplate = string.Empty;

            messageBuilder.AppendLine("{0} {1}");
            messageBuilder.AppendLine("Content-Type: application/json; charset=utf-8");
            if (!returnContent)
            {
                messageBuilder.AppendLine("Prefer: return-no-content");
            }

            messageBuilder.AppendLine("");
            messageBuilder.AppendLine("{2}");
            messageBuilder.AppendLine("");

            messageTemplate = messageBuilder.ToString();

            int index = 0;

            IBatchProvider provider = (IBatchProvider)batch;

            foreach (var s in provider.Items)
            {
                index++;
                string message = string.Format(messageTemplate, s.method.Method, s.query, s.payload);

                StringContent json = new StringContent(message, Encoding.UTF8, "application/json");

                json.Headers.ContentType = new MediaTypeHeaderValue("application/http");
                json.Headers.Add("Content-Transfer-Encoding", "binary");
                json.Headers.Add("Content-ID", index.ToString());

                multipart.Add(json);

                _logger.LogInformation($"POST (batch) {_SLServer}{s.query}");
                if (_logger.IsEnabled(LogLevel.Debug))
                {
                    _logger.LogDebug(s.payload);
                }
            }

            return(await Send(HttpMethod.Post, "$batch", multipart, false));
        }
示例#9
0
        async public Task Insert(ProductTree entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJsonComponete(entity);

            batch.Post(HttpMethod.Post, "/ProductTrees", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                ProductTreeIntegrationStatus status = ProductTreeIntegrationStatus.Processed;

                if (response.internalResponses.Where(x => x.errorCode == "-2035").ToList().Count == 0)
                {
                    if (response.internalResponses.Count(m => !m.success) != 0)
                    {
                        status = ProductTreeIntegrationStatus.Error;
                    }
                }


                var prod = toJsonComponent(status);
                foreach (var item in entity.productTrees_Lines)
                {
                    string query          = Global.BuildQuery($"U_VSITPRODUCT_COMP('{item.RecId}')");
                    var    responseStatus = await _serviceLayerConnector.Patch(query, prod, true);

                    if (!responseStatus.success)
                    {
                        string message = $"Erro ao atualizar status de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                        Console.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
            }
        }
示例#10
0
        async public Task Update(Invoice entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJson(entity);

            batch.Post(HttpMethod.Patch, "/BusinessPartners(CardCode='C20000')", record);
            ServiceLayerResponse response = await _serviceLayerConnector.Post("BusinessPartners", record);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            throw new NotImplementedException();
        }
示例#11
0
        async public Task Insert(Items entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/Items", record);

            foreach (var i in entity.ItemBarCodes.Where(m => m.BarCode != entity.BarCode))
            {
                record = toJsonBarCode(i);
                batch.Post(HttpMethod.Post, "/BarCodes", record);
            }

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                ProductIntegrationStatus status = ProductIntegrationStatus.Processed;

                if (response.internalResponses.Count(m => !m.success) != 0)
                {
                    status = ProductIntegrationStatus.Error;
                }

                var    prod           = toJsonProduct(status);
                string query          = Global.BuildQuery($"U_VSITPRODUCT('{entity.RecId}')");
                var    responseStatus = await _serviceLayerConnector.Patch(query, prod, true);

                if (!responseStatus.success)
                {
                    string message = $"Erro ao atualizar status de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
        }
示例#12
0
        async public Task Insert(Model.LegacyFiscalOperations entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            batch = _serviceLayerConnector.CreateBatch();
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/U_VSCATLGCYCFOP", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);


            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
示例#13
0
        async public Task Insert(BusinessPartners entity)
        {
            try
            {
                var  Cards   = listCardCodes(entity.NATUREZA, entity.CODIGO);
                bool sucesso = true;

                foreach (var card in Cards)
                {
                    IBatchProducer batch = _serviceLayerConnector.CreateBatch();
                    entity.CardCode = card.CardName;
                    entity.CardType = card.CardType;
                    string record = toJson(entity);
                    batch.Post(HttpMethod.Post, "/BusinessPartners", record);
                    ServiceLayerResponse response = await _serviceLayerConnector.Post("BusinessPartners", record);

                    //códigos de erro para se o produto ja existe
                    if (!response.success)
                    {
                        sucesso = false;
                    }
                }

                if (sucesso)
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonEntidades();
                    string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                    var    response   = await _serviceLayerConnector.Patch(query, cad, true);
                }
                else
                {
                    var    idEntidade = entity.RecId;
                    var    cad        = toJsonError();
                    string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                    var    response   = await _serviceLayerConnector.Patch(query, cad, true);
                }
            }
            catch (Exception e)
            {
            }
        }
示例#14
0
        async public Task Insert(VSITVENC entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            entity.status = Data.Model.Integration.VSITVENC.VSITVENCIntegrationStatus.Importing;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/U_VSITINVOICEVENC", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            //
            // Erro no protocolo http ou na estrutura do arquivo
            //
            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
        }
示例#15
0
        async public Task Insert(VSITENTIDADE entity)
        {
            //verifica se ja tem
            try
            {
                IBatchProducer batch = _serviceLayerConnector.CreateBatch();
                entity.cod_x25 = parseCountry(entity.cod_x25);
                entity.status  = Data.Model.Integration.VSITENTIDADE.VSITENTIDADEIntegrationStatus.Importing;
                string record = toJson(entity);

                batch.Post(HttpMethod.Post, "/U_VSITENTIDADE", record);
                ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

                if (!response.success)
                {
                    string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            catch (Exception e)
            {
            }
        }
示例#16
0
        async public Task Insert(ProductComponent entity)
        {
            IBatchProducer batch = _serviceLayerConnector.CreateBatch();

            // entity.status = Data.Model.Integration.Product.ProductIntegrationStatus.Importing;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/U_VSITPRODUCT_COMP", record);

            ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);

            //
            // Erro no protocolo http ou na estrutura do arquivo
            //
            if (!response.success)
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }

            //
            // Verificar erros no lote
            //
            if (response.internalResponses.Count(m => m.success == false) == 0)
            {
                //
                // O registro só será alterado se não houver erros
                //
                // entity.status = Product.ProductIntegrationStatus.Created;
                record   = toJson(entity);
                response = await _serviceLayerConnector.Patch($"U_VSITPRODUCT_COMP('{entity.RecId}')", record, true);

                if (!response.success)
                {
                    string message = $"Erro ao inserir dados em '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";

                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            else
            {
                // Erro no cabeçalho do produto
                if (response.internalResponses.Count == 1)
                {
                    string message = $"Erro ao inserir dados em '{entity.EntityName}': {response.internalResponses[0].errorCode}-{response.internalResponses[0].errorMessage}";
                    Console.WriteLine(message);
                    throw new ApplicationException(message);
                }
                else
                {
                    int position = response.internalResponses.Count - 1;
                    //int item = position - 1;

                    //string message = $"Erro ao inserir dados em '{entity.items[0].EntityName}' item {entity.items[item].itemId} : {response.internalResponses[position].errorCode}-{response.internalResponses[position].errorMessage}";
                    //Console.WriteLine(message);
                    throw new ApplicationException("Vazio");
                }
            }
        }
示例#17
0
        async public Task Insert(BusinessPlaces entity)
        {
            IBatchProducer batch    = _serviceLayerConnector.CreateBatch();
            string         codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "01");

            entity.DefaultWarehouseID         = codigoWH;
            entity.DefaultResourceWarehouseID = codigoWH;
            string recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);

            batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            ServiceLayerResponse response = await _serviceLayerConnector.Post("Warehouses", recordWareHouses);

            codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "99");
            //entity.DefaultWarehouseID = codigoWH;
            //entity.DefaultResourceWarehouseID = codigoWH;
            recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);
            batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            response = await _serviceLayerConnector.Post("Warehouses", recordWareHouses);

            //businessPlaces
            batch = _serviceLayerConnector.CreateBatch();
            entity.BPLNameForeign = entity.BPLName;
            string record = toJson(entity);

            batch.Post(HttpMethod.Post, "/BusinessPlaces", record);
            response = await _serviceLayerConnector.Post("BusinessPlaces", record);

            if (entity.CardCode.Contains("D"))
            {
            }
            //businesspartners F
            entity.CardType = "cSupplier";
            record          = toJsonPartners(entity, "F");
            batch.Post(HttpMethod.Post, "/BusinessPartners", record);
            response = await _serviceLayerConnector.Post("BusinessPartners", record);

            //businesspartners C
            entity.CardType = "cCustomer";
            record          = toJsonPartners(entity, "C");
            batch.Post(HttpMethod.Post, "/BusinessPartners", record);
            response = await _serviceLayerConnector.Post("BusinessPartners", record);

            //descomentar daqui pra baixo
            //IBatchProducer batch = _serviceLayerConnector.CreateBatch();
            //string codigoWH = criaCodigoWareHouses(entity.BPLName, entity.BPLID.ToString(), "01");
            //entity.DefaultWarehouseID = codigoWH;
            //entity.DefaultResourceWarehouseID = codigoWH;
            //string recordFiliais = toJson(entity);
            //string recordWareHouses = toJsonwarehouses(entity.BPLName, codigoWH);
            //batch.Post(HttpMethod.Post, "/Warehouses", recordWareHouses);
            //batch.Post(HttpMethod.Post, "/BusinessPlaces", recordFiliais);
            //ServiceLayerResponse response = await _serviceLayerConnector.Post(batch);


            if (!response.success && !(response.errorMessage.Contains("1320000140")))
            {
                string message = $"Erro ao enviar transação de '{entity.EntityName}': {response.errorCode}-{response.errorMessage}";
                Console.WriteLine(message);
                throw new ApplicationException(message);
            }
            else
            {
                var    idEntidade = entity.RecId;
                var    cad        = toJsonEntidades();
                string query      = Global.BuildQuery($"U_VSITENTIDADE('{idEntidade}')");
                response = await _serviceLayerConnector.Patch(query, cad, true);
            }
        }