/// <summary>
        /// Determine the type of output to produce based a filename extension.
        /// </summary>
        /// <param name="filename">A string containing the filename command line parameter.</param>
        /// <returns>Code for .dll or .exe extensions, Wsdl for .wsdl extensions or None if unsupported.</returns>
        private static TargetOutputType GetTargetType(string filename)
        {
            TargetOutputType target = TargetOutputType.None;

            if (filename != null)
            {
                if (filename.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
                {
                    target = TargetOutputType.Wsdl;
                }
                else
                {
                    // Determine the target type based on the file name extension
                    string ext = Path.GetExtension(filename);

                    switch (ext)
                    {
                    case ".wsdl":
                        target = TargetOutputType.Wsdl;
                        break;

                    case ".exe":
                    case ".dll":
                        target = TargetOutputType.Code;
                        break;
                    }
                }
            }
            return(target);
        }
Exemple #2
0
        /// <summary>
        /// Determine the type of output to produce based a filename extension.
        /// </summary>
        /// <param name="filename">A string containing the filename command line parameter.</param>
        /// <returns>Code for .dll or .exe extensions, Wsdl for .wsdl extensions or None if unsupported.</returns>
        private static TargetOutputType GetTargetType(string filename)
        {
            TargetOutputType target = TargetOutputType.None;

            if (filename != null)
            {
                // Determine the target type based on the file name extension
                if (filename.ToLower().LastIndexOf(".wsdl") == filename.Length - 5)
                {
                    target = TargetOutputType.Wsdl;
                }
                else if (filename.ToLower().LastIndexOf(".exe") == filename.Length - 4 || filename.ToLower().LastIndexOf(".dll") == filename.Length - 4)
                {
                    target = TargetOutputType.Code;
                }
            }
            return(target);
        }
Exemple #3
0
        /// <summary>
        /// Setups the target building environment (native C++). Allows to modify compiler and linker options. Options applied here are used by all modules included into this target (can be overriden per module).
        /// </summary>
        /// <param name="options">The build options.</param>
        public virtual void SetupTargetEnvironment(BuildOptions options)
        {
            options.CompileEnv.PreprocessorDefinitions.AddRange(GlobalDefinitions);
            options.LinkEnv.Output = OutputType == TargetOutputType.Executable ? LinkerOutput.Executable : LinkerOutput.SharedLibrary;

            if (!options.Platform.HasModularBuildSupport)
            {
                // Building target into single executable (forced by platform)
                UseSymbolsExports = false;
                LinkType          = TargetLinkType.Monolithic;
                OutputType        = TargetOutputType.Executable;
                Modules.Add("Main");
            }

            options.CompileEnv.EnableExceptions = true; // TODO: try to disable this!
            switch (options.Configuration)
            {
            case TargetConfiguration.Debug:
                options.CompileEnv.PreprocessorDefinitions.Add("BUILD_DEBUG");
                options.CompileEnv.FunctionLevelLinking = false;
                options.CompileEnv.Optimization         = false;
                options.CompileEnv.FavorSizeOrSpeed     = FavorSizeOrSpeed.Neither;
                options.CompileEnv.DebugInformation     = true;
                options.CompileEnv.RuntimeChecks        = true;
                options.CompileEnv.StringPooling        = false;
                options.CompileEnv.IntrinsicFunctions   = false;
                options.CompileEnv.BufferSecurityCheck  = true;
                options.CompileEnv.Inlining             = false;

                options.LinkEnv.DebugInformation       = true;
                options.LinkEnv.LinkTimeCodeGeneration = false;
                options.LinkEnv.UseIncrementalLinking  = true;
                options.LinkEnv.Optimization           = false;
                break;

            case TargetConfiguration.Development:
                options.CompileEnv.PreprocessorDefinitions.Add("BUILD_DEVELOPMENT");
                options.CompileEnv.FunctionLevelLinking = true;
                options.CompileEnv.Optimization         = true;
                options.CompileEnv.FavorSizeOrSpeed     = FavorSizeOrSpeed.FastCode;
                options.CompileEnv.DebugInformation     = true;
                options.CompileEnv.RuntimeChecks        = false;
                options.CompileEnv.StringPooling        = true;
                options.CompileEnv.IntrinsicFunctions   = true;
                options.CompileEnv.BufferSecurityCheck  = true;
                options.CompileEnv.Inlining             = true;
                //options.CompileEnv.WholeProgramOptimization = true;

                options.LinkEnv.DebugInformation       = true;
                options.LinkEnv.LinkTimeCodeGeneration = true;
                options.LinkEnv.UseIncrementalLinking  = false;
                options.LinkEnv.Optimization           = true;
                break;

            case TargetConfiguration.Release:
                options.CompileEnv.PreprocessorDefinitions.Add("BUILD_RELEASE");
                options.CompileEnv.FunctionLevelLinking = true;
                options.CompileEnv.Optimization         = true;
                options.CompileEnv.FavorSizeOrSpeed     = FavorSizeOrSpeed.FastCode;
                options.CompileEnv.DebugInformation     = false;
                options.CompileEnv.RuntimeChecks        = false;
                options.CompileEnv.StringPooling        = true;
                options.CompileEnv.IntrinsicFunctions   = true;
                options.CompileEnv.BufferSecurityCheck  = false;
                options.CompileEnv.Inlining             = true;
                //options.CompileEnv.WholeProgramOptimization = true;

                options.LinkEnv.DebugInformation       = false;
                options.LinkEnv.LinkTimeCodeGeneration = true;
                options.LinkEnv.UseIncrementalLinking  = false;
                options.LinkEnv.Optimization           = true;
                break;

            default: throw new ArgumentOutOfRangeException();
            }

            if (options.CompileEnv.UseDebugCRT)
            {
                options.CompileEnv.PreprocessorDefinitions.Add("_DEBUG");
            }
            else
            {
                options.CompileEnv.PreprocessorDefinitions.Add("NDEBUG");
            }
        }
        /// <summary>
        /// Application used to generate Microframework data contract, data contract serializers,
        /// hosted service and client proxy source files from a Wsdl file.
        /// </summary>
        /// <param name="args">An array of command line arguments.</param>
        static void Main(string[] args)
        {
            MFSvcImporter      svcImporter          = new MFSvcImporter();
            MFMetadataExporter metadataExporter     = new MFMetadataExporter();
            bool             rpcBindingStyleSupport = false;
            bool             wsiCompliant           = true;
            TargetOutputType target  = TargetOutputType.Wsdl;
            string           refPath = null;

            if (args.Length < 1 || args.Length > 7)
            {
                DisplayUsage();
                return;
            }
            else
            {
                TargetPlatform m_targetPlatform = TargetPlatform.MicroFramework;
                Logger.Verbose = false;

                // Seperate filename parameter from the options and build a list of externally referenced schema files
                List <string> options    = new List <string>();
                string        filename   = null;
                List <string> schemaRefs = null;
                foreach (string cmdArg in args)
                {
                    if (cmdArg[0] == '/')
                    {
                        options.Add(cmdArg);
                    }
                    else if (filename == null && (target = GetTargetType(cmdArg)) != TargetOutputType.None)
                    {
                        filename = cmdArg;
                    }
                    else if (filename == null && (target = GetTargetType(cmdArg)) != TargetOutputType.None)
                    {
                        filename = cmdArg;
                    }
                    else
                    {
                        if (cmdArg.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (schemaRefs == null)
                            {
                                schemaRefs = new List <string>();
                            }
                            schemaRefs.Add(cmdArg);
                        }
                        else
                        {
                            string pathName = Path.GetDirectoryName(cmdArg);
                            if (pathName == "")
                            {
                                pathName = Directory.GetCurrentDirectory();
                            }


                            pathName = Path.GetFullPath(pathName);
                            string   refFileName = Path.GetFileName(cmdArg);
                            string[] fileList    = Directory.GetFiles(pathName, refFileName);
                            if (fileList.Length == 0)
                            {
                                break;
                            }
                            foreach (string refFilename in fileList)
                            {
                                if (refFilename.EndsWith(".xsd", StringComparison.CurrentCultureIgnoreCase))
                                {
                                    if (schemaRefs == null)
                                    {
                                        schemaRefs = new List <string>();
                                    }
                                    if (!schemaRefs.Contains(refFilename))
                                    {
                                        schemaRefs.Add(refFilename);
                                    }
                                }
                            }
                        }
                    }
                }

                // Check for minimum required parameters
                if ((target = GetTargetType(filename)) == TargetOutputType.None)
                {
                    DisplayUsage();
                    return;
                }
                else
                {
                    // Trim filename extension
                    string assemblyFilename = target == TargetOutputType.Code ? filename : null;
                    string wsdlFilename     = target == TargetOutputType.Wsdl ? filename : null;

                    filename = Path.GetFileNameWithoutExtension(filename);
                    string DestinationDirectory = "";
                    string outOverride          = null;

                    // Check for random arguments
                    foreach (string option in options)
                    {
                        string[] arg = option.Split(':');
                        if (arg.Length > 2)
                        {
                            for (int i = 2; i < arg.Length; ++i)
                            {
                                arg[1] = arg[1] + ":" + arg[i];
                            }
                        }
                        switch (arg[0].ToLower())
                        {
                        case "/platform":
                        case "/p":
                            if (arg[1] == "win32")
                            {
                                m_targetPlatform = TargetPlatform.Win32;
                            }
                            break;

                        case "/verbose":
                        case "/v":
                            Logger.Verbose = true;
                            break;

                        case "/out":
                        case "/o":
                            outOverride = arg[1];
                            break;

                        case "/directory":
                        case "/d":
                            DestinationDirectory = arg[1];
                            break;

                        case "/reference":
                        case "/r":
                            refPath = arg[1];
                            break;

                        case "/rpcbindingstyle":
                            rpcBindingStyleSupport = true;
                            break;

                        case "/wsicompliant":
                            if (arg[1] == "false")
                            {
                                wsiCompliant = false;
                            }
                            break;

                        default:
                            DisplayUsage();
                            return;
                        }
                    }

                    if (DestinationDirectory != "" && DestinationDirectory[DestinationDirectory.Length - 1] != '\\')
                    {
                        DestinationDirectory += "\\";
                    }
                    filename = outOverride == null ? filename : outOverride;
                    string ContractFilename = filename + ".cs";
                    ContractFilename = DestinationDirectory + ((ContractFilename.LastIndexOf(".cs") == ContractFilename.Length - 3) ? ContractFilename : ContractFilename + ".cs");
                    string HostedServiceFilename = DestinationDirectory + filename + "HostedService.cs";
                    string ClientProxyFilename   = DestinationDirectory + filename + "ClientProxy.cs";
                    try
                    {
                        svcImporter.WsiCompliant           = wsiCompliant;
                        svcImporter.RpcBindingStyleSupport = rpcBindingStyleSupport;
                        Logger.WriteLine("MfSvcUtil.exe (c) Microsoft 2008", LogLevel.Normal);
                        Logger.WriteLine("", LogLevel.Normal);
                        if (target == TargetOutputType.Wsdl)
                        {
                            svcImporter.ParseWsdl(wsdlFilename, schemaRefs);
                            svcImporter.CreateSourceFiles(ContractFilename, HostedServiceFilename, ClientProxyFilename, m_targetPlatform);
                        }
                        else
                        {
                            metadataExporter.ParseCode(assemblyFilename, refPath, outOverride, null, DestinationDirectory, false);
                        }
                        Logger.WriteLine("Processing complete.", LogLevel.Normal);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Program Error: " + e.Message);
                        Console.WriteLine();
                        DisplayUsage();
                        return;
                    }
                }
            }
        }