public override IEnumerable <ExtensionReferenceProbeEntry> ProbeReferences(ExtensionDescriptor descriptor)
        {
            if (Disabled)
            {
                return(Enumerable.Empty <ExtensionReferenceProbeEntry>());
            }

            Logger.Information("Probing references for module '{0}'", descriptor.Id);

            var assemblyPath = GetAssemblyPath(descriptor);

            if (assemblyPath == null)
            {
                return(Enumerable.Empty <ExtensionReferenceProbeEntry>());
            }

            var result = _virtualPathProvider
                         .ListFiles(_virtualPathProvider.GetDirectoryName(assemblyPath))
                         .Where(s => StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(s), ".dll"))
                         .Where(s => !StringComparer.OrdinalIgnoreCase.Equals(Path.GetFileNameWithoutExtension(s), descriptor.Id))
                         .Select(path => new ExtensionReferenceProbeEntry {
                Descriptor  = descriptor,
                Loader      = this,
                Name        = Path.GetFileNameWithoutExtension(path),
                VirtualPath = path
            })
                         .ToList();

            Logger.Information("Done probing references for module '{0}'", descriptor.Id);
            return(result);
        }
示例#2
0
        public static string GetProjectReferenceVirtualPath(this IVirtualPathProvider virtualPathProvider, string projectPath, string referenceName, string hintPath)
        {
            string basePath    = virtualPathProvider.GetDirectoryName(projectPath);
            string virtualPath = virtualPathProvider.GetReferenceVirtualPath(basePath, referenceName, hintPath);

            if (!string.IsNullOrEmpty(virtualPath))
            {
                return(virtualPathProvider.Combine(basePath, virtualPath));
            }

            return(null);
        }
        private string GetTinyMceLanguageIdentifier()
        {
            var currentCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);

            if (currentCulture.Name.Equals(DefaultLanguage, StringComparison.OrdinalIgnoreCase))
            {
                return(currentCulture.Name);
            }


            return(_cacheManager.Get(string.Format(CacheKeyFormat, currentCulture.Name), ctx => {
                ctx.Monitor(_signals.When("culturesChanged"));

                var customLanguage = currentCulture.Name.Replace('-', '_');

                var directoryName = _virtualPathProvider.GetDirectoryName("~/modules/tinymce/scripts/langs/");

                var languageFiles = _virtualPathProvider
                                    .ListFiles(directoryName)
                                    .Select(file => file.Replace(directoryName + "/", ""))
                                    .ToList();

                if (languageFiles.Any(x => x == string.Format("{0}.js", customLanguage)))
                {
                    return customLanguage;
                }

                if (!DefaultLanguage.Equals(currentCulture.TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase) &&
                    languageFiles.Any(x => x == string.Format("{0}.js", currentCulture.TwoLetterISOLanguageName)))
                {
                    return currentCulture.TwoLetterISOLanguageName;
                }

                return DefaultLanguage;
            }));
        }
示例#4
0
        public void Compile(CompileExtensionContext context)
        {
            Logger.Information("Generate code for file \"{0}\"", context.VirtualPath);
            var moduleName           = Path.GetFileNameWithoutExtension(context.VirtualPath);
            var dependencyDescriptor = _dependenciesFolder.GetDescriptor(moduleName);

            if (dependencyDescriptor == null)
            {
                return;
            }

            try {
                var projectFileDescriptor = _projectFileParser.Parse(context.VirtualPath);

                // Add source files
                var directory = _virtualPathProvider.GetDirectoryName(context.VirtualPath);
                foreach (var filename in projectFileDescriptor.SourceFilenames.Select(f => _virtualPathProvider.Combine(directory, f)))
                {
                    context.AssemblyBuilder.AddCodeCompileUnit(CreateCompileUnit(filename));
                }

                var addedReferences = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                // Add assembly references
                foreach (var reference in dependencyDescriptor.References)
                {
                    var referenceTemp = reference;
                    var loader        = _loaders.SingleOrDefault(l => l.Name == referenceTemp.LoaderName);
                    if (loader == null)
                    {
                        Logger.Warning("Could not find loader '{0}' in active loaders", reference.LoaderName);
                        continue;
                    }

                    var assembly = loader.LoadReference(reference);
                    if (assembly == null)
                    {
                        Logger.Warning("Loader '{0}' could not load reference '{1}'", reference.LoaderName, reference.Name);
                        continue;
                    }

                    addedReferences.Add(reference.Name);
                    context.AssemblyBuilder.AddAssemblyReference(assembly);
                }

                _criticalErrorProvider.Clear();

                // Load references specified in project file (only the ones not yet loaded)
                foreach (var assemblyReference in projectFileDescriptor.References)
                {
                    if (addedReferences.Contains(assemblyReference.SimpleName))
                    {
                        continue;
                    }

                    var assembly = _assemblyLoader.Load(assemblyReference.FullName);
                    if (assembly != null)
                    {
                        context.AssemblyBuilder.AddAssemblyReference(assembly);
                    }
                    else
                    {
                        Logger.Error("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath);
                        _criticalErrorProvider.RegisterErrorMessage(T(
                                                                        "The assembly reference '{0}' could not be loaded for module '{1}'.\r\n\r\n" +
                                                                        "There are generally a few ways to solve this issue:\r\n" +
                                                                        "1. Install any dependent module.\r\n" +
                                                                        "2. Remove the assembly reference from the project file if it's not needed.\r\n" +
                                                                        "3. Ensure the assembly reference is present in the 'bin' directory of the module.\r\n" +
                                                                        "4. Ensure the assembly reference is present in the 'bin' directory of the application.\r\n" +
                                                                        "5. Specify the strong name of the assembly (name, version, culture, publickey) if the assembly is present in the GAC.",
                                                                        assemblyReference.FullName, moduleName));
                        throw new CoeveryCoreException(T("Assembly reference '{0}' for project '{1}' cannot be loaded", assemblyReference.FullName, context.VirtualPath));
                    }
                }
            }
            catch (Exception e) {
                //Note: we need to embed the "e.Message" in the exception text because
                //      ASP.NET build manager "swallows" inner exceptions from this method.
                throw new CoeveryCoreException(T("Error compiling module \"{0}\" from file \"{1}\":\r\n{2}", moduleName, context.VirtualPath, e.Message), e);
            }
        }