Ejemplo n.º 1
0
        public static void Init()
        {
            // If initialized already - don't do this again
            if (m_bInit)
            {
                return;
            }

            try
            {
                // Make sure log directory does exist
                string logDirectory = Path.GetDirectoryName(m_logPath);
                if (!Directory.Exists(logDirectory))
                {
                    Directory.CreateDirectory(logDirectory);
                }
            }
            catch (Exception ex)
            {
                LogFallbackInternal(FormatLogMessage("Log: Cannot create log directory"), FormatLogMessage(ex.Message));
                return;
            }

            string logLevelStr = ParsedArgs.GetArgument("loglevel");

            if (logLevelStr.Length > 0)
            {
                int logLevel = m_logLevel;
                if (int.TryParse(logLevelStr, out logLevel))
                {
                    m_logLevel = LogLevel.Clamp(logLevel, LogLevel.BASIC, LogLevel.MAXLOGLEVELS - 1);
                    Log.Write("Log: Level was forcibly set to " + LogLevel.GetName(m_logLevel));
                }
            }

            m_bInit = true;
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        public MedocTelegram()
        {
            botToken = SessionStorage.inside.TelegramToken;

            string tokenStr = ParsedArgs.GetArgument("telegramtoken");

            if (tokenStr.Length > 0)
            {
                botToken = tokenStr;
                Log.Write("MedocTelegram: Token was forcibly set to " + tokenStr.Substring(0, 3) + "...");                 // Print only first 3 symbols - just to make sure
            }

            try
            {
                botClient = new TelegramBotClient(botToken);
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Created TelegramBotClient object");
            }
            catch (Exception ex)
            {
                Log.Write("MedocTelegram: Cannot create TelegramBotClient object\r\n" + ex.Message);
                return;
            }

            //Console.WriteLine(botClient.GetMeAsync().Result.Username);

            botClient.OnCallbackQuery       += OnCallbackQueryReceived;
            botClient.OnInlineQuery         += BotClient_OnInlineQuery;
            botClient.OnInlineResultChosen  += BotClient_OnInlineResultChosen;
            botClient.OnMessage             += OnMessageReceived;
            botClient.OnReceiveError        += BotClient_OnReceiveError;
            botClient.OnReceiveGeneralError += BotClient_OnReceiveGeneralError;

            try
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Client begins to receive updates...");

                /* Not needed
                 *      UpdateType[] updates = new UpdateType [4]{
                 *              UpdateType.CallbackQuery,
                 *              UpdateType.InlineQuery,
                 *              UpdateType.ChosenInlineResult,
                 *              UpdateType.Message
                 *      };
                 */



                botClient.StartReceiving(/*updates*/);                 // Start loop
            }
            catch (Exception ex)
            {
                Log.Write(LogLevel.NORMAL, "MedocTelegram: Cannot start receiving updates\r\n" + ex.Message);
                return;
            }

            if (TelegramChatsStorage.TelegramChats == null)             // May be rare
            {
                Log.Write(LogLevel.EXPERT, "MedocTelegram: Internal chat list is null");
                return;
            }
        }