async Task RegistryUpdater(CancellationToken cancel, Telemetry.ITelemetryCollector telemetryCollector, bool skipWaiting)
        {
            try
            {
                tracer.Info("pluggable protocol registration updater started");
                if (!skipWaiting)
                {
                    await Task.Delay(TimeSpan.FromSeconds(15), cancel).ConfigureAwait(continueOnCapturedContext: false);

                    tracer.Info("waited enough. waking up");
                }

                if (!TestRegEntries())
                {
                    var exePath = Application.ExecutablePath;
                    if (IsGoodExeToRegister(exePath))
                    {
                        UpdateRegEntries(exePath);
                    }
                }
            }
            catch (TaskCanceledException)
            {
            }
            catch (Exception e)
            {
                telemetryCollector.ReportException(e, "failed to register pluggable protocol");
            }
        }
Exemple #2
0
 public MonoChecker(
     Presenters.MainForm.IPresenter mainWindow,
     Presenters.IAlertPopup alerts,
     Telemetry.ITelemetryCollector telemetryCollector,
     Presenters.IShellOpen shellOpen
     )
 {
     mainWindow.Loaded += (sender, evt) => {
         try {
             CheckMono();
         } catch (Exception ex) {
             telemetryCollector.ReportException(ex, "mono checking");
             if (alerts.ShowPopup(
                     "Error",
                     $"Required mono framework v{minMonoVersion}+ is not found on your system. " +
                     "The program will terminate. " +
                     "Do you want to start mono download before termination?",
                     Presenters.AlertFlags.YesNoCancel
                     ) == Presenters.AlertFlags.Yes)
             {
                 shellOpen.OpenInWebBrowser(
                     new Uri("http://download.mono-project.com/archive/mdk-latest.pkg"));
             }
             Environment.Exit(1);
         }
     };
 }
        public PluginsManager(
            IApplication entryPoint,
            UI.Presenters.MainForm.IPresenter mainFormPresenter,
            Telemetry.ITelemetryCollector telemetry,
            IShutdown shutdown)
        {
            this.tracer            = new LJTraceSource("Extensibility", "plugins-mgr");
            this.entryPoint        = entryPoint;
            this.mainFormPresenter = mainFormPresenter;

            InitPlugins(telemetry);
            RegisterInteropClasses();
            LoadTabExtensions();

            mainFormPresenter.TabChanging += (sender, e) =>
            {
                var ext = e.CustomTabTag as IMainFormTabExtension;
                if (ext == null)
                {
                    return;
                }
                try
                {
                    ext.OnTabPageSelected();
                }
                catch (Exception ex)
                {
                    telemetry.ReportException(ex, "activation of plugin tab: " + ext.Caption);
                    tracer.Error(ex, "Failed to activate extension tab");
                }
            };

            shutdown.Cleanup += (s, e) => Dispose();
        }
Exemple #4
0
        static IReadOnlyList <IPluginInfo> MakePluginInfoList(
            IPluginsIndex index,
            ImmutableArray <IPluginManifest> installedPluginsManifests,
            Telemetry.ITelemetryCollector telemetryCollector
            )
        {
            Dictionary <string, PluginInfo> map = new Dictionary <string, PluginInfo>();

            var installedPluginsMap = installedPluginsManifests.ToLookup(p => p.Id);

            foreach (var indexedPlugin in index.Plugins)
            {
                map[indexedPlugin.Id] = new PluginInfo
                {
                    id                      = indexedPlugin.Id,
                    version                 = indexedPlugin.Version,
                    name                    = indexedPlugin.Name,
                    description             = indexedPlugin.Description,
                    indexItem               = indexedPlugin,
                    installedPluginManifest = installedPluginsMap[indexedPlugin.Id].FirstOrDefault(),
                    dependenciesIds         = indexedPlugin.Dependencies,
                };
            }

            installedPluginsManifests
            .Where(installedPlugin => !map.ContainsKey(installedPlugin.Id))
            .Select(installedPlugin => new PluginInfo
            {
                id                      = installedPlugin.Id,
                version                 = installedPlugin.Version,
                name                    = installedPlugin.Name,
                description             = installedPlugin.Description,
                indexItem               = null,
                installedPluginManifest = installedPlugin,
                dependenciesIds         = installedPlugin.Dependencies
            })
            .ToList()
            .ForEach(p => map[p.id] = p);

            foreach (var p in map.Values.ToArray())
            {
                var deps = p.dependenciesIds.Select(depId =>
                {
                    bool resolved = map.TryGetValue(depId, out var dep);
                    return(resolved, depId, dep);
                }).ToArray();
                var unresolvedDeps = deps.Where(d => !d.resolved).Select(d => d.depId).ToArray();
                if (unresolvedDeps.Length > 0)
                {
                    telemetryCollector.ReportException(new Exception("Bad plug-ins index"),
                                                       $"Plug-in {p.id} depends on non-indexed plug-in(s) {string.Join(",", unresolvedDeps)}");
                }
                var resolvedDeps = deps.Where(d => d.resolved).Select(d => d.dep).ToList();
                p.dependencies = resolvedDeps.AsReadOnly();
                resolvedDeps.ForEach(d => d.dependants = d.dependants.Add(p));
            }

            return(ImmutableArray.CreateRange(map.Values));
        }
Exemple #5
0
 async void AwaitWorker()
 {
     try
     {
         await worker;
     }
     catch (Exception e)
     {
         telemetryCollector.ReportException(e, "search worker");
     }
 }
Exemple #6
0
        Task INavigationManager.NavigateView(Func <CancellationToken, Task> navigate)
        {
            bool wasInProgress = false;

            if (currentNavigationTask != null)
            {
                wasInProgress = true;
                currentNavigationTaskCancellation.Cancel();
                currentNavigationTask = null;
            }
            var taskId = ++currentNavigationTaskId;

            currentNavigationTaskCancellation = new CancellationTokenSource();
            Func <Task> wrapper = async() =>
            {
                // todo: have perf op for navigation
                tracer.Info("nav begin {0} ", taskId);
                var cancellation = currentNavigationTaskCancellation.Token;
                try
                {
                    await navigate(cancellation);
                }
                catch (OperationCanceledException)
                {
                    throw;                     // fail navigation task with same exception. don't telemetrize it.
                }
                catch (Exception e)
                {
                    telemetry.ReportException(e, "LogViewer navigation");
                    throw;
                }
                finally
                {
                    tracer.Info("nav end {0}{1}", taskId, cancellation.IsCancellationRequested ? " (cancelled)" : "");
                    if (taskId == currentNavigationTaskId && currentNavigationTask != null)
                    {
                        currentNavigationTask = null;
                        changeNotification.Post();
                    }
                }
            };
            var tmp = wrapper();

            if (!tmp.IsCompleted)
            {
                currentNavigationTask = tmp;
            }
            if (wasInProgress != (currentNavigationTask != null))
            {
                changeNotification.Post();
            }
            return(tmp);
        }
 void IViewEvents.OnTabPageSelected()
 {
     try
     {
         EnsureInitialized();
         RefreshView();
     }
     catch (Exception e)
     {
         telemetry.ReportException(e, "postprocessors tab page activation failed");
     }
 }
Exemple #8
0
 private async void AwaitWorker()
 {
     try
     {
         await worker;
     }
     catch (SearchCancelledException)
     {
     }
     catch (Exception e)
     {
         telemetryCollector.ReportException(e, "search worker");
     }
 }
Exemple #9
0
 async void AwaitWorker()
 {
     try
     {
         await workerTask;
     }
     catch (Exception e)
     {
         telemetryCollector.ReportException(e, "search all occurences");
     }
     finally
     {
         parent.OnResultCompleted(this);
     }
 }
Exemple #10
0
        private PluginsIndex(XDocument doc, string etag, Telemetry.ITelemetryCollector telemetryCollector)
        {
            this.etag = etag;

            var tmp = new Dictionary <string, Item>();

            foreach (var pluginNode in doc.Elements("plugins").Elements("plugin"))
            {
                var id          = pluginNode.Element("id")?.Value;
                var versionStr  = pluginNode.Element("version")?.Value;
                var name        = pluginNode.Element("name")?.Value;
                var platform    = pluginNode.Element("platform")?.Value;
                var locationStr = pluginNode.Element("location")?.Value;
                var description = pluginNode.Element("description")?.Value;
                var pluginEtag  = pluginNode.Element("etag")?.Value;
                if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(platform) || string.IsNullOrEmpty(pluginEtag) ||
                    !Uri.TryCreate(locationStr ?? "", UriKind.Absolute, out var location) ||
                    !Version.TryParse(versionStr, out var version))
                {
                    telemetryCollector.ReportException(new Exception("Bad entry in plug-ins index"), pluginNode.ToString());
                    continue;
                }
                string thisPlatform =
#if WIN
                    "win";
#elif MONOMAC
                    "mac";
#else
                    "<unk>";
#endif
                if (thisPlatform != platform)
                {
                    continue;
                }
                tmp[id] = new Item
                {
                    id           = id,
                    version      = version,
                    name         = name,
                    description  = description ?? "",
                    location     = location,
                    etag         = pluginEtag,
                    dependencies = ImmutableArray.CreateRange(pluginNode.Elements("dependency").Select(d => d.Value))
                };
            }

            this.items = ImmutableArray.CreateRange(tmp.Values);
        }
Exemple #11
0
 void OnTabPageSelected(bool selected)
 {
     changeNotification.Active = selected;
     if (!selected)
     {
         return;
     }
     try
     {
         EnsureInitialized();
         RefreshView();
     }
     catch (Exception e)
     {
         telemetry.ReportException(e, "postprocessors tab page activation failed");
     }
 }
Exemple #12
0
        async Task Worker()
        {
            try
            {
                await Task.Delay(Constants.initialWorkerDelay, workerCancellationToken);

                HandlePastUpdates(workerCancellationToken);

                SetState(AutoUpdateState.Idle);

                for (;;)
                {
                    var appUpdateInfoFileContent = UpdateInfoFileContent.Read(updateInfoFilePath);
                    var installationUpdateKey    = factory.CreateUpdateKey(
                        appUpdateInfoFileContent.BinariesETag,
                        pluginsManager.InstalledPlugins.ToDictionary(
                            p => p.Id,
                            p => UpdateInfoFileContent.Read(Path.Combine(p.PluginDirectory, Constants.updateInfoFileName)).BinariesETag
                            )
                        );

                    SetLastUpdateCheckInfo(appUpdateInfoFileContent);

                    await IdleUntilItsTimeToCheckForUpdate(appUpdateInfoFileContent.LastCheckTimestamp);

                    SetState(AutoUpdateState.Checking);

                    var appCheckResult = await CheckForUpdate(appUpdateInfoFileContent.BinariesETag);

                    if (appCheckResult.Status == DownloadUpdateResult.StatusCode.Failure)
                    {
                        continue;
                    }

                    var requiredPlugins = await GetRequiredPlugins(pluginsManager, workerCancellationToken);

                    var requiredUpdateKey = factory.CreateUpdateKey(
                        appCheckResult.ETag,
                        requiredPlugins.ToDictionary(p => p.Id, p => p.IndexItem.ETag)
                        );

                    var nullUpdateKey = factory.CreateNullUpdateKey();

                    bool requiredUpdateIsSameAsAlreadyInstalled = requiredUpdateKey.Equals(installationUpdateKey);
                    trace.Info("Comparing required update key '{0}' with already installed '{1}': {2}", requiredUpdateKey, installationUpdateKey, requiredUpdateIsSameAsAlreadyInstalled);
                    if (requiredUpdateIsSameAsAlreadyInstalled)
                    {
                        requiredUpdateKey = nullUpdateKey;
                    }

                    if (!requiredUpdateKey.Equals(currentPendingUpdate?.Key ?? nullUpdateKey))
                    {
                        if (currentPendingUpdate != null)
                        {
                            await currentPendingUpdate.Dispose();

                            currentPendingUpdate = null;
                        }
                        if (!requiredUpdateKey.Equals(nullUpdateKey))
                        {
                            currentPendingUpdate = await factory.CreatePendingUpdate(
                                requiredPlugins,
                                managedAssembliesPath,
                                ComposeUpdateLogFileName(),
                                workerCancellationToken
                                );

                            trace.Info("Created new pending update with key '{0}'", currentPendingUpdate.Key);
                        }
                    }

                    if (currentPendingUpdate != null)
                    {
                        SetState(AutoUpdateState.WaitingRestart);
                    }
                    else
                    {
                        SetState(AutoUpdateState.Idle);
                    }
                }
            }
            catch (TaskCanceledException)
            {
                trace.Info("autoupdater worker cancelled");
            }
            catch (OperationCanceledException)
            {
                trace.Info("autoupdater worker cancelled");
            }
            catch (BadInstallationDirException e)
            {
                trace.Error(e, "bad installation directory detected");
                SetState(AutoUpdateState.FailedDueToBadInstallationDirectory);
                throw;
            }
            catch (Exception e)
            {
                trace.Error(e, "autoupdater worker failed");
                SetState(AutoUpdateState.Failed);
                telemetry.ReportException(e, "autoupdater worker");
                throw;
            }
        }
Exemple #13
0
 private void InitPlugins(Telemetry.ITelemetryCollector telemetry)
 {
     using (tracer.NewFrame)
     {
         string thisPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
         tracer.Info("plugins directory: {0}", thisPath);
         foreach (string pluginPath in Directory.GetFiles(thisPath, "*.plugin.dll"))
         {
             tracer.Info("---> plugin found {0}", pluginPath);
             Stopwatch sw = Stopwatch.StartNew();
             Assembly  pluginAsm;
             try
             {
                 pluginAsm = Assembly.LoadFrom(pluginPath);
             }
             catch (Exception e)
             {
                 tracer.Error(e, "failed to load plugin");
                 telemetry.ReportException(e, "loading pluging " + pluginPath);
                 continue;
             }
             var  loadTime   = sw.Elapsed;
             Type pluginType = pluginAsm.GetType("LogJoint.Plugin");
             if (pluginType == null)
             {
                 tracer.Warning("plugin class not found in plugin assembly");
                 continue;
             }
             if (!typeof(PluginBase).IsAssignableFrom(pluginType))
             {
                 tracer.Warning("plugin class doesn't inherit PluginBase");
                 continue;
             }
             sw.Restart();
             PluginBase plugin;
             try
             {
                 plugin = (PluginBase)Activator.CreateInstance(pluginType);
             }
             catch (Exception e)
             {
                 tracer.Error(e, "failed to create an instance of plugin");
                 telemetry.ReportException(e, "creation of plugin " + pluginPath);
                 continue;
             }
             var instantiationTime = sw.Elapsed;
             sw.Restart();
             try
             {
                 plugin.Init(entryPoint);
             }
             catch (Exception e)
             {
                 plugin.Dispose();
                 tracer.Error(e, "failed to init an instance of plugin");
                 telemetry.ReportException(e, "initializtion of plugin " + pluginPath);
                 continue;
             }
             var initTime = sw.Elapsed;
             tracer.Info("plugin {0} accepted. times: loading={1}, instantiation={2}, initialization={3}",
                         Path.GetFileName(pluginPath), loadTime, instantiationTime, initTime);
             plugins.Add(plugin);
         }
     }
 }