Пример #1
0
        /// <summary>
        ///     Load all plugin data async.
        /// </summary>
        /// <remarks></remarks>
        private void LoadAsync()
        {
            try
            {
                if (InstalledPlugins == null)
                {
                    return;
                }

                _pluginLinkDictionary = new Dictionary <InstalledPlugin, BukgetPlugin>();

                for (UInt16 i = 0; i <= InstalledPlugins.Count - 1; i++)
                {
                    InstalledPlugin plugin = InstalledPlugins[i];
                    if (plugin != null && plugin.Name != null)
                    {
                        SetStatus(T.Tr("Loading plugin data:") + plugin.Name + "(" + i + 1 + "/" +
                                  InstalledPlugins.Count + ")");
                        Logger.Log(LogLevel.Info, "PluginUpdater",
                                   "Loading plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count + ")");
                        if (_pluginLinkDictionary.ContainsKey(plugin) == false)
                        {
                            try
                            {
                                _pluginLinkDictionary.Add(plugin, BukgetPlugin.CreateFromNamespace(plugin.Mainspace));
                            }
                            catch (Exception ex)
                            {
                                _pluginLinkDictionary.Add(plugin, null);
                                Logger.Log(LogLevel.Info, "PluginUpdater",
                                           "Skipped plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count +
                                           ")", ex.Message);
                            }
                            Logger.Log(LogLevel.Info, "PluginUpdater",
                                       "Added plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count + ")");
                        }
                        else
                        {
                            Logger.Log(LogLevel.Info, "PluginUpdater",
                                       "Discarded plugin data:" + plugin.Name + "(" + i + 1 + "/" + InstalledPlugins.Count +
                                       ")");
                        }

                        double tmpp = Math.Round((double)(100 * ((i + 1) / InstalledPlugins.Count)));
                        if (tmpp > 100)
                        {
                            tmpp = 100;
                        }
                        SetProgress(Convert.ToByte(tmpp));
                    }
                }
                Logger.Log(LogLevel.Info, "PluginUpdater", "Loaded plugin data (" + InstalledPlugins.Count + ")");
                LoadUi();
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Severe, "PluginUpdater", "Severe exception in LoadAsync routine!", ex.Message);
            }
        }
Пример #2
0
        private void SetStatus(string text)
        {
            if (Disposing || IsDisposed || lblStatus.IsDisposed || lblStatus.Disposing)
            {
                return;
            }

            if (InvokeRequired)
            {
                Invoke((MethodInvoker)(() => SetStatus(text)));
            }
            else
            {
                lblStatus.Text = T.Tr("Status:") + " " + text;
            }
        }
Пример #3
0
        /// <summary>
        ///     Update each plugin, if it's checked
        /// </summary>
        /// <remarks></remarks>
        private void Plugins_Update(object sender, EventArgs e)
        {
            try
            {
                if (InvokeRequired)
                {
                    Invoke((MethodInvoker)(() => Plugins_Update(sender, e)));
                }
                else
                {
                    Logger.Log(LogLevel.Info, "PluginUpdater", "Starting plugins update");
                    if (SlvPlugins.CheckedItems.Count < 1)
                    {
                        return;
                    }
                    UInt16 i = 1;
                    foreach (ListViewItem item in SlvPlugins.CheckedItems)
                    {
                        if (item.Tag != null)
                        {
                            InstalledPlugin     plugin  = (InstalledPlugin)item.Tag;
                            BukgetPluginVersion version = _pluginLinkDictionary[plugin].LastVersion;

                            if (version == null)
                            {
                                continue;
                            }


                            SetStatus(T.Tr("Updating plugin") + " " + plugin.Name + " " +
                                      T.Tr("to version") + " " + version.VersionNumber +
                                      " (" + i + "/" + SlvPlugins.CheckedItems.Count + ")");

                            Logger.Log(LogLevel.Info, "PluginUpdater", "Updating plugin:" + plugin.Name);
                            BukgetPluginInstaller.Install(version, plugin.Path, false,
                                                          false);
                        }

                        else
                        {
                            SetStatus(T.Tr("Skipping plugin") + " " + item.SubItems[0].Text + " - " +
                                      T.Tr("cannot update") + "(" + i +
                                      1 + " / " + _pluginLinkDictionary.Count + ")");
                            Logger.Log(LogLevel.Info, "PluginUpdater", "Skipping plugin:" + item.SubItems[0].Text);
                        }
                        double tmpp = Math.Round(100 * ((i + 1) / (double)_pluginLinkDictionary.Count));
                        if (tmpp > 100)
                        {
                            tmpp = 100;
                        }
                        SetProgress(Convert.ToByte(tmpp));
                        i++;
                    }


                    SetStatus(T.Tr("Idle"));

                    if (BtnClose != null && !(Disposing || IsDisposed) && !(BtnClose.Disposing || BtnClose.IsDisposed))
                    {
                        BtnClose.Enabled = true;
                    }

                    InstalledPluginManager.RefreshAllInstalledPluginsAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(T.Tr("Something went wrong while updating. Please check if all plugins are updated."),
                                T.Tr("Something went wrong"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                Logger.Log(LogLevel.Warning, "PluginUpdater", "Severe exception in Update routine!", ex.Message);
            }
            CloseThisForm(null, null);
        }
Пример #4
0
 /// <summary>
 ///     Load the user interface with the listview items, once all data is loaded.
 /// </summary>
 /// <remarks></remarks>
 private void LoadUi()
 {
     try
     {
         if (InvokeRequired)
         {
             Invoke((MethodInvoker)LoadUi);
         }
         else
         {
             if (_pluginLinkDictionary == null)
             {
                 return;
             }
             SetStatus(T.Tr("Loading plugin data to screen..."));
             Logger.Log(LogLevel.Info, "PluginUpdater", "Loading UI data (" + _pluginLinkDictionary.Count + ")");
             foreach (KeyValuePair <InstalledPlugin, BukgetPlugin> entry in _pluginLinkDictionary)
             {
                 try
                 {
                     ListViewItem lvi;
                     if (entry.Value == null || entry.Value.VersionsList == null ||
                         entry.Value.VersionsList.Count < 1)
                     {
                         string[] content =
                         {
                             entry.Key.Name,
                             entry.Key.Version,
                             T.Tr("No data available"),
                             T.Tr("No data available")
                         };
                         lvi = new ListViewItem(content)
                         {
                             BackColor = Color.LightGray, Tag = null
                         };
                     }
                     else
                     {
                         string[] content =
                         {
                             entry.Key.Name,
                             entry.Key.Version,
                             entry.Value.VersionsList[0].VersionNumber,
                             StringUtil.ListToCsv(entry.Value.VersionsList[0].CompatibleBuilds)
                         };
                         lvi = new ListViewItem(content)
                         {
                             Tag = entry.Key
                         };
                         if (CheckVersion(entry.Key.Version, entry.Value.VersionsList[0].VersionNumber) == 1)
                         {
                             lvi.Checked = true;
                         }
                         else
                         {
                             lvi.Checked = false;
                         }
                     }
                     SlvPlugins.Items.Add(lvi);
                 }
                 catch (Exception ex)
                 {
                     if (entry.Key != null && entry.Key.Name != null)
                     {
                         Logger.Log(LogLevel.Warning, "PluginUpdater", "Couldn't load plugin:" + entry.Key.Name,
                                    ex.Message);
                     }
                     else
                     {
                         Logger.Log(LogLevel.Warning, "PluginUpdater", "Couldn't load plugin", ex.Message);
                     }
                 }
             }
             SetStatus(T.Tr("Idle"));
         }
         if (UpdateOnLoad)
         {
             Plugins_Update(null, null);
         }
     }
     catch (Exception ex)
     {
         Logger.Log(LogLevel.Severe, "PluginUpdater", "Severe exception in LoadUI routine!", ex.Message);
     }
 }