コード例 #1
0
        public void Can_insert_table_with_blobs()
        {
            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <OrderBlob>();

                var row = OrderBlob.Create(1);

                db.InsertParam(row);

                var rows = db.Select <OrderBlob>();

                Assert.That(rows, Has.Count.EqualTo(1));

                var newRow = rows[0];

                Assert.That(newRow.Id, Is.EqualTo(row.Id));
                Assert.That(newRow.Customer.Id, Is.EqualTo(row.Customer.Id));
                Assert.That(newRow.Employee.Id, Is.EqualTo(row.Employee.Id));
                Assert.That(newRow.IntIds, Is.EquivalentTo(row.IntIds));
                Assert.That(newRow.CharMap, Is.EquivalentTo(row.CharMap));
                Assert.That(newRow.OrderDetails.Count, Is.EqualTo(row.OrderDetails.Count));
                Assert.That(newRow.OrderDetails[0].ProductId, Is.EqualTo(row.OrderDetails[0].ProductId));
                Assert.That(newRow.OrderDetails[1].ProductId, Is.EqualTo(row.OrderDetails[1].ProductId));
                Assert.That(newRow.OrderDetails[2].ProductId, Is.EqualTo(row.OrderDetails[2].ProductId));
            }
        }
コード例 #2
0
        public void Can_insert_table_with_blobs()
        {
            using (var db = ConnectionString.OpenDbConnection())
                using (var dbConn = db.CreateCommand())
                {
                    var dsl = OrmLiteConfig.DialectProvider.DefaultStringLength;
                    OrmLiteConfig.DialectProvider.DefaultStringLength = 1024;

                    dbConn.CreateTable <OrderBlob>(true);
                    OrmLiteConfig.DialectProvider.DefaultStringLength = dsl;

                    var row = OrderBlob.Create(1);

                    dbConn.Insert(row);

                    var rows = dbConn.Select <OrderBlob>();

                    Assert.That(rows, Has.Count.EqualTo(1));

                    var newRow = rows[0];

                    Assert.That(newRow.Id, Is.EqualTo(row.Id));
                    Assert.That(newRow.Customer.Id, Is.EqualTo(row.Customer.Id));
                    Assert.That(newRow.Employee.Id, Is.EqualTo(row.Employee.Id));
                    Assert.That(newRow.IntIds, Is.EquivalentTo(row.IntIds));
                    Assert.That(newRow.CharMap, Is.EquivalentTo(row.CharMap));
                    Assert.That(newRow.OrderDetails.Count, Is.EqualTo(row.OrderDetails.Count));
                    Assert.That(newRow.OrderDetails[0].ProductId, Is.EqualTo(row.OrderDetails[0].ProductId));
                    Assert.That(newRow.OrderDetails[1].ProductId, Is.EqualTo(row.OrderDetails[1].ProductId));
                    Assert.That(newRow.OrderDetails[2].ProductId, Is.EqualTo(row.OrderDetails[2].ProductId));
                }
        }
コード例 #3
0
        public void Can_insert_table_with_blobs()
        {
            SuppressIfOracle("Oracle provider's default string length is short enough that this fails. I think solution is better handling of blobs");

            using (var db = OpenDbConnection())
            {
                db.DropAndCreateTable <OrderBlob>();
                db.GetLastSql().Print();

                var row = OrderBlob.Create(1);

                db.Insert(row);

                var rows = db.Select <OrderBlob>();

                Assert.That(rows, Has.Count.EqualTo(1));

                var newRow = rows[0];

                Assert.That(newRow.Id, Is.EqualTo(row.Id));
                Assert.That(newRow.Customer.Id, Is.EqualTo(row.Customer.Id));
                Assert.That(newRow.Employee.Id, Is.EqualTo(row.Employee.Id));
                Assert.That(newRow.IntIds, Is.EquivalentTo(row.IntIds));
                Assert.That(newRow.CharMap, Is.EquivalentTo(row.CharMap));
                Assert.That(newRow.OrderDetails.Count, Is.EqualTo(row.OrderDetails.Count));
                Assert.That(newRow.OrderDetails[0].ProductId, Is.EqualTo(row.OrderDetails[0].ProductId));
                Assert.That(newRow.OrderDetails[1].ProductId, Is.EqualTo(row.OrderDetails[1].ProductId));
                Assert.That(newRow.OrderDetails[2].ProductId, Is.EqualTo(row.OrderDetails[2].ProductId));
            }
        }
コード例 #4
0
ファイル: OrmLiteInsertTests.cs プロジェクト: cody82/DownSite
        public void Can_insert_table_with_blobs()
        {
            using (var db = new OrmLiteConnectionFactory(ConnectionString, FirebirdDialect.Provider).Open())
            {
                var hold = OrmLiteConfig.DialectProvider.GetStringConverter().StringLength;
                OrmLiteConfig.DialectProvider.GetStringConverter().StringLength = 1024;

                db.CreateTable <OrderBlob>(true);
                OrmLiteConfig.DialectProvider.GetStringConverter().StringLength = hold;

                var row = OrderBlob.Create(1);

                db.Insert(row);

                var rows = db.Select <OrderBlob>();

                Assert.That(rows, Has.Count.EqualTo(1));

                var newRow = rows[0];

                Assert.That(newRow.Id, Is.EqualTo(row.Id));
                Assert.That(newRow.Customer.Id, Is.EqualTo(row.Customer.Id));
                Assert.That(newRow.Employee.Id, Is.EqualTo(row.Employee.Id));
                Assert.That(newRow.IntIds, Is.EquivalentTo(row.IntIds));
                Assert.That(newRow.CharMap, Is.EquivalentTo(row.CharMap));
                Assert.That(newRow.OrderDetails.Count, Is.EqualTo(row.OrderDetails.Count));
                Assert.That(newRow.OrderDetails[0].ProductId, Is.EqualTo(row.OrderDetails[0].ProductId));
                Assert.That(newRow.OrderDetails[1].ProductId, Is.EqualTo(row.OrderDetails[1].ProductId));
                Assert.That(newRow.OrderDetails[2].ProductId, Is.EqualTo(row.OrderDetails[2].ProductId));
            }
        }
コード例 #5
0
        public void DeleteOrder(Order order, string serviceBusConnectionString)
        {
            string    date       = order.Date.ToString("yyyy-MM-dd");
            OrderBlob orderBlob  = new OrderBlob();
            int       weeknumber = (DateTime.Now.DayOfYear / 7) + 1;

            try
            {
                orderBlob = JsonConvert.DeserializeObject <OrderBlob>(BotMethods.GetDocument("orders", "orders_" + date + "_" + order.Name + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));
                int orderID = orderBlob.OrderList.FindIndex(x => x.Name == order.Name);
                orderBlob.OrderList.RemoveAt(orderID);
                BotMethods.PutDocument("orders", "orders_" + date + "_" + order.Name + ".json", JsonConvert.SerializeObject(orderBlob), "q.planbutlerupdateorder", serviceBusConnectionString);
            }
            catch (Exception ex) // enters if blob dont exist
            {
                List <Order> orders = new List <Order>();

                orders.Add(order);
                BotMethods.PutDocument("orders", "orders_" + date + "_" + order.Name + ".json", JsonConvert.SerializeObject(orderBlob), "q.planbutlerupdateorder", serviceBusConnectionString);
            }
        }
コード例 #6
0
        private async Task <DialogTurnResult> RemoveStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            try
            {
                var order = new Order();
                order.CompanyStatus = stepContext.Values["companyStatus"].ToString();
                order.Name          = (string)stepContext.Values["name"].ToString();
                List <Order> mealVal        = new List <Order>();
                OrderBlob    orderBlob      = new OrderBlob();
                string[]     weekDaysList   = { "monday", "tuesday", "wednesday", "thursday", "friday" };
                int          indexDay       = 0;
                int          indexCurentDay = 0;
                string       currentDay     = DateTime.Now.DayOfWeek.ToString().ToLower();
                DateTime     date           = DateTime.Now;
                var          stringDate     = string.Empty;
                for (int i = 0; i < weekDaysList.Length; i++)
                {
                    if (currentDay == weekDaysList[i])
                    {
                        indexCurentDay = i;
                    }
                    if (weekDaysEN[indexer] == weekDaysList[i])
                    {
                        indexDay = i;
                    }
                }
                if (indexDay == indexCurentDay)
                {
                    stringDate = date.ToString("yyyy-MM-dd");
                }
                else
                {
                    indexCurentDay = indexDay - indexCurentDay;
                    date           = DateTime.Now.AddDays(indexCurentDay);
                    stringDate     = date.ToString("yyyy-MM-dd");
                }
                orderBlob = JsonConvert.DeserializeObject <OrderBlob>(BotMethods.GetDocument("orders", "orders_" + stringDate + "_" + order.Name + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));
                var collection = orderBlob.OrderList.FindAll(x => x.Name == order.Name);
                obj = collection.FindLast(x => x.CompanyStatus == order.CompanyStatus);

                var deletDialogDeletePrompt1 = string.Format(deletDialogDeletePrompt, obj.Meal); //Should ... be deleted?

                return(await stepContext.PromptAsync(
                           nameof(ChoicePrompt),
                           new PromptOptions

                {
                    Prompt = MessageFactory.Text(deletDialogDeletePrompt1),
                    Choices = ChoiceFactory.ToChoices(new List <string> {
                        deletDialogYes, deletDialogNo
                    }),
                    Style = ListStyle.HeroCard,
                }, cancellationToken));
            }
            catch (Exception ex)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text(deletDialogNoOrder), cancellationToken);

                await stepContext.EndDialogAsync(null, cancellationToken);

                return(await stepContext.BeginDialogAsync(nameof(OverviewDialog), null, cancellationToken));
            }
        }
コード例 #7
0
        private async Task <DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                var text = innerDc.Context.Activity.Text.ToLowerInvariant();

                if (text == "help" || text == "hilfe")
                {
                    // Help message!
                    await innerDc.Context.SendActivityAsync(MessageFactory.Text(interruptDialogHelpText), cancellationToken);

                    await innerDc.EndDialogAsync(cancellationToken : cancellationToken);

                    return(await innerDc.BeginDialogAsync(nameof(OverviewDialog), null, cancellationToken));
                }
                else if ((text.Contains("wurde") || text.Contains("worden")) && text.Contains("heute") && text.Contains("bestellt"))
                {
                    // Get the Order from the BlobStorage and the current day ID
                    int weeknumber = (DateTime.Now.DayOfYear / 7) + 1;
                    //orderBlob = JsonConvert.DeserializeObject<OrderBlob>(BotMethods.GetDocument("orders", "orders_" + weeknumber + "_" + DateTime.Now.Year + ".json"));
                    HttpRequestMessage req = new HttpRequestMessage();
                    List <OrderBlob>   tmp = await BotMethods.GetDailyOverview(this.botConfig.Value.GetDailyOverviewFunc);

                    string orderlist = string.Empty;

                    foreach (var item in tmp)
                    {
                        foreach (var items in item.OrderList)
                        {
                            if (items.Quantaty > 1)
                            {
                                orderlist += $"{items.Name}: {items.Meal} x{items.Quantaty}  {Environment.NewLine}";
                            }
                            else
                            {
                                orderlist += $"{items.Name}: {items.Meal}  {Environment.NewLine}";
                            }
                        }
                    }

                    await innerDc.Context.SendActivityAsync(MessageFactory.Text($"Es wurde bestellt:  {Environment.NewLine}{orderlist}"), cancellationToken);

                    await innerDc.EndDialogAsync(cancellationToken : cancellationToken);

                    return(await innerDc.BeginDialogAsync(nameof(OverviewDialog), null, cancellationToken));
                }
                else if (text.Contains("ich") && text.Contains("heute") && text.Contains("bestellt"))
                {
                    // Get the Order from the BlobStorage, the current day ID and nameId from the user
                    OrderBlob orderBlob  = new OrderBlob();
                    int       weeknumber = (DateTime.Now.DayOfYear / 7) + 1;
                    orderBlob = JsonConvert.DeserializeObject <OrderBlob>(BotMethods.GetDocument("orders", "orders_" + weeknumber + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));
                    var nameID = orderBlob.OrderList.FindAll(x => x.Name == innerDc.Context.Activity.From.Name);

                    if (nameID.Count != 0)
                    {
                        string message = $"Du hast heute {nameID.LastOrDefault().Meal} bei {nameID.LastOrDefault().Restaurant} bestellt.";
                        if (nameID.Count > 1)
                        {
                            message = string.Empty;
                            string orders = string.Empty;
                            foreach (var item in nameID)
                            {
                                if (item.CompanyStatus.ToLower().ToString() == "kunde" || item.CompanyStatus.ToLower().ToString() == "privat" || item.CompanyStatus.ToLower().ToString() == "praktikant")
                                {
                                    orders += $"Für {item.CompanyName}: {item.Meal} x{item.Quantaty}  {Environment.NewLine}";
                                }
                                else if (item.CompanyStatus == "intern")
                                {
                                    orders += $"{item.Name}: {item.Meal}  {Environment.NewLine}";
                                }
                                else
                                {
                                    orders += $"{item.Name}: {item.Meal}  {Environment.NewLine}";
                                }

                                if (nameID.LastOrDefault() != item)
                                {
                                    orders += " und ";
                                }
                            }

                            message = $"Du hast heute {orders} bestellt";
                        }

                        await innerDc.Context.SendActivityAsync(MessageFactory.Text(message), cancellationToken);
                    }
                    else
                    {
                        await innerDc.Context.SendActivityAsync(MessageFactory.Text($"Du hast heute noch nichts bestellt!"), cancellationToken);
                    }

                    await innerDc.EndDialogAsync(cancellationToken : cancellationToken);

                    return(await innerDc.BeginDialogAsync(nameof(OverviewDialog), null, cancellationToken));
                }
                else if (text.Contains("ende") || text.Contains("exit"))
                {
                    await innerDc.EndDialogAsync(cancellationToken : cancellationToken);

                    return(await innerDc.BeginDialogAsync(nameof(OverviewDialog), null, cancellationToken));
                }
                else if (text.Contains("excel"))
                {
                    await innerDc.Context.SendActivityAsync(MessageFactory.Text($"Einen Moment ich suche schnell alles zusammen!"), cancellationToken);

                    await innerDc.EndDialogAsync(cancellationToken : cancellationToken);

                    return(await innerDc.BeginDialogAsync(nameof(ExcellDialog), null, cancellationToken));

                    //await innerDc.Context.SendActivityAsync(MessageFactory.Text(message), cancellationToken);
                }
            }
            return(null);
        }
コード例 #8
0
        private async Task <DialogTurnResult> TimeDayStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            IMealService mealService = new MealService(this.clientFactory.CreateClient(), this.botConfig.Value);
            var          meals       = await mealService.GetMeals(string.Empty, string.Empty);

            var     mealEnumerator = meals.GetEnumerator();
            PlanDay day            = new PlanDay();

            while (mealEnumerator.MoveNext())
            {
                if (string.IsNullOrEmpty(day.Restaurant1))
                {
                    day.Restaurant1 = mealEnumerator.Current.Restaurant;
                }

                if (string.IsNullOrEmpty(day.Restaurant2) && day.Restaurant1 != mealEnumerator.Current.Restaurant)
                {
                    day.Restaurant2 = mealEnumerator.Current.Restaurant;
                }
            }



            // Get the Plan
            try
            {
                string food = BotMethods.GetDocument("eatingplan", "ButlerOverview.json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey);
                plan  = JsonConvert.DeserializeObject <Plan>(food);
                dayId = plan.Planday.FindIndex(x => x.Name == DateTime.Now.DayOfWeek.ToString().ToLower());
                valid = true;
            }
            catch
            {
                valid = false;
            }

            OrderBlob orderBlob  = new OrderBlob();
            var       tmp        = BotMethods.GetSalaryDeduction("2", this.botConfig.Value.GetSalaryDeduction);
            int       weeknumber = (DateTime.Now.DayOfYear / 7) + 1;

            orderBlob = JsonConvert.DeserializeObject <OrderBlob>(BotMethods.GetDocument("orders", "orders_" + weeknumber + "_" + DateTime.Now.Year + ".json", this.botConfig.Value.StorageAccountUrl, this.botConfig.Value.StorageAccountKey));

            var nameID = orderBlob.OrderList.FindIndex(x => x.Name == stepContext.Context.Activity.From.Name);

            if (DateTime.Now.Hour - 1 >= 12)
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Es ist schon nach 12 Uhr"));

                return(await stepContext.BeginDialogAsync(nameof(OrderForOtherDayDialog)));
            }
            else if (nameID != -1)
            {
                var temp = orderBlob.OrderList.FindAll(x => x.Name == stepContext.Context.Activity.From.Name);
                foreach (var item in temp)
                {
                    if (item.CompanyStatus.ToLower().ToString() == "für mich")
                    {
                        await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Du hast heute schon etwas bestellt"));

                        return(await stepContext.BeginDialogAsync(nameof(NextOrder)));
                    }
                }

                return(await stepContext.NextAsync());
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
コード例 #9
0
        private async Task <DialogTurnResult> GetMoneyStepAsync1(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var msg = string.Empty;

            int             dayNumber = DateTime.Now.DayOfYear;
            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, this.botConfig.Value.GetDailyUserOverviewFunc);

                OrderBlob orderBlob = new OrderBlob();

                msg += $"{dailyCreditDialogDepts} {Environment.NewLine}";
                string message  = string.Empty;
                string orders   = $"{dailyCreditDialogOrderMe} {Environment.NewLine}";
                double sum      = 0;
                string corders  = $"{dailyCreditDialogOrderCostumer}  {Environment.NewLine}";
                double csum     = 0;
                string iorders  = $"{dailyCreditDialogOrderTrainee}  {Environment.NewLine}";
                double isum     = 0;
                bool   check    = false;
                bool   cchecker = false;
                bool   ichecker = false;
                foreach (var item in orderList)
                {
                    foreach (var items in item.OrderList)
                    {
                        if (items.CompanyStatus.ToLower().ToString() == "extern")
                        {
                            corders += $"{items.CompanyName} \t/ {items.Restaurant} \t/ {items.Meal} \t/ {items.Price}€ {Environment.NewLine}";
                            csum    += Convert.ToDouble(items.Price);
                            cchecker = true;
                        }
                        else if (items.CompanyStatus.ToLower().ToString() == "internship")
                        {
                            iorders += $"{items.CompanyName} \t/ {items.Restaurant} \t/ {items.Meal} \t/ {items.Price}€ {Environment.NewLine}";
                            isum    += Convert.ToDouble(items.Price);
                            ichecker = true;
                        }
                        else
                        {
                            var dailyCreditDialogOrderedAt1 = string.Format(dailyCreditDialogOrderedAt, items.Meal, items.Restaurant);

                            if (check = false)
                            {
                                message = dailyCreditDialogOrderedAt1;
                            }
                            orders += $"{items.Name} \t/ {items.Restaurant} \t/ {items.Meal} \t/ {items.Price}€  {Environment.NewLine}";
                            sum    += Convert.ToDouble(items.Price);
                            check   = true;
                        }
                    }
                }

                if (check)
                {
                    var dailyCreditDialogSumMe1 = string.Format(dailyCreditDialogSumMe, sum);
                    orders += $"{dailyCreditDialogSumMe1} {Environment.NewLine}";
                }

                if (cchecker)
                {
                    var dailyCreditDialogSumCostumer1 = string.Format(dailyCreditDialogSumCostumer, csum);
                    orders  += corders;
                    corders += $"{dailyCreditDialogSumCostumer1} {Environment.NewLine}";
                }

                if (ichecker)
                {
                    var dailyCreditDialogSumTrainee1 = string.Format(dailyCreditDialogSumTrainee, csum);
                    iorders += $"{dailyCreditDialogSumTrainee1} {Environment.NewLine}";
                    orders  += iorders;
                }

                msg += $"{orders}";
            }
            catch
            {
            }

            // Get the Order from the BlobStorage, the current day ID and nameId from the user

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(msg), cancellationToken);

            await stepContext.EndDialogAsync(cancellationToken : cancellationToken);

            return(await stepContext.BeginDialogAsync(nameof(OverviewDialog)));
        }