Пример #1
0
        public static string DownloadCertificate(string path)
        {
            try
            {
                string content = String.Empty;
                ApiResponse.Respuesta response = null;

                string json = ApiSICOM.ExecuteApiCommand("DescargarCertificado", "", "");

                if (JSON.IsDeserializable <ApiResponse.Respuesta>(json))
                {
                    response = JSON.Deserialize <ApiResponse.Respuesta>(json);
                    ApiSICOM.ThrowExceptionApi(response);
                }
                else
                {
                    content = json;
                    string pathfolder = String.Empty;

                    if (!String.IsNullOrEmpty(path))
                    {
                        pathfolder = Util.GetFolderPath(path);
                        string file = Util.GetFileName(path).Replace(pathfolder, "");

                        if (String.IsNullOrEmpty(file))
                        {
                            file = String.Format("Certificado{0}.csv", DateTime.Now.ToString("yyyyMMddHHmmss"));
                        }

                        if (!Directory.Exists(pathfolder))
                        {
                            Directory.CreateDirectory(pathfolder);
                        }

                        pathfolder += @"\" + file;

                        if (!String.IsNullOrEmpty(pathfolder))
                        {
                            using (StreamWriter writer = new StreamWriter(pathfolder))
                                writer.Write(content);
                        }
                    }
                }

                return(content);
            }
            catch { throw; }
        }
Пример #2
0
 internal static void ThrowExceptionApi(ApiResponse.Respuesta response)
 {
     if (!String.IsNullOrEmpty(response.Error))
     {
         throw new Exception(String.Format(Errors[2], response.Estado, response.Error, response.Mensaje));
     }
     else if (response.EstadoSICOM.Equals("1"))
     {
         string mensaje = ((ApiResponse.DatosChip)response).MotivoTexto ?? response.MensajeSICOM;
         throw new Exception(String.Format(Errors[2], response.EstadoSICOM, "", mensaje));
     }
     else if (!response.EstadoSICOM.Equals("0"))
     {
         throw new Exception(String.Format(Errors[2], response.EstadoSICOM, "", response.MensajeSICOM));
     }
 }