Ejemplo n.º 1
0
        public bool Equals(SerializableVersion sv)
        {
            // If parameter is null return false:
            if ((object)sv == null)
            {
                return(false);
            }

            // Return true if the fields match:
            return(this.Major == sv.Major && this.Minor == sv.Minor && this.Revision == sv.Revision && this.Build == sv.Build);
        }
 private IEnumerable <Type> FindUpdateClass(SerializableVersion currentFileVersion)
 {
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         foreach (Type type in assembly.GetTypes())
         {
             SerializableVersion upgradeFrom = type.GetCustomAttributes(typeof(SerializableVersion), true).FirstOrDefault() as SerializableVersion;
             if (upgradeFrom == currentFileVersion)
             {
                 yield return(type);
             }
         }
     }
 }
        internal bool UpdateFile(SerializableVersion fromVersion, Tracker tracker)
        {
            if (fromVersion == null)
            {
                return(false);
            }
            IEnumerable <Type> updaterTypes = FindUpdateClass(fromVersion);

            if (updaterTypes.Count() != 1)
            {
                //no updater found, or too many
                return(false);
            }
            IFileUpdater updater = (IFileUpdater)Activator.CreateInstance(updaterTypes.First());

            return(updater.UpdateFile(this.FullDataFilePath, tracker));
        }
        public static SerializableVersion ParseCurrentFileVersion(XmlNode versionNode)
        {
            if (versionNode == null)
            {
                return(null);
            }

            bool allOK = true;
            SerializableVersion ret = new SerializableVersion();

            allOK &= Int32.TryParse(versionNode.SelectSingleNode("Build")?.InnerText, out ret.Build);
            allOK &= Int32.TryParse(versionNode.SelectSingleNode("Major")?.InnerText, out ret.Major);
            allOK &= Int32.TryParse(versionNode.SelectSingleNode("Minor")?.InnerText, out ret.Minor);
            allOK &= Int32.TryParse(versionNode.SelectSingleNode("Revision")?.InnerText, out ret.Revision);

            if (!allOK)
            {
                //parse failed
                return(null);
            }
            return(ret);
        }