public void Add <T>(string key, T value) where T : class { MoMoBotAssert.KeyNotNullOrEmpty(key); MoMoBotAssert.ValueNotNull(value); base.Add(key, value); }
public Task <T> ReadAsync <T>(string key, Func <T> def) { MoMoBotAssert.KeyNotNullOrEmpty(key); lock (_synclock) { if (_memory.TryGetValue(key, out var state)) { if (state != null) { return(Task.FromResult(state.ToObject <T>(StateJsonSerializer))); } } if (def != null) { var result = def.Invoke(); if (result != null) { WriteAsync(new Dictionary <string, object> { { key, result } }); return(Task.FromResult(result)); } } return(default);
private async Task <InvokeResponse> ProcessActivityAsync(string authHeader, Activity activity, BotCallbackHandler callback, CancellationToken cancellationToken) { MoMoBotAssert.NotNull(activity); using (var context = new TurnContext(activity)) { //context.TurnState.Add<IIdentity>(BotIdentityKey, identity); await callback?.Invoke(context, cancellationToken); if (activity.Type == ActivityTypes.Invoke) { var activityInvokeResponse = context.TurnState.Get <Activity>(InvokeReponseKey); if (activityInvokeResponse == null) { return(new InvokeResponse { Status = (int)HttpStatusCode.NotImplemented }); } else { return((InvokeResponse)activityInvokeResponse.Value); } } return(null); } }
public BotState(IStorage storage, string contextServiceKey) { MoMoBotAssert.NotNull(storage); MoMoBotAssert.NotNull(contextServiceKey); _storage = storage; _contextServiceKey = contextServiceKey; }
public Task DeleteAsync(string[] keys, CancellationToken cancellationToken = default) { MoMoBotAssert.NotNull(keys); lock (_synclock) { foreach (var key in keys) { _memory.Remove(key); } } return(Task.CompletedTask); }
public T Get <T>(string key) where T : class { MoMoBotAssert.KeyNotNullOrEmpty(key); if (TryGetValue(key, out var service)) { if (service is T result) { return(result); } } return(null); }
public async Task <DialogContext> CreateContextAsync(TurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { MoMoBotAssert.NotNull(turnContext); // ToDo: Component Dialog doesn't call this code path. This needs to be cleaned up in 4.1. if (_dialogState == null) { // Note: This shouldn't ever trigger, as the _dialogState is set in the constructor and validated there. throw new InvalidOperationException($"DialogSet.CreateContextAsync(): DialogSet created with a null IStatePropertyAccessor."); } // Load/initialize dialog state var state = await _dialogState.GetAsync(turnContext, () => { return(new DialogState()); }, cancellationToken).ConfigureAwait(false); // Create and return context return(new DialogContext(this, turnContext, state)); }
public Task <IDictionary <string, object> > ReadAsync(string[] keys, CancellationToken cancellationToken = default) { MoMoBotAssert.NotNull(keys); var storeItems = new Dictionary <string, object>(keys.Length); lock (_synclock) { foreach (var key in keys) { if (_memory.TryGetValue(key, out var state)) { if (state != null) { storeItems.Add(key, state.ToObject <object>(StateJsonSerializer)); } } } } return(Task.FromResult <IDictionary <string, object> >(storeItems)); }
public void Add(BotState botState) { MoMoBotAssert.NotNull(botState); BotStates.Add(botState); }
public IStatePropertyAccessor <T> CreateProperty <T>(string name) { MoMoBotAssert.NameNullOrWhiteSpace(name); return(new StatePropertyAccessor <T>(this, name)); }