Exemplo n.º 1
0
        public virtual ConcurrentDictionary <string, StampResponseV3> TimbrarV3Async(string[] xmls, bool isb64 = false)
        {
            StampResponseHandlerV3 handler = new StampResponseHandlerV3();
            ConcurrentBag <string> request = new ConcurrentBag <string>(xmls);
            ConcurrentDictionary <string, StampResponseV3> response = new ConcurrentDictionary <string, StampResponseV3>();

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

            Parallel.ForEach(request, new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, async i =>
            {
                try
                {
                    var xmlBytes = Encoding.UTF8.GetBytes(i);
                    var headers  = await GetHeadersAsync();
                    var content  = GetMultipartContent(xmlBytes);
                    var proxy    = Helpers.RequestHelper.ProxySettings(this.Proxy, this.ProxyPort);
                    response.TryAdd(i, await handler.GetPostResponseAsync(this.Url,
                                                                          string.Format("cfdi33/{0}/{1}/{2}",
                                                                                        _operation,
                                                                                        StampTypes.v3.ToString(),
                                                                                        format), headers, content, proxy));
                }
                catch (Exception ex)
                {
                    response.TryAdd(i, handler.HandleException(ex));
                }
            });
            return(response);
        }
Exemplo n.º 2
0
        public virtual async Task <StampResponseV3> TimbrarV3Async(string xml, bool isb64 = false)
        {
            StampResponseHandlerV3 handler = new StampResponseHandlerV3(xml);

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

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