コード例 #1
0
        public static TService Get <TService> () where TService : Service
        {
            // check if shutting down
            if (_shuttingDown)
            {
                return(default(TService));
            }

            Service component   = null;
            Type    serviceType = typeof(TService);

            // attempt to retrieve the service reference from the dictionary (if it exists)
            if (Instance._services.TryGetValue(serviceType, out component))
            {
                return((TService)component);
            }

            Instance.RefreshServices();             // refresh services if nothing was found

            // attempt to retrieve the service reference from the dictionary again (if it exists)
            if (Instance._services.TryGetValue(serviceType, out component))
            {
                return((TService)component);
            }

            // if at this point, add the desired Service component to the Services GameObject, add it to the list, and return it
            TService service = Instance.gameObject.AddComponent <TService>();

            Instance._services[service.GetType()] = service;
            return(service);
        }
コード例 #2
0
    public void Register <TService, TAnimal>()
        where TService : Factory <TAnimal>, ISerialize, new()
        where TAnimal : Animal
    {
        TService service = new TService();

        registry[service.GetType()]   = service;
        registry[service.TypeCreated] = service;
    }
コード例 #3
0
        public TService GetService <TService>() where TService : Service, new()
        {
            TService service = new TService {
                BaseUri = Uri, Gateway = this, RequestBuilder = GetRequest
            };

            if (Log.IsDebugEnabled)
            {
                Log.Debug(string.Format("Service created: {0} type", service.GetType()));
            }

            return(service);
        }
コード例 #4
0
        private static HubConfiguration GetHubConfiguration(TService ServiceType)
        {
            var hub = (HubConfiguration)ServiceType.GetType().GetField(ServiceType.ToString()).GetCustomAttributes(typeof(HubConfiguration), false).FirstOrDefault();

            if (hub == null)
            {
                throw new Exception("Serviço não está declarado.");
            }
            if (string.IsNullOrEmpty(hub.WSName) || string.IsNullOrEmpty(hub.WSMethod))
            {
                throw new Exception("Serviço não está associado.");
            }

            return(hub);
        }
コード例 #5
0
        public static System.Web.Services.Protocols.SoapHttpClientProtocol ClientProxyFactory(Parametro oParam, TService TipoServico)
        {
            if (oParam.versao == VersaoXML.NFe_v400 &&
                (TipoServico == TService.Autorizacao ||
                 TipoServico == TService.RetAutorizacao ||
                 TipoServico == TService.ConsultaProtocolo ||
                 TipoServico == TService.Inutilizacao ||
                 TipoServico == TService.RecepcaoEvento ||
                 TipoServico == TService.Cadastro ||
                 TipoServico == TService.Status))
            {
                if (oParam.conexao == TipoConexao.NFe)
                {
                    var    tServer  = TServer.NaoMapeado;
                    string Ambiente = oParam.tipoAmbiente.ToString();

                    var AtendidoPor = (NFe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFe_AtendidoPor), false).FirstOrDefault();
                    if (AtendidoPor == null)
                    {
                        throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                    }

                    if (oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCAN || oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.ContingenciaSVCRS)
                    {
                        tServer = AtendidoPor.ServidorAutorizadorSVC;
                    }
                    else
                    {
                        tServer = AtendidoPor.ServidorAutorizador;
                    }

                    return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(tServer, Ambiente, TipoServico));
                }
                else if (oParam.conexao == TipoConexao.NFCe)
                {
                    var AtendidoPor = (NFCe_AtendidoPor)typeof(TCodUfIBGE).GetField(oParam.UF.ToString()).GetCustomAttributes(typeof(NFCe_AtendidoPor), false).FirstOrDefault();
                    if (AtendidoPor == null)
                    {
                        throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                    }

                    string Ambiente = oParam.tipoAmbiente.ToString();

                    return(RDI.NFe2.Webservices.WSUtils.SoapHttpClientFactory(AtendidoPor.ServidorAutorizador, Ambiente, TipoServico));
                }
                else
                {
                    throw new Exception("UF não está associado com nenhum Servidor Autorizador.");
                }
            }
            else
            {
                //TODO : enviar todos os webservices ativos para o projeto rdi.nfe.webservices após a desativação da versao 3.10

                String ClassName = "";
                try
                {
                    string nomeClasse = string.Empty;
                    //buscar nome do metodo pelo tServico
                    foreach (ClasseServico atr in TipoServico.GetType().GetField(TipoServico.ToString()).GetCustomAttributes(typeof(ClasseServico), false))
                    {
                        if (String.IsNullOrEmpty(atr.NomeClasse))
                        {
                            throw new Exception("Serviço não esta associado com nenhuma classe cliente.");
                        }
                        nomeClasse = atr.NomeClasse;
                    }

                    //particularidades
                    if (oParam.UF == TCodUfIBGE.Bahia && oParam.tipoEmissao == TNFeInfNFeIdeTpEmis.Normal && oParam.conexao == TipoConexao.NFe)//Bahia
                    {
                        if (TipoServico == TService.Status && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeStatusServico";
                        }

                        if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeConsulta";
                        }

                        if (TipoServico == TService.Inutilizacao && oParam.versao == VersaoXML.NFe_v310)
                        {
                            nomeClasse = "NfeInutilizacao";
                        }
                    }

                    var subNamespace = TipoServico.ToString();

                    if (TipoServico == TService.ConsultaProtocolo)
                    {
                        subNamespace = "Consulta";
                    }
                    else if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC)
                    {
                        subNamespace = "Eventos";
                    }

                    ClassName = "RDI.NFe2.Business." + GetAmbWebService(oParam, TipoServico) + "." + subNamespace + ".";

                    String headerClassName = ClassName + "nfeCabecMsg";
                    ClassName += nomeClasse;

                    Type classType = GetMyAssembly().GetType(ClassName);

                    if (classType == null)
                    {
                        throw new Exception("Não foi possível definir o tipo do cliente de webservice. #ClientProxyFactory");
                    }

                    System.Web.Services.Protocols.SoapHttpClientProtocol oServico =
                        (System.Web.Services.Protocols.SoapHttpClientProtocol)System.Activator.CreateInstance(classType);

                    if (TipoServico != TService.ConsultaDFe) //ConsultaDFe não tem header
                    {
                        #region Instancia cabecalho

                        Type headerClassType = GetMyAssembly().GetType(headerClassName);

                        if (headerClassType == null)
                        {
                            throw new Exception("Não foi possível definir o tipo do header do cliente de webservice. #ClientProxyFactory");
                        }

                        System.Web.Services.Protocols.SoapHeader oCabecalho =
                            (System.Web.Services.Protocols.SoapHeader)System.Activator.CreateInstance(headerClassType);


                        if ((TipoServico == TService.ManifestacaoDestinatario) || //ManifestacaoDestinatario deverá usar AN 91
                            (TipoServico == TService.DownloadNF) ||               //DownloadNF deverá usar AN 91
                            (TipoServico == TService.EPEC))                       //DownloadNF deverá usar AN 91
                        {
                            oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho, "91", null);
                        }
                        else
                        {
                            oCabecalho.GetType().GetProperty("cUF").SetValue(oCabecalho,
                                                                             ((System.Xml.Serialization.XmlEnumAttribute)oParam.UF.GetType().GetField(
                                                                                  oParam.UF.ToString()).GetCustomAttributes(
                                                                                  typeof(System.Xml.Serialization.XmlEnumAttribute), false)[0]).Name,
                                                                             null);
                        }
                        string versao = oParam.versaoDados;

                        //particularidade para ConsSitNFe usando v200
                        if (TipoServico == TService.ConsultaProtocolo && oParam.versao == VersaoXML.NFe_v200)
                        {
                            versao = "2.01";
                        }

                        //Particularidade para RecepcaoEvento
                        if (TipoServico == TService.RecepcaoEvento)
                        {
                            versao = oParam.versaoDadosEventos;
                        }

                        //particularidade para consultaCadastro
                        if (TipoServico == TService.Cadastro)
                        {
                            versao = "2.00";
                        }

                        //particularidade para manifestacao destinatario
                        if (TipoServico == TService.ManifestacaoDestinatario || TipoServico == TService.EPEC || TipoServico == TService.DownloadNF)
                        {
                            versao = "1.00";
                        }

                        oCabecalho.GetType().GetProperty("versaoDados").SetValue(oCabecalho, versao, null);
                        oServico.GetType().GetProperty("nfeCabecMsgValue").SetValue(oServico, oCabecalho, null);
                        #endregion
                    }
                    return(oServico);
                }
                catch (Exception ex)
                {
                    throw new Exception("ClientProxyFactory # não foi possível criar o cliente (" + ClassName + ") para acesso aos webservices da SEFAZ. InnerException: " + ex.Message);
                }
            }
        }