예제 #1
0
        private bool UnsubscribeInternal(long chatID)
        {
            if (!IsSubscribed(chatID))
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot unsubscribe chat #" + chatID + " - already not subscribed");
                return(false);
            }

            if (!TelegramChatsStorage.TelegramChats.Remove(chatID))
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot unsubscribe chat #" + chatID + " - something wrong with internal chat list");
                return(false);
            }

            // Does this user still subscribed?
            if (IsSubscribed(chatID))
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot unsubscribe chat #" + chatID + " - chat list still has this chat in it");
                return(false);
            }

            TelegramChatsStorage.Save();

            return(true);
        }
예제 #2
0
        private bool SubscribeInternal(long chatID)
        {
            if (IsSubscribed(chatID))
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot subscribe chat #" + chatID + " - already subscribed");
                return(false);
            }

            TelegramChatsStorage.TelegramChats.Add(chatID);

            // Double check
            if (!IsSubscribed(chatID))
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot subscribe chat #" + chatID + " - something wrong with internal chat list");
                return(false);
            }

            TelegramChatsStorage.Save();

            return(true);
        }
예제 #3
0
        static void Main()
        {
            // Windows Forms specific
            Application.ThreadException += Application_ThreadException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            // Non-UI specific
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            System.Reflection.Assembly entryassembly = System.Reflection.Assembly.GetEntryAssembly();
            if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(entryassembly.Location)).Count() > 1)
            {
                MessageBox.Show("Cannot run another instance of this app!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Fix for Telegram.Bot not being able to do something on Windows Server 2008 R2
            try
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls |
                                                        SecurityProtocolType.Tls11 |
                                                        SecurityProtocolType.Tls12 |
                                                        SecurityProtocolType.Ssl3;
            }
            catch (Exception ex)
            {
                MessageBox.Show("MedocUpdates: Cannot set the security protocol type - TLS/TLS1.1/TLS1.2/SSL3 probably not supported\r\n" + ex.Message);
                return;
            }

            ParsedArgs.SetArgs(Environment.GetCommandLineArgs());
            ParsedArgs.PrintArgs();

            bool bSettingsWasRestoredFromFile = SessionStorage.Restore();

            TelegramChatsStorage.Restore();

            Log.Init();
            Log.Write("");
            Log.Write(String.Format("MedocUpdates: Initializing version {0}...", entryassembly.GetName().Version));

            string forcedLang = ParsedArgs.GetArgument("forcelanguage");

            if (forcedLang.Trim().Length > 0)
            {
                Loc.Init(forcedLang);
            }
            else
            {
                Loc.Init();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

#if DEBUG
            //MUVersion.Init();
            //Update update = new Update(MUVersion.latestRelease);
            //update.UpdateRoutine();

            // Crash test zone
            //throw new ArgumentException("The parameter was invalid");
#endif

            if (/*true || */ !bSettingsWasRestoredFromFile)
            {
                Application.Run(new frmFirstRun());                 // Only show if SessionStorage file doesn't exist
            }
            Application.Run(new frmMain());

            Log.Write("MedocUpdates: Shutting down the application");
            SessionStorage.Save();
        }