Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 public LingvoExtension()
 {
     translateCommand = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
                                        COMMAND_DESC, COMMAND_HELP, EnsoPostfixType.Arbitrary);
     quitCommand = new EnsoCommand(QUIT_NAME, null, QUIT_DESC,
                                   QUIT_DESC, EnsoPostfixType.None);
 }
Exemplo n.º 3
0
        public void OnCommand(EnsoCommand command, string postfix)
        {
            Action action = commandActions[command.Name];

            if (action != null)
            {
                new Thread(new ThreadStart(action)).Start();
            }
        }
Exemplo n.º 4
0
        public void OnCommand(EnsoCommand command, String postfix)
        {
            Action <String, IEnsoService> action = commandActions[command.Name];

            if (action != null)
            {
                new Thread(() => action(postfix, service)).Start();
            }
        }
Exemplo n.º 5
0
        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);
            }
        }
Exemplo n.º 6
0
        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);
                }
            }
        }
Exemplo n.º 7
0
        public void OnCommand(EnsoCommand command, string postfix)
        {
            Guid   guid = Guid.NewGuid();
            String result;

            if (POSTFIX_NUMERIC.Equals(postfix))
            {
                result = guid.ToString("N").ToUpper();
            }
            else
            {
                result = POSTFIX_LOWER.Equals(postfix)
                                ? guid.ToString()
                                : guid.ToString().ToUpper();
            }

            service.InsertUnicodeAtCursor(result, command);
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        public void OnCommand(EnsoCommand command, String postfix)
        {
            Match m = boundsParser.Match(postfix);

            int    from   = 0;
            String s_from = m.Groups[1].Value;

            try
            {
                if (!"".Equals(s_from.Trim()))
                {
                    from = Convert.ToInt32(s_from);
                }
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR));
            }

            int    to   = int.MaxValue;
            String s_to = m.Groups[2].Value;

            try
            {
                if (!"".Equals(s_to.Trim()))
                {
                    to = Convert.ToInt32(s_to);
                }
            }
            catch (Exception)
            {
                service.DisplayMessage(new EnsoMessage(INVALID_BOUNDS_ERROR));
            }

            int result = random.Next(from, to);

            service.InsertUnicodeAtCursor(result.ToString(), command);
        }
Exemplo n.º 10
0
 public GUIDExtension()
 {
     command = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
                               COMMAND_DESC, COMMAND_DESC, EnsoPostfixType.Bounded);
 }
Exemplo n.º 11
0
 public RandomExtension()
 {
     command = new EnsoCommand(COMMAND_NAME, COMMAND_POSTFIX,
                               COMMAND_DESC, COMMAND_DESC, EnsoPostfixType.Arbitrary);
 }
Exemplo n.º 12
0
        public void OnCommand(EnsoCommand command, string postfix)
        {
            CommandDesc desc = commandActions[command.Name];

            new Thread(() => desc.action(postfix, service)).Start();
        }