Пример #1
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            if (ParsedArgs.GetToken("minimize"))
            {
                this.WindowState = FormWindowState.Minimized;
            }

            this.Text += " - " + Assembly.GetEntryAssembly().GetName().Version;

            CheckingRoutine();

            TimerRoutine();

            SessionStorage.NotificationDelayChanged += frmMain_NotificationDelayChanged;
            network.NetworkIsUp += Network_NetworkIsUp;
        }
Пример #2
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;
        }
Пример #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();
        }
Пример #4
0
        private void CheckingRoutine()
        {
            // Cleaning up a bit
            //flowDownloads.Controls.Clear();

            labelVersion.Text = Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.Checking", "Checking...");
            Log.Write("Checking for updates on the medoc.ua server");

            bool success = medoc.RefreshDoc();

            if (success)
            {
                MedocVersion version = medoc.GetLatestVersion();
                if (!MedocVersion.IsValid(version))
                {
                    Log.Write("Application cannot get the latest remote M.E.Doc version");
                    return;
                }

                //version = "11.01.023";
                labelVersion.Text = String.Format(Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.LatestVersion", "Latest version: {0}"), version);

                //MedocVersion test = new MedocVersion(version);

                //MedocVersion test2 = "11.01.024";
                //MedocVersion test3 = "11.01.023";


                MedocVersion localversion = localmedoc.LocalVersion;
                if (!MedocVersion.IsValid(version))
                {
                    Log.Write("Application cannot get a local version of M.E.Doc installation.");
                    MessageBox.Show(
                        Loc.Get("frmMain.MessageBox.CheckingRoutine.NoLocalVersion", "This application must be ran only on systems with M.E.Doc installed."),
                        "Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    return;
                }
                //localversion = "11.01.021";
                labelLocalVersion.Text = String.Format(Loc.Get("frmMain.labelLocalVersion.Text.CheckingRoutine.LatestLocalVersion", "Latest local version: {0}"), localversion);

                Log.Write(labelVersion.Text);
                Log.Write(labelLocalVersion.Text);

                // Does some updates are performing now? Then don't recreate the buttons
                // FIXME: Still can be a better solution probably
                bool isStillUpdating = false;
                foreach (DownloadButton button in flowDownloads.Controls)
                {
                    if (button.IsUpdating)
                    {
                        isStillUpdating = true;
                        break;
                    }
                }

                if (!isStillUpdating)
                {
                    MedocDownloadItem[] items;
                    success = medoc.GetItems(out items);
                    if (success)
                    {
                        /*
                         *      if (lastDownloadsCount != items.Length)
                         *      {
                         *              // Initial download items update
                         *              //if(lastDownloadsCount == 0)
                         *              if(false) // Test
                         *              {
                         *                      flowDownloads.Controls.Clear();
                         *                      foreach (MedocDownloadItem item in items)
                         *                      {
                         *                              DownloadButton btn = new DownloadButton(item);
                         *                              btn.IsHighlighted = (item.version > localversion);
                         *                              btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                         *                              flowDownloads.Controls.Add(btn);
                         *
                         *                              //	Console.WriteLine("Added {0}", item.link);
                         *                      }
                         *              }
                         *              else // Update count was changed since the last checking for updates
                         *              {
                         *                      // Determine what count should we add to existing download items
                         *                      int newItemsCount = items.Length - lastDownloadsCount;
                         *                      int i = 0;
                         *                      for (; newItemsCount > 0; newItemsCount--, i++)
                         *                      {
                         *                              //MedocDownloadItem item = items[newItemsCount-1]; // Reverse order
                         *                              MedocDownloadItem item = items[i];
                         *                              DownloadButton btn = new DownloadButton(item);
                         *                              btn.IsHighlighted = (item.version > localversion);
                         *                              btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                         *                              flowDownloads.Controls.Add(btn); // This whole thing might be working if I could add to the begin of the Controls
                         *                      }
                         *              }
                         *
                         *              lastDownloadsCount = items.Length;
                         *      }
                         */

                        flowDownloads.Controls.Clear();
                        foreach (MedocDownloadItem item in items)
                        {
                            DownloadButton btn = new DownloadButton(item);
                            btn.IsHighlighted            = (item.version > localversion);
                            btn.FileDownloadedAndRunned += Btn_FileDownloadedAndRunned;
                            flowDownloads.Controls.Add(btn);

                            //	Console.WriteLine("Added {0}", item.link);
                        }
                    }
                }

                Status(Loc.Get("frmMain_Done", "Done."));
                trayIcon.Text = labelVersion.Text + "\r\n" + labelLocalVersion.Text;

                if (localversion != version)
                {
                    trayIcon.ShowBalloonTip(5000, Loc.Get("frmMain.trayIcon.BalloonTipTitle.CheckingRoutine.UpdateReleased", "M.E.Doc update has been released!"),
                                            labelVersion.Text + "\r\n" + labelLocalVersion.Text, ToolTipIcon.Info);
                }
                else
                {
                    if (this.WindowState != FormWindowState.Minimized)
                    {
                        trayIcon.ShowBalloonTip(5000, Loc.Get("frmMain.trayIcon.BalloonTipTitle.CheckingRoutine.NoUpdates", "No updates for M.E.Doc"),
                                                String.Format(Loc.Get("frmMain.trayIcon.BalloonTipText.CheckingRoutine.NoUpdates", "Minimize the app to deny \"no updates\" notifications\r\n{0}"),
                                                              labelVersion.Text + "\r\n" +
                                                              labelLocalVersion.Text), ToolTipIcon.Info);
                    }
                }

                if (ParsedArgs.GetToken("telegramforcemsg") || localversion != version)
                {
                    string versionChangelog = medoc.GetLatestChangelog();

                    telegram.SendMessageAll(String.Format(Loc.Get("frmMain.telegram.CheckingRoutine.UpdateAvailable", "Update from {0} to [{1}]({2}) is available"),
                                                          localversion, version, versionChangelog),
                                            Telegram.Bot.Types.Enums.ParseMode.Markdown);
                }
            }
            else
            {
                labelVersion.Text = Loc.Get("frmMain.labelVersion.Text.CheckingRoutine.Error", "Something went wrong");
                Log.Write("Cannot connect to medoc.ua");
                Status(Loc.Get("frmMain.Status.CheckingRoutine.CannotConnect", "Cannot connect to medoc.ua"));
            }
        }
Пример #5
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;
            }
        }