Exemple #1
0
        public override void Execute()
        {
            string outputFile;

            if (String.IsNullOrEmpty(npandaySettingsPath))
            {
                npandaySettingsPath = PathUtil.GetHomeM2Folder();
            }
            outputFile = PathUtil.BuildSettingsFilePath(npandaySettingsPath);

            XmlSerializer serializer = new XmlSerializer(typeof(npandaySettings));

            npandaySettings settings = new npandaySettings();

            settings.operatingSystem = Environment.OSVersion.ToString();

            RegistryKey monoRegistryKey      = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Novell\Mono");
            RegistryKey microsoftRegistryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");

            string defaultMonoCLR = (monoRegistryKey != null) ? (string)monoRegistryKey.GetValue("DefaultCLR") : null;

            settings.defaultSetup = GetDefaultSetup(defaultMonoCLR,
                                                    (string)microsoftRegistryKey.GetValue("InstallRoot"));

            npandaySettingsVendorsVendor[] microsoftVendors = null;
            try
            {
                microsoftVendors = GetVendorsForMicrosoft(microsoftRegistryKey);
            }
            catch (ExecutionException e)
            {
                Console.WriteLine(e.ToString());
            }

            npandaySettingsVendorsVendor[] monoVendors  = null;
            npandaySettingsVendorsVendor   dotGnuVendor = null;

            if (File.Exists(outputFile))
            {
                try
                {
                    monoVendors = GetVendorsForMono(monoRegistryKey, defaultMonoCLR);
                }
                catch (ExecutionException e)
                {
                    if (microsoftVendors == null)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }

                try
                {
                    dotGnuVendor = GetVendorForGnu(Environment.GetEnvironmentVariable("CSCC_LIB_PATH"));
                }
                catch (ExecutionException e)
                {
                    if (microsoftVendors == null)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
            int monoVendorsLength      = (monoVendors == null) ? 0 : monoVendors.Length;
            int dotGnuVendorLength     = (dotGnuVendor == null) ? 0 : 1;
            int microsoftVendorsLength = (microsoftVendors == null) ? 0 : microsoftVendors.Length;

            npandaySettingsVendorsVendor[] vendors =
                new npandaySettingsVendorsVendor[microsoftVendorsLength + monoVendorsLength + dotGnuVendorLength];

            int copyLocation = 0;

            if (microsoftVendors != null)
            {
                microsoftVendors.CopyTo(vendors, copyLocation);
                copyLocation += microsoftVendors.Length;
            }
            if (monoVendors != null)
            {
                monoVendors.CopyTo(vendors, copyLocation);
                copyLocation += monoVendors.Length;
            }
            if (dotGnuVendor != null)
            {
                vendors[copyLocation] = dotGnuVendor;
            }

            settings.vendors = vendors;
            TextWriter writer = new StreamWriter(@outputFile);

            serializer.Serialize(writer, settings);
            writer.Close();
        }
        public override void Execute()
        {
            string outputFile;
            if (String.IsNullOrEmpty(npandaySettingsPath))
            {
                npandaySettingsPath = PathUtil.GetHomeM2Folder();
            }
            outputFile = PathUtil.BuildSettingsFilePath(npandaySettingsPath);

            XmlSerializer serializer = new XmlSerializer(typeof(npandaySettings));

            npandaySettings settings = new npandaySettings();
            settings.operatingSystem = Environment.OSVersion.ToString();

            RegistryKey monoRegistryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Novell\Mono");
            RegistryKey microsoftRegistryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework");

            string defaultMonoCLR = (monoRegistryKey != null) ? (string)monoRegistryKey.GetValue("DefaultCLR") : null;

            settings.defaultSetup = GetDefaultSetup(defaultMonoCLR,
                (string)microsoftRegistryKey.GetValue("InstallRoot"));

            npandaySettingsVendorsVendor[] microsoftVendors = null;
            try
            {
                microsoftVendors = GetVendorsForMicrosoft(microsoftRegistryKey);
            }
            catch (ExecutionException e)
            {
                Console.WriteLine(e.ToString());
            }

            npandaySettingsVendorsVendor[] monoVendors = null;
            npandaySettingsVendorsVendor dotGnuVendor = null;

            if (File.Exists(outputFile))
            {
                try
                {
                    monoVendors = GetVendorsForMono(monoRegistryKey, defaultMonoCLR);
                }
                catch (ExecutionException e)
                {
                    if (microsoftVendors == null)
                        Console.WriteLine(e.ToString());
                }

                try
                {
                    dotGnuVendor = GetVendorForGnu(Environment.GetEnvironmentVariable("CSCC_LIB_PATH"));
                }
                catch (ExecutionException e)
                {
                    if (microsoftVendors == null)
                        Console.WriteLine(e.ToString());
                }
            }
            int monoVendorsLength = (monoVendors == null) ? 0 : monoVendors.Length;
            int dotGnuVendorLength = (dotGnuVendor == null) ? 0 : 1;
            int microsoftVendorsLength = (microsoftVendors == null) ? 0 : microsoftVendors.Length;

            npandaySettingsVendorsVendor[] vendors =
                new npandaySettingsVendorsVendor[microsoftVendorsLength + monoVendorsLength + dotGnuVendorLength];

            int copyLocation = 0;
            if (microsoftVendors != null)
            {
                microsoftVendors.CopyTo(vendors, copyLocation);
                copyLocation += microsoftVendors.Length;
            }
            if (monoVendors != null)
            {
                monoVendors.CopyTo(vendors, copyLocation);
                copyLocation += monoVendors.Length;
            }
            if (dotGnuVendor != null)
                vendors[copyLocation] = dotGnuVendor;

            settings.vendors = vendors;
            TextWriter writer = new StreamWriter(@outputFile);
            serializer.Serialize(writer, settings);
            writer.Close();
        }