예제 #1
0
        internal override Task ResolveView(ResolveViewArgs resolveViewArgs)
        {
            if (resolveViewArgs.Success == true)
            {
                return(Task.CompletedTask);
            }

            var path = new[] { resolveViewArgs.Name }
            .SelectMany(pattern => ViewExtensions.Select(ext => $"{pattern}{ext}"))
            .SelectMany(pattern => SearchPaths.Select(searchPath => CombineAndRestrictPath(searchPath, pattern)))
            .Where(_ => File.Exists(_))
            .FirstOrDefault();

            if (path == null)
            {
                return(Task.CompletedTask);
            }

            if (RoutableOptions.TryGetMimeType(Path.GetExtension(path), out var mimeType) == false)
            {
                mimeType = DefaultMimeType;
            }
            resolveViewArgs.MimeType     = mimeType;
            resolveViewArgs.LastModified = File.GetLastWriteTimeUtc(path);
            resolveViewArgs.GetStream    = () => Task.FromResult <Stream>(File.OpenRead(path));
            resolveViewArgs.Success      = true;

            return(Task.CompletedTask);
        }
예제 #2
0
        /// <summary>
        ///     Enumerate local library assemblies and add them to DynamoController's
        ///     dictionaries and search.
        /// </summary>
        internal static void LoadBuiltinTypes()
        {
            string location = GetDynamoDirectory();

            #region determine assemblies to load

            var allLoadedAssembliesByPath = new Dictionary <string, Assembly>();
            var allLoadedAssemblies       = new Dictionary <string, Assembly>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allLoadedAssembliesByPath[assembly.Location] = assembly;
                    allLoadedAssemblies[assembly.FullName]       = assembly;
                }
                catch { }
            }

            IEnumerable <string> allDynamoAssemblyPaths =
                SearchPaths.Select(path => Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly))
                .Aggregate(
                    Directory.GetFiles(location, "*.dll") as IEnumerable <string>,
                    Enumerable.Concat);

            var resolver = new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
            {
                Assembly result;
                allLoadedAssemblies.TryGetValue(args.Name, out result);
                return(result);
            });

            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            foreach (var assemblyPath in allDynamoAssemblyPaths)
            {
                var fn = Path.GetFileName(assemblyPath);

                if (fn == null)
                {
                    continue;
                }

                if (LoadedAssemblyNames.Contains(fn))
                {
                    continue;
                }

                LoadedAssemblyNames.Add(fn);

                if (allLoadedAssembliesByPath.ContainsKey(assemblyPath))
                {
                    LoadNodesFromAssembly(allLoadedAssembliesByPath[assemblyPath]);
                }
                else
                {
                    try
                    {
                        var assembly = Assembly.LoadFrom(assemblyPath);
                        allLoadedAssemblies[assembly.GetName().Name] = assembly;
                        LoadNodesFromAssembly(assembly);
                    }
                    catch (BadImageFormatException)
                    {
                        //swallow these warnings.
                    }
                    catch (Exception e)
                    {
                        dynSettings.Controller.DynamoLogger.Log(e);
                    }
                }
            }

#if USE_DSENGINE
            dynSettings.Controller.SearchViewModel.Add(dynSettings.Controller.EngineController.GetFunctionGroups());
#endif
            AppDomain.CurrentDomain.AssemblyResolve -= resolver;

            #endregion
        }
예제 #3
0
        /// <summary>
        /// Load all types which inherit from NodeModel whose assemblies are located in
        /// the bin/nodes directory. Add the types to the searchviewmodel and
        /// the controller's dictionaries.
        /// </summary>
        internal static void LoadNodeModels()
        {
            string location = Path.Combine(GetDynamoDirectory(), "nodes");

            var allLoadedAssembliesByPath = new Dictionary <string, Assembly>();
            var allLoadedAssemblies       = new Dictionary <string, Assembly>();

            // cache the loaded assembly information
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allLoadedAssembliesByPath[assembly.Location] = assembly;
                    allLoadedAssemblies[assembly.FullName]       = assembly;
                }
                catch { }
            }

            // find all the dlls registered in all search paths
            // and concatenate with all dlls in the current directory
            List <string> allDynamoAssemblyPaths =
                SearchPaths.Select(path => Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly))
                .Aggregate(
                    Directory.GetFiles(location, "*.dll") as IEnumerable <string>,
                    Enumerable.Concat).ToList();

            // add the core assembly to get things like code block nodes and watches.
            allDynamoAssemblyPaths.Add(Path.Combine(GetDynamoDirectory(), "DynamoCore.dll"));

            var resolver = new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
            {
                Assembly result;
                allLoadedAssemblies.TryGetValue(args.Name, out result);
                return(result);
            });

            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            foreach (var assemblyPath in allDynamoAssemblyPaths)
            {
                var fn = Path.GetFileName(assemblyPath);

                if (fn == null)
                {
                    continue;
                }

                // if the assembly has already been loaded, then
                // skip it, otherwise cache it.
                if (LoadedAssemblyNames.Contains(fn))
                {
                    continue;
                }

                LoadedAssemblyNames.Add(fn);

                if (allLoadedAssembliesByPath.ContainsKey(assemblyPath))
                {
                    LoadNodesFromAssembly(allLoadedAssembliesByPath[assemblyPath]);
                }
                else
                {
                    try
                    {
                        var assembly = Assembly.LoadFrom(assemblyPath);
                        allLoadedAssemblies[assembly.GetName().Name] = assembly;
                        LoadNodesFromAssembly(assembly);
                    }
                    catch (BadImageFormatException)
                    {
                        //swallow these warnings.
                    }
                    catch (Exception e)
                    {
                        dynSettings.Controller.DynamoLogger.Log(e);
                    }
                }
            }

            dynSettings.Controller.SearchViewModel.Add(dynSettings.Controller.EngineController.GetFunctionGroups());
            AppDomain.CurrentDomain.AssemblyResolve -= resolver;
        }
예제 #4
0
        /// <summary>
        ///     Enumerate local library assemblies and add them to DynamoController's
        ///     dictionaries and search.
        /// </summary>
        /// <param name="searchViewModel">The searchViewModel to which the nodes will be added</param>
        /// <param name="controller">The DynamoController, whose dictionaries will be modified</param>
        internal static void LoadBuiltinTypes()
        {
            string location = GetDynamoDirectory();

            #region determine assemblies to load

            var allLoadedAssembliesByPath = new Dictionary <string, Assembly>();
            var allLoadedAssemblies       = new Dictionary <string, Assembly>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                try
                {
                    allLoadedAssembliesByPath[assembly.Location] = assembly;
                    allLoadedAssemblies[assembly.FullName]       = assembly;
                }
                catch { }
            }

            IEnumerable <string> allDynamoAssemblyPaths = Directory.GetFiles(location, "*.dll");

            allDynamoAssemblyPaths = SearchPaths.Select(path => Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly)).Aggregate(allDynamoAssemblyPaths, (current, dlls) => current.Concat(dlls));

            var resolver = new ResolveEventHandler(delegate(object sender, ResolveEventArgs args)
            {
                Assembly result;
                allLoadedAssemblies.TryGetValue(args.Name, out result);
                return(result);
            });

            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            foreach (var assemblyPath in allDynamoAssemblyPaths)
            {
                var fn = Path.GetFileName(assemblyPath);

                if (fn == null)
                {
                    continue;
                }

                if (LoadedAssemblyNames.Contains(fn))
                {
                    continue;
                }

                LoadedAssemblyNames.Add(fn);

                if (allLoadedAssembliesByPath.ContainsKey(assemblyPath))
                {
                    LoadNodesFromAssembly(allLoadedAssembliesByPath[assemblyPath]);
                }
                else
                {
                    try
                    {
                        var assembly = Assembly.LoadFrom(assemblyPath);
                        allLoadedAssemblies[assembly.GetName().Name] = assembly;
                        LoadNodesFromAssembly(assembly);
                    }
                    catch
                    {
                    }
                }
            }

            AppDomain.CurrentDomain.AssemblyResolve -= resolver;

            #endregion
        }
        public override bool Execute()
        {
            FilteredReferences = References;

            if (!File.Exists(s_deniedListFullPath))
            {
                if (!s_haveWarnedAboutMissingList)
                {
                    Log.LogWarning(null, "MSB3911", null, BuildEngine.ProjectFileOfTaskNode, BuildEngine.LineNumberOfTaskNode, BuildEngine.ColumnNumberOfTaskNode, 0, 0,
                                   $"INTERNAL WARNING: Could not find the list of denied assemblies at {s_deniedListFullPath}. Please file a bug report at https://bugzilla.xamarin.com .");

                    s_haveWarnedAboutMissingList = true;
                }

                return(!Log.HasLoggedErrors);
            }

            if (s_db.Value.Empty)
            {
                // nothing to filter!
                return(!Log.HasLoggedErrors);
            }

            var deniedReferencesNotFixedItemsList = new List <ITaskItem> ();
            var filteredItems = new List <ITaskItem> ();

            foreach (var referenceItem in References)
            {
                // Try to find the path corresponding to a reference
                // - item Include might itself be a path
                // - or it might have a HintPath with the path
                bool foundInHintPath           = false;
                var  assemblyPathFromReference = referenceItem.GetMetadata("FullPath");

                if (!File.Exists(assemblyPathFromReference))
                {
                    var hintPath = referenceItem.GetMetadata("HintPath");
                    if (!String.IsNullOrEmpty(hintPath))
                    {
                        assemblyPathFromReference = Path.GetFullPath(hintPath);
                        if (!File.Exists(assemblyPathFromReference))
                        {
                            assemblyPathFromReference = null;
                        }
                        else
                        {
                            foundInHintPath = true;
                        }
                    }
                }

                if (assemblyPathFromReference != null && s_db.Value.IsDeniedAssembly(assemblyPathFromReference))
                {
                    referenceItem.SetMetadata("DeniedAssemblyPath", assemblyPathFromReference);

                    // Try to find the "safe" assembly under @SearchPaths, and update the reference

                    var assemblyFilename     = Path.GetFileName(assemblyPathFromReference);
                    var safeAssemblyFilePath = SearchPaths
                                               .Select(d => Path.Combine(d, assemblyFilename))
                                               .Where(f => File.Exists(f))
                                               .FirstOrDefault();

                    if (safeAssemblyFilePath != null)
                    {
                        if (foundInHintPath)
                        {
                            referenceItem.SetMetadata("HintPath", safeAssemblyFilePath);
                        }
                        else
                        {
                            referenceItem.ItemSpec = safeAssemblyFilePath;
                        }

                        referenceItem.SetMetadata("FixedDeniedAssemblyPath", "true");

                        Log.LogMessage(MessageImportance.Low, $"Changed the denied (windows specific) assembly reference path from {assemblyPathFromReference} to the safe assembly path {safeAssemblyFilePath}.");
                    }
                    else
                    {
                        Log.LogWarning(null, "MSB3912", null, BuildEngine.ProjectFileOfTaskNode, BuildEngine.LineNumberOfTaskNode, BuildEngine.ColumnNumberOfTaskNode, 0, 0,
                                       $"INTERNAL WARNING: Could not find the replacement assembly ({assemblyFilename}) for the Windows specific reference {assemblyPathFromReference}." +
                                       " Please file a bug report at https://bugzilla.xamarin.com .");

                        referenceItem.SetMetadata("FixedDeniedAssemblyPath", "false");
                        deniedReferencesNotFixedItemsList.Add(referenceItem);
                    }
                }

                filteredItems.Add(referenceItem);
            }

            DeniedReferencesThatCouldNotBeFixed = deniedReferencesNotFixedItemsList.ToArray();
            FilteredReferences = filteredItems.ToArray();

            return(!Log.HasLoggedErrors);
        }