/// <summary> /// Constructor. /// </summary> /// <param name="encodingfactory"></param> /// <param name="transmissionLogger"></param> /// <param name="transmissionPartFactory"></param> public FileTransmitter(IEncodingFactory encodingfactory, ITransmissionLogger transmissionLogger, ITransmissionPartFactory transmissionPartFactory) { ParameterCheck.ParameterRequired(encodingfactory, "encodingfactory"); ParameterCheck.ParameterRequired(transmissionLogger, "transmissionLogger"); ParameterCheck.ParameterRequired(transmissionPartFactory, "transmissionPartFactory"); this.encodingfactory = encodingfactory; this.transmissionLogger = transmissionLogger; this.transmissionPartFactory = transmissionPartFactory; }
/// <summary> /// Constructor. /// </summary> /// <param name="transmissionPartFactory"></param> public PassThroughEncoding(ITransmissionPartFactory transmissionPartFactory) { ParameterCheck.ParameterRequired(transmissionPartFactory, "transmissionPartFactory"); this.transmissionPartFactory = transmissionPartFactory; }
/// <summary> /// Constructor. /// </summary> /// <param name="transmissionPartFactory"></param> public MimeEncoding(ITransmissionPartFactory transmissionPartFactory) { ParameterCheck.ParameterRequired(transmissionPartFactory, "transmissionPartFactory"); this.transmissionPartFactory = transmissionPartFactory; }
/// <summary> /// Prepare a collection of files for transmission. /// </summary> /// <param name="parts">The transmission parts.</param> /// <param name="transmissionFactory">Transmission factory that is needed but not used.</param> /// <param name="encodingfactory">The encodingfactory</param> /// <param name="transmissionLogger">The transmissionLogger</param> /// <returns>A collection of file transmission items in order of sending.</returns> /// <remarks> /// <para> /// Path variables supported : /// </para> /// <para> /// ${Root} = urlBase attribute of the FileTransmitterEncoder configuration. /// </para> /// <para> /// ${Guid} = A GUID directory. /// </para> /// <para> /// ${JobId} = A JobId directory. JobId used is from the first JDF found in the parts. /// </para> /// <para> /// ${JobKey} = A JobKey directory. JobKey used is from the first JDF found in the parts (tree.Key). /// </para> /// </remarks> public virtual List <FileTransmissionItem> PrepareTransmission(ITransmissionPartCollection parts, ITransmissionPartFactory transmissionFactory, IEncodingFactory encodingfactory, ITransmissionLogger transmissionLogger) { var items = new List <FileTransmissionItem>(); try { if (UseMime) { MimeEncoding encoding = new MimeEncoding(transmissionFactory); var encoded = encoding.Encode(parts); using (var mimeResult = encoded.Stream) { //TODO determine better way to provide the part. items.Add(new FileTransmissionItem(null, mimeResult, new Uri(Path.Combine(LocalPath, Guid.NewGuid().ToString() + ".mim")), encoded.ContentType, 0)); } } else { if (JmfFolderInfo == null && JdfFolderInfo == null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaild, Id)); } if (JmfFolderInfo != null && (JdfFolderInfo == null || AttachmentFolderInfo == null)) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJMFNoJDF, Id)); } if (JdfFolderInfo != null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJDFNoAttach, Id)); } Guid transmissionGuid = Guid.NewGuid(); string jobId = "JDF_JobIdUnknown"; string jobKey = "JDF_JobKeyUnknown"; var jdfTransmissionPart = parts.TicketPart; //pass over parts to get the job id and key if (jdfTransmissionPart != null) { //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. var ticket = parts.Ticket; if (ticket.Root.GetJobId().Length > 0) { jobId = "JDF_" + ticket.Root.GetJobId(); } if (ticket.Root.GetId().Length > 0) { jobKey = "JDF_" + ticket.Root.GetId(); } } var itemsToProcess = new List <KeyValuePair <ITransmissionPart, string> >(); //pass over parts to generate destination file names and mapping var urlMapping = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (ITransmissionPart part in parts) { FileTransmitterFolderInfo folder; string extension = null; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; extension = ".jdf"; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; extension = ".jmf"; } else { folder = AttachmentFolderInfo; extension = MimeTypeHelper.MimeTypeExtension(part.MimeType); } string fileName = part.Id.ToString() + extension; if (folder != null) { var newFileName = Path.Combine(ExpandFolder(folder.DestinationFolder, transmissionGuid, jobId, jobKey), fileName); string referencePath = Path.Combine(ExpandFolder(folder.ReferenceFolder, transmissionGuid, jobId, jobKey), fileName); urlMapping.Add("cid:" + part.Id.ToLower(), referencePath); itemsToProcess.Add(new KeyValuePair <ITransmissionPart, string>(part, newFileName)); } } //fixup urls and add to the collection of files to send foreach (var processPart in itemsToProcess) { FileTransmitterFolderInfo folder; var part = processPart.Key; var file = processPart.Value; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; } else { folder = AttachmentFolderInfo; } //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JdfMimeType) { FileSpecUrlMangler.MapFileSpecUrls(parts.Ticket, urlMapping, true); FileSpecUrlMangler.MapPreviewUrls(parts.Ticket, urlMapping, true); } //TODO is this the best way to obtain the message? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JmfMimeType) { MapMessageUrls(parts.Message, urlMapping); } if (folder != null) { if (!folder.Suppress) { var encodingResult = encodingfactory.GetEncodingForMimeType(part.MimeType).Encode(part); encodingResult.Stream.Seek(0, SeekOrigin.Begin); transmissionLogger.Log(new TransmissionData(encodingResult.Stream, encodingResult.ContentType, "Request")); items.Add(new FileTransmissionItem(part, encodingResult.Stream, new Uri(file), part.MimeType, folder.Order)); } } } } } catch (Exception err) { throw new JdfException(string.Format(FluentJdf.Resources.Messages.ErrorOccuredWhileTryingToEncodeTransmissionMessageIs, err.Message), err); } return(items); }
/// <summary> /// Prepare a collection of files for transmission. /// </summary> /// <param name="parts">The transmission parts.</param> /// <param name="transmissionFactory">Transmission factory that is needed but not used.</param> /// <param name="encodingfactory">The encodingfactory</param> /// <param name="transmissionLogger">The transmissionLogger</param> /// <returns>A collection of file transmission items in order of sending.</returns> /// <remarks> /// <para> /// Path variables supported : /// </para> /// <para> /// ${Root} = urlBase attribute of the FileTransmitterEncoder configuration. /// </para> /// <para> /// ${Guid} = A GUID directory. /// </para> /// <para> /// ${JobId} = A JobId directory. JobId used is from the first JDF found in the parts. /// </para> /// <para> /// ${JobKey} = A JobKey directory. JobKey used is from the first JDF found in the parts (tree.Key). /// </para> /// </remarks> public virtual List<FileTransmissionItem> PrepareTransmission(ITransmissionPartCollection parts, ITransmissionPartFactory transmissionFactory, IEncodingFactory encodingfactory, ITransmissionLogger transmissionLogger) { var items = new List<FileTransmissionItem>(); try { if (UseMime) { MimeEncoding encoding = new MimeEncoding(transmissionFactory); var encoded = encoding.Encode(parts); using (var mimeResult = encoded.Stream) { //TODO determine better way to provide the part. items.Add(new FileTransmissionItem(null, mimeResult, new Uri(Path.Combine(LocalPath, Guid.NewGuid().ToString() + ".mim")), encoded.ContentType, 0)); } } else { if (JmfFolderInfo == null && JdfFolderInfo == null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaild, Id)); } if (JmfFolderInfo != null && (JdfFolderInfo == null || AttachmentFolderInfo == null)) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJMFNoJDF, Id)); } if (JdfFolderInfo != null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJDFNoAttach, Id)); } Guid transmissionGuid = Guid.NewGuid(); string jobId = "JDF_JobIdUnknown"; string jobKey = "JDF_JobKeyUnknown"; var jdfTransmissionPart = parts.TicketPart; //pass over parts to get the job id and key if (jdfTransmissionPart != null) { //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. var ticket = parts.Ticket; if (ticket.Root.GetJobId().Length > 0) { jobId = "JDF_" + ticket.Root.GetJobId(); } if (ticket.Root.GetId().Length > 0) { jobKey = "JDF_" + ticket.Root.GetId(); } } var itemsToProcess = new List<KeyValuePair<ITransmissionPart, string>>(); //pass over parts to generate destination file names and mapping var urlMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); foreach (ITransmissionPart part in parts) { FileTransmitterFolderInfo folder; string extension = null; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; extension = ".jdf"; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; extension = ".jmf"; } else { folder = AttachmentFolderInfo; extension = MimeTypeHelper.MimeTypeExtension(part.MimeType); } string fileName = part.Id.ToString() + extension; if (folder != null) { var newFileName = Path.Combine(ExpandFolder(folder.DestinationFolder, transmissionGuid, jobId, jobKey), fileName); string referencePath = Path.Combine(ExpandFolder(folder.ReferenceFolder, transmissionGuid, jobId, jobKey), fileName); urlMapping.Add("cid:" + part.Id.ToLower(), referencePath); itemsToProcess.Add(new KeyValuePair<ITransmissionPart, string>(part, newFileName)); } } //fixup urls and add to the collection of files to send foreach (var processPart in itemsToProcess) { FileTransmitterFolderInfo folder; var part = processPart.Key; var file = processPart.Value; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; } else { folder = AttachmentFolderInfo; } //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JdfMimeType) { FileSpecUrlMangler.MapFileSpecUrls(parts.Ticket, urlMapping, true); FileSpecUrlMangler.MapPreviewUrls(parts.Ticket, urlMapping, true); } //TODO is this the best way to obtain the message? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JmfMimeType) { MapMessageUrls(parts.Message, urlMapping); } if (folder != null) { if (!folder.Suppress) { var encodingResult = encodingfactory.GetEncodingForMimeType(part.MimeType).Encode(part); encodingResult.Stream.Seek(0, SeekOrigin.Begin); transmissionLogger.Log(new TransmissionData(encodingResult.Stream, encodingResult.ContentType, "Request")); items.Add(new FileTransmissionItem(part, encodingResult.Stream, new Uri(file), part.MimeType, folder.Order)); } } } } } catch (Exception err) { throw new JdfException(string.Format(FluentJdf.Resources.Messages.ErrorOccuredWhileTryingToEncodeTransmissionMessageIs, err.Message), err); } return items; }