示例#1
0
 void critical_CriticalUpdatesFound(object sender, CriticalUpdatesFoundEventArgs e)
 {
     try
     {
         var pnu = sender as PNUpdateChecker;
         if (pnu != null) pnu.CriticalUpdatesFound -= critical_CriticalUpdatesFound;
         _UnsubscribedCritical = true;
         var commandLinePrepared = !string.IsNullOrWhiteSpace(e.ProgramFileName) &&
                                   prepareCriticalVersionUpdateCommandLine(e.ProgramFileName);
         var pluginsXmlPrepared = e.Plugins != null && e.Plugins.Any() &&
                                  preparePreRunCriticalPluginsXml(e.Plugins);
         e.Accepted = commandLinePrepared | pluginsXmlPrepared;
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
示例#2
0
 private CriticalUpdateAction parsCriticalUpdate(XDocument xdoc, string productVersion)
 {
     try
     {
         var result = CriticalUpdateAction.None;
         if (string.IsNullOrWhiteSpace(productVersion))
         {
             return(CriticalUpdateAction.None);
         }
         if (xdoc.Root == null)
         {
             return(CriticalUpdateAction.None);
         }
         string progFileName = null;
         var    progs        = xdoc.Root.Element("programs");
         if (progs != null)
         {
             // current product version should be equal to version from critical.xml
             foreach (var pg in progs.Elements("program").Where(pg => pg.Attribute("version") != null &&
                                                                pg.Attribute("version").Value ==
                                                                Application.ProductVersion))
             {
                 progFileName = pg.Attribute("file").Value;
                 break;
             }
         }
         var plugins = xdoc.Root.Element("plugins");
         if (plugins == null)
         {
             return(CriticalUpdateAction.None);
         }
         var criticalPlugins = (from pl in plugins.Elements("plugin")
                                where
                                pl.Attribute("type") != null && pl.Attribute("name") != null &&
                                pl.Attribute("version") != null && pl.Attribute("file") != null &&
                                pl.Attribute("progversion") != null
                                select new _PluginClass
         {
             Type = Convert.ToInt32(pl.Attribute("type").Value),
             Name = pl.Attribute("name").Value,
             Version = pl.Attribute("version").Value,
             FileName = pl.Attribute("file").Value,
             MainProductVersion = pl.Attribute("progversion").Value
         }).ToList();
         // get the max version from critical_update.xml which is less or equal to current product version
         var maxVersion =
             criticalPlugins.Where(p => String.CompareOrdinal(p.MainProductVersion, productVersion) <= 0)
             .Select(p => p.MainProductVersion)
             .OrderByDescending(s => s, new VersionComparer())
             .FirstOrDefault();
         var pluginsList = new List <CriticalPluginUpdate>();
         if (!string.IsNullOrEmpty(maxVersion))
         {
             // current main product version should equal to max version from critical.xml
             // and critical plugin version should be more than current plugin version
             pluginsList.AddRange(from pl in PNPlugins.Instance.SocialPlugins
                                  select
                                  criticalPlugins.FirstOrDefault(
                                      p =>
                                      p.Type == 0 && p.MainProductVersion == maxVersion &&
                                      new Version(p.Version) > new Version(pl.Version) && p.Name == pl.ProductName)
                                  into cp
                                  where cp != null
                                  select new CriticalPluginUpdate {
                 FileName = cp.FileName, ProductName = cp.Name
             });
             pluginsList.AddRange(from pl in PNPlugins.Instance.SyncPlugins
                                  select
                                  criticalPlugins.FirstOrDefault(
                                      p => p.Type == 1 && p.MainProductVersion == maxVersion &&
                                      new Version(p.Version) > new Version(pl.Version) && p.Name == pl.ProductName)
                                  into cp
                                  where cp != null
                                  select new CriticalPluginUpdate {
                 FileName = cp.FileName, ProductName = cp.Name
             });
         }
         if (string.IsNullOrWhiteSpace(progFileName) && !pluginsList.Any())
         {
             return(CriticalUpdateAction.None);
         }
         if (CriticalUpdatesFound == null)
         {
             return(CriticalUpdateAction.None);
         }
         var ev = new CriticalUpdatesFoundEventArgs(progFileName, pluginsList);
         CriticalUpdatesFound(this, ev);
         if (!string.IsNullOrWhiteSpace(progFileName))
         {
             result |= CriticalUpdateAction.Program;
         }
         if (pluginsList.Any())
         {
             result |= CriticalUpdateAction.Plugins;
         }
         return(ev.Accepted ? result : CriticalUpdateAction.None);
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex, false);
         return(CriticalUpdateAction.None);
     }
     finally
     {
         PNSingleton.Instance.CriticalChecking = false;
     }
 }