Beispiel #1
0
        internal static void CreateLog(string eventDate, string location, string eventCode, string tag)
        {
            var tenantId    = TenantHelper.GetTenantByTagId(tag);
            var doorId      = LocationHelper.FindLocationByDoor(location);
            var eventCodeId = EventHelper.GetEventCodeId(eventCode);

            CreateLog(tenantId, doorId, eventCodeId, eventDate, false);
        }
Beispiel #2
0
        /// <summary>
        /// MakeLogHumanReaable.
        /// </summary>
        /// <param name="tenantId">Long<see cref="long"/> med hyresgästens ID.</param>
        /// <param name="doorId">Long<see cref="long"/> med dörrens ID.</param>
        /// <param name="eventCode">Long<see cref="long"/> med kodens ID. .</param>
        /// <param name="eventDate">Sträng<see cref="string"/> med händelsens datum.</param>
        private static void MakeLogHumanReaable(long tenantId, long doorId, long eventCode, string eventDate)
        {
            string name = TenantHelper.GetTenantName(tenantId);
            string tag  = TagHelper.GetTenantTag(tenantId);
            object door = DoorHelper.GetDoorName(doorId);
            string code = EventHelper.GetEventCode(eventCode);

            Console.WriteLine(
                name +
                "used tag " + tag +
                "to open " + door +
                " at " + eventDate +
                " from the " + (code.EndsWith("IN") ? "inside" : "outside") + " " +
                (code.EndsWith("FD") ? "but had not access to open it" : "sucessfully")
                );
        }
        /// <summary>
        /// CreateEvents.
        /// </summary>
        internal static void CreateEvents()
        {
            DataTable tenants = DBHandler.GetDataTable("SELECT Tenants.Id, Name, Tag, Location FROM Tenants JOIN Locations ON Locations.Id = LocationId WHERE (NAME NOT LIKE 'Vaktmästare' AND NAME NOT LIKE 'Lilly Adolfsson')");

            if (tenants?.Rows.Count > 0)
            {
                foreach (DataRow item in tenants.Rows)
                {
                    bool   hasBike           = GetRandomProbability();
                    bool   takesBikeToWork   = GetRandomProbability();
                    bool   morningWashing    = GetRandomProbability();
                    bool   breakfastShopping = GetRandomProbability();
                    bool   eveningWashing    = GetRandomProbability();
                    bool   morningTrash      = GetRandomProbability();
                    bool   eveningTrash      = GetRandomProbability();
                    bool   visitSuper        = GetRandomProbability();
                    bool   goesToWork        = GetRandomProbability();
                    long   tenantId          = (long)item["Id"];
                    string home = item["Location"].ToString();

                    GetStartTime(5);

                    Console.Write($"{item["Name"]} ");

                    if (breakfastShopping)
                    {
                        // Går ut och handlar frukost
                        Console.WriteLine("Buying breakfast");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        if (hasBike)
                        {
                            // Tar cykeln
                            Console.WriteLine("Takes the bike");
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 2));
                        }
                        // Lämnar huset
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("UT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 1));
                        Console.WriteLine("Leaves the house");

                        // Kommer tillbaka
                        Console.WriteLine("Comes back");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("UT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: -1));
                        if (hasBike)
                        {
                            // Ställer in cykeln
                            Console.WriteLine("Puts back the bike");
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 2));
                        }
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }

                    if (morningWashing)
                    {
                        // Går ut till tvättstugan
                        Console.WriteLine("Morning laundry");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        // Går in
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        // Stannar en stund
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        GetTime(addMinutes: 45);
                        // Går ut till tvättstugan igen
                        Console.WriteLine("Back to the laundry");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        // Går in
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        // Stannar en stund
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }

                    if (morningTrash)
                    {
                        // Går ut till soprummet
                        Console.WriteLine("Throwing out some trash");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("SOPRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("SOPRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }

                    if (visitSuper)
                    {
                        // Går ut till vaktmästaren
                        Console.WriteLine("Visits the super");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        if (GetRandomProbability())
                        {
                            Console.WriteLine("Tries to open the door to the super");
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("VAKT"), EventHelper.GetEventCodeId("FDUT"), GetTime(addMinutes: 1));
                        }

                        long superId = TenantHelper.GetTenantId("Vaktmästare");

                        // Vaktmästaren öppnar dörren inifrån
                        Console.WriteLine("Knocks on the door and the super opens it");
                        LogHelper.CreateLog(superId, DoorHelper.GetDoorId("VAKT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 1));
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("VAKT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        DateTime oldTime = CurrentTime;
                        GetTime(addHours: Settings.Rnd.Next(1, 4));
                        GetTime(addMinutes: -1);
                        Console.WriteLine("The super goes to fix the problem at the tenants home");
                        LogHelper.CreateLog(superId, DoorHelper.GetDoorId("VAKT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        LogHelper.CreateLog(superId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        LogHelper.CreateLog(superId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        LogHelper.CreateLog(superId, DoorHelper.GetDoorId("VAKT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 1));
                        CurrentTime = oldTime;
                    }

                    if (goesToWork)
                    {
                        // Går ut till soprummet
                        Console.WriteLine("Goes to work");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        if (hasBike && takesBikeToWork)
                        {
                            // Ställer in cykeln
                            Console.WriteLine("Takes the bike to work");
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 2));
                        }
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("UT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));

                        Console.WriteLine("Comes back from work");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("UT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addHours: 8, addMinutes: 1));
                        if (hasBike && takesBikeToWork)
                        {
                            // Ställer in cykeln
                            Console.WriteLine("Returns the bike");
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                            LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("CYKELRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 2));
                        }
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }

                    if (CurrentTime.Hour < 18)
                    {
                        CurrentTime = CurrentTime.AddHours(19 - CurrentTime.Hour);
                    }

                    if (eveningWashing)
                    {
                        // Går ut till tvättstugan
                        Console.WriteLine("Doing some laundry");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        // Går in
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        // Stannar en stund
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        GetTime(addMinutes: 45);
                        // Går ut till tvättstugan igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        // Går in
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        // Stannar en stund
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("TVÄTT"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: -1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }

                    if (eveningTrash)
                    {
                        // Går ut till soprummet
                        Console.WriteLine("Discarding some trash");
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖIN"), GetTime());
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("SOPRUM"), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("SOPRUM"), EventHelper.GetEventCodeId("DÖIN"), GetTime(addMinutes: 1));
                        // Går hem igen
                        LogHelper.CreateLog(tenantId, DoorHelper.GetDoorId("LGH" + home), EventHelper.GetEventCodeId("DÖUT"), GetTime(addMinutes: 1));
                    }
                }
            }
        }