Skip to content

Commit

Permalink
#54 Clean Up, #47 Replace current settings management
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusMeyer13 committed Feb 18, 2020
1 parent 5347d54 commit ee4e9c2
Show file tree
Hide file tree
Showing 24 changed files with 725 additions and 397 deletions.
2 changes: 1 addition & 1 deletion PlanB.Butler.Bot/AdapterWithErrorHandler.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace ButlerBot
namespace PlanB.Butler.Bot
{
using System;
using Microsoft.Bot.Builder;
Expand Down
67 changes: 67 additions & 0 deletions PlanB.Butler.Bot/BotConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) PlanB. GmbH. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace PlanB.Butler.Bot
{
/// <summary>
/// BotConfig.
/// </summary>
public class BotConfig
{
/// <summary>
/// Gets or sets the storage account URL.
/// </summary>
/// <value>
/// The storage account URL.
/// </value>
public string StorageAccountUrl { get; set; }

/// <summary>
/// Gets or sets the storage account key.
/// </summary>
/// <value>
/// The storage account key.
/// </value>
public string StorageAccountKey { get; set; }

/// <summary>
/// Gets or sets the storage account connection string.
/// </summary>
/// <value>
/// The storage account connection string.
/// </value>
public string StorageAccountConnectionString { get; set; }

/// <summary>
/// Gets or sets the service bus connection string.
/// </summary>
/// <value>
/// The service bus connection string.
/// </value>
public string ServiceBusConnectionString { get; set; }

/// <summary>
/// Gets or sets the get daily overview function.
/// </summary>
/// <value>
/// The get daily overview function.
/// </value>
public string GetDailyOverviewFunc { get; set; }

/// <summary>
/// Gets or sets the get salary deduction.
/// </summary>
/// <value>
/// The get salary deduction.
/// </value>
public string GetSalaryDeduction { get; set; }

/// <summary>
/// Gets or sets the get daily user overview function.
/// </summary>
/// <value>
/// The get daily user overview function.
/// </value>
public string GetDailyUserOverviewFunc { get; set; }
}
}
2 changes: 1 addition & 1 deletion PlanB.Butler.Bot/Bots/DialogBot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ButlerBot
namespace PlanB.Butler.Bot
{
using System.Threading;
using System.Threading.Tasks;
Expand Down
2 changes: 1 addition & 1 deletion PlanB.Butler.Bot/Bots/TeamsBot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ButlerBot
namespace PlanB.Butler.Bot
{
using System.Collections.Generic;
using System.Threading;
Expand Down
2 changes: 1 addition & 1 deletion PlanB.Butler.Bot/Cards.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace ButlerBot
namespace PlanB.Butler.Bot
{
using System.Collections.Generic;
using System.IO;
Expand Down
24 changes: 13 additions & 11 deletions PlanB.Butler.Bot/Controllers/BotController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Generated with Bot Builder V4 SDK Template for Visual Studio EchoBot v4.5.0
// Copyright (c) PlanB. GmbH. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace ButlerBot.Controllers
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Extensions.Options;

namespace PlanB.Butler.Bot.Controllers
{
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
// achieved by specifying a more specific type for the bot constructor argument.
Expand All @@ -19,11 +19,13 @@ public class BotController : ControllerBase
{
private readonly IBotFrameworkHttpAdapter Adapter;
private readonly IBot Bot;
private readonly IOptions<BotConfig> botConfig;

public BotController(IBotFrameworkHttpAdapter adapter, IBot bot)
public BotController(IBotFrameworkHttpAdapter adapter, IBot bot, IOptions<BotConfig> config)
{
this.Adapter = adapter;
this.Bot = bot;
this.botConfig = config;
}

[HttpPost]
Expand Down
39 changes: 25 additions & 14 deletions PlanB.Butler.Bot/Dialogs/CreditDialog.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
namespace ButlerBot
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using BotLibraryV2;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Newtonsoft.Json;
// Copyright (c) PlanB. GmbH. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using BotLibraryV2;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace PlanB.Butler.Bot
{
public class CreditDialog : ComponentDialog
{
public CreditDialog()
/// <summary>
/// The bot configuration.
/// </summary>
private readonly IOptions<BotConfig> botConfig;

public CreditDialog(IOptions<BotConfig> config)
: base(nameof(CreditDialog))
{
this.botConfig = config;
// This array defines how the Waterfall will execute.
var waterfallSteps = new WaterfallStep[]
{
Expand Down Expand Up @@ -54,7 +65,7 @@ private async Task<DialogTurnResult> GetMoneyStepAsync1(WaterfallStepContext ste

try
{
MoneyLog money = JsonConvert.DeserializeObject<MoneyLog>(BotMethods.GetDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json"));
MoneyLog money = JsonConvert.DeserializeObject<MoneyLog>(BotMethods.GetDocument("moneylog", "money_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));

var userId = money.User.FindIndex(x => x.Name == (string)stepContext.Values["name"]);
if (userId != -1)
Expand Down Expand Up @@ -93,7 +104,7 @@ private async Task<DialogTurnResult> GetMoneyStepAsync2(WaterfallStepContext ste
try
{
var lastmonth = DateTime.Now.Month - 1;
MoneyLog money = JsonConvert.DeserializeObject<MoneyLog>(BotMethods.GetDocument("moneylog", "money_" + lastmonth.ToString() + "_" + DateTime.Now.Year + ".json"));
MoneyLog money = JsonConvert.DeserializeObject<MoneyLog>(BotMethods.GetDocument("moneylog", "money_" + lastmonth.ToString() + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));

var userId = money.User.FindIndex(x => x.Name == (string)stepContext.Values["name"]);
if (userId != -1)
Expand Down
46 changes: 29 additions & 17 deletions PlanB.Butler.Bot/Dialogs/DailyCreditDialog.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
namespace ButlerBot
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using BotLibraryV2;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Choices;
using Newtonsoft.Json;
// Copyright (c) PlanB. GmbH. All Rights Reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

using System;
using System.Threading;
using System.Threading.Tasks;

using BotLibraryV2;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace PlanB.Butler.Bot
{
/// <summary>
/// DailyCreditDialog.
/// </summary>
/// <seealso cref="Microsoft.Bot.Builder.Dialogs.ComponentDialog" />
public class DailyCreditDialog : ComponentDialog
{
public DailyCreditDialog()
/// <summary>
/// The bot configuration.
/// </summary>
private readonly IOptions<BotConfig> botConfig;

public DailyCreditDialog(IOptions<BotConfig> config)
: base(nameof(DailyCreditDialog))
{
this.botConfig = config;

// This array defines how the Waterfall will execute.
var waterfallSteps = new WaterfallStep[]
{
Expand All @@ -42,15 +54,15 @@ private async Task<DialogTurnResult> NameStepAsync(WaterfallStepContext stepCont

private async Task<DialogTurnResult> GetMoneyStepAsync1(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
var msg = "";
var msg = string.Empty;

int dayNumber = DateTime.Now.DayOfYear;
SalaryDeduction money = JsonConvert.DeserializeObject<SalaryDeduction>(BotMethods.GetDocument("salarydeduction", "orders_" + dayNumber.ToString() + "_" + DateTime.Now.Year + ".json"));
SalaryDeduction money = JsonConvert.DeserializeObject<SalaryDeduction>(BotMethods.GetDocument("salarydeduction", "orders_" + dayNumber.ToString() + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));
var userId = money.Order.FindIndex(x => x.Name == (string)stepContext.Values["name"]);
try
{
string name = stepContext.Values["name"].ToString();
var orderList = await BotMethods.GetDailyUserOverview(name);
var orderList = await BotMethods.GetDailyUserOverview(name, this.botConfig.Value.GetDailyUserOverviewFunc);
OrderBlob orderBlob = new OrderBlob();

msg += $"Heute beträgt die Belastung: {Environment.NewLine}";
Expand Down
Loading

0 comments on commit ee4e9c2

Please sign in to comment.