Esempio n. 1
0
        private void CopyAttachment(string tempDir, Domain.Entity.File file)
        {
            string fileName = Path.Combine(tempDir, "Attachments", file.NewName);

            ValidateChecksum(fileName);
            System.IO.File.Copy(fileName, Path.Combine(System.Environment.CurrentDirectory, "Data", "Attachments", file.NewName), true);
        }
Esempio n. 2
0
        private Domain.Entity.File ImportFile(FileObject fileObj, Guid itemId)
        {
            if (fileObj == null)
            {
                return(null);
            }

            bool isNew = false;

            Domain.Entity.File file = importRepo.FileRepo.Get(fileObj.Id);
            if (file == null)
            {
                isNew = true;
                file  = new Domain.Entity.File();
            }

            file.Id          = fileObj.Id;
            file.IsActive    = fileObj.IsActive;
            file.FileName    = fileObj.FileName;
            file.Description = fileObj.Description;
            file.UploadDate  = fileObj.UploadDate;
            file.NewName     = fileObj.NewName;
            file.Item        = itemId;

            if (isNew)
            {
                importRepo.FileRepo.Save(file);
            }
            else
            {
                importRepo.FileRepo.SaveOrUpdate(file);
            }

            return(file);
        }
        public void RefreshFiles(Guid item)
        {
            if (item != Guid.Empty)
            {
                IList<Prizm.Domain.Entity.File> fileList = new List<Prizm.Domain.Entity.File>();
                try
                {
                    fileList = repos.FileRepo.GetByItem(item);
                }
                catch(RepositoryException ex)
                {
                    log.Warn("ExternalFilesViewModel " + ex.ToString());
                    notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
                }
                

                foreach (var dictItem in this.FilesToAttach)
                {
                    Prizm.Domain.Entity.File file = new Domain.Entity.File() 
                    { 
                        FileName = dictItem.Value,
                        UploadDate = DateTime.Now,
                        NewName = string.Format("{0}{1}", Directories.FilesToAttachFolder, dictItem.Key)
                    };
                    fileList.Add(file);
                }

                if (fileList != null)
                {
                    files = new BindingList<Prizm.Domain.Entity.File>(fileList);
                }
                else
                {
                    log.Warn(string.Format("List of attached files for Entity id:{0} is NULL", item));
                }
            }
            else
            {
                if (files == null)
                {
                    files = new BindingList<Prizm.Domain.Entity.File>();
                }
            }
           
        }
Esempio n. 4
0
        public void Execute()
        {
            if (CanExecute())
            {
                if (!Directory.Exists(Directories.TargetPath))
                {
                    Directory.CreateDirectory(Directories.TargetPath);
                    DirectoryInfo directoryInfo = new DirectoryInfo(Directories.TargetPath);
                    directoryInfo.Attributes |= FileAttributes.Hidden;
                }
                try
                {
                    foreach (KeyValuePair <string, string> kvp in viewModel.FilesToAttach)
                    {
                        Prizm.Domain.Entity.File fileEntity = new Domain.Entity.File()
                        {
                            FileName   = kvp.Value,
                            UploadDate = DateTime.Now,
                            Item       = viewModel.Item,
                            IsActive   = true,
                            NewName    = kvp.Key
                        };
                        repo.BeginTransaction();
                        repo.Save(fileEntity);
                        repo.Commit();
                        repo.Evict(fileEntity);
                        System.IO.File.Copy(Directories.FilesToAttachFolder + fileEntity.NewName, Directories.TargetPath + fileEntity.NewName);

                        log.Info(string.Format("The file #{0}, id:{1} has been added to entity.",
                                               fileEntity.FileName,
                                               fileEntity.Id));
                    }
                    viewModel.FilesToAttach.Clear();
                    viewModel.RefreshFiles(viewModel.Item);
                }
                catch (RepositoryException ex)
                {
                    log.Error(ex.Message);
                    notify.ShowFailure(ex.InnerException.Message, ex.Message);
                }

                Directory.Delete(Directories.FilesToAttachFolder, true);
                notify.ShowNotify(Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccess), Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccessHeader));
            }
        }
Esempio n. 5
0
        public void RefreshFiles(Guid item)
        {
            if (item != Guid.Empty)
            {
                IList <Prizm.Domain.Entity.File> fileList = new List <Prizm.Domain.Entity.File>();
                try
                {
                    fileList = repos.FileRepo.GetByItem(item);
                }
                catch (RepositoryException ex)
                {
                    log.Warn("ExternalFilesViewModel " + ex.ToString());
                    notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                                       Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
                }


                foreach (var dictItem in this.FilesToAttach)
                {
                    Prizm.Domain.Entity.File file = new Domain.Entity.File()
                    {
                        FileName   = dictItem.Value,
                        UploadDate = DateTime.Now,
                        NewName    = string.Format("{0}{1}", Directories.FilesToAttachFolder, dictItem.Key)
                    };
                    fileList.Add(file);
                }

                if (fileList != null)
                {
                    files = new BindingList <Prizm.Domain.Entity.File>(fileList);
                }
                else
                {
                    log.Warn(string.Format("List of attached files for Entity id:{0} is NULL", item));
                }
            }
            else
            {
                if (files == null)
                {
                    files = new BindingList <Prizm.Domain.Entity.File>();
                }
            }
        }
        public void Execute()
        {

                if (!Directory.Exists(Directories.TargetPath))
                {
                    Directory.CreateDirectory(Directories.TargetPath);
                    DirectoryInfo directoryInfo = new DirectoryInfo(Directories.TargetPath);
                    directoryInfo.Attributes |= FileAttributes.Hidden;
                }
                try
                {
                    foreach (KeyValuePair<string, string> kvp in viewModel.FilesToAttach)
                    {
                        Prizm.Domain.Entity.File fileEntity = new Domain.Entity.File()
                        {
                            FileName = kvp.Value,
                            UploadDate = DateTime.Now,
                            Item = viewModel.Item,
                            IsActive = true,
                            NewName = kvp.Key
                        };
                        repo.BeginTransaction();
                        repo.Save(fileEntity);
                        repo.Commit();
                        repo.Evict(fileEntity);
                        System.IO.File.Copy(Directories.FilesToAttachFolder + fileEntity.NewName, Directories.TargetPath + fileEntity.NewName);

                        log.Info(string.Format("The file #{0}, id:{1} has been added to entity.",
                            fileEntity.FileName,
                            fileEntity.Id));
                    }
                    viewModel.FilesToAttach.Clear();
                    viewModel.RefreshFiles(viewModel.Item);
                }
                catch (RepositoryException ex)
                {
                    log.Error(ex.Message);
                    notify.ShowFailure(ex.InnerException.Message, ex.Message);
                }

                Directory.Delete(Directories.FilesToAttachFolder, true);
                notify.ShowNotify(Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccess), Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccessHeader));
            
        }
Esempio n. 7
0
        public void PersistFiles(Domain.Entity.Item item)
        {
            foreach (KeyValuePair <string, string> kvp in FilesToAttach)
            {
                Prizm.Domain.Entity.File fileEntity = new Domain.Entity.File()
                {
                    FileName   = kvp.Value,
                    UploadDate = DateTime.Now,
                    Item       = Item,
                    IsActive   = true,
                    NewName    = kvp.Key
                };
                repos.FileRepo.Save(fileEntity);
            }

            FilesToAttach.Clear();

            notify.ShowNotify(Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccess),
                              Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccessHeader));
        }
Esempio n. 8
0
        public void PersistFiles(Domain.Entity.Item item)
        {
            foreach (KeyValuePair <string, string> kvp in FilesToAttach)
            {
                Prizm.Domain.Entity.File fileEntity = new Domain.Entity.File()
                {
                    FileName   = kvp.Value,
                    UploadDate = DateTime.Now,
                    Item       = Item,
                    IsActive   = true,
                    NewName    = kvp.Key
                };

                try
                {
                    repos.FileRepo.Save(fileEntity);
                }
                catch (RepositoryException ex)
                {
                    log.Warn("ExternalFilesViewModel " + ex.ToString());
                    notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                                       Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
                }


                if (System.IO.File.Exists(Directories.FilesToAttachFolder + kvp.Key))
                {
                    System.IO.File.Delete(Directories.FilesToAttachFolder + kvp.Key);
                }
            }

            FilesToAttach.Clear();

            notify.ShowNotify(Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccess),
                              Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccessHeader));
        }
        public void PersistFiles(Domain.Entity.Item item)
        {
           foreach (KeyValuePair<string, string> kvp in FilesToAttach)
           {
                Prizm.Domain.Entity.File fileEntity = new Domain.Entity.File()
                {
                    FileName = kvp.Value,
                    UploadDate = DateTime.Now,
                    Item = Item,
                    IsActive = true,
                    NewName = kvp.Key
                };

                try
                {
                    repos.FileRepo.Save(fileEntity);
                }
                catch(RepositoryException ex)
                {
                    log.Warn("ExternalFilesViewModel " + ex.ToString());
                    notify.ShowWarning(Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Message),
                Program.LanguageManager.GetString(StringResources.Notification_Error_Db_Header));
                }
                

               if(System.IO.File.Exists(Directories.FilesToAttachFolder + kvp.Key))
               {
                   System.IO.File.Delete(Directories.FilesToAttachFolder + kvp.Key);
               }
           }
           
           FilesToAttach.Clear();

           notify.ShowNotify(Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccess),
               Program.LanguageManager.GetString(StringResources.ExternalFiles_FileAttachSuccessHeader));
        }