private void Dispose(bool disposing) { if (!disposed) { EnsoExtensionProxy[] extensionProxies = new EnsoExtensionProxy[extensions.Values.Count]; extensions.Values.CopyTo(extensionProxies, 0); foreach (EnsoExtensionProxy extensionProxy in extensionProxies) { try { extensionProxy.Extension.Unload(); } catch (Exception e) { Debug.Fail(e.Message); } } extensions = null; commands = null; } disposed = true; }
void IEnsoService.RegisterCommand(IEnsoExtension extension, string uri, EnsoCommand command) { if (disposed) { throw new ObjectDisposedException(GetType().Name); } if (extension == null) { throw new ArgumentNullException("extension"); } if (command == null) { throw new ArgumentNullException("command"); } IDictionary <string, EnsoExtensionProxy> extensions = this.extensions; IDictionary <EnsoCommand, EnsoExtensionProxy> commands = this.commands; if (extensions == null || commands == null) { throw new ObjectDisposedException(GetType().Name); } lock (this) { EnsoExtensionProxy extensionProxy; if (!extensions.TryGetValue(uri, out extensionProxy)) { extensionProxy = new EnsoExtensionProxy(extension, uri); RemotingServices.Marshal(extensionProxy, uri, typeof(EnsoExtensionProxy)); extensions.Add(uri, extensionProxy); } else if (extensionProxy.Extension != extension) { throw new EnsoException("Invalid uri."); } try { ensoProxy.RegisterCommand(GetUrlForUri(uri), command.ToString(), command.Description, command.Help, postfixTypes[(int)command.PostfixType]); } catch (Exception e) { throw new EnsoException("RegisterCommand failed", e); } commands.Add(command, extensionProxy); extensionProxy.Commands.Add(command.ToString(), command); } }
void IEnsoService.RegisterCommand(IEnsoExtension extension, string uri, EnsoCommand command) { if (disposed) throw new ObjectDisposedException(GetType().Name); if (extension == null) throw new ArgumentNullException("extension"); if (command == null) throw new ArgumentNullException("command"); IDictionary<string, EnsoExtensionProxy> extensions = this.extensions; IDictionary<EnsoCommand, EnsoExtensionProxy> commands = this.commands; if (extensions == null || commands == null) throw new ObjectDisposedException(GetType().Name); lock (this) { EnsoExtensionProxy extensionProxy; if (!extensions.TryGetValue(uri, out extensionProxy)) { extensionProxy = new EnsoExtensionProxy(extension, uri); RemotingServices.Marshal(extensionProxy, uri, typeof(EnsoExtensionProxy)); extensions.Add(uri, extensionProxy); } else if (extensionProxy.Extension != extension) throw new EnsoException("Invalid uri."); try { ensoProxy.RegisterCommand(GetUrlForUri(uri), command.ToString(), command.Description, command.Help, postfixTypes[(int)command.PostfixType]); } catch (Exception e) { throw new EnsoException("RegisterCommand failed", e); } commands.Add(command, extensionProxy); extensionProxy.Commands.Add(command.ToString(), command); } }