Exemplo n.º 1
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var options = request.Options;

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user, UpdateOperation, context.CancellationToken).ConfigureAwait(false))
            {
                throw AccessDenied();
            }
            var updateSource = new TaskCompletionSource <bool>();

            var envelope = new CallbackEnvelope(OnMessage);

            _publisher.Publish(new UserManagementMessage.Update(envelope, user, options.LoginName, options.FullName,
                                                                options.Groups.ToArray()));

            await updateSource.Task.ConfigureAwait(false);

            return(new UpdateResp());

            void OnMessage(Message message)
            {
                if (HandleErrors(options.LoginName, message, updateSource))
                {
                    return;
                }

                updateSource.TrySetResult(true);
            }
        }
Exemplo n.º 2
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var options = request.Options;

            var user = await GetUser(_authenticationProvider, context.RequestHeaders);

            var updateSource = new TaskCompletionSource <bool>();

            var envelope = new CallbackEnvelope(OnMessage);

            _queue.Publish(new UserManagementMessage.Update(envelope, user, options.LoginName, options.FullName,
                                                            options.Groups.ToArray()));

            await updateSource.Task;

            return(new UpdateResp());

            void OnMessage(Message message)
            {
                if (HandleErrors(options.LoginName, message, updateSource))
                {
                    return;
                }

                updateSource.TrySetResult(true);
            }
        }
Exemplo n.º 3
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatePersistentSubscriptionSource = new TaskCompletionSource <UpdateResp>();
            var settings      = request.Options.Settings;
            var correlationId = Guid.NewGuid();

            var user = context.GetHttpContext().User;

            _queue.Publish(new ClientMessage.UpdatePersistentSubscription(
                               correlationId,
                               correlationId,
                               new CallbackEnvelope(HandleUpdatePersistentSubscriptionCompleted),
                               request.Options.StreamName,
                               request.Options.GroupName,
                               settings.ResolveLinks,
                               new StreamRevision(settings.Revision).ToInt64(),
                               (int)TimeSpan.FromTicks(settings.MessageTimeout).TotalMilliseconds,
                               settings.ExtraStatistics,
                               settings.MaxRetryCount,
                               settings.HistoryBufferSize,
                               settings.LiveBufferSize,
                               settings.ReadBatchSize,
                               (int)TimeSpan.FromTicks(settings.CheckpointAfter).TotalMilliseconds,
                               settings.MinCheckpointCount,
                               settings.MaxCheckpointCount,
                               settings.MaxSubscriberCount,
                               settings.NamedConsumerStrategy.ToString(),
                               user,
Exemplo n.º 4
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatePersistentSubscriptionSource = new TaskCompletionSource <UpdateResp>();
            var settings      = request.Options.Settings;
            var correlationId = Guid.NewGuid();

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user,
                                                               UpdateOperation, context.CancellationToken).ConfigureAwait(false))
            {
                throw AccessDenied();
            }
            _publisher.Publish(new ClientMessage.UpdatePersistentSubscription(
                                   correlationId,
                                   correlationId,
                                   new CallbackEnvelope(HandleUpdatePersistentSubscriptionCompleted),
                                   request.Options.StreamIdentifier,
                                   request.Options.GroupName,
                                   settings.ResolveLinks,
                                   new StreamRevision(settings.Revision).ToInt64(),
                                   settings.MessageTimeoutCase switch {
                UpdateReq.Types.Settings.MessageTimeoutOneofCase.MessageTimeoutMs => settings.MessageTimeoutMs,
                UpdateReq.Types.Settings.MessageTimeoutOneofCase.MessageTimeoutTicks => (int)TimeSpan
                .FromTicks(settings.MessageTimeoutTicks).TotalMilliseconds,
                _ => 0
            },
Exemplo n.º 5
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatedSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = await GetUser(_authenticationProvider, context.RequestHeaders).ConfigureAwait(false);

            const string handlerType = "JS";
            var          name        = options.Name;
            var          query       = options.Query;
            bool?        emitEnabled = (options.EmitOptionCase, options.EmitEnabled) switch {
                (EmitOptionOneofCase.EmitEnabled, true) => true,
                (EmitOptionOneofCase.EmitEnabled, false) => false,
                (EmitOptionOneofCase.NoEmitOptions, _) => default,
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatedSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = context.GetHttpContext().User;

            const string handlerType = "JS";
            var          name        = options.Name;
            var          query       = options.Query;
            bool?        emitEnabled = (options.EmitOptionCase, options.EmitEnabled) switch {
                (EmitOptionOneofCase.EmitEnabled, true) => true,
                (EmitOptionOneofCase.EmitEnabled, false) => false,
                (EmitOptionOneofCase.NoEmitOptions, _) => default,
Exemplo n.º 7
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatedSource = new TaskCompletionSource <bool>();
            var options       = request.Options;

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user, UpdateOperation, context.CancellationToken)
                .ConfigureAwait(false))
            {
                throw AccessDenied();
            }
            const string handlerType = "JS";
            var          name        = options.Name;
            var          query       = options.Query;
            bool?        emitEnabled = (options.EmitOptionCase, options.EmitEnabled) switch {
                (EmitOptionOneofCase.EmitEnabled, true) => true,
                (EmitOptionOneofCase.EmitEnabled, false) => false,
                (EmitOptionOneofCase.NoEmitOptions, _) => default,
Exemplo n.º 8
0
 protected bool IsUserRegistred(UpdateReq msg)
 {
     if (msg.type == 0)
     {
         QuerySelectClientByEmailNick query = new QuerySelectClientByEmailNick("",
                                                                               msg.email,
                                                                               DBUtils.GetDBConnection(),
                                                                               null);
         query.Execute();
         return(query.clients.Count != 0);
     }
     else
     {
         QuerySelectSalerByEmailNick query = new QuerySelectSalerByEmailNick("",
                                                                             msg.email,
                                                                             DBUtils.GetDBConnection(),
                                                                             null);
         query.Execute();
         return(query.salers.Count != 0);
     }
 }
Exemplo n.º 9
0
        public UpdateAck OnUpdateStart(UpdateReq msg)
        {
            if (!IsValidEmail(msg.email))
            {
                return(new UpdateAck(UpdateAck.Result.FAIL_INCORRECT_EMAIL));
            }
            DropExpiredCodes();
            UpdateRequest req = GetRequestByEmail(msg.email);

            if (req != null)
            {
                req.createdTime = DateTime.Now;
            }
            else if (!IsUserRegistred(msg))
            {
                return(new UpdateAck(UpdateAck.Result.FAIL_UNREGISTER_USER));
            }
            else
            {
                req             = new UpdateRequest();
                req.createdTime = DateTime.Now;
                req.code        = GenerateCode();
                req.msg         = msg;
                requests.Add(req);
            }
            if (req != null)
            {
                try
                {
                    SendCode(req.msg.email, req.code);
                }
                catch
                {
                    return(new UpdateAck(UpdateAck.Result.FAIL_INCORRECT_EMAIL));
                }
                return(new UpdateAck(UpdateAck.Result.SUCCESS));
            }
            return(new UpdateAck(UpdateAck.Result.UNKNOWN_ERROR));
        }
Exemplo n.º 10
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatePersistentSubscriptionSource = new TaskCompletionSource <UpdateResp>();
            var settings      = request.Options.Settings;
            var correlationId = Guid.NewGuid();

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user,
                                                               UpdateOperation, context.CancellationToken).ConfigureAwait(false))
            {
                throw AccessDenied();
            }

            string streamId = null;

            switch (request.Options.StreamOptionCase)
            {
            case StreamOptionOneofCase.Stream:
            case StreamOptionOneofCase.None:                     /*for backwards compatibility*/
            {
                StreamRevision startRevision;

                if (request.Options.StreamOptionCase == StreamOptionOneofCase.Stream)
                {
                    streamId      = request.Options.Stream.StreamIdentifier;
                    startRevision = request.Options.Stream.RevisionOptionCase switch {
                        RevisionOptionOneofCase.Revision => new StreamRevision(request.Options.Stream.Revision),
                        RevisionOptionOneofCase.Start => StreamRevision.Start,
                        RevisionOptionOneofCase.End => StreamRevision.End,
                        _ => throw new InvalidOperationException()
                    };
                }
                else                             /*for backwards compatibility*/
                {
                                                #pragma warning disable 612
                    streamId      = request.Options.StreamIdentifier;
                    startRevision = new StreamRevision(request.Options.Settings.Revision);
                                                #pragma warning restore 612
                }

                _publisher.Publish(new ClientMessage.UpdatePersistentSubscriptionToStream(
                                       correlationId,
                                       correlationId,
                                       new CallbackEnvelope(HandleUpdatePersistentSubscriptionCompleted),
                                       streamId,
                                       request.Options.GroupName,
                                       settings.ResolveLinks,
                                       startRevision.ToInt64(),
                                       settings.MessageTimeoutCase switch {
                        UpdateReq.Types.Settings.MessageTimeoutOneofCase.MessageTimeoutMs => settings.MessageTimeoutMs,
                        UpdateReq.Types.Settings.MessageTimeoutOneofCase.MessageTimeoutTicks => (int)TimeSpan
                        .FromTicks(settings.MessageTimeoutTicks).TotalMilliseconds,
                        _ => 0
                    },
                                       settings.ExtraStatistics,
                                       settings.MaxRetryCount,
                                       settings.HistoryBufferSize,
                                       settings.LiveBufferSize,
                                       settings.ReadBatchSize,
                                       settings.CheckpointAfterCase switch {
                        UpdateReq.Types.Settings.CheckpointAfterOneofCase.CheckpointAfterMs => settings.CheckpointAfterMs,
                        UpdateReq.Types.Settings.CheckpointAfterOneofCase.CheckpointAfterTicks => (int)TimeSpan
                        .FromTicks(settings.CheckpointAfterTicks).TotalMilliseconds,
                        _ => 0
                    },
Exemplo n.º 11
0
        public override async Task <UpdateResp> Update(UpdateReq request, ServerCallContext context)
        {
            var updatePersistentSubscriptionSource = new TaskCompletionSource <UpdateResp>();
            var settings      = request.Options.Settings;
            var correlationId = Guid.NewGuid();

            var user = context.GetHttpContext().User;

            if (!await _authorizationProvider.CheckAccessAsync(user,
                                                               UpdateOperation, context.CancellationToken).ConfigureAwait(false))
            {
                throw AccessDenied();
            }
            _publisher.Publish(new ClientMessage.UpdatePersistentSubscription(
                                   correlationId,
                                   correlationId,
                                   new CallbackEnvelope(HandleUpdatePersistentSubscriptionCompleted),
                                   request.Options.StreamName,
                                   request.Options.GroupName,
                                   settings.ResolveLinks,
                                   new StreamRevision(settings.Revision).ToInt64(),
                                   (int)TimeSpan.FromTicks(settings.MessageTimeout).TotalMilliseconds,
                                   settings.ExtraStatistics,
                                   settings.MaxRetryCount,
                                   settings.HistoryBufferSize,
                                   settings.LiveBufferSize,
                                   settings.ReadBatchSize,
                                   (int)TimeSpan.FromTicks(settings.CheckpointAfter).TotalMilliseconds,
                                   settings.MinCheckpointCount,
                                   settings.MaxCheckpointCount,
                                   settings.MaxSubscriberCount,
                                   settings.NamedConsumerStrategy.ToString(),
                                   user));

            return(await updatePersistentSubscriptionSource.Task.ConfigureAwait(false));

            void HandleUpdatePersistentSubscriptionCompleted(Message message)
            {
                if (message is ClientMessage.NotHandled notHandled && RpcExceptions.TryHandleNotHandled(notHandled, out var ex))
                {
                    updatePersistentSubscriptionSource.TrySetException(ex);
                    return;
                }

                if (!(message is ClientMessage.UpdatePersistentSubscriptionCompleted completed))
                {
                    updatePersistentSubscriptionSource.TrySetException(
                        RpcExceptions.UnknownMessage <ClientMessage.UpdatePersistentSubscriptionCompleted>(message));
                    return;
                }

                switch (completed.Result)
                {
                case ClientMessage.UpdatePersistentSubscriptionCompleted.UpdatePersistentSubscriptionResult.Success:
                    updatePersistentSubscriptionSource.TrySetResult(new UpdateResp());
                    return;

                case ClientMessage.UpdatePersistentSubscriptionCompleted.UpdatePersistentSubscriptionResult.Fail:
                    updatePersistentSubscriptionSource.TrySetException(RpcExceptions.PersistentSubscriptionFailed(request.Options.StreamName, request.Options.GroupName, completed.Reason));
                    return;

                case ClientMessage.UpdatePersistentSubscriptionCompleted.UpdatePersistentSubscriptionResult
                    .AccessDenied:
                    updatePersistentSubscriptionSource.TrySetException(RpcExceptions.AccessDenied());
                    return;

                default:
                    updatePersistentSubscriptionSource.TrySetException(RpcExceptions.UnknownError(completed.Result));
                    return;
                }
            }
        }
Exemplo n.º 12
0
 public UpdateAck Post([FromBody] UpdateReq request)
 {
     return(eEngine.GetUpdateCardControl().OnUpdateStart(request));
 }