Пример #1
0
 public PackageSearchPTO GetPackages(string query, int page)
 {
     using (var dc = new DocuContext())
     {
         var result   = new PackageSearchPTO();
         var packages = dc.Packages.Where(s => s.Name.Contains(query));
         result.count = packages.Count();
         var packs = new List <PackagePTO>();
         packages = packages.OrderBy(n => n.Name).Skip((page - 1) * 5).Take(5);
         foreach (var p in packages.ToList())
         {
             var pto = new PackagePTO
             {
                 Name              = p.Name,
                 PackageId         = p.PackageId,
                 NumberOfDocuments = 0,
                 Documents         = dc.PackageDocuments.Where(d => d.PackageId == p.PackageId).Select(s => new BasicDocumentPTO {
                     Title = s.Document.Title, DocumentID = s.DocumentId
                 }).ToList()
             };
             packs.Add(pto);
         }
         result.packages = packs;
         return(result);
     }
 }
Пример #2
0
 public SearchResultPTO TempSearch()
 {
     using (var dc = new DocuContext())
     {
         var docs    = dc.Documents.Where(i => i.FileSize > 0).ToList();
         var newDocs = new List <ResultPTO>();
         foreach (var s in docs.ToList())
         {
             var d2 = new ResultPTO()
             {
                 DocuID         = s.DocuID,
                 DocumentID     = s.DocumentID,
                 DocuType       = s.DocuType,
                 FileSize       = s.FileSize,
                 FilePath       = s.FilePath.FileName,
                 Subtitle       = s.Subtitle,
                 FunctionalArea = s.FunctionalArea,
                 LastModified   = s.LastModified,
                 Release        = s.Release,
                 SubType        = s.SubType,
                 Title          = s.Title,
                 InPackage      = false,
                 PrevInPackage  = false
             };
             newDocs.Add(d2);
         }
         return(new SearchResultPTO
         {
             Total = docs.Count(),
             Page = 1,
             Results = newDocs,
             QueryTime = 999
         });
     }
 }
Пример #3
0
        public void AddDocumentToPackage(int documentId, int packageId)
        {
            using (var dc = new DocuContext())
            {
                //var testDocument = new Document
                //{
                //    Title = "Test Document",
                //    Description = "A document as a test",
                //    FilePath = "www.google.com",
                //    UploadDate = DateTime.Today
                //};
                //dc.Documents.Add(testDocument);
                //dc.SaveChanges();

                //documentId = testDocument.DocumentId;
                //packageId = 1;

                var added = new PackageDocument
                {
                    DocumentId = documentId,
                    PackageId  = packageId
                };
                dc.PackageDocuments.Add(added);
                dc.SaveChanges();
            }
        }
Пример #4
0
 public void Delete(string path)
 {
     using (var dc = new DocuContext())
     {
         dc.Documents.Remove(dc.Documents.First(s => s.FilePath.FileName == path));
         dc.SaveChanges();
     }
 }
Пример #5
0
 public ActionResult DownloadDocument(int documentId)
 {
     using (var dc = new DocuContext())
     {
         var doc = dc.Documents.Find(documentId);
         return(File(Server.MapPath("~/UploadFiles/" + doc.FilePath.FileName), "application/pdf"));
     }
 }
Пример #6
0
        public void Create(HttpPostedFileBase upload)
        {
            // client to interact with elasticSearch
            client = ElasticSearchConfig.GetClient();

            //Most of Avaloq's document filenames follow the format of ID-ReleaseNum-ClientNum-Subtype-Subtitle.pdf
            //The service checks if the given file follows the same format, and if so, retrieves the metadata.
            using (var dc = new DocuContext())
            {
                var document      = new Models.Document {
                };
                var      fileName = upload.FileName;
                String[] metadata = fileName.Split('-');
                if (upload != null && upload.ContentLength > 0 && metadata.Length >= 5)
                {
                    document.SubType = metadata[3];
                    document.DocuID  = Convert.ToInt32(metadata[0]);
                    if (metadata[1].Equals("en"))
                    {
                        document.Release = "Release Independent";
                    }
                    else
                    {
                        document.Release = "Release " + metadata[1];
                    }
                    document.LastModified = DateTime.Today.Date;
                    document.FileSize     = upload.ContentLength;
                    document.Title        = upload.FileName;
                    document.Subtitle     = metadata[4];
                    var filepath = new Models.FilePath
                    {
                        FileName = Path.GetFileName(upload.FileName),
                    };
                    document.FilePath = filepath;
                }
                else if (upload != null && upload.ContentLength > 0)
                {
                    document.SubType      = "null";
                    document.DocuID       = 0;
                    document.Release      = "null";
                    document.LastModified = DateTime.Today.Date;
                    document.FileSize     = upload.ContentLength;
                    document.Title        = upload.FileName;
                    document.Subtitle     = "null";
                    var filepath = new Models.FilePath
                    {
                        FileName = Path.GetFileName(upload.FileName),
                    };
                    document.FilePath = filepath;
                }
                dc.Documents.Add(document);
                dc.SaveChanges();
                document.FilePath = null;
                var result = client.Index(document);
            }
        }
Пример #7
0
        public int AddPackage(string name)
        {
            using (var dc = new DocuContext())
            {
                var package = new Package
                {
                    Name = name
                };
                dc.Packages.Add(package);
                dc.SaveChanges();

                return(package.PackageId);
            }
        }
Пример #8
0
        public ActionResult DownloadPackageAsZip(int packageId)
        {
            using (var dc = new DocuContext())
            {
                var    package     = dc.Packages.Find(packageId);
                string archiveName = String.Format("{0}-{1}.zip",
                                                   package.Name,
                                                   DateTime.Now.ToString("dd-MM-yyyy"));
                var memoryStream = new MemoryStream();
                using (var zip = new ZipFile())
                {
                    var files = dc.PackageDocuments.Where(p => p.PackageId == packageId).Select(f => f.Document.FilePath.FileName).ToList().Select(s => Server.MapPath("~/UploadFiles/" + s));
                    zip.AddFiles(files, "");
                    //zip.Save(memoryStream);
                    var saveToFilePath = Server.MapPath("~/ExportFiles/" + package.Name + ".zip");
                    zip.Save(saveToFilePath);
                    return(File(saveToFilePath, "application/zip", archiveName));
                    //return File(memoryStream, "application/zip", archiveName);
                }
            }

            //using (var dc = new DocuContext())
            //{
            //    var package = dc.Packages.Find(packageId);
            //    System.Web.HttpContext c = System.Web.HttpContext.Current;
            //    c.Response.Clear();
            //    c.Response.BufferOutput = false; // false = stream immediately
            //    string archiveName = String.Format("{0}-{1}.zip",
            //                                      package.Name,
            //                                      DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
            //    c.Response.ContentType = "application/zip";
            //    c.Response.AddHeader("content-disposition", "filename=" + archiveName);

            //    using (ZipFile zip = new ZipFile())
            //    {
            //        var files = dc.PackageDocuments.Where(p => p.PackageId == packageId).Select(f => f.Document.FilePath.FileName).ToList().Select(s => System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFiles/" + s));
            //        zip.AddFiles(files);
            //        zip.Save(c.Response.OutputStream);
            //    }
            //    c.Response.Close();
            //    c.ApplicationInstance.CompleteRequest();
            //}
        }
Пример #9
0
 public SearchResultPTO GetDocumentsMissingMetadata()
 {
     using (var dc = new DocuContext())
     {
         var final           = new SearchResultPTO();
         var missingMetadata = dc.Documents.Where(m => String.IsNullOrEmpty(m.DocuType) || String.IsNullOrEmpty(m.SubType) || String.IsNullOrEmpty(m.FunctionalArea) || String.IsNullOrEmpty(m.Release));
         final.Total   = missingMetadata.Count();
         final.Results = missingMetadata.Take(10).Select(r => new ResultPTO
         {
             DocumentID     = r.DocumentID,
             DocuID         = r.DocuID,
             DocuType       = r.DocuType,
             FilePath       = r.FilePath.FileName,
             FileSize       = r.FileSize,
             FunctionalArea = r.FunctionalArea,
             LastModified   = r.LastModified,
             Release        = r.Release,
             Subtitle       = r.Subtitle,
             SubType        = r.SubType,
             Title          = r.Title
         }).ToList();
         return(final);
     }
 }
Пример #10
0
        public void DownloadPackage(int packageId /*, object sender, EventArgs e*/)
        {
            using (var dc = new DocuContext())
            {
                var package = dc.Packages.Find(packageId);
                System.Web.HttpContext c = System.Web.HttpContext.Current;
                c.Response.Clear();
                c.Response.BufferOutput = false; // false = stream immediately
                string archiveName = String.Format("{0}-{1}.zip",
                                                   package.Name,
                                                   DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
                c.Response.ContentType = "application/zip";
                c.Response.AddHeader("content-disposition", "filename=" + archiveName);

                using (ZipFile zip = new ZipFile())
                {
                    var files = dc.PackageDocuments.Where(p => p.PackageId == packageId).Select(f => f.Document.FilePath.FileName).ToList().Select(s => System.Web.Hosting.HostingEnvironment.MapPath("~/UploadFiles/" + s));
                    zip.AddFiles(files);
                    zip.Save(c.Response.OutputStream);
                }
                c.Response.Close();
                c.ApplicationInstance.CompleteRequest();
            }
        }