Ejemplo n.º 1
0
        public static void SaveFileToTransitoAttachLocalPath(DocumentAttach attach, Byte[] content)
        {
            if (attach == null)
            {
                throw new Exceptions.DocumentNotFound_Exception("SaveFileToTransitoAttachLocalPath : document is null");
            }

            if (attach.Document == null)
            {
                throw new Exceptions.DocumentNotFound_Exception("SaveFileToTransitoAttachLocalPath : referrer document is null");
            }

            if (attach.Document.Archive == null || attach.Document.Archive.IdArchive == Guid.Empty)
            {
                throw new Exceptions.Archive_Exception("SaveFileToTransitoAttachLocalPath : document archive is null");
            }

            if (string.IsNullOrWhiteSpace(attach.Document.Archive.PathTransito))
            {
                attach.Document.Archive = ArchiveService.GetArchive(attach.Document.Archive.IdArchive);
                if (attach.Document.Archive == null || string.IsNullOrWhiteSpace(attach.Document.Archive.PathTransito))
                {
                    throw new Exceptions.Archive_Exception("SaveFileToTransitoAttachLocalPath : document archive transit's path is not valid");
                }
            }

            if (!Directory.Exists(attach.Document.Archive.PathTransito))
            {
                Directory.CreateDirectory(attach.Document.Archive.PathTransito);
            }

            File.WriteAllBytes(Path.Combine(attach.Document.Archive.PathTransito, attach.Document.IdDocument + "_" + attach.IdDocumentAttach + Path.GetExtension(attach.Name)), content);
        }
    /// <summary>Page's load event</summary>
    /// <param name="sender">Loaded page</param>
    /// <param name="e">Event's arguments</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        var    file = this.Request.Files[0];
        string path = Request.PhysicalApplicationPath;

        if (!path.EndsWith("\\"))
        {
            path += "\\";
        }

        long   itemId            = Convert.ToInt64(this.Request.Form["ItemId"]);
        int    companyId         = Convert.ToInt32(this.Request.Form["CompanyId"]);
        string description       = this.Request.Form["Description"];
        string version           = this.Request.Form["Version"];
        int    applicationUserId = Convert.ToInt32(this.Request.Form["ApplicationUserId"]);
        string extension         = Path.GetExtension(file.FileName).Replace(".", string.Empty);

        var uploadFile = new DocumentAttach
        {
            DocumentId  = itemId,
            Description = description,
            CompanyId   = companyId,
            Version     = Convert.ToInt32(version),
            Extension   = extension,
            Active      = true,
            CreatedBy   = new ApplicationUser {
                Id = applicationUserId
            },
            CreatedOn  = Constant.Now,
            ModifiedBy = new ApplicationUser {
                Id = applicationUserId
            },
            ModifiedOn = Constant.Now
        };

        var res = uploadFile.Insert(applicationUserId);

        // Document_7_V12_1
        string fileName = string.Format(@"Document_{0}_V{1}_{2}.{3}", itemId, version, uploadFile.Id, extension);

        string folder      = string.Format(CultureInfo.InvariantCulture, @"{0}DOCS\{1}\", path, companyId);
        string filePattern = string.Format(CultureInfo.InvariantCulture, @"Document_{0}_V{1}_*.*", itemId, version);
        var    files       = Directory.GetFiles(folder, filePattern);

        foreach (string fileVictim in files)
        {
            if (File.Exists(fileVictim))
            {
                File.Delete(fileVictim);
            }
        }

        file.SaveAs(string.Format(@"{0}DOCS\{1}\Document_{2}_V{3}_{4}.{5}", path, companyId, itemId, version, uploadFile.Id, extension));
        this.Response.Clear();
        this.Response.ContentType = "application/json";
        this.Response.Write(res.MessageError);
        this.Response.End();
    }
Ejemplo n.º 3
0
        public void AddDocumentAttach(DocumentAttach attach)
        {
            string localPath     = string.Empty;
            bool   forceDelete   = false;
            string localFilePath = string.Empty;

            CheckPrerequisite(attach);
            attach.IdDocument = attach.IdDocumentAttach;

            if (ConfigurationManager.AppSettings["PathCache"] != null && !string.IsNullOrEmpty(ConfigurationManager.AppSettings["PathCache"].ToString()))
            {
                localFilePath = CacheService.AddCache(attach, attach.Content, attach.Name, "");
            }
            if (string.IsNullOrEmpty(localFilePath))
            {
                forceDelete   = true;
                localPath     = Path.GetTempPath();
                localFilePath = Path.Combine(localPath, attach.IdDocumentAttach.ToString() + Path.GetExtension(attach.Name));
            }
            try
            {
                //Document.StorageArea = DocumentService.GetStorageArea(Document, AttributeValues);
                //

                File.WriteAllBytes(localFilePath, attach.Content.Blob);
                //
                //Document.Content = new DocumentContent(GetByteArrayFromFile(localFilePath));
                //Save the document on the storageArea
                attach.Size = SaveDocument(localFilePath, attach.Storage, attach.StorageArea, attach, null);
                StorageService.UpdateStorageAreaSize(attach.StorageArea.IdStorageArea, (long)attach.Size);
                attach.Status = new Status((short)DocumentTarnsitoStatus.StorageProcessing);
                //Update the calculated value.
                //TODO Update del Attach
                //DocumentService.UpdateDocumentAttach(attach));
                if (attach.Storage.EnableFulText)
                {
                    SaveSearchableDocument(attach);
                }
            }
            finally
            {
                if (forceDelete)
                {
                    try
                    {
                        File.Delete(localFilePath);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public ActionResult Delete(long attachId, int companyId)
 {
     return(DocumentAttach.Delete(attachId, companyId));
 }
Ejemplo n.º 5
0
    /// <summary>Generates HTML code for historical changes table</summary>
    private void RenderHistorico()
    {
        this.DocumentAttachActual = Constant.JavaScriptNull;
        var firstDate = DateTime.Now;
        var rows      = new List <DocumentVersionRow>();
        var attachs   = DocumentAttach.ByDocument(this.DocumentId, this.Company.Id).Where(d => d.Active == true).ToList();

        foreach (var version in this.Document.Versions)
        {
            string fileName   = string.Empty;
            long   documentId = 0;
            string extension  = string.Empty;
            if (attachs.Any(f => f.Version == version.Version))
            {
                var attach = attachs.First(f => f.Version == version.Version);
                fileName   = attach.Description;
                documentId = attach.Id;
                extension  = attach.Extension;

                if (attach.Version == this.Document.LastVersion.Version)
                {
                    this.DocumentAttachActual = attach.Json;
                }
            }

            rows.Add(new DocumentVersionRow
            {
                Id         = this.DocumentId,
                DocumentId = documentId,
                Version    = version.Version,
                Date       = version.Date,
                Attach     = fileName,
                Extension  = extension,
                Reason     = version.Reason,
                AprovedBy  = version.UserCreateName,
                CompanyId  = this.Company.Id
            });
        }

        var res = new StringBuilder();

        foreach (var row in rows.OrderByDescending(r => r.Version).ThenByDescending(r => r.Date))
        {
            //firstDate = row.Date;
            string rowText = row.Render(this.dictionary, this.ApplicationUser.Grants);

            /*string extension = rowText.Replace("window.open(", "^");
             * if (extension.IndexOf("^") != -1)
             * {
             *  extension = extension.Split('^')[1].Split('.')[1].Split('\'')[0];
             *  rowText = rowText.Replace("icon-edit bigger-120", "icon-download");
             *
             *  if (extension == "jpg" || extension == "jpeg" || extension == "png" || extension == "gif")
             *  {
             *  }
             *  else
             *  {
             *      rowText = rowText.Replace("btn-success\"", "btn-success\" style=\"display:none;\"");
             *  }
             * }
             * else
             * {
             *  extension = string.Empty;
             * }*/

            //rowText = rowText.Replace("icon-edit bigger-120", "icon-download");

            //res.Append("<!-- ").Append(extension).Append(" -->");

            res.Append(rowText);
        }

        this.LtHistorico.Text = res.ToString();
        this.FirstVersionDate = string.Format(CultureInfo.InvariantCulture, "new Date({0:yyyy}, {0:MM} - 1, {0:dd})", firstDate);
    }