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.SetUnicodeSelection(string text, EnsoCommand fromCommand) { if (disposed) { throw new ObjectDisposedException(GetType().Name); } if (text == null) { throw new ArgumentNullException("text"); } if (fromCommand == null) { throw new ArgumentNullException("fromCommand"); } try { ensoProxy.SetUnicodeSelection(text, fromCommand.ToString()); } catch (Exception e) { throw new EnsoException("SetUnicodeSelection failed", e); } }
void IEnsoService.UnregisterCommand(EnsoCommand command) { if (disposed) { throw new ObjectDisposedException(GetType().Name); } if (command == null) { throw new ArgumentNullException("command"); } IDictionary <EnsoCommand, EnsoExtensionProxy> commands = this.commands; if (commands == null) { throw new ObjectDisposedException(GetType().Name); } lock (this) { EnsoExtensionProxy extensionProxy; if (!commands.TryGetValue(command, out extensionProxy)) { throw new EnsoException("Command not registered."); } try { ensoProxy.UnregisterCommand(GetUrlForUri(extensionProxy.Uri), command.ToString()); } catch (Exception e) { throw new EnsoException("UnregisterCommand failed", e); } commands.Remove(command); extensionProxy.Commands.Remove(command.ToString()); if (extensionProxy.Commands.Count == 0) { extensions.Remove(extensionProxy.Uri); } } }
void IEnsoService.SetCommandValidPostfixes(EnsoCommand command, string[] postfixes) { if (disposed) { throw new ObjectDisposedException(GetType().Name); } if (command == null) { throw new ArgumentNullException("command"); } if (postfixes == null) { throw new ArgumentNullException("postfixes"); } IDictionary <EnsoCommand, EnsoExtensionProxy> commands = this.commands; if (commands == null) { throw new ObjectDisposedException(GetType().Name); } EnsoExtensionProxy extensionProxy; if (!commands.TryGetValue(command, out extensionProxy)) { throw new EnsoException("Command not registered."); } try { ensoProxy.SetCommandValidPostfixes(GetUrlForUri(extensionProxy.Uri), command.ToString(), postfixes); } catch (Exception e) { throw new EnsoException("SetCommandValidPostfixes failed", e); } }