Ejemplo n.º 1
0
        private void FillContext(IEnumerable <IFileInfo> sources, ApplicationModelProviderContext context)
        {
            var reflector = new TypeReflectionEngine();

            _fw.Environment.LoadMemory(MachineInstance.Current);
            foreach (var virtualPath in sources)
            {
                LoadedModule module;
                ICodeSource  codeSrc;
                string       typeName;
                if (virtualPath.IsDirectory)
                {
                    var info = FindModule(virtualPath.Name, MODULE_FILENAME)
                               ?? FindModule(virtualPath.Name, virtualPath.Name + ".os");

                    if (info == null)
                    {
                        continue;
                    }

                    codeSrc  = new FileInfoCodeSource(info);
                    typeName = virtualPath.Name;
                }
                else
                {
                    codeSrc  = new FileInfoCodeSource(virtualPath);
                    typeName = System.IO.Path.GetFileNameWithoutExtension(virtualPath.Name);
                }

                try
                {
                    _classAttribResolver.BeforeCompilation();
                    module = LoadControllerCode(codeSrc);
                }
                finally
                {
                    _classAttribResolver.AfterCompilation();
                }

                var reflectedType = reflector.Reflect <ScriptedController>(module, typeName);
                var attrList      = MapAnnotationsToAttributes(_classAttribResolver.Attributes);
                var cm            = new ControllerModel(typeof(ScriptedController).GetTypeInfo(), attrList.AsReadOnly());
                cm.ControllerName = reflectedType.Name;
                cm.Properties.Add("module", module);
                cm.Properties.Add("type", reflectedType);

                FillActions(cm, reflectedType);
                FillFilters(cm);

                context.Result.Controllers.Add(cm);
            }
        }
        private LoadedModule CompileControllerModule(ICodeSource codeSrc)
        {
            LoadedModule module;

            try
            {
                _fw.DebugCurrentThread();
                _classAttribResolver.BeforeCompilation();
                module = LoadControllerCode(codeSrc);
            }
            finally
            {
                _fw.StopDebugCurrentThread();
                _classAttribResolver.AfterCompilation();
            }

            return(module);
        }