public List <DTOFile> Buscar(DTOFile filtro)
 {
     return(servicios.obtenerListadoInformes().Where(s =>
                                                     (s.NUMERO_INFORME.Contains(filtro.NUMERO_INFORME == null ? "" : filtro.NUMERO_INFORME) || filtro.NUMERO_INFORME == null) &&
                                                     (s.NOMBRE_USUARIO.Contains(filtro.NOMBRE_USUARIO == null ? "" : filtro.NOMBRE_USUARIO) || filtro.NOMBRE_USUARIO == null) &&
                                                     (s.FECHA_ELBORACION == filtro.FECHA_ELBORACION || filtro.FECHA_ELBORACION == new System.DateTime(1, 1, 1))).ToList());
 }
        public List <DTOFile> obtenerListadoInformes()
        {
            List <DTOFile> respuesta = new List <DTOFile>();
            List <string>  archivos  = new List <string>();
            DTOFile        file;

            try
            {
                SFTP   ftp     = new SFTP();
                string carpeta = WebConfigurationManager.AppSettings["ftp_informes"];
                archivos = ftp.obtenerContenido(carpeta);
                foreach (string archivo in archivos)
                {
                    if (archivo.Contains(".pdf"))
                    {
                        file = new DTOFile();
                        try { file.NUMERO_INFORME = archivo.Split('_')[0]; } catch (Exception) { file.NUMERO_INFORME = "0"; }
                        try { file.NOMBRE_USUARIO = archivo.Split('_')[1]; } catch (Exception) { file.NOMBRE_USUARIO = ""; }
                        try { file.FECHA_ELBORACION = new DateTime(int.Parse(archivo.Split('_')[4]), int.Parse(archivo.Split('_')[3]), int.Parse(archivo.Split('_')[2])); } catch (Exception) { file.FECHA_ELBORACION = DateTime.Now; }
                        try { file.NOMBRE_ARCHIVO = archivo; } catch (Exception) { file.NOMBRE_ARCHIVO = ""; }

                        respuesta.Add(file);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(respuesta);
        }
Beispiel #3
0
        public JsonResult Buscar(DTOFile filtro)
        {
            List <DTOFile> files = new List <DTOFile>();

            try
            {
                files = modelo.Buscar(filtro);
                Response.StatusCode = (int)HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.InternalServerError;
                Response.StatusDescription = ex.Message.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("\v", "").Replace("\f", "").ToString();
            }

            return(new JsonResult {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = files
            });
        }
Beispiel #4
0
        public static DTOFile ReturnFileMethod(DTOFileParameter paramDTOFileParameter, string _SystemFiles, string ConnectionString)
        {
            GeneralSettings objGeneralSettings = new GeneralSettings(ConnectionString);
            DTOFile         objDTOFile         = new DTOFile();

            // Find record
            var optionsBuilder = new DbContextOptionsBuilder <ADefHelpDeskContext>();

            optionsBuilder.UseSqlServer(ConnectionString);

            using (var context = new ADefHelpDeskContext(optionsBuilder.Options))
            {
                var objTask = (from task in context.AdefHelpDeskTasks
                               .Include(details => details.AdefHelpDeskTaskDetails)
                               where task.TaskId == paramDTOFileParameter.taskId
                               where task.TicketPassword == paramDTOFileParameter.ticketPassword
                               select task).FirstOrDefault();

                if (objTask != null)
                {
                    var objTaskDetail = (from taskDetail in context.AdefHelpDeskTaskDetails
                                         .Include(attachment => attachment.AdefHelpDeskAttachments)
                                         where taskDetail.DetailId == paramDTOFileParameter.detailId
                                         select taskDetail).FirstOrDefault();

                    if (objTaskDetail != null)
                    {
                        var objAttachment = (from Attachments in context.AdefHelpDeskAttachments
                                             where Attachments.AttachmentId == paramDTOFileParameter.attachmentID
                                             select Attachments).FirstOrDefault();

                        if (objAttachment != null)
                        {
                            // Construct path
                            string FullPath = "";
                            if (objGeneralSettings.StorageFileType == "AzureStorage")
                            {
                                FullPath = objAttachment.FileName;
                            }
                            else
                            {
                                FullPath = Path.Combine(objAttachment.AttachmentPath, objAttachment.FileName).Replace(@"\", @"/");
                            }

                            // See if this is a file in an .Eml file
                            if (paramDTOFileParameter.emailFileName != null)
                            {
                                // This is a file contained in an .eml file
                                MimeEntity emailFile = GetEmailFile(FullPath, paramDTOFileParameter.emailFileName, ConnectionString);

                                // Get file contents
                                using (var memory = new MemoryStream())
                                {
                                    if (emailFile is MessagePart)
                                    {
                                        var rfc822 = (MessagePart)emailFile;
                                        rfc822.Message.WriteTo(memory);
                                    }
                                    else
                                    {
                                        var part = (MimePart)emailFile;
                                        part.Content.DecodeTo(memory);
                                    }

                                    objDTOFile.Buffer   = memory.ToArray();
                                    objDTOFile.FileName = paramDTOFileParameter.emailFileName;
                                    return(objDTOFile);
                                }
                            }
                            else
                            {
                                if (objGeneralSettings.StorageFileType == "AzureStorage")
                                {
                                    CloudStorageAccount storageAccount     = null;
                                    CloudBlobContainer  cloudBlobContainer = null;

                                    // Retrieve the connection string for use with the application.
                                    string storageConnectionString = objGeneralSettings.AzureStorageConnection;

                                    // Check whether the connection string can be parsed.
                                    if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
                                    {
                                        // Ensure there is a AdefHelpDesk Container
                                        CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
                                        cloudBlobContainer = cloudBlobClient.GetContainerReference("adefhelpdesk-files");
                                        CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(objAttachment.FileName);

                                        // Download
                                        cloudBlockBlob.FetchAttributesAsync().Wait();
                                        long   fileByteLength = cloudBlockBlob.Properties.Length;
                                        byte[] fileContent    = new byte[fileByteLength];
                                        for (int i = 0; i < fileByteLength; i++)
                                        {
                                            fileContent[i] = 0x20;
                                        }
                                        cloudBlockBlob.DownloadToByteArrayAsync(fileContent, 0).Wait();

                                        objDTOFile.Buffer   = fileContent;
                                        objDTOFile.FileName = objAttachment.OriginalFileName;
                                        return(objDTOFile);
                                    }
                                    else
                                    {
                                        throw new Exception("AzureStorage configured but AzureStorageConnection value cannot connect.");
                                    }
                                }
                                else
                                {
                                    // Get file contents
                                    var fileContents = System.IO.File.ReadAllBytes(FullPath);

                                    objDTOFile.Buffer   = fileContents;
                                    objDTOFile.FileName = objAttachment.OriginalFileName;
                                    return(objDTOFile);
                                }
                            }
                        }
                    }
                }
            }

            // Return missing file
            string strPath             = Path.Combine(_SystemFiles, "MissingFile.html").Replace(@"\", @"/");
            var    missingFileContents = System.IO.File.ReadAllBytes(strPath);

            objDTOFile.Buffer   = missingFileContents;
            objDTOFile.FileName = "MissingFile.html";
            return(objDTOFile);
        }