/// <summary> /// Constructor. /// </summary> /// <param name="encodingfactory"></param> /// <param name="httpWebRequestFactory"></param> /// <param name="transmissionLogger"></param> public HttpTransmitter(IEncodingFactory encodingfactory, IHttpWebRequestFactory httpWebRequestFactory, ITransmissionLogger transmissionLogger) { ParameterCheck.ParameterRequired(encodingfactory, "encodingfactory"); ParameterCheck.ParameterRequired(httpWebRequestFactory, "httpWebRequestFactory"); ParameterCheck.ParameterRequired(transmissionLogger, "transmissionLogger"); this.encodingfactory = encodingfactory; this.httpWebRequestFactory = httpWebRequestFactory; this.transmissionLogger = transmissionLogger; }
/// <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> /// Initializes a new instance of the <see cref="ProducerAssociation"/> class. /// </summary> /// <param name="data">The semantic data description.</param> /// <param name="aliasName">Name of the alias - .</param> /// <param name="dataSet">The data set configuration.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> internal ProducerAssociation(ISemanticData data, string aliasName, DataSetConfiguration dataSet, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) : base(data, dataSet.AssociationName) { m_ConfigurationVersion = dataSet.ConfigurationVersion; m_DataSetBindings = dataSet.DataSet.Select<FieldMetaData, IProducerBinding> ((_fieldMetadata) => { IProducerBinding _ret = _fieldMetadata.GetProducerBinding4DataMember(dataSet.RepositoryGroup, bindingFactory, encodingFactory); _ret.PropertyChanged += ProducerBinding_PropertyChanged; return _ret; }).ToArray<IProducerBinding>(); m_Timer = new Timer(1000) { AutoReset = true }; m_Timer.Elapsed += M_Timer_Elapsed; m_Timer.Start(); }
public UaooiMessageBus( IConfigurationFactory configurationFactory, IEncodingFactory encodingFactory, IBindingFactory subscriptionFactory, IMessageHandlerFactory messageHandlerFactory, ILogger logger) { ConfigurationFactory = configurationFactory ?? throw new ComponentNotInitialisedException(nameof(configurationFactory)); EncodingFactory = encodingFactory ?? throw new ComponentNotInitialisedException(nameof(encodingFactory)); BindingFactory = subscriptionFactory ?? throw new ComponentNotInitialisedException(nameof(subscriptionFactory)); MessageHandlerFactory = messageHandlerFactory ?? throw new ComponentNotInitialisedException(nameof(messageHandlerFactory)); _logger = logger; }
public ContentCriterion(string text, bool ignoreCase, bool matchFullWords, IEncodingFactory encodingFactory) { if (text == null) { throw new ArgumentNullException("text"); } if (encodingFactory == null) { throw new ArgumentNullException("encodingFactory"); } _text = text; _ignoreCase = ignoreCase; _matchFullWords = matchFullWords; _encodingFactory = encodingFactory; _textInChars = StringToCharArrays(text, ignoreCase); }
/// <summary> /// Initializes a new instance of the <see cref="ConsumerAssociation" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="dataSet">The members.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> internal ConsumerAssociation(ISemanticData data, DataSetConfiguration dataSet, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) : base(data, dataSet.AssociationName) { m_DataSetBindings = dataSet.DataSet.Select <FieldMetaData, IConsumerBinding>(x => x.GetConsumerBinding4DataMember(dataSet.RepositoryGroup, bindingFactory, encodingFactory)).ToArray <IConsumerBinding>(); }
/// <summary> /// Creates the message handlers. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="messageHandlerFactory">The message handler factory.</param> /// <param name="encodingFactory">The encoding factory that provides functionality to lookup a dictionary containing value converters..</param> /// <param name="addMessageHandler">The add message handler.</param> /// <returns>MessageHandlersCollection.</returns> /// <exception cref="System.ArgumentOutOfRangeException">Name;Duplicated transport name</exception> internal static MessageHandlersCollection CreateMessageHandlers (MessageHandlerConfiguration[] configuration, IMessageHandlerFactory messageHandlerFactory, IEncodingFactory encodingFactory, Action <IMessageHandler, AssociationConfiguration> addMessageHandler) { MessageHandlersCollection _collection = new MessageHandlersCollection(); foreach (MessageHandlerConfiguration _configuration in configuration) { if (_collection.ContainsKey(_configuration.Name)) { throw new ArgumentOutOfRangeException("Name", "Duplicated transport name"); } IMessageHandler _handler = null; switch (_configuration.TransportRole) { case AssociationRole.Consumer: MessageReaderConfiguration _readerConfiguration = (MessageReaderConfiguration)_configuration; _handler = messageHandlerFactory.GetIMessageReader(_configuration.Name, _configuration.Configuration, encodingFactory.UADecoder); foreach (ConsumerAssociationConfiguration _consumerAssociation in _readerConfiguration.ConsumerAssociationConfigurations) { addMessageHandler(_handler, _consumerAssociation); } break; case AssociationRole.Producer: MessageWriterConfiguration _writerConfiguration = (MessageWriterConfiguration)_configuration; _handler = messageHandlerFactory.GetIMessageWriter(_configuration.Name, _configuration.Configuration, encodingFactory.UAEncoder); foreach (ProducerAssociationConfiguration _producerAssociation in _writerConfiguration.ProducerAssociationConfigurations) { addMessageHandler(_handler, _producerAssociation); } break; default: break; } _collection.Add(_configuration.Name, _handler); } return(_collection); }
/// <summary> /// Gets the consumer binding for data member. /// </summary> /// <param name="member">The field description captured bu object of type <see cref="FieldMetaData"/> .</param> /// <param name="repositoryGroup">The repository group.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> /// <returns>An instance of <see cref="IProducerBinding" /> type.</returns> internal static IProducerBinding GetProducerBinding4DataMember(this FieldMetaData member, string repositoryGroup, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) { IProducerBinding _binding = bindingFactory.GetProducerBinding(repositoryGroup, member.ProcessValueName, member.TypeInformation); encodingFactory.UpdateValueConverter(_binding, repositoryGroup, member.TypeInformation); return _binding; }
/// <summary> /// Creates the associations and populates the new dictionary with the associations instances created using the configuration <paramref name="configuration"/>. /// </summary> /// <param name="configuration">The configuration used to populate the collection.</param> /// <param name="bindingFactory">The binding factory responsible to create and return <see cref="IBinding"/> instance for each association.</param> /// <param name="encodingFactory">The encoding factory responsible to updated the created <see cref="IBinding"/> by provisioning all information necessary for encoding/decoding including <see cref="IValueConverter"/>.</param> /// <returns>New dictionary of type <see cref="AssociationsCollection"/>.</returns> /// <exception cref="System.ArgumentOutOfRangeException">Alias; Alias of any <see cref="Association"/> must be unique.</exception> internal static AssociationsCollection CreateAssociations(DataSetConfiguration[] configuration, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) { AssociationsCollection _collection = new AssociationsCollection(); Association _newAssociation = null; foreach (DataSetConfiguration _dataSet in configuration) { if (_collection.ContainsKey(_dataSet.AssociationName)) { throw new ArgumentOutOfRangeException("Alias", "Alias of any Association must be unique"); } SemanticData _newSemanticData = new SemanticData(new Uri(_dataSet.InformationModelURI), _dataSet.DataSymbolicName, null, _dataSet.Id); switch (_dataSet.AssociationRole) { case AssociationRole.Consumer: _newAssociation = new ConsumerAssociation(_newSemanticData, _dataSet, bindingFactory, encodingFactory); break; case AssociationRole.Producer: _newAssociation = new ProducerAssociation(_newSemanticData, _dataSet.AssociationName, _dataSet, bindingFactory, encodingFactory); break; default: break; } _collection.Add(_dataSet.AssociationName, _newAssociation); } return(_collection); }
/// <summary> /// Initializes a new instance of the <see cref="ProducerAssociation"/> class. /// </summary> /// <param name="data">The semantic data description.</param> /// <param name="aliasName">Name of the alias - .</param> /// <param name="dataSet">The data set configuration.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> internal ProducerAssociation(ISemanticData data, string aliasName, DataSetConfiguration dataSet, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) : base(data, dataSet.AssociationName) { m_ConfigurationVersion = dataSet.ConfigurationVersion; m_DataSetBindings = dataSet.DataSet.Select <FieldMetaData, IProducerBinding> ((_fieldMetadata) => { IProducerBinding _ret = _fieldMetadata.GetProducerBinding4DataMember(dataSet.RepositoryGroup, bindingFactory, encodingFactory); _ret.PropertyChanged += ProducerBinding_PropertyChanged; return(_ret); }).ToArray <IProducerBinding>(); m_Timer = new Timer(1000) { AutoReset = true }; m_Timer.Elapsed += M_Timer_Elapsed; m_Timer.Start(); }
/// <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> /// Gets the consumer binding for data member. /// </summary> /// <param name="member">The field description captured bu object of type <see cref="FieldMetaData"/> .</param> /// <param name="repositoryGroup">The repository group.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> /// <returns>An instance of <see cref="IProducerBinding" /> type.</returns> internal static IProducerBinding GetProducerBinding4DataMember(this FieldMetaData member, string repositoryGroup, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) { IProducerBinding _binding = bindingFactory.GetProducerBinding(repositoryGroup, member.ProcessValueName, member.TypeInformation); encodingFactory.UpdateValueConverter(_binding, repositoryGroup, member.TypeInformation); return(_binding); }
/// <summary> /// Initializes a new instance of the <see cref="ConsumerAssociation" /> class. /// </summary> /// <param name="data">The data.</param> /// <param name="dataSet">The members.</param> /// <param name="bindingFactory">The binding factory.</param> /// <param name="encodingFactory">The encoding factory.</param> internal ConsumerAssociation(ISemanticData data, DataSetConfiguration dataSet, IBindingFactory bindingFactory, IEncodingFactory encodingFactory) : base(data, dataSet.AssociationName) { m_DataSetBindings = dataSet.DataSet.Select<FieldMetaData, IConsumerBinding>(x => x.GetConsumerBinding4DataMember(dataSet.RepositoryGroup, bindingFactory, encodingFactory)).ToArray<IConsumerBinding>(); }
/// <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; }