/// <summary> /// Initializes a new instance of the <see cref="CommunicationAgentBase"/> class. /// </summary> /// <param name="capabilities">The agent capabilities. The default is bidirectional.</param> /// <param name="serializerId">The optional preferred serializer identifier.</param> /// <param name="compressionId">The optional preferred compression identifier.</param> /// <param name="encryptionId">The optional preferred encryption identifier.</param> protected CommunicationAgentBase( CommunicationAgentCapabilities capabilities = CommunicationAgentCapabilities.Bidirectional , SerializationHandlerId serializerId = null , CompressionHandlerId compressionId = null , EncryptionHandlerId encryptionId = null) : base(capabilities, serializerId, compressionId, encryptionId) { }
/// <summary> /// Adds an events hub data colletor to the pipeline /// </summary> /// <typeparam name="P">Type of IPipeline</typeparam> /// <param name="pipeline">Pipeline</param> /// <param name="connectionString">Event Hub Connection String</param> /// <param name="entityPath">Event Path</param> /// <param name="adjustPolicy">Adjust Policy Action</param> /// <param name="resourceProfile">Resource Profile</param> /// <param name="encryptionHandler">Encryption Handler</param> /// <param name="onCreate">Collector OnCreate Action</param> /// <returns></returns> public static P AddEventHubsDataCollector <P>(this P pipeline , string connectionString = null , string entityPath = null , Action <EventHubsDataCollectorPolicy> adjustPolicy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionHandler = null , Action <EventHubsDataCollector> onCreate = null) where P : IPipeline { var policy = new EventHubsDataCollectorPolicy(); if (encryptionHandler != null && !pipeline.Service.Security.HasEncryptionHandler(encryptionHandler.Id)) { throw new EncryptionHandlerNotResolvedException(encryptionHandler.Id); } adjustPolicy?.Invoke(policy); if (connectionString == null) { connectionString = pipeline.Configuration.EventHubsConnection(); } var component = new EventHubsDataCollector(connectionString , entityPath , policy , resourceProfile , encryptionHandler); onCreate?.Invoke(component); pipeline.AddDataCollector(component); return(pipeline); }
/// <summary> /// Attaches the UDP listener to the incoming channel. /// </summary> /// <typeparam name="C">The pipeline type.</typeparam> /// <param name="cpipe">The pipeline.</param> /// <param name="udp">The UDP endpoint configuration.</param> /// <param name="serializerId">Default serializer MIME Content-type id, i.e application/json.</param> /// <param name="compressionId">Default serializer MIME Content-encoding id, i.e. GZIP.</param> /// <param name="encryptionId">The encryption handler id.</param> /// <param name="requestAddress">This is the optional address fragment which specifies the incoming message destination. If this is not set then ("","") will be used. This does not include a channelId as this will be provided by the pipeline.</param> /// <param name="responseAddress">This is the optional return address destination to be set for the incoming messages.</param> /// <param name="requestAddressPriority">This is the default priority for the request message. The default is null. This will inherit from the channel priority.</param> /// <param name="responseAddressPriority">This is the priority for the response address. The default is 1.</param> /// <param name="serializer">This is an optional serializer that can be added with the specific mime type. Note: the serializer mime type will be changed, so you should not share this serializer instance.</param> /// <param name="action">The optional action to be called when the listener is created.</param> /// <returns>Returns the pipeline.</returns> public static C AttachUdpListener <C>(this C cpipe , UdpConfig udp , SerializationHandlerId serializerId = null , CompressionHandlerId compressionId = null , EncryptionHandlerId encryptionId = null , ServiceMessageHeaderFragment requestAddress = null , ServiceMessageHeader responseAddress = null , int?requestAddressPriority = null , int responseAddressPriority = 1 , IServiceHandlerSerialization serializer = null , Action <IListener> action = null ) where C : IPipelineChannelIncoming <IPipeline> { serializerId = (serializerId?.Id ?? serializer?.Id ?? $"udp_in/{cpipe.Channel.Id}").ToLowerInvariant(); var listener = new UdpCommunicationAgent(udp , CommunicationAgentCapabilities.Listener , serializerId, compressionId, encryptionId , requestAddress, responseAddress, requestAddressPriority, responseAddressPriority ); if (serializer != null) { cpipe.Pipeline.AddPayloadSerializer(serializer); } cpipe.AttachListener(listener, action, true); return(cpipe); }
/// <summary> /// Attaches the UDP sender to the outgoing channel. /// </summary> /// <typeparam name="C">The pipeline type.</typeparam> /// <param name="cpipe">The pipeline.</param> /// <param name="udp">The UDP endpoint configuration.</param> /// <param name="serializerId">Default serializer MIME Content-type id, i.e application/json.</param> /// <param name="compressionId">Default serializer MIME Content-encoding id, i.e. GZIP.</param> /// <param name="encryptionId">The encryption handler id.</param> /// <param name="serialize">The serialize action.</param> /// <param name="canSerialize">The optional serialize check function.</param> /// <param name="action">The optional action to be called when the sender is created.</param> /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param> /// <returns>Returns the pipeline.</returns> public static C AttachUdpSender <C>(this C cpipe , UdpConfig udp , SerializationHandlerId serializerId = null , CompressionHandlerId compressionId = null , EncryptionHandlerId encryptionId = null , Action <ServiceHandlerContext> serialize = null , Func <ServiceHandlerContext, bool> canSerialize = null , Action <ISender> action = null , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize ) where C : IPipelineChannelOutgoing <IPipeline> { serializerId = ( serializerId?.Id ?? $"udp_out/{cpipe.Channel.Id}" ).ToLowerInvariant(); var sender = new UdpCommunicationAgent(udp , CommunicationAgentCapabilities.Sender , serializerId, compressionId, encryptionId , maxUdpMessagePayloadSize: maxUdpMessagePayloadSize ); if (serialize != null) { cpipe.Pipeline.AddPayloadSerializer(serializerId , serialize: serialize , canSerialize: canSerialize); } cpipe.AttachSender(sender, action, true); return(cpipe); }
/// <summary> /// This constructor passes in the support types for the collector. /// </summary> protected DataCollectorBase(EncryptionHandlerId encryptionId = null , ResourceProfile resourceProfile = null , DataCollectionSupport?supportMap = null , P policy = null) : base(policy) { mResourceProfile = resourceProfile; mSupportMapSubmitted = supportMap; mEncryption = encryptionId; }
/// <summary> /// Initializes a new instance of the <see cref="UdpChannelSender"/> class. /// </summary> /// <param name="udp">The UDP endpoint configuration.</param> /// <param name="contentType">The MIME Content Type which is used to specify the serialization handler.</param> /// <param name="contentEncoding">The optional content encoding handler for the binary blob.</param> /// <param name="encryption">The optional payload encryption handler.</param> /// <param name="maxUdpMessagePayloadSize">This is the max UDP message payload size. The default is 508 bytes. If you set this to null, the sender will not check the size before transmitting.</param> public UdpChannelSender(UdpConfig udp , SerializationHandlerId contentType , CompressionHandlerId contentEncoding = null , EncryptionHandlerId encryption = null , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize ) { Config = udp; ContentType = contentType ?? throw new ArgumentNullException("contentType"); ContentEncoding = contentEncoding; Encryption = encryption; UdpMessageMaximumPayloadSize = maxUdpMessagePayloadSize; }
/// <summary> /// Initializes a new instance of the <see cref="UdpCommunicationAgent"/> class. /// </summary> /// <param name="config">The UDP endpoint configuration.</param> /// <param name="serializerId">The optional serializer identifier.</param> /// <param name="compressionId">The optional compression identifier.</param> /// <param name="encryptionId">The optional encryption identifier.</param> /// <param name="requestAddress">The optional request address.</param> /// <param name="responseAddress">The optional response address.</param> /// <param name="requestAddressPriority">The optional request address priority.</param> /// <param name="responseAddressPriority">The optional response address priority.</param> /// <param name="capabilities">The agent capabilities. The default is bidirectional.</param> /// <param name="maxUdpMessagePayloadSize">Maximum size of the UDP message payload.</param> public UdpCommunicationAgent(UdpConfig config , CommunicationAgentCapabilities capabilities = CommunicationAgentCapabilities.Bidirectional , SerializationHandlerId serializerId = null , CompressionHandlerId compressionId = null , EncryptionHandlerId encryptionId = null , ServiceMessageHeaderFragment requestAddress = null , ServiceMessageHeader responseAddress = null , int?requestAddressPriority = null , int responseAddressPriority = 1 , int?maxUdpMessagePayloadSize = UdpHelper.PacketMaxSize ) : base(capabilities, serializerId, compressionId, encryptionId) { mConfig = config ?? throw new ArgumentNullException("config", "Udp configuration cannot be null."); }
/// <summary> /// Validates that the required handler is supported. /// </summary> /// <param name="handler">The handler identifier.</param> /// <param name="throwErrors">if set to <c>true</c> [throw errors].</param> /// <returns>Returns true if the encryption handler is supported.</returns> /// <exception cref="EncryptionHandlerNotResolvedException">This exception is thrown if the handler is not present and throwErrors is set to true.</exception> public bool EncryptionValidate(EncryptionHandlerId handler, bool throwErrors = true) { if (!mEncryptionHandlers.ContainsKey(handler.Id)) { if (throwErrors) { throw new EncryptionHandlerNotResolvedException(handler.Id); } else { return(false); } } return(true); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="policy"></param> /// <param name="context"></param> /// <param name="resourceProfile"></param> /// <param name="encryptionId"></param> /// <param name="supportMap"></param> public AzureStorageDataCollector(StorageCredentials credentials , AzureStorageDataCollectorPolicy policy = null , OperationContext context = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionId = null , DataCollectionSupport?supportMap = null) : base(encryptionId, resourceProfile, supportMap, policy) { if (credentials == null) { throw new ArgumentNullException($"{nameof(AzureStorageDataCollector)}: credentials cannot be null."); } mCredentails = credentials; mContext = context; }
/// <summary> /// Constructor /// </summary> /// <param name="connection">Connection string to Event Hub including the entity path</param> /// <param name="entityPath">Entity path if not supplied in the connection string</param> /// <param name="policy">Policy</param> /// <param name="resourceProfile">Resource Profile</param> /// <param name="encryptionId">Encryption Id</param> /// <param name="supportMap">Support Map</param> public EventHubsDataCollector(string connection , string entityPath , EventHubsDataCollectorPolicy policy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionId = null , DataCollectionSupport?supportMap = null) : base(encryptionId, resourceProfile, supportMap, policy) { var connectionStringBuilder = new EventHubsConnectionStringBuilder(connection); if (!string.IsNullOrWhiteSpace(entityPath)) { connectionStringBuilder.EntityPath = entityPath; } mConnection = connectionStringBuilder.ToString(); }
/// <summary> /// This extension method can be used to assign a registered encryption handler to the channel to ensure /// that the message payload in encrypted during transmission. /// </summary> /// <typeparam name="C">The pipeline channel extension type.</typeparam> /// <param name="cpipe">The pipeline.</param> /// <param name="handler">The encryption id.</param> /// <returns>Returns the pipeline.</returns> public static C AttachTransportPayloadDecryption <C>(this C cpipe, EncryptionHandlerId handler) where C : IPipelineChannelIncoming <IPipeline> { Channel channel = cpipe.ToChannel(ChannelDirection.Incoming); if (!cpipe.Pipeline.Service.ServiceHandlers.Encryption.Contains(handler.Id)) { throw new EncryptionHandlerNotResolvedException(channel.Id, handler.Id); } if (channel.Encryption != null) { throw new ChannelEncryptionHandlerAlreadySetException(cpipe.Channel.Id); } channel.Encryption = handler; return(cpipe); }
/// <summary> /// This extension method can be used to assign a registered encryption handler to the channel to ensure /// that the message payload in encrypted during transmission. /// </summary> /// <typeparam name="C">The pipeline channel extension type.</typeparam> /// <param name="cpipe">The pipeline.</param> /// <param name="handler">The encryption id.</param> /// <returns>Returns the pipeline.</returns> public static C AttachTransportPayloadEncryption <C>(this C cpipe, EncryptionHandlerId handler) where C : IPipelineChannelOutgoing <IPipeline> { Channel channel = cpipe.ChannelResolve(ChannelDirection.Outgoing); if (!cpipe.Pipeline.Service.Security.HasEncryptionHandler(handler.Id)) { throw new EncryptionHandlerNotResolvedException(channel.Id, handler.Id); } if (channel.Encryption != null) { throw new ChannelEncryptionHandlerAlreadySetException(channel.Id); } channel.Encryption = handler; return(cpipe); }
public static P AddAzureStorageDataCollector <P>(this P pipeline , StorageCredentials creds = null , Action <AzureStorageDataCollectorPolicy> adjustPolicy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId handler = null , Action <AzureStorageDataCollector> onCreate = null , OperationContext context = null ) where P : IPipeline { AzureStorageDataCollectorPolicy policy = new AzureStorageDataCollectorPolicy(); if (handler != null) { if (!pipeline.Service.Security.HasEncryptionHandler(handler.Id)) { throw new EncryptionHandlerNotResolvedException(handler.Id); } } adjustPolicy?.Invoke(policy); if (creds == null) { creds = pipeline.Configuration.AzureStorageCredentials(true); } var component = new AzureStorageDataCollector(creds, policy , context: context , encryptionId: handler); onCreate?.Invoke(component); pipeline.AddDataCollector(component); return(pipeline); }
/// <summary> /// Decrypts the specified blob using the handler provided.. /// </summary> /// <param name="handler">The handler.</param> /// <param name="input">The input blob.</param> /// <returns>Returns the unencrypted blob.</returns> public byte[] Decrypt(EncryptionHandlerId handler, byte[] input) { EncryptionValidate(handler); return(mEncryptionHandlers[handler.Id].Decrypt(input)); }