public Asset DeleteAsset(string id, string driveName = null)
        {
            var asset = GetAsset(id);

            if (asset.AgentId == null)//asset is a global asset
            {
                var childAssets = _repo.Find(null, a => a.Name == asset.Name && a.AgentId != null)?.Items;

                if (childAssets.Count > 0)
                {
                    throw new EntityOperationException("Child assets exist for this asset, please delete those first");
                }
            }

            //remove file associated with asset
            if (asset.Type == "File")
            {
                var file   = _fileManager.DeleteFileFolder(asset.FileId.ToString(), driveName);
                var folder = _fileManager.GetFileFolder(file.ParentId.ToString(), driveName);
                if (!folder.HasChild.Value)
                {
                    _fileManager.DeleteFileFolder(folder.Id.ToString(), driveName);
                }
                else
                {
                    _fileManager.AddBytesToFoldersAndDrive(new List <FileFolderViewModel> {
                        file
                    });
                }
            }

            return(asset);
        }
Пример #2
0
        public void DeleteAutomation(Automation automation, string driveName)
        {
            //remove file associated with automation
            var file = _fileManager.GetFileFolder(automation.FileId.ToString(), driveName);

            _fileManager.DeleteFileFolder(automation.FileId.ToString(), driveName);
            var folder = _fileManager.GetFileFolder(file.ParentId.ToString(), driveName);

            if (!folder.HasChild.Value)
            {
                _fileManager.DeleteFileFolder(folder.Id.ToString(), driveName);
            }
            else
            {
                _fileManager.AddBytesToFoldersAndDrive(new List <FileFolderViewModel> {
                    file
                });
            }

            //remove automation entity
            _repo.SoftDelete(automation.Id.Value);

            //remove automation version entity associated with automation
            var automationVersion = _automationVersionRepository.Find(null, q => q.AutomationId == automation.Id).Items?.FirstOrDefault();

            _automationVersionRepository.SoftDelete(automationVersion.Id.Value);
            DeleteExistingParameters(automation.Id);
        }
Пример #3
0
        public List <EmailAttachment> AddFileAttachments(string emailId, string[] requests, string driveName = null)
        {
            if (requests.Length == 0 || requests == null)
            {
                throw new EntityOperationException("No files found to attach");
            }

            if (driveName != "Files" && !string.IsNullOrEmpty(driveName))
            {
                throw new EntityOperationException("Component files can only be saved in the Files drive");
            }
            else if (string.IsNullOrEmpty(driveName))
            {
                driveName = "Files";
            }

            var emailAttachments = new List <EmailAttachment>();
            var files            = new List <FileFolderViewModel>();

            foreach (var request in requests)
            {
                var file = _fileManager.ExportFileFolder(request, driveName).Result;
                if (file == null)
                {
                    throw new EntityDoesNotExistException($"File could not be found");
                }

                long?size = file.Size;
                if (size <= 0)
                {
                    throw new EntityOperationException($"File size of file {file.Name} cannot be 0");
                }

                //create email attachment file under email id folder
                var path = Path.Combine(driveName, "Email Attachments", emailId);
                using (var stream = IOFile.OpenRead(file.FullStoragePath))
                {
                    file.Files = new IFormFile[] { new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) };
                };
                file.StoragePath     = path;
                file.FullStoragePath = path;

                CheckStoragePathExists(file, 0, Guid.Parse(emailId), "Files");
                file = _fileManager.AddFileFolder(file, "Files")[0];
                files.Add(file);

                //create email attachment
                EmailAttachment emailAttachment = new EmailAttachment()
                {
                    Name                  = file.Name,
                    FileId                = file.Id,
                    ContentType           = file.ContentType,
                    ContentStorageAddress = file.FullStoragePath,
                    SizeInBytes           = file.Size,
                    EmailId               = Guid.Parse(emailId),
                    CreatedBy             = _applicationUser?.UserName,
                    CreatedOn             = DateTime.UtcNow
                };
                _emailAttachmentRepository.Add(emailAttachment);
                emailAttachments.Add(emailAttachment);
            }

            _fileManager.AddBytesToFoldersAndDrive(files);

            return(emailAttachments);
        }
        public List <QueueItemAttachment> AddFileAttachments(QueueItem queueItem, string[] requests, string driveId)
        {
            if (requests.Length == 0 || requests == null)
            {
                throw new EntityOperationException("No files found to attach");
            }

            var drive = GetDrive(driveId);

            driveId = drive.Id.ToString();

            long?payload = 0;
            var  queueItemAttachments = new List <QueueItemAttachment>();
            var  files = new List <FileFolderViewModel>();

            foreach (var request in requests)
            {
                var file      = _fileManager.GetFileFolder(request, driveId, "Files");
                var fileToAdd = _storageFileRepository.GetOne(file.Id.Value);
                if (file == null)
                {
                    throw new EntityDoesNotExistException($"File could not be found");
                }

                long?size = file.Size;
                if (size <= 0)
                {
                    throw new EntityOperationException($"File size of file {file.Name} cannot be 0");
                }

                //create queue item attachment file under queue item id folder
                var path = Path.Combine(drive.Name, "Queue Item Attachments", queueItem.Id.ToString());
                using (var stream = IOFile.OpenRead(fileToAdd.StorageLocation))
                {
                    file.Files           = new IFormFile[] { new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) };
                    file.StoragePath     = path;
                    file.FullStoragePath = path;

                    CheckStoragePathExists(file, 0, queueItem.Id, driveId, drive.Name);
                    file = _fileManager.AddFileFolder(file, driveId)[0];
                    files.Add(file);
                }

                //create queue item attachment
                QueueItemAttachment queueItemAttachment = new QueueItemAttachment()
                {
                    FileId      = file.Id.Value,
                    QueueItemId = queueItem.Id.Value,
                    CreatedBy   = _httpContextAccessor.HttpContext.User.Identity.Name,
                    CreatedOn   = DateTime.UtcNow,
                    SizeInBytes = file.Size.Value
                };
                _queueItemAttachmentRepository.Add(queueItemAttachment);
                payload += queueItemAttachment.SizeInBytes;
                queueItemAttachments.Add(queueItemAttachment);
            }

            _fileManager.AddBytesToFoldersAndDrive(files);

            //update queue item payload
            queueItem.PayloadSizeInBytes += payload.Value;
            _repo.Update(queueItem);

            return(queueItemAttachments);
        }
Пример #5
0
        public List <EmailAttachment> AddFileAttachments(string emailId, string[] requests, string driveId = null)
        {
            if (requests.Length == 0 || requests == null)
            {
                throw new EntityOperationException("No files found to attach");
            }

            var drive = GetDrive(driveId);

            driveId = drive.Id.ToString();

            var emailAttachments = new List <EmailAttachment>();
            var files            = new List <FileFolderViewModel>();

            foreach (var request in requests)
            {
                var file = _fileManager.ExportFileFolder(request, driveId).Result;
                if (file == null)
                {
                    throw new EntityDoesNotExistException("File could not be found");
                }

                long?size = file.Size;
                if (size <= 0)
                {
                    throw new EntityOperationException($"File size of file {file.Name} cannot be 0");
                }

                //create email attachment file under email id folder
                var fileToCheck = _storageFileRepository.GetOne(file.Id.Value);
                var orgId       = _organizationManager.GetDefaultOrganization().Id.ToString();
                using (var stream = IOFile.OpenRead(fileToCheck.StorageLocation))
                {
                    file.Files = new IFormFile[] { new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name)) };
                };
                var path = Path.Combine(driveId, "Email Attachments", emailId);
                file.StoragePath     = path;
                file.FullStoragePath = path;

                CheckStoragePathExists(file, 0, Guid.Parse(emailId), driveId, drive.Name);
                file = _fileManager.AddFileFolder(file, driveId)[0];
                files.Add(file);

                //create email attachment
                EmailAttachment emailAttachment = new EmailAttachment()
                {
                    Name                  = file.Name,
                    FileId                = file.Id,
                    ContentType           = file.ContentType,
                    ContentStorageAddress = file.FullStoragePath,
                    SizeInBytes           = file.Size,
                    EmailId               = Guid.Parse(emailId),
                    CreatedBy             = _applicationUser?.UserName,
                    CreatedOn             = DateTime.UtcNow
                };
                _emailAttachmentRepository.Add(emailAttachment);
                emailAttachments.Add(emailAttachment);
            }

            _fileManager.AddBytesToFoldersAndDrive(files);

            return(emailAttachments);
        }