Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        public bool TrySaveFiles(Domain.Entity.Item item)
        {
            bool successCopy = true;

            if (FilesToAttach.Count > 0)
            {
                if (!Directory.Exists(Directories.TargetPath))
                {
                    Directory.CreateDirectory(Directories.TargetPath);
                    DirectoryInfo directoryInfo = new DirectoryInfo(Directories.TargetPath);
                    directoryInfo.Attributes |= FileAttributes.Hidden;
                }
                foreach (KeyValuePair <string, string> kvp in FilesToAttach)
                {
                    var newFileName = kvp.Key;
                    try
                    {
                        System.IO.File.Copy(
                            Directories.FilesToAttachFolder + newFileName,
                            Directories.TargetPath + newFileName
                            );
                    }
                    catch (Exception e)
                    {
                        successCopy = false;
                        log.Error(e.Message);
                        RemoveCopiedFilesIfError();
                        break;
                    }
                }
            }

            if (successCopy)
            {
                PersistFiles(item);
            }

            return(successCopy);
        }
Ejemplo n.º 3
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));
        }