コード例 #1
0
 public static NotaFiscal LoadFromFile(Stream stream) => ACBrIniFile.Load(stream);
コード例 #2
0
 public static NotaFiscal LoadFromFile(string filePath) => ACBrIniFile.Load(filePath);
コード例 #3
0
ファイル: Manifesto.cs プロジェクト: atkins126/ACBr
 public static Manifesto LoadFromFile(Stream stream) => ACBrIniFile.Load(stream);
コード例 #4
0
        /// <summary>
        /// Função para importar endereços no padrão de Ini do ACBr.
        /// </summary>
        /// <param name="stream"></param>
        public static void ImportIniACBr(Stream stream)
        {
            var ini = ACBrIniFile.Load(stream);

            var dataSource = (from DFeSiglaUF value in Enum.GetValues(typeof(DFeSiglaUF))
                              where !value.IsIn(DFeSiglaUF.EX, DFeSiglaUF.AN, DFeSiglaUF.SU)
                              orderby value.GetDescription()
                              select value).ToArray();

            var servicoCTes =
                (from TipoServicoCTe value in Enum.GetValues(typeof(TipoServicoCTe)) select value).ToArray();

            var getVersion = new Func <CTeVersao, string>(versao =>
            {
                switch (versao)
                {
                case CTeVersao.v200: return("2.00");

                case CTeVersao.v300: return("3.00");

                default: throw new ArgumentOutOfRangeException(nameof(versao), versao, null);
                }
            });

            // Emissão Normal
            foreach (var codUf in dataSource)
            {
                var sectionName = $"CTe_{codUf}_H";

                var sessao     = ini[sectionName];
                var sessaoUsar = ini[sectionName];

                while (sessaoUsar.ContainsKey("Usar"))
                {
                    sessaoUsar = ini[sessaoUsar["Usar"]];
                }

                foreach (var service in servicoCTes)
                {
                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao.ContainsKey(key) ? sessao[key] : sessaoUsar.ContainsKey(key) ? sessaoUsar[key] : "";

                    Servicos[CTeVersao.v300, DFeTipoEmissao.Normal][DFeTipoAmbiente.Homologacao, codUf].Enderecos[service] = url;
                }

                sectionName = $"CTe_{codUf.GetDescription()}_P";
                sessao      = ini[sectionName];
                sessaoUsar  = ini[sectionName];

                while (sessaoUsar.ContainsKey("Usar"))
                {
                    sessaoUsar = ini[sessaoUsar["Usar"]];
                }

                foreach (var service in servicoCTes)
                {
                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao.ContainsKey(key) ? sessao[key] :
                              sessaoUsar.ContainsKey(key) ? sessaoUsar[key] : "";

                    Servicos[CTeVersao.v300, DFeTipoEmissao.Normal][DFeTipoAmbiente.Producao, codUf]
                    .Enderecos[service] = url;
                }
            }

            //Emissão DPEC
            foreach (var codUf in dataSource)
            {
                var sectionName = string.Empty;

                switch (codUf)
                {
                case DFeSiglaUF.PE:
                case DFeSiglaUF.SP:
                case DFeSiglaUF.MS:
                case DFeSiglaUF.MT:
                    sectionName = "CTe_SVC-RS_";
                    break;

                default:
                    sectionName = "CTe_SVC-SP_";
                    break;
                }

                var sessao = ini[sectionName + "H"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.DPEC][DFeTipoAmbiente.Homologacao, codUf][service] = url;
                }

                sessao = ini[sectionName + "P"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.DPEC][DFeTipoAmbiente.Producao, codUf][service] = url;
                }
            }

            //Emissão SVCRS
            foreach (var codUf in dataSource)
            {
                var sectionName = "CTe_SVC-RS_";

                var sessao = ini[sectionName + "H"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.SVCRS][DFeTipoAmbiente.Homologacao, codUf][service] = url;
                }

                sessao = ini[sectionName + "P"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.SVCRS][DFeTipoAmbiente.Producao, codUf][service] = url;
                }
            }

            //Emissão SVCSP
            foreach (var codUf in dataSource)
            {
                var sectionName = "CTe_SVC-SP_";

                var sessao = ini[sectionName + "H"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.SVCSP][DFeTipoAmbiente.Homologacao, codUf][service] = url;
                }

                sessao = ini[sectionName + "P"];
                foreach (var service in servicoCTes)
                {
                    if (service == TipoServicoCTe.RecepcaoEventoAN)
                    {
                        continue;
                    }

                    var key = $"{service.GetDescription()}_{getVersion(CTeVersao.v300)}";
                    var url = sessao[key];

                    Servicos[CTeVersao.v300, DFeTipoEmissao.SVCSP][DFeTipoAmbiente.Producao, codUf][service] = url;
                }
            }
        }
コード例 #5
0
ファイル: Manifesto.cs プロジェクト: atkins126/ACBr
 public static Manifesto LoadFromFile(string filePath) => ACBrIniFile.Load(filePath);