コード例 #1
0
        static bool StartAndSaveSession(string subject)
        {
            Console.WriteLine($"Starting new work session with subject \"{subject}\".");
            try
            {
                WorkSession session = new WorkSession(subject);
                Console.WriteLine($"Saving session information to disk.");
                session.SaveSession(sessionLocation);
                //Notify Telegram
                botClient.SendTextMessageAsync(
                    new Telegram.Bot.Types.ChatId(botChatId),
                    $"User *{Environment.UserName}* started working on `{subject}`",
                    Telegram.Bot.Types.Enums.ParseMode.Markdown
                    );

                return(true);
            }
            catch (RemoteTimeUnavailableException)
            {
                Console.WriteLine("Your session could not be started because the remote time server is unavailable.");
                return(false);
            }
            catch
            {
                Console.WriteLine("An unspecified error occured and your session could not be started.");
                if (File.Exists(sessionLocation))
                {
                    File.Delete(sessionLocation);
                }

                return(false);
            }
        }