Esempio n. 1
0
        static IEnumerable <ClientVersion> LoadClientVersionsOrDefaults(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            IEnumerable <ClientVersion> clientVersions = null;

            try
            {
                // Load client versions from file
                if (File.Exists(fileName))
                {
                    var xml  = XDocument.Load(fileName);
                    var root = xml.Descendants("SupportedClients").FirstOrDefault();

                    if (root != null)
                    {
                        var fileVersionString = (string)root.Attribute("FileVersion");

                        // Parse the versions for comparison
                        var fileVersion   = Version.Parse(fileVersionString);
                        var latestVersion = Version.Parse(App.ClientVersionsFileVersion);

                        clientVersions = ClientVersionSerializer.DeserializeAll(xml);

                        // Check if client version file is out of date
                        if (fileVersion < latestVersion)
                        {
                            Debug.WriteLine(string.Format("Migrating supported client versions... ({0} -> {1})", fileVersion, latestVersion));

                            // Perform a migration (union) of the old and new client versions
                            if (clientVersions != null)
                            {
                                clientVersions = clientVersions.Union(ClientVersion.GetDefaultVersions(), ClientVersion.VersionComparer);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(string.Format("Unable to load client versions: {0}", ex.Message));
                clientVersions = null;
            }

            // Use the deserialized client versions (or the defaults)
            return(clientVersions ?? ClientVersion.GetDefaultVersions());
        }