Exemplo n.º 1
0
        public static string[] GetOrphanFiles(int _authenticatedUserId, string _connectionString)
        {
            List <string> toReturn = new List <string>();

            Models.DocumenteScanateRepository        dsr  = new Models.DocumenteScanateRepository(_authenticatedUserId, _connectionString);
            Models.DocumentScanat[]                  dss  = (Models.DocumentScanat[])dsr.GetAll().Result;
            Models.DocumenteScanateProceseRepository dspr = new Models.DocumenteScanateProceseRepository(_authenticatedUserId, _connectionString);
            Models.DocumentScanatProces[]            dsps = (Models.DocumentScanatProces[])dsr.GetAll().Result;

            //var files = Directory.GetFiles(CommonFunctions.GetScansFolder()).AsQueryable().Except(Directory.GetFiles(CommonFunctions.GetScansFolder(), "*_Custom.jpg")); // requires System.Linq.Queryable (4.3.0)
            string[] files = Directory.GetFiles(CommonFunctions.GetScansFolder());
            foreach (string fileName in files)
            {
                if (fileName.IndexOf("*_Custom.jpg") < 0)
                {
                    string fName = Path.GetFileName(fileName);
                    try
                    {
                        int f = dss.Where(item => item.CALE_FISIER == fName).Count();
                        int p = dsps.Where(item => item.CALE_FISIER == fName).Count();
                        if (f == 0 && p == 0)
                        {
                            toReturn.Add(fName);
                        }
                    }
                    catch { toReturn.Add(fName); }
                }
            }
            return(toReturn.ToArray());
        }
Exemplo n.º 2
0
 //public static response RestoreFileFromDb(Models.DocumentScanat ds)
 public static response RestoreFileFromDb(dynamic ds)
 {
     try
     {
         if (ds.FILE_CONTENT == null)
         {
             ds.GetFileContent();
         }
         if (!File.Exists(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER)))
         {
             FileStream fs = new FileStream(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER), FileMode.CreateNew, FileAccess.ReadWrite);
             fs.Write(ds.FILE_CONTENT, 0, ds.FILE_CONTENT.Length);
             fs.Flush();
             fs.Dispose();
         }
         try
         {
             string outputThumbFile = ds.CALE_FISIER.Replace(ds.EXTENSIE_FISIER, "_Custom.jpg");
             if (!File.Exists(Path.Combine(CommonFunctions.GetScansFolder(), outputThumbFile)))
             {
                 ThumbNails.GenerateImgThumbNail(CommonFunctions.GetThumbNailSizes(ThumbNailType.Custom), ds.CALE_FISIER);
             }
         }
         catch (Exception exp) { LogWriter.Log(exp); }
         return(new response(true, "", null, null, null));
         // to do - restore thumbnails
     }catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new List <Error>()
         {
             new Error(exp)
         })); }
 }
Exemplo n.º 3
0
 public static bool DeleteOrphan(string fileName)
 {
     try
     {
         string extension = fileName.Substring(fileName.LastIndexOf('.'));
         File.Delete(Path.Combine(CommonFunctions.GetScansFolder(), fileName.Replace(extension, "_Custom.jpg")));
         File.Delete(Path.Combine(CommonFunctions.GetScansFolder(), fileName));
         return(true);
     }catch (Exception exp) { LogWriter.Log(exp); return(false); }
 }
Exemplo n.º 4
0
 public static bool DeleteOrphans(string[] fileNames)
 {
     try
     {
         foreach (string fileName in fileNames)
         {
             File.Delete(Path.Combine(CommonFunctions.GetScansFolder(), fileName));
         }
         return(true);
     }
     catch (Exception exp) { LogWriter.Log(exp); return(false); }
 }
Exemplo n.º 5
0
 public static bool RestoreFileFromDb(Models.DocumentScanat ds)
 {
     try
     {
         FileStream fs = new FileStream(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER), FileMode.Create, FileAccess.ReadWrite);
         fs.Write(ds.FILE_CONTENT, 0, ds.FILE_CONTENT.Length);
         fs.Flush();
         fs.Dispose();
         return(true);
         // to do - restore thumbnails
     }catch (Exception exp) { LogWriter.Log(exp); return(false); }
 }
Exemplo n.º 6
0
        /*
         * public static Dictionary<string, byte[]> UploadFile(ICollection<IFormFile> files)
         * {
         *  Dictionary<string, byte[]> toReturn = new Dictionary<string, byte[]>();
         *
         *  foreach (IFormFile file in files)
         *  {
         *      if (file.Length > 0)
         *      {
         *          toReturn.Add(file.FileName, UploadFile(file));
         *      }
         *  }
         *  return toReturn;
         * }
         */

        /*
         * public static byte[] UploadFile(IFormFile file)
         * {
         *  BinaryReader reader = new BinaryReader(file.OpenReadStream());
         *  byte[]  toReturn = reader.ReadBytes((int)file.Length);
         *  return toReturn;
         * }
         */

        public static byte[] UploadFile(string filePath)
        {
            string     newFilePath = File.Exists(filePath) ? filePath : Path.Combine(CommonFunctions.GetScansFolder(), filePath);
            FileStream fs          = File.Open(newFilePath, FileMode.Open, FileAccess.Read);

            byte[] toReturn = new byte[fs.Length];
            fs.Read(toReturn, 0, (int)fs.Length);
            fs.Flush();
            fs.Dispose();
            response r = ThumbNails.GenerateImgThumbNail(filePath);

            return(toReturn);
        }
Exemplo n.º 7
0
        public static string SaveBinaryContentToFile(byte[] fileContent, string extension)
        {
            string     filePath    = Guid.NewGuid() + extension;
            string     newFilePath = File.Exists(filePath) ? filePath : Path.Combine(CommonFunctions.GetScansFolder(), filePath);
            FileStream fs          = File.Create(newFilePath);

            fs.Write(fileContent, 0, fileContent.Length);
            fs.Flush();
            fs.Dispose();
            response r = ThumbNails.GenerateImgThumbNail(filePath);

            return(filePath);
        }
Exemplo n.º 8
0
        public static Models.DocumentScanatProces[] GetOrphanDocumentsProcese(int _authenticatedUserId, string _connectionString)
        {
            List <Models.DocumentScanatProces> toReturn = new List <Models.DocumentScanatProces>();

            Models.DocumenteScanateProceseRepository dsr = new Models.DocumenteScanateProceseRepository(_authenticatedUserId, _connectionString);
            Models.DocumentScanatProces[]            dss = (Models.DocumentScanatProces[])dsr.GetAll().Result;
            foreach (Models.DocumentScanatProces ds in dss)
            {
                if (!File.Exists(Path.Combine(CommonFunctions.GetScansFolder(), ds.CALE_FISIER)))
                {
                    toReturn.Add(ds);
                }
            }
            return(toReturn.ToArray());
        }
Exemplo n.º 9
0
 public static string CopyFileToServer(string fileName)
 {
     try
     {
         string extension   = fileName.Substring(fileName.LastIndexOf('.'));
         string filePath    = Guid.NewGuid() + extension;
         string newFilePath = Path.Combine(CommonFunctions.GetScansFolder(), filePath);
         File.Copy(fileName, newFilePath);
         return(filePath);
     }
     catch (Exception exp)
     {
         LogWriter.Log(exp);
         return(null);
     }
 }
Exemplo n.º 10
0
        /*
         * public static byte[] GenerateImgThumbNail(Models.DocumentScanat _documentScanat, ThumbNailSizes s)
         * {
         *  MemoryStream ms = new MemoryStream(_documentScanat.FILE_CONTENT);
         *  Image image = Image.FromStream(ms);
         *  string tmp_file = "tmp_" + DateTime.Now.ToString("ddMMyyyyHHmmss");
         *  response r = SaveThumbNail(ThumbNailType.Custom.ToString(), CommonFunctions.GetScansFolder(), tmp_file, image, s.Width, s.Height);
         *  FileStream fs = new FileStream(Path.Combine(CommonFunctions.GetScansFolder(), r.Message), FileMode.Open, FileAccess.Read);
         *  byte[] b = new byte[fs.Length];
         *  fs.Read(b, 0, (int)fs.Length);
         *  fs.Dispose();
         *  try
         *  {
         *      File.Delete(Path.Combine(CommonFunctions.GetScansFolder(), tmp_file));
         *  }
         *  catch { }
         *  return b;
         * }
         */
        public static byte[] GenerateImgThumbNail(object _documentScanat, ThumbNailSizes s)
        {
            PropertyInfo pi       = _documentScanat.GetType().GetProperty("FILE_CONTENT");
            MemoryStream ms       = new MemoryStream((byte[])pi.GetValue(_documentScanat));
            Image        image    = Image.FromStream(ms);
            string       tmp_file = "tmp_" + DateTime.Now.ToString("ddMMyyyyHHmmss");
            response     r        = SaveThumbNail(ThumbNailType.Custom.ToString(), CommonFunctions.GetScansFolder(), tmp_file, image, s.Width, s.Height);
            FileStream   fs       = new FileStream(Path.Combine(CommonFunctions.GetScansFolder(), r.Message), FileMode.Open, FileAccess.Read);

            byte[] b = new byte[fs.Length];
            fs.Read(b, 0, (int)fs.Length);
            fs.Dispose();
            try
            {
                File.Delete(Path.Combine(CommonFunctions.GetScansFolder(), tmp_file));
            }
            catch { }
            return(b);
        }
Exemplo n.º 11
0
 public static response GenerateByteThumbNail(string fileName, ThumbNailSizes tSize)
 {
     return(GenerateByteThumbNail(File.Exists(fileName) ? "" : CommonFunctions.GetScansFolder(), fileName, tSize));
 }
Exemplo n.º 12
0
 public static response GenerateImgThumbNail(ThumbNailSizes tSize, string fileName)
 {
     return(GenerateImgThumbNail(tSize.thumbNailType.ToString(), CommonFunctions.GetScansFolder(), fileName, tSize.Width, tSize.Height));
 }
Exemplo n.º 13
0
 public static response GenerateImgThumbNail(string fileName)
 {
     return(GenerateImgThumbNail(CommonFunctions.GetThumbNailSizes(ThumbNailType.Custom), File.Exists(fileName) ? "" : CommonFunctions.GetScansFolder(), fileName));
 }
Exemplo n.º 14
0
        public static response ExportDocumenteDosarToPdf(Models.Dosar dosar)
        {
            try
            {
                PdfFixedDocument        poDocument = new PdfFixedDocument();
                Models.DocumentScanat[] ds         = (Models.DocumentScanat[])dosar.GetDocumente().Result;
                foreach (Models.DocumentScanat dsj in ds)
                {
                    try
                    {
                        if (dsj.VIZA_CASCO)
                        {
                            //MemoryStream ms = new MemoryStream(dsj.FILE_CONTENT); // -- pt. citire content fisier din  BD
                            FileStream ms = File.Open(Path.Combine(CommonFunctions.GetScansFolder(), dsj.CALE_FISIER), FileMode.Open, FileAccess.Read);
                            switch (dsj.EXTENSIE_FISIER.Replace(".", "").ToLower())
                            {
                            case "pdf":
                                PdfFixedDocument pd = new PdfFixedDocument(ms);
                                for (int i = 0; i < pd.Pages.Count; i++)
                                {
                                    poDocument.Pages.Add(pd.Pages[i]);
                                }
                                break;

                            case "png":
                                Xfinium.Pdf.Graphics.PdfPngImage pngImg = new Xfinium.Pdf.Graphics.PdfPngImage(ms);
                                PdfPage       p   = new PdfPage();
                                ThumbNailSize tns = ThumbNails.ScaleImage(pngImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(pngImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(pngImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            case "jpg":
                            case "jpeg":
                                Xfinium.Pdf.Graphics.PdfJpegImage jpgImg = new Xfinium.Pdf.Graphics.PdfJpegImage(ms);
                                p   = new PdfPage();
                                tns = ThumbNails.ScaleImage(jpgImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(jpgImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(jpgImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            case "tiff":
                                Xfinium.Pdf.Graphics.PdfTiffImage tiffImg = new Xfinium.Pdf.Graphics.PdfTiffImage(ms);
                                p   = new PdfPage();
                                tns = ThumbNails.ScaleImage(tiffImg, p.Width - PDF_PAGE_MARGIN, p.Height - PDF_PAGE_MARGIN);
                                p.Graphics.DrawImage(tiffImg, (p.Width - tns.Width) / 2, (p.Height - tns.Height) / 2, tns.Width, tns.Height);
                                //p.Graphics.DrawImage(tiffImg, 0, 0, p.Width, p.Height);
                                poDocument.Pages.Add(p);
                                break;

                            default:
                                ms.Flush();
                                ms.Dispose();
                                throw new Exception("unsupportedFormat");
                            }
                            ms.Flush();
                            ms.Dispose();
                        }
                    }
                    catch (Exception exp) { LogWriter.Log(exp); }
                }
                if (poDocument.Pages.Count > 0)
                {
                    string     fileName = dosar.NR_DOSAR_CASCO.Replace('/', '_').Replace(' ', '_') + "_documente.pdf";
                    FileStream fs       = File.Open(Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), FileMode.Create, FileAccess.ReadWrite);
                    poDocument.Save(fs);
                    fs.Flush();
                    fs.Dispose();
                    return(new response(true, Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), Path.Combine(CommonFunctions.GetPdfsFolder(), fileName), null, null));
                }
                else
                {
                    return(new response(false, ErrorParser.ErrorMessage("dosarFaraDocumente").ERROR_MESSAGE, null, null, new List <Error>()
                    {
                        ErrorParser.ErrorMessage("dosarFaraDocumente")
                    }));
                }
            }
            catch (Exception exp) { LogWriter.Log(exp); return(new response(false, exp.Message, null, null, new System.Collections.Generic.List <Error>()
                {
                    new Error(exp)
                })); }
        }