Пример #1
0
        internal void Load(Editor editor, string path)
        {
            Verify.DirectoryExists(path, "path");

            Trace.TraceInformation("Loading default editor extensions at folder {0}", Path.GetFullPath(path));

            var extensions = Directory.GetFiles(path, "*.DLL").Concat(Directory.GetFiles(path, "*.EXE"))
                             .SelectMany(file => LoadExportedTypes(file))
                             .Select(type => new { Export = type.GetCustomAttributes(typeof(ExportAttribute), false).SingleOrDefault(), Type = type })
                             .Where(pair => pair.Export != null)
                             .ToLookup(pair => ((ExportAttribute)pair.Export).ContractType, pair => pair.Type);

            AttributeProviders.AddRange(from type in extensions[typeof(IAttributeProvider)] where !AttributeProviders.Any(x => x.GetType() == type) select(IAttributeProvider) Activator.CreateInstance(type));
            Factories.AddRange(from type in extensions[typeof(IFactory)] where !Factories.Any(x => x.Value.GetType() == type) select new Extension <IFactory>(editor, (IFactory)Activator.CreateInstance(type)));
            Visualizers.AddRange(from type in extensions[typeof(IVisualizer)] where !Visualizers.Any(x => x.Value.GetType() == type) select new Extension <IVisualizer>(editor, (IVisualizer)Activator.CreateInstance(type)));
            Tools.AddRange(from type in extensions[typeof(ITool)] where !Tools.Any(x => x.Value.GetType() == type) select new Extension <ITool>(editor, (ITool)Activator.CreateInstance(type)));
            Importers.AddRange(from type in extensions[typeof(IImporter)] where !Importers.Any(x => x.Value.GetType() == type) select new Extension <IImporter>(editor, (IImporter)Activator.CreateInstance(type)));
            Exporters.AddRange(from type in extensions[typeof(IExporter)] where !Exporters.Any(x => x.Value.GetType() == type) select new Extension <IExporter>(editor, (IExporter)Activator.CreateInstance(type)));
            Settings.AddRange(from type in extensions[typeof(ISettings)] where !Settings.Any(x => x.Value.GetType() == type) select new Extension <ISettings>(editor, (ISettings)Activator.CreateInstance(type)));

            TraceExtensions();

            Trace.TraceInformation("Extensions Loaded.");
        }
Пример #2
0
 public bool HasValidFactory()
 {
     return(Factories.Any());
 }
        /// <summary>
        /// Determines whether a file can be loaded in the application.
        /// </summary>
        /// <param name="fileName">The file name.</param>
        /// <returns>
        /// <see langword="true"/> if the file can be loaded; otherwise, <see langword="false"/>.
        /// </returns>
        private bool IsFileSupported(string fileName)
        {
            var uri = new Uri(fileName);

            return(Factories.Any(f => f.GetDocumentType(uri) != null));
        }