Esempio n. 1
0
 private SwcDepFile LoadSwcDep(string swcName)
 {
     foreach (var res in Assembly.MainModule.Resources)
     {
         string resName = res.Name;
         if (resName.EndsWith(".swcdep", StringComparison.InvariantCultureIgnoreCase))
         {
             string fname = GetResFileName(resName);
             if (string.Equals(fname, swcName, StringComparison.InvariantCultureIgnoreCase))
             {
                 var f = new SwcDepFile();
                 f.Load(res.Data);
                 return(f);
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
        private void ImportEmbeddedStyleMixins(AbcFile app)
        {
            var swcResource = GetType().GetResourceStream("mixins.swc");

            if (swcResource == null)
            {
                throw new InvalidOperationException("Unable to load mixins");
            }

            var depsResource = GetType().GetResourceStream("mixins.dep");
            var deps         = new SwcDepFile(depsResource);

            var swc = new SwcFile(swcResource);

            swc.ResolveDependencies(new SimpleSwcLinker(_compiler.AppAssembly), deps);

            ImportStyleMixins(app, swc, false);
        }
Esempio n. 3
0
        public Linker(IAssembly assembly)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException("assembly");
            }

            var data = assembly.CustomData();

            if (data.Linker != null)
            {
                throw new InvalidOperationException();
            }

            data.Linker = this;

            Assembly = assembly;

            // we should always listen TypeLoaded event to fill AssemblyLinked
            if (Assembly.Loader != null)
            {
                Assembly.Loader.TypeLoaded += OnTypeLoaded;
            }

            var resource = Assembly.MainModule.Resources.FirstOrDefault(
                x => x.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase) ||
                x.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase));

            if (resource != null)
            {
                data.Flags |= InternalAssembyFlags.HasAbcImports;

                if (resource.Name.EndsWith(".abc", StringComparison.OrdinalIgnoreCase))
                {
                    _abc = new AbcFile(resource.Data)
                    {
                        Assembly = Assembly
                    };
                    data.Abc = _abc;
                    _cache   = new AbcCache();
                    _cache.Add(_abc);
                }
                else if (resource.Name.EndsWith(".swc", StringComparison.OrdinalIgnoreCase))
                {
                    string swcName = GetResFileName(resource.Name);

                    _swcDeps = LoadSwcDep(swcName);
                    _swc     = new SwcFile(resource.Data)
                    {
                        Assembly = Assembly,
                        Name     = swcName
                    };
                    _cache = _swc.AbcCache;

                    data.SWC = _swc;
                }
            }

            // create all linkers to subscribe on AssemblyLoader.TypeLoaded event before we start process
            assembly.ProcessReferences(true,
                                       asm =>
            {
                if (asm.CustomData().Linker == null)
                {
                    asm.CustomData().Linker = new Linker(asm);
                }
            });

            if (_swc != null)
            {
                _swc.ResolveDependencies(this, _swcDeps);
            }
        }