Ejemplo n.º 1
0
        /// <summary>
        /// Constructs an OData request body using the given settings
        /// </summary>
        /// <param name="contentType">The content type of the body</param>
        /// <param name="uri">The request uri</param>
        /// <param name="rootElement">The root payload element</param>
        /// <returns>An OData request body</returns>
        public ODataPayloadBody BuildBody(string contentType, ODataUri uri, ODataPayloadElement rootElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");
            ExceptionUtilities.CheckArgumentNotNull(rootElement, "rootElement");
            ExceptionUtilities.CheckAllRequiredDependencies(this);

            string charset = HttpUtilities.GetContentTypeCharsetOrNull(contentType);

            byte[] serializedBody      = null;
            var    batchRequestPayload = rootElement as BatchRequestPayload;

            if (batchRequestPayload != null)
            {
                string boundary;
                ExceptionUtilities.Assert(HttpUtilities.TryGetContentTypeParameter(contentType, HttpHeaders.Boundary, out boundary), "Could not find boundary in content type for batch payload. Content type was: '{0}'", contentType);
                serializedBody = this.BatchSerializer.SerializeBatchPayload(batchRequestPayload, boundary, charset);
            }
            else
            {
                IProtocolFormatStrategy strategy = this.FormatSelector.GetStrategy(contentType, uri);
                ExceptionUtilities.CheckObjectNotNull(strategy, "Strategy selector did not return a strategy for content type '{0}'", contentType);

                IPayloadSerializer serializer = strategy.GetSerializer();
                ExceptionUtilities.CheckObjectNotNull(serializer, "Strategy returned a null serializer");

                serializedBody = serializer.SerializeToBinary(rootElement, charset);
            }

            return(new ODataPayloadBody(serializedBody, rootElement));
        }
        /// <summary>
        /// This method resolves the relevant serializer for the object type.
        /// </summary>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="serializer">The output serializer.</param>
        /// <returns>Returns true if a serializer can be resolved.</returns>
        /// <exception cref="ArgumentNullException">objectType cannot be null.</exception>
        protected bool SerializerResolve(Type objectType, out IPayloadSerializer serializer)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException("objectType", "objectType cannot be null.");
            }

            serializer = null;

            serializer = mLookUpCache.GetOrAdd(objectType
                                               , (t) =>
            {
                IPayloadSerializer ser = null;
                try
                {
                    ser = mPayloadSerializers.Values.FirstOrDefault((s) => s.SupportsContentTypeSerialization(t));
                }
                catch (Exception ex)
                {
                    Collector?.LogException("", ex);
                    ser = null;
                }

                return(ser);
            }
                                               );

            return(serializer != null);
        }
Ejemplo n.º 3
0
 public AuthenticateController(
     IOpenidAuthenticateResourceOwnerAction openidAuthenticateResourceOwnerAction,
     IProfileActions profileActions,
     IDataProtectionProvider dataProtectionProvider,
     IEncoder encoder,
     ITranslationManager translationManager,
     IOpenIdEventSource simpleIdentityServerEventSource,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     IUserActions userActions,
     IPayloadSerializer payloadSerializer,
     IConfigurationService configurationService,
     IAuthenticateHelper authenticateHelper,
     ISmsAuthenticationOperation smsAuthenticationOperation,
     IGenerateAndSendSmsCodeOperation generateAndSendSmsCodeOperation,
     IResourceOwnerAuthenticateHelper resourceOwnerAuthenticateHelper,
     SmsAuthenticationOptions basicAuthenticateOptions) : base(openidAuthenticateResourceOwnerAction, profileActions, dataProtectionProvider, encoder,
                                                               translationManager, simpleIdentityServerEventSource, urlHelperFactory, actionContextAccessor, eventPublisher,
                                                               authenticationService, authenticationSchemeProvider, userActions, payloadSerializer, configurationService,
                                                               authenticateHelper, basicAuthenticateOptions)
 {
     _smsAuthenticationOperation      = smsAuthenticationOperation;
     _generateAndSendSmsCodeOperation = generateAndSendSmsCodeOperation;
     _resourceOwnerAuthenticateHelper = resourceOwnerAuthenticateHelper;
 }
Ejemplo n.º 4
0
        /// <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="defaultDeserializerContentType">Default deserializer MIME Content-type, i.e application/json.</param>
        /// <param name="defaultDeserializerContentEncoding">Default deserializer MIME Content-encoding, i.e. GZIP.</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
                                              , string defaultDeserializerContentType       = null
                                              , string defaultDeserializerContentEncoding   = null
                                              , ServiceMessageHeaderFragment requestAddress = null
                                              , ServiceMessageHeader responseAddress        = null
                                              , int?requestAddressPriority         = null
                                              , int responseAddressPriority        = 1
                                              , IPayloadSerializer serializer      = null
                                              , Action <UdpChannelListener> action = null
                                              )
            where C : IPipelineChannelIncoming <IPipeline>
        {
            defaultDeserializerContentType = (
                defaultDeserializerContentType
                ?? serializer?.ContentType
                ?? $"udp_in/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

            var listener = new UdpChannelListener(udp
                                                  , defaultDeserializerContentType, defaultDeserializerContentEncoding
                                                  , requestAddress, responseAddress, requestAddressPriority, responseAddressPriority
                                                  );

            if (serializer != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(serializer, defaultDeserializerContentType);
            }

            cpipe.AttachListener(listener, action, true);

            return(cpipe);
        }
Ejemplo n.º 5
0
 public AuthenticateController(
     IAuthenticateActions authenticateActions,
     IProfileActions profileActions,
     IDataProtectionProvider dataProtectionProvider,
     IEncoder encoder,
     ITranslationManager translationManager,
     IOpenIdEventSource simpleIdentityServerEventSource,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     IUserActions userActions,
     IPayloadSerializer payloadSerializer,
     IConfigurationService configurationService,
     IAuthenticateHelper authenticateHelper,
     IResourceOwnerAuthenticateHelper resourceOwnerAuthenticateHelper,
     ITwoFactorAuthenticationHandler twoFactorAuthenticationHandler,
     BasicAuthenticateOptions basicAuthenticateOptions) : base(authenticateActions, profileActions, dataProtectionProvider, encoder,
                                                               translationManager, simpleIdentityServerEventSource, urlHelperFactory, actionContextAccessor, eventPublisher,
                                                               authenticationService, authenticationSchemeProvider, userActions, payloadSerializer, configurationService,
                                                               authenticateHelper, twoFactorAuthenticationHandler, basicAuthenticateOptions)
 {
     _resourceOwnerAuthenticateHelper = resourceOwnerAuthenticateHelper;
 }
Ejemplo n.º 6
0
        private void FinalizeHandshake(HandshakeFrame handshakeFrame)
        {
            _extensionService.ServerConfirm(handshakeFrame);
            _connection.SetHandshakeCompleted();
            _state = ServerState.Ready;
            var extensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack");

            if (extensionId != 0)
            {
                var name          = _extensionService.FindFirstExtensionNamed("batch-ack", "ack");
                var extProperties = handshakeFrame.GetExtension(name);
                var ackExtension  = (IAckExtension)_extensionService.Get(extensionId);
                _ackReceiver = ackExtension.CreateAckReceiver(_connection, extensionId, DeliverMessage, extProperties);
                _ackSender   = ackExtension.CreateAckSender(_connection, extensionId, extProperties);
            }


            extensionId = _extensionService.FindFirstExtensionId("json", "protobuf", "xml");
            if (extensionId != 0)
            {
                var payloadExtension = (IPayloadExtension)_extensionService.Get(extensionId);
                _payloadSerializer = payloadExtension.CreatePayloadSerializer();
            }


            if (HandshakeCompleted != null)
            {
                HandshakeCompleted();
            }
        }
Ejemplo n.º 7
0
 public void PostSerialize(IPayloadSerializer serializer, Stream stream)
 {
     lock (Event)
     {
         Arguments = null;
     }
 }
Ejemplo n.º 8
0
 public RedisEventRegistry(
     IConnectionMultiplexer connection,
     IPayloadSerializer serializer)
 {
     _connection = connection;
     _serializer = serializer;
 }
Ejemplo n.º 9
0
 public UserInfoActions(IGetJwsPayload getJwsPayload, IEventPublisher eventPublisher,
                        IPayloadSerializer payloadSerializer)
 {
     _getJwsPayload     = getJwsPayload;
     _eventPublisher    = eventPublisher;
     _payloadSerializer = payloadSerializer;
 }
Ejemplo n.º 10
0
        public void PostDeserialize(IPayloadSerializer serializer, Stream stream)
        {
            lock (Event)
            {
                if (Arguments == null || Arguments.Length == 0)
                {
                    Types   = null;
                    Objects = null;
                }
                else
                {
                    Types   = new Type[Arguments.Length];
                    Objects = new object[Arguments.Length];
                    for (var i = 0; i < Arguments.Length; i++)
                    {
                        var arg = Arguments[i];
                        using (var mm = new MemoryStream(arg))
                        {
                            Objects[i] = serializer.Deserialize(serializer.SupportedContentType, mm, out Types[i]);
                        }
                    }
                }

                Arguments = null;
            }
        }
Ejemplo n.º 11
0
 public BaseAuthenticateController(
     IOpenidAuthenticateResourceOwnerAction openidAuthenticateResourceOwnerAction,
     IProfileActions profileActions,
     IDataProtectionProvider dataProtectionProvider,
     IEncoder encoder,
     ITranslationManager translationManager,
     IOpenIdEventSource simpleIdentityServerEventSource,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     IUserActions userActions,
     IPayloadSerializer payloadSerializer,
     IConfigurationService configurationService,
     IAuthenticateHelper authenticateHelper,
     BasicAuthenticateOptions basicAuthenticateOptions) : base(authenticationService)
 {
     _openidAuthenticateResourceOwnerAction = openidAuthenticateResourceOwnerAction;
     _profileActions     = profileActions;
     _dataProtector      = dataProtectionProvider.CreateProtector("Request");
     _encoder            = encoder;
     _translationManager = translationManager;
     _simpleIdentityServerEventSource = simpleIdentityServerEventSource;
     _urlHelper                    = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
     _eventPublisher               = eventPublisher;
     _payloadSerializer            = payloadSerializer;
     _authenticationSchemeProvider = authenticationSchemeProvider;
     _userActions                  = userActions;
     _configurationService         = configurationService;
     _authenticateHelper           = authenticateHelper;
     _basicAuthenticateOptions     = basicAuthenticateOptions;
 }
 public AuthenticateController(
     IOpenidAuthenticateResourceOwnerAction openidAuthenticateResourceOwnerAction,
     IProfileActions profileActions,
     IDataProtectionProvider dataProtectionProvider,
     IEncoder encoder,
     ITranslationManager translationManager,
     IOpenIdEventSource simpleIdentityServerEventSource,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     IUserActions userActions,
     IPayloadSerializer payloadSerializer,
     IConfigurationService configurationService,
     IAuthenticateHelper authenticateHelper,
     IResourceOwnerAuthenticateHelper resourceOwnerAuthenticateHelper,
     IChangePasswordAction changePasswordAction,
     ILoginPwdAuthenticateAction loginPwdAuthenticateAction,
     LoginPasswordOptions basicAuthenticateOptions) : base(openidAuthenticateResourceOwnerAction, profileActions, dataProtectionProvider, encoder,
                                                           translationManager, simpleIdentityServerEventSource, urlHelperFactory, actionContextAccessor, eventPublisher,
                                                           authenticationService, authenticationSchemeProvider, userActions, payloadSerializer, configurationService,
                                                           authenticateHelper, basicAuthenticateOptions)
 {
     _resourceOwnerAuthenticateHelper = resourceOwnerAuthenticateHelper;
     _changePasswordAction            = changePasswordAction;
     _loginPwdAuthenticateAction      = loginPwdAuthenticateAction;
 }
Ejemplo n.º 13
0
        private void BackFillDefaults()
        {
            if (_validated)
            {
                return;
            }

            LoggerFactory = LoggerFactory ?? new LoggerFactory();
            _serializer   = _serializer ?? new PayloadSerializer();
            _protector    = _protector ?? new PayloadProtector();
            _cronProvider = _cronProvider ?? new CronProvider();
            _resolver     = _resolver ?? new DependencyResolver(_services, GetConfiguredAssemblies());
            _dispatcher   = _dispatcher ?? new WorkDispatcher(_resolver);


            _services.Add(typeof(ILoggerFactory), LoggerFactory);
            _services.Add(typeof(IPayloadProtector), _protector);
            _services.Add(typeof(IPayloadSerializer), _serializer);
            _services.Add(typeof(IWorkDispatcher), _dispatcher);

            Validate();

            var logger = LoggerFactory.CreateLogger <QuidjiboBuilder>();

            logger.LogDebug("Work Factory : {WorkerFactory}", WorkProviderFactory.GetType().Name);
            logger.LogDebug("Schedule Factory : {ScheduleFactory}", ScheduleProviderFactory.GetType().Name);
            logger.LogDebug("Progress Factory : {ProgressFactory}", ProgressProviderFactory.GetType().Name);
            logger.LogDebug("Serializer : {Serializer}", _serializer.GetType().Name);
            logger.LogDebug("Protector : {Protector}", _protector.GetType().Name);
            logger.LogDebug("Cron : {Cron}", _cronProvider.GetType().Name);
            logger.LogDebug("Resolver: {Resolver}", _resolver.GetType().Name);
            logger.LogDebug("Dispatcher: {Dispatcher}", _dispatcher.GetType().Name);
        }
 public static T Deserialize <T>(this byte[] data, IPayloadSerializer serializer)
 {
     using (var ms = new MemoryStream(data))
     {
         return((T)serializer.Deserialize(serializer.SupportedContentType, ms, out var type));
     }
 }
Ejemplo n.º 15
0
 public AuthenticateController(
     IAuthenticateActions authenticateActions,
     IDataProtectionProvider dataProtectionProvider,
     IEncoder encoder,
     ITranslationManager translationManager,
     ISimpleIdentityServerEventSource simpleIdentityServerEventSource,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     IUserActions userActions,
     IPayloadSerializer payloadSerializer,
     AuthenticateOptions authenticateOptions,
     IConfigurationService configurationService,
     IAuthenticateHelper authenticateHelper) : base(authenticationService, authenticateOptions)
 {
     _authenticateActions             = authenticateActions;
     _dataProtector                   = dataProtectionProvider.CreateProtector("Request");
     _encoder                         = encoder;
     _translationManager              = translationManager;
     _simpleIdentityServerEventSource = simpleIdentityServerEventSource;
     _urlHelper                       = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext);
     _eventPublisher                  = eventPublisher;
     _payloadSerializer               = payloadSerializer;
     _authenticationSchemeProvider    = authenticationSchemeProvider;
     _configurationService            = configurationService;
     _authenticateHelper              = authenticateHelper;
 }
 public AuthorizationActions(
     IGetAuthorizationCodeOperation getAuthorizationCodeOperation,
     IGetTokenViaImplicitWorkflowOperation getTokenViaImplicitWorkflowOperation,
     IGetAuthorizationCodeAndTokenViaHybridWorkflowOperation getAuthorizationCodeAndTokenViaHybridWorkflowOperation,
     IAuthorizationCodeGrantTypeParameterAuthEdpValidator authorizationCodeGrantTypeParameterValidator,
     IParameterParserHelper parameterParserHelper,
     IOAuthEventSource oauthEventSource,
     IAuthorizationFlowHelper authorizationFlowHelper,
     IEventPublisher eventPublisher,
     IPayloadSerializer payloadSerializer,
     IAmrHelper amrHelper,
     IResourceOwnerAuthenticateHelper resourceOwnerAuthenticateHelper)
 {
     _getAuthorizationCodeOperation        = getAuthorizationCodeOperation;
     _getTokenViaImplicitWorkflowOperation = getTokenViaImplicitWorkflowOperation;
     _getAuthorizationCodeAndTokenViaHybridWorkflowOperation =
         getAuthorizationCodeAndTokenViaHybridWorkflowOperation;
     _authorizationCodeGrantTypeParameterValidator = authorizationCodeGrantTypeParameterValidator;
     _parameterParserHelper   = parameterParserHelper;
     _oauthEventSource        = oauthEventSource;
     _authorizationFlowHelper = authorizationFlowHelper;
     _eventPublisher          = eventPublisher;
     _payloadSerializer       = payloadSerializer;
     _amrHelper = amrHelper;
     _resourceOwnerAuthenticateHelper = resourceOwnerAuthenticateHelper;
 }
Ejemplo n.º 17
0
        public static P AddPayloadSerializer <P>(this P pipeline, IPayloadSerializer serializer)
            where P : IPipeline
        {
            pipeline.Service.Serialization.RegisterPayloadSerializer(serializer);

            return(pipeline);
        }
Ejemplo n.º 18
0
 public TokenActions(
     IGetTokenByResourceOwnerCredentialsGrantTypeAction getTokenByResourceOwnerCredentialsGrantType,
     IGetTokenByAuthorizationCodeGrantTypeAction getTokenByAuthorizationCodeGrantTypeAction,
     IResourceOwnerGrantTypeParameterValidator resourceOwnerGrantTypeParameterValidator,
     IAuthorizationCodeGrantTypeParameterTokenEdpValidator authorizationCodeGrantTypeParameterTokenEdpValidator,
     IRefreshTokenGrantTypeParameterValidator refreshTokenGrantTypeParameterValidator,
     IGetTokenByRefreshTokenGrantTypeAction getTokenByRefreshTokenGrantTypeAction,
     IGetTokenByClientCredentialsGrantTypeAction getTokenByClientCredentialsGrantTypeAction,
     IClientCredentialsGrantTypeParameterValidator clientCredentialsGrantTypeParameterValidator,
     ISimpleIdentityServerEventSource simpleIdentityServerEventSource,
     IRevokeTokenAction revokeTokenAction,
     IEventPublisher eventPublisher,
     IPayloadSerializer payloadSerializer)
 {
     _getTokenByResourceOwnerCredentialsGrantType          = getTokenByResourceOwnerCredentialsGrantType;
     _getTokenByAuthorizationCodeGrantTypeAction           = getTokenByAuthorizationCodeGrantTypeAction;
     _resourceOwnerGrantTypeParameterValidator             = resourceOwnerGrantTypeParameterValidator;
     _authorizationCodeGrantTypeParameterTokenEdpValidator = authorizationCodeGrantTypeParameterTokenEdpValidator;
     _refreshTokenGrantTypeParameterValidator      = refreshTokenGrantTypeParameterValidator;
     _getTokenByRefreshTokenGrantTypeAction        = getTokenByRefreshTokenGrantTypeAction;
     _simpleIdentityServerEventSource              = simpleIdentityServerEventSource;
     _getTokenByClientCredentialsGrantTypeAction   = getTokenByClientCredentialsGrantTypeAction;
     _clientCredentialsGrantTypeParameterValidator = clientCredentialsGrantTypeParameterValidator;
     _revokeTokenAction = revokeTokenAction;
     _eventPublisher    = eventPublisher;
     _payloadSerializer = payloadSerializer;
 }
Ejemplo n.º 19
0
        /// <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="defaultSerializerContentType">Default serializer MIME Content-type, i.e application/json.</param>
        /// <param name="defaultSerializerContentTypeEncoding">Default serializer MIME Content-encoding, i.e. GZIP.</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 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
                                            , string defaultSerializerContentType         = null
                                            , string defaultSerializerContentTypeEncoding = null
                                            , IPayloadSerializer serializer    = null
                                            , Action <UdpChannelSender> action = null
                                            , int?maxUdpMessagePayloadSize     = UdpHelper.PacketMaxSize
                                            )
            where C : IPipelineChannelOutgoing <IPipeline>
        {
            defaultSerializerContentType = (
                defaultSerializerContentType
                ?? serializer?.ContentType
                ?? $"udp_out/{cpipe.Channel.Id}"
                ).ToLowerInvariant();

            var sender = new UdpChannelSender(udp, defaultSerializerContentType, defaultSerializerContentTypeEncoding, maxUdpMessagePayloadSize);

            if (serializer != null)
            {
                cpipe.Pipeline.AddPayloadSerializer(serializer, defaultSerializerContentType);
            }

            cpipe.AttachSender(sender, action, true);

            return(cpipe);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MicroDecoder" /> class.
 /// </summary>
 /// <param name="serializer">The serializer used to decode the payload</param>
 /// <exception cref="System.ArgumentNullException">serializer</exception>
 public MicroDecoder(IPayloadSerializer serializer)
 {
     Serializer = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _bytesLeftForCurrentState = sizeof(short);
     _stateMethod   = ReadHeaderLength;
     _contentStream = MemoryManager.Instance.GetStream();
 }
Ejemplo n.º 21
0
 public RegistrationActions(IRegisterClientAction registerClientAction, IEventPublisher eventPublisher,
                            IPayloadSerializer payloadSerializer)
 {
     _registerClientAction = registerClientAction;
     _eventPublisher       = eventPublisher;
     _payloadSerializer    = payloadSerializer;
 }
 public IntrospectionActions(IPostIntrospectionAction postIntrospectionAction, IEventPublisher eventPublisher,
                             IPayloadSerializer payloadSerializer, IIntrospectionParameterValidator introspectionParameterValidator)
 {
     _postIntrospectionAction         = postIntrospectionAction;
     _eventPublisher                  = eventPublisher;
     _payloadSerializer               = payloadSerializer;
     _introspectionParameterValidator = introspectionParameterValidator;
 }
 public static byte[] SerializeContent(object obj, IPayloadSerializer serializer)
 {
     using (var ms = MemoryManager.Instance.GetStream())
     {
         serializer.SerializeContent(obj, ms);
         return(ms.ToArray());
     }
 }
Ejemplo n.º 24
0
 public RedisEventStream(
     IEventDescription eventDescription,
     ChannelMessageQueue channel,
     IPayloadSerializer serializer)
 {
     _eventDescription = eventDescription;
     _channel          = channel;
     _serializer       = serializer;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Adds the payload serializer.
        /// </summary>
        /// <typeparam name="P">The pipeline type.</typeparam>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="serializer">The serializer to add.</param>
        /// <param name="mimeContentType">The override for the mime content type.</param>
        /// <returns>The pipeline.</returns>
        public static P AddPayloadSerializer <P>(this P pipeline, IPayloadSerializer serializer
                                                 , string mimeContentType = null)
            where P : IPipeline
        {
            if (mimeContentType != null)
            {
                serializer.ContentType = mimeContentType;
            }

            pipeline.Service.Serialization.RegisterPayloadSerializer(serializer);

            return(pipeline);
        }
Ejemplo n.º 26
0
 public ConsentController(
     IConsentActions consentActions,
     IDataProtectionProvider dataProtectionProvider,
     ITranslationManager translationManager,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IPayloadSerializer payloadSerializer) : base(authenticationService)
 {
     _consentActions     = consentActions;
     _dataProtector      = dataProtectionProvider.CreateProtector("Request");
     _translationManager = translationManager;
     _eventPublisher     = eventPublisher;
     _payloadSerializer  = payloadSerializer;
 }
Ejemplo n.º 27
0
 public QuidjiboClient(
     ILoggerFactory loggerFactory,
     IWorkProviderFactory workProviderFactory,
     IScheduleProviderFactory scheduleProviderFactory,
     IPayloadSerializer payloadSerializer,
     IPayloadProtector payloadProtector,
     ICronProvider cronProvider)
 {
     _logger = loggerFactory.CreateLogger(GetType());
     _workProviderFactory     = workProviderFactory;
     _scheduleProviderFactory = scheduleProviderFactory;
     _payloadSerializer       = payloadSerializer;
     _payloadProtector        = payloadProtector;
     _cronProvider            = cronProvider;
 }
Ejemplo n.º 28
0
        public void Run()
        {
            _serializer = new BinaryFormatterPayloadSerializer();

            Thread consumerThread = new Thread(ConsumerLoop);
            Thread producerThread = new Thread(ProducerLoop);

            consumerThread.IsBackground = true;
            producerThread.IsBackground = true;

            consumerThread.Start();
            producerThread.Start();

            Console.ReadKey();
        }
Ejemplo n.º 29
0
        public void Run()
        {
            _serializer = new BinaryFormatterPayloadSerializer();

            Thread consumerThread = new Thread(ConsumerLoop);
            Thread producerThread = new Thread(ProducerLoop);

            consumerThread.IsBackground = true;
            producerThread.IsBackground = true;

            consumerThread.Start();
            producerThread.Start();

            Console.ReadKey();
        }
Ejemplo n.º 30
0
 public IQuidjiboPipeline Build(
     ILoggerFactory loggerFactory,
     IDependencyResolver resolver,
     IPayloadProtector protector,
     IPayloadSerializer serializer,
     IWorkDispatcher dispatcher)
 {
     return(new QuidjiboPipeline(
                _steps,
                loggerFactory,
                resolver,
                protector,
                serializer,
                dispatcher));
 }
Ejemplo n.º 31
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MicroEncoder" /> class.
        /// </summary>
        /// <param name="serializer">
        ///     Serializer used to serialize the messages that should be sent.
        /// </param>
        /// <param name="bufferSlice">Used when sending information.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     bufferSlice; At least the header should fit in the buffer
        /// </exception>
        public MicroEncoder(IPayloadSerializer serializer, IBufferSlice bufferSlice) : this()
        {
            if (bufferSlice == null)
            {
                throw new ArgumentNullException(nameof(bufferSlice));
            }
            if (bufferSlice.Capacity < 520 - 256 + 2048)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSlice), bufferSlice.Capacity,
                                                      "At least the header should fit in the buffer, and the header can be up to *520-256+2048* bytes");
            }


            Serializer   = serializer ?? throw new ArgumentNullException(nameof(serializer));
            _bufferSlice = bufferSlice;
        }
Ejemplo n.º 32
0
        public void Run()
        {
            Random rnd = new Random();
            int option = rnd.Next(1, 5);
            working = true;

            switch (option)
            {
                case 1:
                    sType = "Xml Serializer";
                    _serializer = new XmlSerializationClass();
                    break;
                case 2:
                    sType = "JSON Serializer";
                    _serializer = new JSONStreamSerializer();
                    break;
                case 3:
                    sType = "Binary Serializer";
                    _serializer = new BinaryFormatterPayloadSerializer();
                    break;
                case 4:
                    sType = "Protobuf Serializer";
                    _serializer = new ProtobufSerialization();
                    break;
            }

            Thread consumerThread = new Thread(ConsumerLoop);
            Thread producerThread = new Thread(ProducerLoop);

            consumerThread.IsBackground = true;
            producerThread.IsBackground = true;

            consumerThread.Start();
            producerThread.Start();

            Console.ReadKey();
        }
Ejemplo n.º 33
0
        private void FinalizeHandshake(HandshakeFrame handshakeFrame)
        {
            _extensionService.ServerConfirm(handshakeFrame);
            _connection.SetHandshakeCompleted();
            _state = ServerState.Ready;
            var extensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack");
            if (extensionId != 0)
            {
                var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack");
                var extProperties = handshakeFrame.GetExtension(name);
                var ackExtension = (IAckExtension) _extensionService.Get(extensionId);
                _ackReceiver = ackExtension.CreateAckReceiver(_connection, extensionId, DeliverMessage, extProperties);
                _ackSender = ackExtension.CreateAckSender(_connection, extensionId, extProperties);
            }

            extensionId = _extensionService.FindFirstExtensionId("json", "protobuf", "xml");
            if (extensionId != 0)
            {
                var payloadExtension = (IPayloadExtension) _extensionService.Get(extensionId);
                _payloadSerializer = payloadExtension.CreatePayloadSerializer();
            }

            if (HandshakeCompleted != null)
                HandshakeCompleted();
        }
        private void OnServerHandshakeFrame(object source, HandshakeFrameReceivedEventArgs e)
        {
            if (_state != ClientState.ServerToClientHandshake)
                throw new Exception("Server handshake should not be received during " + _state);
            var frame = _extensionService.ClientConfirmExtensions(e.Handshake, _connection.Identity);

            _state = ClientState.Ready;
            _connection.SetHandshakeCompleted();
            _connection.Send(frame);

            //TODO: This is a mess. Create a better way
            // to identify and activate extensions.
            // maybe by defining extension behavior like IInboundMessageProcessor.

            var id = _extensionService.FindFirstExtensionId("json", "xml", "protobuf");
            if (id > 0)
                _payloadSerializer = (((IPayloadExtension)_extensionService.Get(id))).CreatePayloadSerializer();

            id = _extensionService.FindFirstExtensionId("dotnet");
            if (id > 0)
                _dotNetExtension = (DotNetTypeExtension) _extensionService.Get(id);

            _ackExtensionId = _extensionService.FindFirstExtensionId("batch-ack", "ack");
            if (_ackExtensionId != 0)
            {
                var name = _extensionService.FindFirstExtensionNamed("batch-ack", "ack");
                var extProperties = frame.GetExtension(name);
                var ackExtension = (IAckExtension) _extensionService.Get(_ackExtensionId);
                _ackReceiver = ackExtension.CreateAckReceiver(_connection, _ackExtensionId, DeliverMessage,
                    extProperties);
                _ackSender = ackExtension.CreateAckSender(_connection, _ackExtensionId, extProperties);

            }

            _authenticationEvent.Set();
        }