Пример #1
0
        public FtpOutboundData QueueUploadItem(string fileData, string targetDirectory, string targetFileName, string ftpSettingsKey, EnumSettingSource ftpSettingsSource)
        {
            string attachmentID = Guid.NewGuid().ToString();

            using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                IsolationLevel = IsolationLevel.Serializable
            }))
            {
                bool anyExistingItems = _documentSession.Query <FtpOutboundData>()
                                        .Customize(i => i.WaitForNonStaleResultsAsOfNow(TimeSpan.FromSeconds(120)))
                                        .Where(i => i.TargetFileName == targetFileName)
                                        .Any();
                if (anyExistingItems)
                {
                    throw new Exception(string.Format("FtpOutputData record for file name {0} already exists", targetFileName));
                }
                _ravenManager.SetAttachment(attachmentID, fileData);
                var newItem = new FtpOutboundData
                {
                    AttachmentId      = attachmentID,
                    QueuedDateTimeUtc = DateTime.UtcNow,
                    SettingKey        = ftpSettingsKey,
                    SettingSource     = ftpSettingsSource,
                    Status            = EnumJobStatus.New,
                    TargetDirectory   = targetDirectory,
                    TargetFileName    = targetFileName
                };
                _documentSession.Store(newItem);
                _documentSession.SaveChanges();
                transaction.Complete();

                return(newItem);
            }
        }