Exemplo n.º 1
0
        static OperatingSystem()
        {
            string path = (string)PowerShellHelper.InvokeCommand("Get-PSFConfigValue -FullName AutomatedLab.LabAppDataRoot").FirstOrDefault().BaseObject;

            string productKeysXmlFilePath      = $@"{path}/Assets/ProductKeys.xml";
            string productKeysCusomXmlFilePath = string.Format(@"{0}/{1}",
                                                               path,
                                                               @"Assets/ProductKeysCustom.xml");

            try
            {
                productKeys = ListXmlStore <ProductKey> .Import(productKeysXmlFilePath);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Could not read 'ProductKeys.xml' file. Make sure the file exist in path '{0}': {1}", productKeysXmlFilePath, ex.Message));
            }

            try
            {
                productKeysCustom = ListXmlStore <ProductKey> .Import(productKeysCusomXmlFilePath);
            }
            catch (Exception)
            {
                //don't throw, the file is not mandatory
            }

            //merge keys from custom file
            foreach (var key in productKeysCustom)
            {
                var existingKey = productKeys.Where(pk => pk.OperatingSystemName == key.OperatingSystemName && pk.Version == key.Version);
                if (existingKey.Count() == 0)
                {
                    productKeys.Add(new ProductKey()
                    {
                        OperatingSystemName = key.OperatingSystemName,
                        Version             = key.Version,
                        Key = key.Key
                    });
                }
                else if (existingKey.Count() == 1)
                {
                    existingKey.First().Key = key.Key;
                }
                else
                {
                }
            }
        }
Exemplo n.º 2
0
        static OperatingSystem()
        {
            try
            {
                productKeys = ListXmlStore <ProductKey> .Import(productKeysXmlFilePath);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Could not read 'ProductKeys.xml' file. Make sure the file exist in path '{0}': {1}", productKeysXmlFilePath, ex.Message));
            }

            try
            {
                productKeysCustom = ListXmlStore <ProductKey> .Import(productKeysCusomXmlFilePath);
            }
            catch (Exception)
            {
                //don't throw, the file is not mandatory
            }

            //merge keys from custom file
            foreach (var key in productKeysCustom)
            {
                var existingKey = productKeys.Where(pk => pk.OperatingSystemName == key.OperatingSystemName && pk.Version == key.Version);
                if (existingKey.Count() == 0)
                {
                    productKeys.Add(new ProductKey()
                    {
                        OperatingSystemName = key.OperatingSystemName,
                        Version             = key.Version,
                        Key = key.Key
                    });
                }
                else if (existingKey.Count() == 1)
                {
                    existingKey.First().Key = key.Key;
                }
                else
                {
                }
            }
        }