public void generateButton_Click(object sender, System.EventArgs e)
        {
            string license;
            UPnPDevice[] devices = this.GetDevices();

            UpdateSettings();

            DirectoryInfo outputDir = null;
            try
            {
                outputDir = new DirectoryInfo(outputPathTextBox.Text);
            }
            catch (Exception) { }
            if (outputDir == null || outputDir.Exists == false)
            {
                MessageBox.Show(this, "Output Path is invalid", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (StackConfiguration.TargetPlatform == ServiceGenerator.PLATFORMS.ANDROID)
            {
                //
                // Validate for Java/Android Projects that the appopriate fields are filled in
                //
                if (projectNameTextBox.Text == "")
                {
                    MessageBox.Show("Project name must be filled out!", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (classNameTextBox.Text.Split(new String[] { "." }, StringSplitOptions.None).Length < 2)
                {
                    MessageBox.Show("Namespace (Package) is too short. Must be at least two identifiers seperated by a period. (sample.application)", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            string buttonText = generateButton.Text;
            generateButton.Text = "Generating Stack...";
            generateButton.Enabled = false;

            CodeGenerator gen = null;

            if (StackConfiguration.SchemaGeneration != ServiceGenerator.XSDSchemaGeneration.NONE)
            {
                foreach(UPnPDevice device in devices)
                {
                    // Build the Control Schemas
                    GenerateControlSchemas(device,outputDir,StackConfiguration.SchemaGeneration==ServiceGenerator.XSDSchemaGeneration.WITHOUT_ANY_TAGS);

                    // Build the Event Schemas
                    GenerateEventSchemas(device,outputDir,StackConfiguration.SchemaGeneration==ServiceGenerator.XSDSchemaGeneration.WITHOUT_ANY_TAGS);
                }
            }

            if (StackConfiguration.GenerateCertToolFiles)
            {
                foreach(UPnPDevice device in devices)
                {
                    ServiceGenerator.Configuration DeviceConf = (ServiceGenerator.Configuration)device.User;
                    if (DeviceConf.ConfigType==ServiceGenerator.ConfigurationType.DEVICE)
                    {
                        BuildCertToolFiles(device,outputDir);
                    }
                }
            }

            switch(StackConfiguration.TargetPlatform)
            {
                case ServiceGenerator.PLATFORMS.ANDROID:
                        #region Java/Android Device Stack

                        gen = new JavaAndroidGenerator(StackConfiguration);
                        genOutputTextBox.Clear();

                        gen.OnLogOutput += new DotNetGenerator.LogOutputHandler(Log);
                        try
                        {
                            gen.Generate(devices,outputDir);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, "Error Generating Code. Exception logged to \"Exceptions.txt\".", "Code Generator");
                            LogErrorToFile(string.Format("{0} - {1}\r\n", DateTime.Now.ToString(), ex.ToString()));
                            OpenSource.UPnP.AutoUpdate.ReportCrash(Application.ProductName, ex.ToString());
                        }
                        gen.OnLogOutput -= new DotNetGenerator.LogOutputHandler(Log);
                        #endregion
                    break;
                case ServiceGenerator.PLATFORMS.DOTNET:
                    #region .NET Stack (Device & Control Point)
                        #region .NET Device Stack
                        gen = new DotNetGenerator(classNameTextBox.Text,StackConfiguration);
                        genOutputTextBox.Clear();

                        gen.OnLogOutput += new DotNetGenerator.LogOutputHandler(Log);
                        try
                        {
                            gen.Generate(devices,outputDir);
                        }
                        catch
                        {
                            MessageBox.Show(this,"Error Generating Code","Code Generator");
                        }
                        gen.OnLogOutput -= new DotNetGenerator.LogOutputHandler(Log);
                        #endregion
                        #region .NET CP Stack
                        gen = new CPDotNetGenerator(classNameTextBox.Text,StackConfiguration);
                        genOutputTextBox.Clear();

                        gen.OnLogOutput += new CPDotNetGenerator.LogOutputHandler(Log);
                        try
                        {
                            gen.Generate(devices,outputDir);
                        }
                        catch
                        {
                            MessageBox.Show(this,"Error Generating Code","Code Generator");
                        }
                        gen.OnLogOutput -= new CPDotNetGenerator.LogOutputHandler(Log);
                        #endregion
                    #endregion
                    break;
                default:
                    // POSIX, Windows, PocketPC Code Generation
                    #region POSIX, Windows, PocketPC (Device & Control Point), Symbian OS

                    #region Generator Setup
                    gen = new EmbeddedCGenerator(StackConfiguration);

                    // Setup License
                    license = licenseTextBox.Text;
                    license = license.Replace("<AUTHOR>","Device Builder");
                    license = license.Replace("<REVISION>","#" + Application.ProductVersion);
                    license = license.Replace("<DATE>",DateTime.Now.ToLongDateString());
                    gen.License = license;

                    gen.OnLogOutput += new EmbeddedCGenerator.LogOutputHandler(Log);
                    #endregion

                    gen.Generate(devices,outputDir);

                    gen.OnLogOutput -= new EmbeddedCGenerator.LogOutputHandler(Log);
                    #endregion
                    break;
            }

            generateButton.Enabled = true;
            generateButton.Text = buttonText;
        }
 public static bool GenerateEx(object[] deviceList, DirectoryInfo outputDirectory, ServiceGenerator.StackConfiguration Config)
 {
     EmbeddedCGenerator g = new EmbeddedCGenerator(Config);
     return (g.Generate((UPnPDevice[])deviceList, outputDirectory));
 }