本文整理汇总了C#中System.ComponentModel.Composition.Hosting.DirectoryCatalog.Refresh方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryCatalog.Refresh方法的具体用法?C# DirectoryCatalog.Refresh怎么用?C# DirectoryCatalog.Refresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ComponentModel.Composition.Hosting.DirectoryCatalog
的用法示例。
在下文中一共展示了DirectoryCatalog.Refresh方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init()
{
try
{
AggregateCatalog catalog = new AggregateCatalog();
var c1 = new DirectoryCatalog("Extensions");
c1.Refresh();
var c2 = new DirectoryCatalog("EventHandlers");
c2.Refresh();
var c3 = new AssemblyCatalog(Assembly.GetExecutingAssembly());
catalog.Catalogs.Add(c1);
catalog.Catalogs.Add(c2);
catalog.Catalogs.Add(c3);
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
WindowsLogWriter.LogMessage("Error occurred while composing Denso Extensions", System.Diagnostics.EventLogEntryType.Error);
WindowsLogWriter.LogException(ex);
}
foreach (var plugin in Extensions)
{
plugin.Init();
}
EventHandlerManager.AnalyzeCommandHandlers(ImportedHandlers);
}
示例2: Run
private void Run(DirectoryCatalog catalog)
{
while (true)
{
_feedbackProvider.ProvideFeedback("Options: {0}", String.Join(", ", _plugins.Select(x => x.Name)));
_feedbackProvider.ProvideFeedback("What now!");
var response = Console.ReadLine().Trim();
Execute(response);
catalog.Refresh();
}
}
示例3: AddDirectoryCatalog
private static void AddDirectoryCatalog(AggregateCatalog catalog, string directoryname)
{
try
{
var c1 = new DirectoryCatalog(directoryname);
c1.Refresh();
catalog.Catalogs.Add(c1);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
LogWriter.LogMessage("Error occurred while composing Denso Extensions", LogEntryType.Error);
LogWriter.LogException(ex);
}
}
示例4: Bootstrapper
public Bootstrapper()
{
var path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var directoryCatalog = new DirectoryCatalog(path);
var assemblyCatalog = new AssemblyCatalog(typeof(Bootstrapper).Assembly);
var aggregateCatalog = new AggregateCatalog(directoryCatalog, assemblyCatalog);
var compositionContainer = new CompositionContainer(aggregateCatalog);
compositionContainer.ComposeParts(this);
var fileSystemWatcher = new FileSystemWatcher(path);
fileSystemWatcher.Filter = "*.dll";
fileSystemWatcher.Changed += (s, e) => directoryCatalog.Refresh();
fileSystemWatcher.EnableRaisingEvents = true;
}
示例5: Refresh
/// <summary>
/// Refreshes the catalog and initializes all simulators with the host (Telemetry class).
/// </summary>
private void Refresh()
{
try
{
var catalog = new DirectoryCatalog(Telemetry.m.binaryDirectory + "simulators/", "SimTelemetry.Game.*.dll");
catalog.Refresh();
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
foreach (ISimulator sim in Sims)
{
sim.Host = Telemetry.m;
sim.Initialize();
}
if (Network != null)
{
throw new Exception("Network already added");
}
Network = new NetworkGame {Host = Telemetry.m};
Network.Initialize();
Sims.Add(Network);
}
catch (Exception ex)
{
Debug.WriteLine("Failed loading assemblies");
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
}
}
示例6: Refresh_DirectoryRemoved_ShouldThrowDirectoryNotFound
public void Refresh_DirectoryRemoved_ShouldThrowDirectoryNotFound()
{
DirectoryCatalog cat;
using (var directory = CreateTemporaryDirectory())
{
cat = new DirectoryCatalog(directory.DirectoryPath);
}
ExceptionAssert.Throws<DirectoryNotFoundException>(RetryMode.DoNotRetry, () =>
cat.Refresh());
}
示例7: Refresh_NoChanges_ShouldNotFireOnChanged
public void Refresh_NoChanges_ShouldNotFireOnChanged()
{
using (var directory = CreateTemporaryDirectory())
{
var cat = new DirectoryCatalog(directory.DirectoryPath);
cat.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) =>
Assert.Fail("Should not recieve any change notifications"));
cat.Refresh();
}
}
示例8: Refresh_AssemblyRemoved_ShouldFireOnChanged
public void Refresh_AssemblyRemoved_ShouldFireOnChanged()
{
using (var directory = CreateTemporaryDirectory())
{
string file = Path.Combine(directory.DirectoryPath, "Test.dll");
File.Copy(Assembly.GetExecutingAssembly().Location, file);
bool changedFired = false;
var cat = new DirectoryCatalog(directory.DirectoryPath);
cat.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) =>
changedFired = true);
// This assembly can be deleted because it was already loaded by the CLR in another context
// in another location so it isn't locked on disk.
File.Delete(file);
cat.Refresh();
Assert.IsTrue(changedFired);
}
}
示例9: Refresh_AssemblyAdded_ShouldFireOnChanged
public void Refresh_AssemblyAdded_ShouldFireOnChanged()
{
using (var directory = new TemporaryDirectory())
{
bool changedFired = false;
bool changingFired = false;
var cat = new DirectoryCatalog(directory.DirectoryPath);
Assert.AreEqual(0, cat.Parts.Count(), "Catalog should initially be empty");
cat.Changing += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) =>
{
Assert.AreEqual(0, cat.Parts.Count(), "Catalog changes should NOT have been completeed yet");
changingFired = true;
});
cat.Changed += new EventHandler<ComposablePartCatalogChangeEventArgs>((o, e) =>
{
Assert.AreNotEqual(0, cat.Parts.Count(), "Catalog changes should have been completeed");
changedFired = true;
});
File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(directory.DirectoryPath, "Test.dll"));
cat.Refresh();
Assert.IsTrue(changingFired);
Assert.IsTrue(changedFired);
}
}
示例10: LoadPlugins
private void LoadPlugins()
{
try
{
if (!Directory.Exists(@".\Plugins")) return;
var catalog = new DirectoryCatalog(@".\Plugins", "CInject.Plugin.*.dll");
catalog.Refresh();
var container = new CompositionContainer(catalog);
Plugins = container.GetExportedValues<IPlugin>();
var pluginArray = Plugins as IPlugin[] ?? Plugins.ToArray();
PluginList = pluginArray.ToList();
Parallel.ForEach(pluginArray, (current) =>
{
try
{
if (current.Menu != null)
PopulatePluginMenu(current);
}
catch
{
}
});
}
catch (AggregateException aggregateException)
{
string message = String.Concat(aggregateException.InnerExceptions.Select(x => x.Message));
MessageBox.Show(Resources.PluginLoadErrorAggregate + message);
}
catch (Exception exception)
{
MessageBox.Show(Resources.PluginLoadErrorAggregate + exception.Message);
}
}
示例11: Load
/// <summary>
/// Refresh the plugin catalog.
/// </summary>
public void Load()
{
// Check if environmental settings are correct:
if (!Directory.Exists(PluginDirectory))
{
throw new PluginHostException("Could not find plug-in directory!");
}
if (Simulators != null || Widgets != null || Extensions != null)
{
throw new PluginHostException("Can only load plug-ins from a clean set of lists.");
}
var simulatorsToDrop = new List<IPluginSimulator>();
var widgetsToDrop = new List<IPluginWidget>();
var extensionsToDrop = new List<IPluginExtension>();
Simulators = new List<IPluginSimulator>();
Widgets = new List<IPluginWidget>();
Extensions = new List<IPluginExtension>();
// Try to refresh DLL's from the plugin directory:
try
{
PluginCatalog = new DirectoryCatalog(PluginDirectory, "SimTelemetry.Plugins.*.dll");
PluginCatalog.Refresh();
PluginContainer = new CompositionContainer(PluginCatalog);
PluginContainer.ComposeParts(this);
}
catch (ReflectionTypeLoadException ex)
{
foreach (var exc in ex.LoaderExceptions)
GlobalEvents.Fire(new DebugWarning("Error whilst importing plugin namespaces; the following type couldn't be loaded correctly.", exc), false);
throw new PluginHostException("Could not initialize plug-ins!", ex);
}
catch (CompositionException ex)
{
foreach (var exc in ex.Errors)
GlobalEvents.Fire(new DebugWarning("Error whilst importing plugin namespaces; the following type couldn't be loaded correctly.", exc.Exception), false);
throw new PluginHostException("Could not initialize plug-ins!", ex);
}
catch (Exception ex)
{
throw new PluginHostException("Could not initialize plug-ins!", ex);
}
if (Simulators == null)
{
throw new PluginHostException("Simulators aren't properly initialized");
}
if (Widgets == null)
{
throw new PluginHostException("Widgets aren't properly initialized");
}
if (Extensions == null)
{
throw new PluginHostException("Extensions aren't properly initialized");
}
// Initialize all plug-ins
foreach (var sim in Simulators)
{
string simName = "??";
try
{
simName = sim.Name;
sim.Initialize();
}
catch (Exception ex)
{
simulatorsToDrop.Add(sim);
GlobalEvents.Fire(new DebugWarning("Unloading simulator plugin '" + simName + "' (assembly " + ex.Source + "), exception was thrown during initialize()", ex), false);
}
}
Simulators = Simulators.Where(x => !simulatorsToDrop.Contains(x)).ToList();
foreach (var widget in Widgets)
{
string widgetName = "??";
try
{
widgetName = widget.Name;
widget.Initialize();
}
catch (Exception ex)
{
widgetsToDrop.Add(widget);
GlobalEvents.Fire(new DebugWarning("Unloading widget plugin '" + widgetName + "' (assembly " + ex.Source+ "), exception was thrown during initialize()", ex), false);
}
}
Widgets = Widgets.Where(x => !widgetsToDrop.Contains(x)).ToList();
foreach (var ext in Extensions)
{
string extName = "??";
try
{
//.........这里部分代码省略.........