public static async Task Run([TimerTrigger("0 0 * * * *")] TimerInfo overviewTimer, TraceWriter log) { var logger = new LoggerConfiguration().WriteTo.TraceWriter(log).CreateLogger(); try { logger.Information("Starting processing..."); // Either use the default options as defined in TradeOptions or override them. // You can override them using the property setters here or by providing keys in your configuration mechanism // matching the property names in this class. var azureTableStorageOptions = AppSettings.Get <AzureTableStorageOptions>(); var telegramNotificationOptions = AppSettings.Get <TelegramNotificationOptions>(); var dataStore = new AzureTableStorageDataStore(azureTableStorageOptions); await dataStore.InitializeAsync(); var telegram = new TelegramNotificationManager(telegramNotificationOptions); await SendTradeOverviewMessage(telegram, dataStore); await SendProfitText(telegram, dataStore); logger.Information("Done..."); } catch (Exception ex) { // If anything goes wrong log an error to Azure. logger.Error(ex.Message + ex.StackTrace); if (ex.InnerException != null) { logger.Error(ex.InnerException.Message + ex.InnerException.StackTrace); } } }
private static CommandLineApplication CreateCommandLineApplication() { CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false); CommandOption consoleOption = commandLineApplication.Option( "-console", "The result goes to the Console.", CommandOptionType.NoValue); CommandOption productsFileOption = commandLineApplication.Option( "-file <productsFileOption>", "Products file path.", CommandOptionType.SingleValue); CommandOption telegramOption = commandLineApplication.Option( "-telegram", "The result goes to the Telegram.", CommandOptionType.NoValue); CommandOption telegramChatIdOption = commandLineApplication.Option( "-chatid <telegramChatIdOption>", "ChatId in Telegram.", CommandOptionType.SingleValue); CommandOption telegramTokenOption = commandLineApplication.Option( "-token <telegramTokenOption>", "Token in Telegram.", CommandOptionType.SingleValue); commandLineApplication.HelpOption("-? | -h | --help"); commandLineApplication.OnExecute(async() => { if (!productsFileOption.HasValue()) { Console.WriteLine("Specify the file path with the Products to search!"); return(0); } if (!consoleOption.HasValue() && !telegramOption.HasValue()) { Console.WriteLine("Notifier type not found! Possible values: '-console' or '-telegram'."); return(0); } var productsInfoRequest = JsonSerializer.Deserialize <ProductInfoRequest[]>( File.ReadAllText(productsFileOption.Value()), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); AppController appController = new AppController(); var message = await appController.GetProductsInfoAsync(productsInfoRequest); if (!string.IsNullOrEmpty(message)) { INotificationManager notificationManager = null; if (consoleOption.HasValue()) { notificationManager = new ConsoleNotificationManager(); } if (telegramOption.HasValue()) { if (!telegramChatIdOption.HasValue() || !telegramTokenOption.HasValue()) { Console.WriteLine($"Specify Telegram chatid and token values: '-chatid' and '-token'."); return(0); } notificationManager = new TelegramNotificationManager(telegramChatIdOption.Value(), telegramTokenOption.Value()); } if (notificationManager != null) { await notificationManager.SendMessage(message); } } return(0); }); return(commandLineApplication); }