This class works as the main interface between the client and the code generation API.
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            try
            {
                string destinationNamespace = "Namespace";
                string wsdlLocation = string.Empty;
                string outputFolder = ".";
                bool isServer = false;
                bool separateFiles = false;

                foreach (string arg in args)
                {
                    if (arg.Substring(0, 2) == "/n")
                    {
                        destinationNamespace = arg.Substring(3);
                    }
                    else if (arg.Substring(0, 2) == "/i")
                    {
                        wsdlLocation = arg.Substring(3); ;
                    }
                    else if (arg.Substring(0, 2) == "/o")
                    {
                        outputFolder = arg.Substring(3); ;
                    }
                    else if (arg == "/server")
                    {
                        isServer = true;
                    }
                    else if (arg == "/separateFiles")
                    {
                        separateFiles = true;
                    }
                    else
                    {
                        PrintUsage();
                        return;
                    }
                }


                if (wsdlLocation == string.Empty)
                {
                    System.Console.WriteLine("Please specifi a WSDL file.");
                    PrintUsage();
                    return;
                }
                                
                CodeGenerator codeGen = new CodeGenerator();

                CodeGenerationOptions options = new CodeGenerationOptions();

                options.GenerateDataContracts = false;
                options.GenerateProperties = true;
                options.GenerateCollections = false;
                options.GenerateSeparateFiles = separateFiles;
                options.OverwriteExistingFiles = true;
                options.AdjustCasing = false;
                options.EnableDataBinding = false;
                options.GenerateOrderIdentifiers = true;
                options.GenerateTypedLists = false;

                options.ClrNamespace = destinationNamespace;
                options.OutputFileName = destinationNamespace + ".cs";
                options.OutputLocation = outputFolder;
                options.ProjectDirectory = outputFolder;

                // only support C# for now
                options.Language = CodeLanguage.CSharp;
                options.ConfigurationFile = "App.config";
                options.EnableWsdlEndpoint = false;
                options.FormatSoapActions = false;
                options.GenerateAsyncCode = false;
                options.GenerateService = isServer;

                options.GenerateSvcFile = true;
                options.ConcurrencyMode = "Single";
                options.InstanceContextMode = "PerCall";

                string wsdlFullPath = Path.GetFullPath(wsdlLocation);
                System.Console.WriteLine("Wsdl Full Path: " + wsdlFullPath);

                options.MetadataLocation = wsdlFullPath;
                options.MethodImplementation = MethodImplementation.NotImplementedException;
                options.UseSynchronizationContext = true;
                
                codeGen.GenerateCode(options);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Exception: " + e.Message);

                PrintUsage();
            }
        }
        private bool ProcessXsdCodeGenerationRequest()
        {
			try
			{
				VisualStudioProject project = currentProject;
				IEnumerable<VisualStudioSelectedItem> selectedItems = vsInstance.SelectedItems;

				if (selectedItems.Count() == 0)
				{
					MessageBox.Show(
						"Cannot generate code for items outside of a project.",
						"Web Services Contract-First code generation",
						MessageBoxButtons.OK,
						MessageBoxIcon.Exclamation);

					return true;
				}

				foreach (VisualStudioSelectedItem selectedItem in selectedItems)
				{
					string extension = Path.GetExtension(selectedItem.FileName).ToLower();
					if (extension == ".xsd" || extension == ".wsdl") continue;

					MessageBox.Show(
						"Data Contracts can only be generated for .xsd or .wsdl files.",
						"Web Services Contract-First code generation",
						MessageBoxButtons.OK,
						MessageBoxIcon.Exclamation);

					return true;
				}

				string[] dataContractFiles = selectedItems.Select(i => i.FileName).ToArray();
				XsdCodeGenDialog dialogForm = new XsdCodeGenDialog(dataContractFiles);
				if (!project.IsWebProject)
				{
					dialogForm.Namespace = project.AssemblyNamespace;
				}
				dialogForm.TargetFileName = project.GetDefaultDestinationFilename(dataContractFiles[0]);

				if (dialogForm.ShowDialog() == DialogResult.Cancel)
				{
					return false;
				}

				CodeGenerationOptions options = new CodeGenerationOptions();
				options.GenerateDataContracts = true;
				options.DataContractFiles = dataContractFiles;
				options.GenerateProperties = dialogForm.PublicProperties;
				options.GenerateCollections = dialogForm.Collections;
				options.GenerateSeparateFiles = dialogForm.GenerateMultipleFiles;
				options.OverwriteExistingFiles = dialogForm.OverwriteFiles;
				options.AdjustCasing = dialogForm.AdjustCasing;
				options.EnableDataBinding = dialogForm.DataBinding;
				options.GenerateOrderIdentifiers = dialogForm.OrderIdentifiers;
				options.GenerateTypedLists = dialogForm.GenericLists;
				options.ClrNamespace = dialogForm.Namespace;
				options.OutputFileName = dialogForm.TargetFileName;
				options.OutputLocation = GetOutputDirectory();
				options.ProjectDirectory = project.ProjectDirectory;
				options.Language = project.ProjectLanguage;

				CodeGenerator codeGenerator = new CodeGenerator();
				CodeWriterOutput output = codeGenerator.GenerateCode(options);

				AddGeneratedFilesToProject(output);

				// Finally add the project references.
				AddAssemblyReferences();

				MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
			catch (Exception ex)
			{
				AppLog.LogMessage(ex.ToString());
				MessageBox.Show(ex.ToString(), "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
				// TODO: Log the exception.
				//System.Diagnostics.Debugger.Break();
			}

            return true;
        } // End of ProcessXsdCodeGenerationRequestFunction.
        /// <summary>
        /// This overloaded method handles the generation of client or server code
        /// for a supplied WSDL file
        /// </summary>
        /// <param name="wsdlFile"></param>
        /// <returns></returns>
        private bool ProcessStubGenerationRequest(string wsdlFile)
        {
            try
            {
                // Fist display the UI and get the options.
                WebServiceCodeGenDialogNew dialog = new WebServiceCodeGenDialogNew();
                if (!currentProject.IsWebProject)
                {
                    dialog.DestinationNamespace = currentProject.AssemblyNamespace;
                }
                dialog.DestinationFilename = GetDefaultDestinationFilename(wsdlFile);

                if (!selectedItem.IsProject)
                {
                    //dialog.WsdlLocation = selectedItem.FileName;
                    dialog.WsdlLocation = wsdlFile;
                }

                //if we havent passed the wsdl file in, there is still 
                // the option for the user to use the BROWSE button and pick
                // the wsdl. 

                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return false;
                }


                //Get the options set in the dialog and add other things
                // that are specific to VS 
                CodeGenerationOptions options = dialog.Options;

				options.Language = currentProject.ProjectLanguage;
                options.ProjectDirectory = currentProject.ProjectDirectory;
                options.OutputLocation = GetOutputDirectory();
                // TODO: Infer the config file type according to the project type
                // and merge the generated config file with the existing one.
                options.ConfigurationFile = "output.config";

				outputWindowWriter.Clear();

                CodeGenerator codeGenerator = new CodeGenerator();
                CodeWriterOutput output = codeGenerator.GenerateCode(options);

                AddGeneratedFilesToProject(output);

                // Finally add the project references.
                AddAssemblyReferences();

				// add custom assembly references if necessary
				if (options.EnableWsdlEndpoint)
				{
					AddMetadataExtensionsReference();
				}

                MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
			catch (ClientServiceGenerationException ex)
			{
				AppLog.LogMessage(ex.ToString());

				const string separator = "---------------------------------------------------------------------------------";
				foreach (string message in ex.Messages)
				{
					outputWindowWriter.WriteMessage(message + "\r\n" + separator + "\r\n");
				}

				MessageBox.Show("Errors were found while importing the contract. Please check the 'WSCF.blue' pane in the Output window for more information.",
					"CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.ToString());
                MessageBox.Show(ex.ToString(), "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // TODO: Log the exception.
                //System.Diagnostics.Debugger.Break();
                return false;
            }
            return true;

        }
        private bool ProcessCodeGenerationRequestCore(string wsdlFile)
        {
            try
            {
                VisualStudioProject project = this.visualStudio.SelectedProject;
                VisualStudioSelectedItem selectedItem = this.visualStudio.SelectedItem;

                // Fist display the UI and get the options.
                WebServiceCodeGenDialogNew dialog = new WebServiceCodeGenDialogNew();                
				if (!project.IsWebProject)
				{
					dialog.DestinationNamespace = project.AssemblyNamespace;                					
				}
                dialog.DestinationFilename = project.GetDefaultDestinationFilename(wsdlFile);
                
                if (!selectedItem.IsProject)
                {
                    //dialog.WsdlLocation = selectedItem.FileName;
                    dialog.WsdlLocation = wsdlFile;
                }
                if (dialog.ShowDialog() == DialogResult.Cancel)
                {
                    return false;
                }

                wsdlFile = dialog.WsdlPath;
                // Try the Rpc2DocumentLiteral translation first.
                // wsdlFile = TryTranslateRpc2DocumentLiteral(wsdlFile);

                CodeGenerationOptions options = new CodeGenerationOptions();
                options.MetadataLocation = wsdlFile;
                options.ClrNamespace = dialog.DestinationNamespace;
                options.OutputFileName = dialog.DestinationFilename;
                options.OutputLocation = GetOutputDirectory();
            	options.ProjectDirectory = project.ProjectDirectory;
				options.Language = project.ProjectLanguage;
                // TODO: Infer the config file type according to the project type
                // and merge the generated config file with the existing one.
                options.ConfigurationFile = "output.config";
                options.GenerateService = dialog.ServiceCode;
                options.GenerateProperties = dialog.GenerateProperties;
            	options.FormatSoapActions = dialog.FormatSoapActions;
                options.GenerateCollections = dialog.Collections;
                options.GenerateTypedLists = dialog.GenericList;
                options.EnableDataBinding = dialog.EnableDataBinding;
                options.GenerateOrderIdentifiers = dialog.OrderIdentifiers;
                options.GenerateAsyncCode = dialog.AsyncMethods;
                options.GenerateSeparateFiles = dialog.GenerateMultipleFiles;
                options.AdjustCasing = dialog.ChangeCasing;
                options.OverwriteExistingFiles = dialog.Overwrite;
                options.EnableWsdlEndpoint = dialog.EnabledWsdlEndpoint;
            	options.GenerateSvcFile = dialog.GenerateSvcFile;
            	options.ConcurrencyMode = dialog.ConcurrencyMode;
            	options.InstanceContextMode = dialog.InstanceContextMode;
            	options.UseSynchronizationContext = dialog.UseSynchronizationContext;
            	options.MethodImplementation = dialog.MethodImplementation;

				outputWindowWriter.Clear();

                CodeGenerator codeGenerator = new CodeGenerator();
                CodeWriterOutput output = codeGenerator.GenerateCode(options);

                AddGeneratedFilesToProject(output);

                // Finally add the project references.
                AddAssemblyReferences();

                // add custom assembly references if necessary
                if(options.EnableWsdlEndpoint)
                {
                    AddMetadataExtensionsReference();
                }

                MessageBox.Show("Code generation successfully completed.", "WSCF.Blue", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
			catch (ClientServiceGenerationException ex)
			{
				AppLog.LogMessage(ex.ToString());

				const string separator = "---------------------------------------------------------------------------------";
				foreach (string message in ex.Messages)
				{
					outputWindowWriter.WriteMessage(message + "\r\n" + separator + "\r\n");
				}

				MessageBox.Show("Errors were found while importing the contract. Please check the 'WSCF.blue' pane in the Output window for more information.", 
					"CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
            catch (Exception ex)
            {
                AppLog.LogMessage(ex.ToString());
                MessageBox.Show(ex.ToString(), "CodeGeneration", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // TODO: Log the exception.
                //System.Diagnostics.Debugger.Break();
            }
            return true;
        }