示例#1
0
        public static void ShowRemainingLessonTime(UntisCache cache)
        {
            var currentPeriod = UntisUtil.GetCurrentPeriod(cache.Periods);

            var lessonEnd = DateTime.Now.TimeOfDay - currentPeriod.EndTime;

            Console.WriteLine(lessonEnd.Duration().ToString(@"hh\:mm\:ss"));
        }
示例#2
0
        public static void ShowNextLesson(UntisCache cache, UntisClient untisClient, string className)
        {
            if (className == null)
            {
                Console.Error.WriteLine("The class for the next lesson is not specified");
                return;
            }

            // Get my class
            var untisClass = UntisUtil.GetSchoolClass(cache.Classes, className);

            var currentPeriod = UntisUtil.GetCurrentPeriod(cache.Periods);

            var lesson = untisClient.GetLessons(untisClass).Result
                         .Where(l => l.Date.Date == DateTime.Today.Date)
                         .FirstOrDefault(l => l.Period.Nr == currentPeriod.Nr + 1);

            Console.WriteLine(lesson == null ? "FREE" : lesson.SubjectsString);

            untisClient.LogoutAsync();
        }
示例#3
0
        public static void ShowTimeTable(UntisCache cache, UntisClient untisClient, string className,
                                         string[] daysOfWeek)
        {
            if (className == null)
            {
                Console.Error.WriteLine("The class for the next lesson is not specified");
                return;
            }

            const int sidebarColumnWidth = 16;
            const int mainColumnWidth    = 10;

            var untisClass = UntisUtil.GetSchoolClass(cache.Classes, className);
            var lessons    = untisClient.GetLessons(untisClass).Result.ToList();

            // Print table head
            Console.Write($" {untisClass.UniqueName,-sidebarColumnWidth}|");
            for (var d = 0; d < 5; d++) // Loop through days of the week (columns)
            {
                Console.Write($" {daysOfWeek[d],-mainColumnWidth}|");
            }
            //Console.Write(lessons.Count);

            Console.WriteLine();

            // Print table body
            foreach (var period in cache.Periods) // Loop through periods (Rows)
            {
                Console.Write(
                    $"{period.Nr,02} {period.StartTime.Duration():hh\\:mm} - {period.StartTime.Duration():hh\\:mm} | ");
                foreach (var lesson in lessons.Where(l => l.Period.Nr == period.Nr))
                {
                    // TODO: Complete timetable printout. Can't test until untis is fixed
                    Console.Write($" {lesson.Subject.DisplayName,-mainColumnWidth}|");
                }

                Console.WriteLine();
            }
        }
示例#4
0
        private static void Main(string[] args)
        {
            Arguments.Populate();

            // Create cache and config dirs & files
            Directory.CreateDirectory(CacheDir);
            Directory.CreateDirectory(ConfigDir);
            if (!File.Exists(ConfigFile))
            {
                using (var writer = File.CreateText(ConfigFile))
                {
                    var templateConfig = new Config();
                    templateConfig.user            = "******";
                    templateConfig.pass            = "******";
                    templateConfig.server          = "neilo.webuntis.com";
                    templateConfig.schoolName      = "Spengergasse";
                    templateConfig.dayOfWeekLabels = new[] { "Mon", "Die", "Mit", "Don", "Fre" };

                    writer.Write(JsonConvert.SerializeObject(templateConfig, Formatting.Indented));
                }
            }
            // ========================================
            // Switch actions that don't require untis
            // ----------------------------------------

            if (ArgHelp)
            {
                ShowHelp();
            }

            // =============================================
            // Switch actions that require untis connection
            // ---------------------------------------------

            // Try to read config
            var configText = File.ReadAllText(ConfigFile);

            if (configText == null)
            {
                Console.Error.WriteLine("Failed to load config");
                return;
            }

            // Try to parse config
            var config = JsonConvert.DeserializeObject <Config>(configText);

            // Read the cache
            UntisCache cache;

            if (ArgRefreshCache)
            {
                var untisClient = UntisUtil.ConnectUntis(config);
                cache = UntisCache.DownloadCache(untisClient);
                untisClient.LogoutAsync();
                LogVerbose("Refreshed the cache");
                cache.WriteCache(CacheFile);
                LogVerbose("Wrote cache to disk");
            }
            else
            {
                cache = UntisCache.ReadCache(CacheFile);
                LogVerbose("Reading cache");
            }

            if (ArgRemaining)
            {
                CliFrontend.ShowRemainingLessonTime(cache);
            }

            if (ArgListPeriods)
            {
                CliFrontend.ShowPeriodList(cache);
            }

            if (ArgNextLesson)
            {
                CliFrontend.ShowNextLesson(cache, UntisUtil.ConnectUntis(config), ArgClass);
            }

            if (ArgTable)
            {
                CliFrontend.ShowTimeTable(cache, UntisUtil.ConnectUntis(config), ArgClass, config.dayOfWeekLabels);
            }
        }