Example #1
0
        public void Initialize()
        {
            var catalog     = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            var pluginPaths = Directory.EnumerateFiles(directoryPath, "*.dll", SearchOption.AllDirectories);

            pluginPaths.ForEach(pluginPath =>
            {
                try
                {
                    if (ZoneIdentifier.IsBlocked(pluginPath))
                    {
                        if (UIAssistantAPI.Instance.ViewAPI.GetConfirmation("The plugin is blocked",
                                                                            string.Format(TextID.PluginBlocked.GetLocalizedText(), Path.GetFileName(pluginPath), pluginPath)))
                        {
                            ZoneIdentifier.Unblock(pluginPath);
                        }
                    }
                }
                catch
                {
                }

                try
                {
                    var asmCatalog = new AssemblyCatalog(pluginPath);
                    if (asmCatalog.Parts.ToList().Count > 0)
                    {
                        catalog.Catalogs.Add(asmCatalog);
                    }
                }
                catch (FileLoadException ex)
                {
                    var message = string.Format(TextID.PluginInitializeError.GetLocalizedText(), pluginPath);
                    UIAssistantAPI.Instance.NotificationAPI.NotifyWarnMessage("Warning", message);
                    Log.Error(ex);
                    Log.Warn(message);
                }
                catch (ReflectionTypeLoadException ex)
                {
                    var message = string.Format(TextID.PluginInitializeError.GetLocalizedText(), pluginPath);
                    UIAssistantAPI.Instance.NotificationAPI.NotifyWarnMessage("Warning", message);
                    (ex as ReflectionTypeLoadException).LoaderExceptions.ForEach(x =>
                    {
                        Log.Error(x);
                    });
                }
                catch (Exception ex)
                {
                    var message = string.Format(TextID.PluginInitializeError.GetLocalizedText(), pluginPath);
                    UIAssistantAPI.Instance.NotificationAPI.NotifyWarnMessage("Warning", message);
                    Log.Error(ex);
                    Log.Warn(message);
                }
            });

            container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            LoadAllPlugins();

            RemoveRemovedPlugins();
        }
 public override string ToString()
 {
     return(ZoneIdentifier.ToString(System.Globalization.CultureInfo.InvariantCulture) + Easting.ToString(System.Globalization.CultureInfo.InvariantCulture) + "E, " + Northing.ToString(System.Globalization.CultureInfo.InvariantCulture) + "N");
 }