Inheritance: JSIL.AssemblyTranslator
コード例 #1
0
        private void GenerateContainer(SilverlightAssemblyTranslator translator)
        {
            var container = File.ReadAllText("container.html");

            var applicationEntrypoint = translator.GetEntrypointNameFromAssembly(configuration.Filename);
            var dependencies = GetJavascriptFilenames()
                .Select(x => string.Format("'{0}'", x))
                .ToArray();
            var templates = GetTemplateFilenames()
                .Select(x => string.Format("'{0}'", x))
                .ToArray();

            var configurationDirectiveBuilder = new StringBuilder();
            configurationDirectiveBuilder.AppendLine("sljsconfig = {");
            configurationDirectiveBuilder.AppendFormat("entryPoint: '{0}',", applicationEntrypoint).AppendLine();
            configurationDirectiveBuilder.AppendFormat("code: [{0}]", string.Join("\r\n,", dependencies)).AppendLine(",");
            configurationDirectiveBuilder.AppendFormat("templates: [{0}]", string.Join("\r\n,", templates)).AppendLine();
            configurationDirectiveBuilder.AppendLine("};");

            container = container.Replace("{configuration}", configurationDirectiveBuilder.ToString());
            File.WriteAllText(Path.Combine(configuration.OutputDirectory, "index.html"), container);
        }
コード例 #2
0
 public void ProcessWith(SilverlightAssemblyTranslator translator)
 {
     ProcessAssembly(translator);
     ProcessResources(translator);
     GenerateContainer(translator);
 }
コード例 #3
0
        private void ProcessResources(SilverlightAssemblyTranslator translator)
        {
            var resourceFolderName = Path.GetFileNameWithoutExtension(configuration.Filename);
            var resourceFolder = Path.Combine(configuration.OutputDirectory, resourceFolderName);
            translator.DumpResourcesFromAssemblyToDirectory(configuration.Filename, resourceFolder);

            if (!Directory.Exists(resourceFolder)) return;

            foreach (var file in Directory.GetFiles(resourceFolder, "*.resources"))
            {
                resourceFileTranslator.Translate(file, resourceFolder);
            }

            ClumpJsonFromDirectoryIntoFile(resourceFolder);
        }
コード例 #4
0
 private void ProcessAssembly(SilverlightAssemblyTranslator translator)
 {
     translator.OutputDirectory = configuration.OutputDirectory;
     translator.IncludeDependencies = configuration.IncludeDependencies;
     translator.AddProxyAssembly(typeof (MessageBox).Assembly, false);
     translator.Translate(configuration.Filename);
     translator.EliminateTemporaries = false;
     translator.SimplifyLoops = false;
     translator.SimplifyOperators = false;
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: nsavga/SLJS
        private static void HookTranslatorEvents(SilverlightAssemblyTranslator translator)
        {
            translator.LoadingAssembly += (fn, progress) =>
            {
                Console.Error.WriteLine("// Loading {0}...", fn);
            };
            translator.Decompiling += (progress) =>
            {
                Console.Error.Write("// Decompiling ");

                var previous = new int[1] { 0 };

                progress.ProgressChanged += (s, p, max) =>
                {
                    var current = p * 20 / max;
                    if (current != previous[0])
                    {
                        previous[0] = current;
                        Console.Error.Write(".");
                    }
                };

                progress.Finished += (s, e) =>
                {
                    Console.Error.WriteLine(" done");
                };
            };
            translator.Optimizing += (progress) =>
            {
                Console.Error.Write("// Optimizing ");

                var previous = new int[1] { 0 };

                progress.ProgressChanged += (s, p, max) =>
                {
                    var current = p * 20 / max;
                    if (current != previous[0])
                    {
                        previous[0] = current;
                        Console.Error.Write(".");
                    }
                };

                progress.Finished += (s, e) =>
                {
                    Console.Error.WriteLine(" done");
                };
            };
            translator.Writing += (progress) =>
            {
                Console.Error.Write("// Writing JS ");

                var previous = new int[1] { 0 };

                progress.ProgressChanged += (s, p, max) =>
                {
                    var current = p * 20 / max;
                    if (current != previous[0])
                    {
                        previous[0] = current;
                        Console.Error.Write(".");
                    }
                };

                progress.Finished += (s, e) =>
                {
                    Console.Error.WriteLine(" done");
                };
            };
            translator.CouldNotLoadSymbols += (fn, ex) =>
            {
                Console.Error.WriteLine("// {0}", ex.Message);
            };
            translator.CouldNotResolveAssembly += (fn, ex) =>
            {
                Console.Error.WriteLine("// Could not load module {0}: {1}", fn, ex.Message);
            };
            translator.CouldNotDecompileMethod += (fn, ex) =>
            {
                Console.Error.WriteLine("// Could not decompile method {0}: {1}", fn, ex.Message);
            };
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: nsavga/SLJS
        static void Main(string[] arguments)
        {
            var assemblyTranslator = new SilverlightAssemblyTranslator();
            HookTranslatorEvents(assemblyTranslator);

            var configuration = new SilverlightApplicationTranslatorConfiguration();
            configuration.ParseArguments(arguments);

            var xamlTranslator = new XamlTranslator();
            var resourceTranslator = new ResourceFileTranslator(xamlTranslator);
            var applicationTranslator = new SilverlightApplicationTranslator(configuration, resourceTranslator);
            applicationTranslator.ProcessWith(assemblyTranslator);
        }