예제 #1
0
        /// <summary>
        /// Carrega o arquivo de serviços.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="clean">if set to <c>true</c> [clean].</param>
        public static void Load(Stream stream)
        {
            Guard.Against <ArgumentException>(stream == null, "Arquivo de serviços não encontrado");

            Servicos = DFeServices <TipoServicoCTe, CTeVersao> .Load(stream);
        }
예제 #2
0
        static CTeServiceManager()
        {
            Servicos = new DFeServices <TipoServicoCTe, CTeVersao>
            {
                Webservices = new DFeCollection <DFeServiceInfo <TipoServicoCTe, CTeVersao> >
                {
                    new DFeServiceInfo <TipoServicoCTe, CTeVersao>
                    {
                        Versao      = CTeVersao.v300,
                        Tipo        = DFeTipoServico.CTe,
                        TipoEmissao = DFeTipoEmissao.Normal
                    },
                    new DFeServiceInfo <TipoServicoCTe, CTeVersao>
                    {
                        Versao      = CTeVersao.v300,
                        Tipo        = DFeTipoServico.CTe,
                        TipoEmissao = DFeTipoEmissao.DPEC
                    },
                    new DFeServiceInfo <TipoServicoCTe, CTeVersao>
                    {
                        Versao      = CTeVersao.v300,
                        Tipo        = DFeTipoServico.CTe,
                        TipoEmissao = DFeTipoEmissao.SVCRS
                    },
                    new DFeServiceInfo <TipoServicoCTe, CTeVersao>
                    {
                        Versao      = CTeVersao.v300,
                        Tipo        = DFeTipoServico.CTe,
                        TipoEmissao = DFeTipoEmissao.SVCSP
                    }
                }
            };

            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();

            foreach (var serviceInfo in Servicos.Webservices)
            {
                foreach (var siglaUF in dataSource)
                {
                    var ambiente = serviceInfo.Ambientes.AddNew();
                    ambiente.UF       = siglaUF;
                    ambiente.Ambiente = DFeTipoAmbiente.Homologacao;

                    foreach (var servicoCTe in servicoCTes)
                    {
                        ambiente.Enderecos.Add(servicoCTe, "");
                    }

                    ambiente          = serviceInfo.Ambientes.AddNew();
                    ambiente.UF       = siglaUF;
                    ambiente.Ambiente = DFeTipoAmbiente.Producao;

                    foreach (var servicoCTe in servicoCTes)
                    {
                        ambiente.Enderecos.Add(servicoCTe, "");
                    }
                }
            }

            Load();
        }
        public void TestDFeServiceSerializer()
        {
            var services = new DFeServices <DFeTipo, DFeVersao>();

            services.Webservices.Add(new DFeServiceInfo <DFeTipo, DFeVersao>()
            {
                Versao      = DFeVersao.v200,
                Tipo        = DFeTipoServico.CTe,
                TipoEmissao = DFeTipoEmissao.Normal,
                Ambientes   = new DFeCollection <DFeServiceEnvironment <DFeTipo> >()
                {
                    new DFeServiceEnvironment <DFeTipo>()
                    {
                        Ambiente  = DFeTipoAmbiente.Homologacao,
                        UF        = DFeSiglaUF.MS,
                        Enderecos = new Dictionary <DFeTipo, string>()
                        {
                            { DFeTipo.Envio, "Envio" },
                            { DFeTipo.Consulta, "Consulta" }
                        }
                    },
                    new DFeServiceEnvironment <DFeTipo>()
                    {
                        Ambiente  = DFeTipoAmbiente.Producao,
                        UF        = DFeSiglaUF.MS,
                        Enderecos = new Dictionary <DFeTipo, string>()
                        {
                            { DFeTipo.Envio, "Envio" },
                            { DFeTipo.Consulta, "Consulta" }
                        }
                    }
                }
            });

            services.Webservices.Add(new DFeServiceInfo <DFeTipo, DFeVersao>()
            {
                Versao      = DFeVersao.v300,
                Tipo        = DFeTipoServico.CTe,
                TipoEmissao = DFeTipoEmissao.Normal,
                Ambientes   = new DFeCollection <DFeServiceEnvironment <DFeTipo> >()
                {
                    new DFeServiceEnvironment <DFeTipo>()
                    {
                        Ambiente  = DFeTipoAmbiente.Homologacao,
                        UF        = DFeSiglaUF.MS,
                        Enderecos = new Dictionary <DFeTipo, string>()
                        {
                            { DFeTipo.Envio, "Envio" },
                            { DFeTipo.Consulta, "Consulta" }
                        }
                    },
                    new DFeServiceEnvironment <DFeTipo>()
                    {
                        Ambiente  = DFeTipoAmbiente.Producao,
                        UF        = DFeSiglaUF.MS,
                        Enderecos = new Dictionary <DFeTipo, string>()
                        {
                            { DFeTipo.Envio, "Envio" },
                            { DFeTipo.Consulta, "Consulta" }
                        }
                    }
                }
            });

            var xml = services.GetXml();

            Assert.NotEqual(string.Empty, xml);
        }