Beispiel #1
0
        private static async void HandleNotificationWhenRateWillLessThan(RateNotificationTask task, CurrencyDto currencyInfo, TraceWriter log)
        {
            if (currencyInfo.price_usd < task.Value)
            {
                task.IsDone = true;
                var taskRepository = new RateNotificationTaskRepository();
                await taskRepository.Replace(task);

                var message = $"Warning. {currencyInfo.name}({currencyInfo.symbol}) is less than {task.Value} USD. ({currencyInfo.price_usd})";
                await SendMessageToChannel(message, task.ConnectionParameters, log);
            }
        }
Beispiel #2
0
        private static async void HandleNotificationWhenRateWillDecreaseBy(RateNotificationTask task, CurrencyDto currencyInfo, TraceWriter log)
        {
            var diff = task.CurrentPrice - currencyInfo.price_usd;

            if (diff >= task.Value)
            {
                task.IsDone = true;
                var taskRepository = new RateNotificationTaskRepository();
                await taskRepository.Replace(task);

                var message = $"Warning. The {currencyInfo.name}({currencyInfo.symbol}) rate fell by {task.Value} USD. ({currencyInfo.price_usd})";
                await SendMessageToChannel(message, task.ConnectionParameters, log);
            }
        }
        private async Task Notify(
            IDialogContext context,
            LuisResult result,
            RateNotificationTaskType taskType)
        {
            var currencyEntity = result.Entities.GetLastEntity(EntityCurrencyName);
            var valueEntity    = result.Entities.GetLastEntity("builtin.number");

            if (currencyEntity != null && valueEntity != null)
            {
                var cacheService = new CacheService();
                var currency     = cacheService.Currencies.Single(c =>
                                                                  c.symbol.Equals(currencyEntity.Entity, StringComparison.InvariantCultureIgnoreCase));
                var value          = decimal.Parse(valueEntity.GetValue().ToString());
                var taskRepository = new RateNotificationTaskRepository();

                var currencyProvider = new CurrencyProvider();

                var currentRate = currencyProvider.Get(currency.id);
                var task        = new RateNotificationTask
                {
                    ConnectionParameters = new ConnectionParameters
                    {
                        ChanelId       = context.Activity.ChannelId,
                        ServiceUrl     = context.Activity.ServiceUrl,
                        ConversationId = context.Activity.Conversation.Id,
                        BotId          = context.Activity.Recipient.Id,
                        BotName        = context.Activity.Recipient.Name,
                        UserId         = context.Activity.From.Id,
                        UserName       = context.Activity.From.Name,
                    },

                    CryptoCurrencyId = currency.id,
                    DateAdded        = DateTime.UtcNow,
                    Type             = taskType,
                    CurrentPrice     = currentRate.price_usd,
                    Value            = value
                };

                await taskRepository.SaveRateNotificationTaskAsync(task);

                await context.PostAsync(string.Format(messages[taskType], currency.name, currency.symbol, value));
            }
            else
            {
                await context.PostAsync("Sorry, i don't have information about this currency");
            }
        }