Ejemplo n.º 1
0
        public FrontendCompiler(PackageArchitecture architecture, List <System.Reflection.Assembly> referenceAssemblies)
        {
            this.namedItems    = new Dictionary <string, PackageItem>();
            this.Substitutions = new Dictionary <string, string>();

            this.Architecture = architecture;

            this.items = new List <PackageItem>();
            this.roots = new List <Swix>();

            this.services = new Dictionary <Type, object>();

            this.fileSystemManager = new FileSystemResourceManager(FrontendCompiler.DefaultFileSystemManagerRootFolderId);
            this.services.Add(this.fileSystemManager.GetType(), this.fileSystemManager);

            this.unresolved = new List <PackageItem>();

            this.AddSystemPackage(); // ensure the system resources are always loaded.
        }
        /// <summary>
        /// Resolves the lookup but may not fail if missing.
        /// </summary>
        /// <param name="context">Frontend compiler containing all the objects that may satisfy the resolution.</param>
        /// <param name="allowUnresolved">Flag specifying whether to allow unresolved items to be returned.</param>
        /// <returns>Item resolved.</returns>
        public PackageItem Resolve(FrontendCompiler context, bool allowUnresolved)
        {
            if (this.ResolvedItem == null)
            {
                string          targetPropertyName = this.targetProperty == null ? String.Empty : this.targetProperty.Name;
                CompilerMessage message            = null;

                PackageItem item = null;
                if (context.TryGetItemById(this.Lookup, out item))
                {
                    if (this.targetType.IsInstanceOfType(item))
                    {
                        if (this.targetProperty != null)
                        {
                            this.SetTarget(context, item);
                        }
                    }
                    else if (!allowUnresolved)
                    {
                        message = CompilerMessage.InvalidIdResolution(
                            targetPropertyName,
                            this.Lookup,
                            this.targetType.Name,
                            item.GetType().Name);
                    }
                }
                else if (this.targetType.IsSubclassOf(typeof(FileSystemResource)) || this.targetType == typeof(IFileReference))
                {
                    Resource resource;
                    FileSystemResourceManager manager = (FileSystemResourceManager)context.GetService(typeof(FileSystemResourceManager));
                    if (manager.TryFindResourceByPath(context, this.Lookup, out resource))
                    {
                        if (this.targetType.IsInstanceOfType(resource))
                        {
                            if (this.targetProperty != null)
                            {
                                item = this.SetTarget(context, resource);
                            }
                            else
                            {
                                item = resource;
                            }
                        }
                        else
                        {
                            message = CompilerMessage.InvalidIdResolution(
                                targetPropertyName,
                                this.Lookup,
                                this.targetType.Name,
                                resource.GetType().Name);
                        }
                    }
                    else if (!allowUnresolved)
                    {
                        message = CompilerMessage.UnknownFileSystemResolution(
                            targetPropertyName,
                            this.Lookup,
                            this.targetType.Name);
                    }
                }
                else if (!allowUnresolved)
                {
                    message = CompilerMessage.UnknownIdResolution(
                        targetPropertyName,
                        this.Lookup,
                        this.targetType.Name);
                }

                if (message != null)
                {
                    context.OnMessage(new CompilerMessageEventArgs(message, this.targetItem));
                }

                this.ResolvedItem = item;
            }

            return(this.ResolvedItem);
        }