示例#1
0
        public virtual ConcurrentDictionary <string, StampResponseV4> TimbrarV4(string[] xmls, bool isb64 = false)
        {
            StampResponseHandlerV4 handler = new StampResponseHandlerV4();
            ConcurrentBag <string> request = new ConcurrentBag <string>(xmls);
            ConcurrentDictionary <string, StampResponseV4> response = new ConcurrentDictionary <string, StampResponseV4>();

            string format = isb64 ? "b64" : "";

            Parallel.ForEach(request, new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, i =>
            {
                try
                {
                    var xmlBytes = Encoding.UTF8.GetBytes(i);
                    var headers  = GetHeaders();
                    var content  = GetMultipartContent(xmlBytes);
                    var proxy    = Helpers.RequestHelper.ProxySettings(this.Proxy, this.ProxyPort);
                    response.TryAdd(i, handler.GetPostResponse(this.Url,
                                                               string.Format("cfdi33/{0}/{1}/{2}",
                                                                             _operation,
                                                                             StampTypes.v4.ToString(),
                                                                             format), headers, content, proxy));
                }
                catch (Exception ex)
                {
                    response.TryAdd(i, handler.HandleException(ex));
                }
            });
            return(response);
        }
示例#2
0
        public virtual StampResponseV4 TimbrarV4(string xml, bool isb64 = false)
        {
            StampResponseHandlerV4 handler = new StampResponseHandlerV4();

            try
            {
                string format   = isb64 ? "b64" : "";
                var    xmlBytes = Encoding.UTF8.GetBytes(xml);
                var    request  = RequestStamping(xmlBytes, StampTypes.v4.ToString(), format, _operation);
                return(handler.GetResponse(request));
            }
            catch (Exception ex)
            {
                return(handler.HandleException(ex));
            }
        }
示例#3
0
        public virtual StampResponseV4 TimbrarV4(string xml, bool isb64 = false)
        {
            StampResponseHandlerV4 handler = new StampResponseHandlerV4(xml);

            try
            {
                string format   = isb64 ? "b64" : "";
                var    xmlBytes = Encoding.UTF8.GetBytes(xml);
                var    headers  = GetHeaders();
                var    content  = GetMultipartContent(xmlBytes);
                var    proxy    = Helpers.RequestHelper.ProxySettings(this.Proxy, this.ProxyPort);
                return(handler.GetPostResponse(this.Url,
                                               string.Format("cfdi33/v2/{0}/{1}/{2}",
                                                             _operation,
                                                             StampTypes.v4.ToString(),
                                                             format), headers, content, proxy));
            }
            catch (Exception ex)
            {
                return(handler.HandleException(ex));
            }
        }
        public virtual async Task <StampResponseV4> TimbrarV4Async(string xml, string email = null, string customId = null, bool isb64 = false, string[] extras = null)
        {
            StampResponseHandlerV4 handler = new StampResponseHandlerV4(xml);

            try
            {
                string format   = isb64 ? "b64" : "";
                var    xmlBytes = Encoding.UTF8.GetBytes(xml);
                var    headers  = await GetHeadersAsync(email, customId, extras);

                var content = GetMultipartContent(xmlBytes);
                var proxy   = Helpers.RequestHelper.ProxySettings(this.Proxy, this.ProxyPort);
                return(await handler.GetPostResponseAsync(this.Url,
                                                          string.Format("v4/cfdi33/{0}/{1}/{2}",
                                                                        _operation,
                                                                        StampTypes.v4.ToString(),
                                                                        format), headers, content, proxy));
            }
            catch (Exception ex)
            {
                return(handler.HandleException(ex));
            }
        }