Exemplo n.º 1
0
        private void HandlePastUpdates(CancellationToken cancel)
        {
            try             // do not fail updater on handling old updates
            {
                foreach (var sectionInfo in updatesStorageEntry.EnumSections(cancel))
                {
                    if (!sectionInfo.Key.StartsWith(Constants.updateLogKeyPrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                    trace.Info("found update log key={0}, id={1}", sectionInfo.Key, sectionInfo.Id);
                    string sectionAbsolutePath;
                    using (var section = updatesStorageEntry.OpenRawStreamSection(sectionInfo.Key, StorageSectionOpenFlag.ReadOnly))
                    {
                        string logContents;
                        using (var reader = new StreamReader(section.Data))
                            logContents = reader.ReadToEnd();
                        trace.Info("log:{1}{0}", logContents, Environment.NewLine);
                        sectionAbsolutePath = section.AbsolutePath;

                        if (!logContents.Contains("Update SUCCEEDED"))
                        {
                            trace.Warning("last update was not successful. reporting to telemetry.");
                            telemetry.ReportException(new PastUpdateFailedException(sectionInfo.Key, logContents), "past update failed");
                        }

                        // todo: find pending update folder, check if it exists, clean
                    }
                    try
                    {
                        File.Delete(sectionAbsolutePath);
                        trace.Info("deleted update log {0}", sectionAbsolutePath);
                    }
                    catch (Exception e)
                    {
                        trace.Error(e, "failed to delete old update log");
                        telemetry.ReportException(e, "delete old update log");
                    }
                }
            }
            catch (Exception e)
            {
                trace.Error(e, "failed to handle old updates");
            }
        }
Exemplo n.º 2
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);
         }
     }
 }