Пример #1
0
        /// <summary>
        /// Compile all resources.
        /// </summary>
        private static bool CompileResources(CommandLineOptions options)
        {
            // Locate base.apk
            var baseApkPath = SearchBaseApk(options);

            // Create the compiler
            var compiler = new ResourceCompiler(options.OutputFolder, options.GeneratedCodeFolder, options.TempFolder, options.PackageName, options.RootNamespace, options.GeneratedCodeNamespace, options.GeneratedCodeLanguage, options.ResourceTypeUsageInformationPath);

            // Compile the resources
            return(compiler.Compile(options.Resources, options.AppWidgetProviders, options.References, options.ReferenceFolders, baseApkPath));
        }
Пример #2
0
        public override bool Execute()
        {
            foreach (ITaskItem item in source)
            {
                string outPath = String.IsNullOrEmpty(outputPath) ?
                                 Path.GetDirectoryName(item.ItemSpec) :
                                 outputPath;

                Log.LogMessage("EOS Resource Compiler");
                Log.LogMessage(String.Format("        Input file : '{0}'", item.ItemSpec));
                Log.LogMessage(String.Format("        Output path: '{0}'", outputPath));
                Log.LogMessage(String.Format("        Parameters : '{0}'", parameters));

                CompilerParameters compilerParameters = new CompilerParameters();
                foreach (string parameter in parameters.Split(';'))
                {
                    compilerParameters.Add(parameter);
                }

                try {
                    ResourcePool resources;
                    using (Stream stream = new FileStream(
                               item.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.None)) {
                        IResourceReader reader = new ResourceReader(stream);
                        resources = reader.Read();
                    }

                    IResourceCompiler compiler = new ResourceCompiler();
                    compiler.Compile(resources, outPath, compilerParameters);
                }
                catch (Exception ex) {
                    Exception e = ex;
                    while (e != null)
                    {
                        Log.LogMessage(e.Message);
                        e = e.InnerException;
                    }

                    throw;
                }
            }

            return(true);
        }
        private static void DoCompile(CompileParameters p)
        {
            using (var provider = new CSharpCodeProvider())
            {
                var compileUnits = new List <CodeCompileUnit>();

                if (p.ResourceDatabase != null)
                {
                    var compiler = new ResourceCompiler();

                    compiler.ClassName = TypeSafeUtil.GetFinalClassName(Strings.ResourcesTypeName);
                    compiler.Namespace = Settings.Instance.Namespace;

                    try
                    {
                        var u = compiler.Compile(p.ResourceDatabase);
                        compileUnits.Add(u);
                    }
                    catch (Exception e)
                    {
                        TSLog.LogError(LogCategory.Compile, "Exception occured while compiling resources unit.");
                        TSLog.LogError(LogCategory.Compile, e.ToString());
                    }
                }

                if (p.DataUnits != null)
                {
                    var compiler = new DataUnitCompiler();
                    compiler.Namespace = Settings.Instance.Namespace;

                    foreach (var dataUnit in p.DataUnits)
                    {
                        try
                        {
                            compileUnits.Add(compiler.Compile(dataUnit));
                        }
                        catch (Exception e)
                        {
                            TSLog.LogError(LogCategory.Compile, string.Format("Exception occured while compiling data unit {0}", dataUnit.ClassName));
                            TSLog.LogError(LogCategory.Compile, e.ToString());
                        }
                    }
                }

                var results = new List <string>();

                var didSucceed = false;

                switch (p.CompileMode)
                {
                case CompileModes.Dll:

                    string path;
                    didSucceed = CompileToDll(provider, compileUnits, p, out path);
                    results.Add(path);
                    break;

                case CompileModes.SourceFiles:

                    IList <string> r;
                    didSucceed = CompileToSourceFiles(provider, compileUnits, p, out r);
                    results.AddRange(r);
                    break;
                }

                if (p.OnComplete != null)
                {
                    p.OnComplete(didSucceed, results);
                }
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            try {
                CmdLineParser cmdLineParser = new CmdLineParser("EosResourceCompiler v1.0");
                cmdLineParser.Add(new ArgumentDefinition("source", 1, "Archivo de entrada.", true));
                cmdLineParser.Add(new OptionDefinition("O", "Carpeta de salida."));
                cmdLineParser.Add(new OptionDefinition("V", "Muestra informacion detallada."));
                cmdLineParser.Add(new OptionDefinition("P", "Parametro personalizado.", false, true));

                if (args.Length == 0)
                {
                    Console.WriteLine(cmdLineParser.HelpText);
                    Console.ReadKey(true);
                }

                else
                {
                    CompilerParameters parameters = new CompilerParameters();

                    string outputFolder   = null;
                    string sourceFileName = null;

                    cmdLineParser.Parse(args);
                    foreach (OptionInfo optionInfo in cmdLineParser.Options)
                    {
                        switch (optionInfo.Name)
                        {
                        case "O":
                            outputFolder = optionInfo.Value;
                            break;

                        case "V":
                            parameters.Add("verbose");
                            break;

                        case "P":
                            parameters.Add(optionInfo.Value);
                            break;
                        }
                    }
                    foreach (ArgumentInfo argumentInfo in cmdLineParser.Arguments)
                    {
                        switch (argumentInfo.Name)
                        {
                        case "source":
                            sourceFileName = argumentInfo.Value;
                            break;
                        }
                    }

                    if (String.IsNullOrEmpty(sourceFileName))
                    {
                        throw new InvalidOperationException("No se especifico el fichero fuente.");
                    }

                    if (outputFolder == null)
                    {
                        outputFolder = Path.GetDirectoryName(sourceFileName);
                    }

                    ResourcePool resources;
                    using (Stream stream = new FileStream(
                               sourceFileName, FileMode.Open, FileAccess.Read, FileShare.None)) {
                        IResourceReader reader = new ResourceReader(stream);
                        resources = reader.Read();
                    }

                    IResourceCompiler compiler = new ResourceCompiler();
                    compiler.Compile(resources, outputFolder, parameters);
                }
            }

            catch (Exception e) {
                while (e != null)
                {
                    Console.WriteLine(e.Message);
                    e = e.InnerException;
                }
                Console.ReadKey(true);
            }
        }