/// <summary> /// Pega o tipo do DocZip /// </summary> /// <param name="docZip">DocZip</param> /// <returns>Tipo</returns> public static Type PegarTipoConteudoDocZip(NFeSharp.Esquemas.v1_00.DocZip docZip) { Match match = Regex.Match(docZip.schema, SchemaRegex); String type = match.Groups["Tipo"].ToString(); String versao = match.Groups["Versao"].ToString(); var key = Tuple.Create <String, String>(type, versao); if (TypeDicionary.ContainsKey(key)) { return(TypeDicionary[key]); } return(null); }
/// <summary> /// Decodifica e descompacta o centúdo do DocZip /// </summary> /// <param name="docZip">DocZip</param> /// <returns>Conteúdo desserializado</returns> public static Object LerConteudoDocZip(NFeSharp.Esquemas.v1_00.DocZip docZip) { XmlDocument doc = new XmlDocument(); Type type = PegarTipoConteudoDocZip(docZip); Object result; if (type == null) { return(null); } using (GZipStream stream = new GZipStream(new MemoryStream(docZip.Conteudo), CompressionMode.Decompress)) { var ser = new XmlSerializer(type); using (XmlReader reader = XmlReader.Create(stream)) { result = ser.Deserialize(reader); } } return(result); }