public void generateButton_Click(object sender, System.EventArgs e)
        {
            DirectoryInfo outputDir = new DirectoryInfo(outputPathTextBox.Text);

            if (outputDir.Exists == false)
            {
                MessageBox.Show(this, "Output Path is invalid", "Code Generator");
                return;
            }

            string buttonText = generateButton.Text;

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

            if (UPnP1dot1Enabled.Checked == true)
            {
                device.ArchitectureVersion = "1.1";
            }
            else
            {
                device.ArchitectureVersion = "1.0";
            }

            if (platformComboBox.SelectedIndex == 4)
            {
                // .net
                CPDotNetGenerator gen = new CPDotNetGenerator(classNameTextBox.Text);
                genOutputTextBox.Clear();

                gen.VersionString = "Intel StackBuilder Build#" + Application.ProductVersion;
                gen.StartupPath   = Application.StartupPath;
                gen.OnLogOutput  += new CPDotNetGenerator.LogOutputHandler(Log);
                try
                {
                    gen.Generate(device, outputDir, serviceNames);
                }
                catch
                {
                    MessageBox.Show(this, "Error Generating Code", "Code Generator");
                }
                gen.OnLogOutput -= new CPDotNetGenerator.LogOutputHandler(Log);
            }
            else
            {
                CPEmbeddedCGenerator gen    = new CPEmbeddedCGenerator();
                LibraryGenerator     libgen = new LibraryGenerator();

                genOutputTextBox.Clear();

                gen.EnableDefaultIPAddressMonitor = IPAddressMonitor.Checked;

                switch (platformComboBox.SelectedIndex)
                {
                case 0:
                    gen.Platform     = CPEmbeddedCGenerator.PLATFORMS.POSIX;
                    gen.SubTarget    = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                    libgen.Platform  = LibraryGenerator.PLATFORMS.POSIX;
                    libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                    break;

                case 1:
                    gen.Platform     = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                    gen.SubTarget    = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                    gen.WinSock      = 1;
                    libgen.Platform  = LibraryGenerator.PLATFORMS.WINDOWS;
                    libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                    libgen.WinSock   = 1;
                    break;

                case 2:
                    gen.Platform     = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                    gen.SubTarget    = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                    gen.WinSock      = 2;
                    libgen.Platform  = LibraryGenerator.PLATFORMS.WINDOWS;
                    libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                    libgen.WinSock   = 2;
                    break;

                case 3:
                    gen.Platform     = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                    gen.SubTarget    = CPEmbeddedCGenerator.SUBTARGETS.PPC2003;
                    gen.WinSock      = 1;
                    libgen.Platform  = LibraryGenerator.PLATFORMS.WINDOWS;
                    libgen.SubTarget = LibraryGenerator.SUBTARGETS.PPC2003;
                    libgen.WinSock   = 1;
                    break;

                case 4:
                    gen.Platform     = CPEmbeddedCGenerator.PLATFORMS.POSIX;
                    gen.SubTarget    = CPEmbeddedCGenerator.SUBTARGETS.NUCLEUS;
                    gen.WinSock      = 1;
                    libgen.Platform  = LibraryGenerator.PLATFORMS.POSIX;
                    libgen.SubTarget = LibraryGenerator.SUBTARGETS.NUCLEUS;
                    libgen.WinSock   = 1;
                    break;
                }

                switch (languageComboBox.SelectedIndex)
                {
                case 0:
                    gen.Language    = CPEmbeddedCGenerator.LANGUAGES.C;
                    libgen.Language = LibraryGenerator.LANGUAGES.C;
                    break;

                case 1:
                    gen.Language    = CPEmbeddedCGenerator.LANGUAGES.CPP;
                    libgen.Language = LibraryGenerator.LANGUAGES.CPP;
                    break;
                }

                switch (newLineComboBox.SelectedIndex)
                {
                case 0:
                    gen.CodeNewLine = "\r\n"; break;

                case 1:
                    gen.CodeNewLine = "\n"; break;
                }

                switch (callConventionComboBox.SelectedIndex)
                {
                case 0:
                    gen.CallingConvention = ""; break;

                case 1:
                    gen.CallingConvention = "_stdcall "; break;

                case 2:
                    gen.CallingConvention = "_fastcall "; break;
                }

                switch (indentComboBox.SelectedIndex)
                {
                case 0:
                    gen.CodeTab = "\t"; break;

                case 1:
                    gen.CodeTab = " "; break;

                case 2:
                    gen.CodeTab = "  "; break;

                case 3:
                    gen.CodeTab = "   "; break;

                case 4:
                    gen.CodeTab = "    "; break;

                case 5:
                    gen.CodeTab = "     "; break;

                case 6:
                    gen.CodeTab = "      "; break;
                }

                gen.CallPrefix          = prefixTextBox.Text;
                gen.CallLibPrefix       = libPrefixTextBox.Text;
                gen.Settings            = Settings;
                gen.FragResponseActions = FragResponseActions;
                gen.EscapeActions       = EscapeActions;
                gen.VersionString       = "Intel DeviceBuilder Build#" + Application.ProductVersion;
                gen.ClassName           = classNameTextBox.Text;
                gen.UseVersion          = Application.ProductVersion.Substring(0, Application.ProductVersion.LastIndexOf("."));
                gen.BasicHTTP           = !(HTTP.Checked);

                libgen.CodeNewLine       = gen.CodeNewLine;
                libgen.CallingConvention = gen.CallingConvention;
                libgen.CodeTab           = gen.CodeTab;
                libgen.CodeNewLine       = gen.CodeNewLine;
                libgen.CallPrefix        = libPrefixTextBox.Text;
                libgen.VersionString     = gen.VersionString;
                libgen.ClassName         = gen.ClassName;

                foreach (System.Data.DataRow r in dataSet1.Tables[0].Rows)
                {
                    gen.CustomTagList.Add(new object[2] {
                        (string)r.ItemArray[0], (string)r.ItemArray[1]
                    });
                }


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

                gen.OnLogOutput    += new CPEmbeddedCGenerator.LogOutputHandler(Log);
                libgen.OnLogOutput += new LibraryGenerator.LogOutputHandler(Log);

                try
                {
                    SourceCodeRepository.Generate_UPnPControlPointStructs(libPrefixTextBox.Text, outputDir);
                    SourceCodeRepository.Generate_Parsers(this.libPrefixTextBox.Text, outputDir);
                    SourceCodeRepository.Generate_SSDPClient(this.libPrefixTextBox.Text, outputDir, UPnP1dot1Enabled.Checked);

                    SourceCodeRepository.Generate_AsyncSocket(this.libPrefixTextBox.Text, outputDir);
                    SourceCodeRepository.Generate_AsyncServerSocket(this.libPrefixTextBox.Text, outputDir);
                    SourceCodeRepository.Generate_WebClient(this.libPrefixTextBox.Text, outputDir, !HTTP.Checked);
                    SourceCodeRepository.Generate_WebServer(this.libPrefixTextBox.Text, outputDir, !HTTP.Checked);

                    gen.Generate(device, outputDir, serviceNames, !(bool)gen.Settings["SupressSample"]);
                }
                catch (Exception ddd)
                {
                    MessageBox.Show(this, "Error Generating Code", "Code Generator");
                }

                libgen.OnLogOutput -= new LibraryGenerator.LogOutputHandler(Log);
                gen.OnLogOutput    -= new CPEmbeddedCGenerator.LogOutputHandler(Log);
            }

            generateButton.Enabled = true;
            generateButton.Text    = buttonText;
        }
        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 void generateButton_Click(object sender, System.EventArgs e)
        {
            DirectoryInfo outputDir = new DirectoryInfo(outputPathTextBox.Text);
            if (outputDir.Exists == false)
            {
                MessageBox.Show(this,"Output Path is invalid","Code Generator");
                return;
            }

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

            if(UPnP1dot1Enabled.Checked==true)
            {
                device.ArchitectureVersion = "1.1";
            }
            else
            {
                device.ArchitectureVersion = "1.0";
            }

            if(platformComboBox.SelectedIndex==4)
            {
                // .net
                CPDotNetGenerator gen = new CPDotNetGenerator(classNameTextBox.Text);
                genOutputTextBox.Clear();

                gen.VersionString = "Intel StackBuilder Build#" + Application.ProductVersion;
                gen.StartupPath = Application.StartupPath;
                gen.OnLogOutput += new CPDotNetGenerator.LogOutputHandler(Log);
                try
                {
                    gen.Generate(device,outputDir,serviceNames);
                }
                catch
                {
                    MessageBox.Show(this,"Error Generating Code","Code Generator");
                }
                gen.OnLogOutput -= new CPDotNetGenerator.LogOutputHandler(Log);
            }
            else
            {
                CPEmbeddedCGenerator gen = new CPEmbeddedCGenerator();
                LibraryGenerator libgen = new LibraryGenerator();

                genOutputTextBox.Clear();

                gen.EnableDefaultIPAddressMonitor = IPAddressMonitor.Checked;

                switch (platformComboBox.SelectedIndex)
                {
                    case 0:
                        gen.Platform = CPEmbeddedCGenerator.PLATFORMS.POSIX;
                        gen.SubTarget = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                        libgen.Platform = LibraryGenerator.PLATFORMS.POSIX;
                        libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                        break;
                    case 1:
                        gen.Platform = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                        gen.SubTarget = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                        gen.WinSock = 1;
                        libgen.Platform = LibraryGenerator.PLATFORMS.WINDOWS;
                        libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                        libgen.WinSock = 1;
                        break;
                    case 2:
                        gen.Platform = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                        gen.SubTarget = CPEmbeddedCGenerator.SUBTARGETS.NONE;
                        gen.WinSock = 2;
                        libgen.Platform = LibraryGenerator.PLATFORMS.WINDOWS;
                        libgen.SubTarget = LibraryGenerator.SUBTARGETS.NONE;
                        libgen.WinSock = 2;
                        break;
                    case 3:
                        gen.Platform = CPEmbeddedCGenerator.PLATFORMS.WINDOWS;
                        gen.SubTarget = CPEmbeddedCGenerator.SUBTARGETS.PPC2003;
                        gen.WinSock = 1;
                        libgen.Platform = LibraryGenerator.PLATFORMS.WINDOWS;
                        libgen.SubTarget = LibraryGenerator.SUBTARGETS.PPC2003;
                        libgen.WinSock = 1;
                        break;
                    case 4:
                        gen.Platform = CPEmbeddedCGenerator.PLATFORMS.POSIX;
                        gen.SubTarget = CPEmbeddedCGenerator.SUBTARGETS.NUCLEUS;
                        gen.WinSock = 1;
                        libgen.Platform = LibraryGenerator.PLATFORMS.POSIX;
                        libgen.SubTarget = LibraryGenerator.SUBTARGETS.NUCLEUS;
                        libgen.WinSock = 1;
                        break;
                }

                switch (languageComboBox.SelectedIndex)
                {
                    case 0:
                        gen.Language = CPEmbeddedCGenerator.LANGUAGES.C;
                        libgen.Language = LibraryGenerator.LANGUAGES.C;
                        break;
                    case 1:
                        gen.Language = CPEmbeddedCGenerator.LANGUAGES.CPP;
                        libgen.Language = LibraryGenerator.LANGUAGES.CPP;
                        break;
                }

                switch (newLineComboBox.SelectedIndex)
                {
                    case 0:
                        gen.CodeNewLine = "\r\n"; break;
                    case 1:
                        gen.CodeNewLine = "\n"; break;
                }

                switch (callConventionComboBox.SelectedIndex)
                {
                    case 0:
                        gen.CallingConvention = ""; break;
                    case 1:
                        gen.CallingConvention = "_stdcall "; break;
                    case 2:
                        gen.CallingConvention = "_fastcall "; break;
                }

                switch (indentComboBox.SelectedIndex)
                {
                    case 0:
                        gen.CodeTab = "\t"; break;
                    case 1:
                        gen.CodeTab = " "; break;
                    case 2:
                        gen.CodeTab = "  "; break;
                    case 3:
                        gen.CodeTab = "   "; break;
                    case 4:
                        gen.CodeTab = "    "; break;
                    case 5:
                        gen.CodeTab = "     "; break;
                    case 6:
                        gen.CodeTab = "      "; break;
                }

                gen.CallPrefix = prefixTextBox.Text;
                gen.CallLibPrefix = libPrefixTextBox.Text;
                gen.Settings = Settings;
                gen.FragResponseActions = FragResponseActions;
                gen.EscapeActions = EscapeActions;
                gen.VersionString = "Intel DeviceBuilder Build#" + Application.ProductVersion;
                gen.ClassName = classNameTextBox.Text;
                gen.UseVersion = Application.ProductVersion.Substring(0,Application.ProductVersion.LastIndexOf("."));
                gen.BasicHTTP = !(HTTP.Checked);

                libgen.CodeNewLine = gen.CodeNewLine;
                libgen.CallingConvention = gen.CallingConvention;
                libgen.CodeTab = gen.CodeTab;
                libgen.CodeNewLine = gen.CodeNewLine;
                libgen.CallPrefix = libPrefixTextBox.Text;
                libgen.VersionString = gen.VersionString;
                libgen.ClassName = gen.ClassName;

                foreach(System.Data.DataRow r in dataSet1.Tables[0].Rows)
                {
                    gen.CustomTagList.Add(new object[2]{(string)r.ItemArray[0],(string)r.ItemArray[1]});
                }

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

                gen.OnLogOutput += new CPEmbeddedCGenerator.LogOutputHandler(Log);
                libgen.OnLogOutput += new LibraryGenerator.LogOutputHandler(Log);

                try
                {
                    SourceCodeRepository.Generate_UPnPControlPointStructs(libPrefixTextBox.Text,outputDir);
                    SourceCodeRepository.Generate_Parsers(this.libPrefixTextBox.Text,outputDir);
                    SourceCodeRepository.Generate_SSDPClient(this.libPrefixTextBox.Text,outputDir,UPnP1dot1Enabled.Checked);

                    SourceCodeRepository.Generate_AsyncSocket(this.libPrefixTextBox.Text,outputDir);
                    SourceCodeRepository.Generate_AsyncServerSocket(this.libPrefixTextBox.Text,outputDir);
                    SourceCodeRepository.Generate_WebClient(this.libPrefixTextBox.Text,outputDir,!HTTP.Checked);
                    SourceCodeRepository.Generate_WebServer(this.libPrefixTextBox.Text,outputDir,!HTTP.Checked);

                    gen.Generate(device,outputDir,serviceNames,!(bool)gen.Settings["SupressSample"]);
                }
                catch(Exception ddd)
                {
                    MessageBox.Show(this,"Error Generating Code","Code Generator");
                }

                libgen.OnLogOutput -= new LibraryGenerator.LogOutputHandler(Log);
                gen.OnLogOutput -= new CPEmbeddedCGenerator.LogOutputHandler(Log);
            }

            generateButton.Enabled = true;
            generateButton.Text = buttonText;
        }