コード例 #1
0
        private void DispatchAction(string tile_id,
                                    string action)
        {
            Tile t = GetTile(tile_id);

            if (t == null)
            {
                return;
            }


            MethodInfo info = t.GetType().GetMethod(action,
                                                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
                                                    null,
                                                    CallingConventions.Any,
                                                    new Type[] {},
                                                    null);

            if (info == null)
            {
                Console.WriteLine("Couldn't find method called {0}", action);
                return;
            }
            object[] attrs = info.GetCustomAttributes(false);
            foreach (object attr in attrs)
            {
                if (attr is TileActionAttribute)
                {
                    info.Invoke(t, null);
                    return;
                }
            }
            Console.WriteLine("{0} does not have the TileAction attribute");
        }
コード例 #2
0
ファイル: WebBackEnd.cs プロジェクト: ArsenShnurkov/beagle-1
        public void dispatchAction(string sessId, string actionString)
        {
            string tile_id = null, action = null;
            bool   actionDone = false;

            //if (actionString.StartsWith ("dynaction:"))  {

            bufferRenderContext b = ((Resp)sessionResp[sessId]).bufferContext;

            if (b != null)
            {
                actionDone = b.DoAction(actionString);
            }
            //}

            if (actionDone)
            {
                return;
            }

            if (actionString.StartsWith("action:"))
            {
                int pos1 = "action:".Length;
                int pos2 = actionString.IndexOf("!");

                if (pos2 <= 0)
                {
                    return;
                }

                tile_id = actionString.Substring(pos1, pos2 - pos1);
                action  = actionString.Substring(pos2 + 1);

                log.Debug("WebBackEnd tile_id: {0}, action: {1}", tile_id, action);

                BT.Tile t = ((Resp)sessionResp[sessId]).GetTile(tile_id);

                if (t == null)
                {
                    return;
                }

                MethodInfo info = t.GetType().GetMethod(action,
                                                        BindingFlags.Public | BindingFlags.NonPublic |
                                                        BindingFlags.Instance, null,
                                                        CallingConventions.Any, new Type[] {}, null);

                if (info == null)
                {
                    log.Warn("WebBackEnd:dispatchAction couldn't find method called {0}", action);
                    return;
                }

                object[] attrs = info.GetCustomAttributes(false);
                foreach (object attr in attrs)
                {
                    if (attr is BT.TileActionAttribute)
                    {
                        info.Invoke(t, null);
                        return;
                    }
                }
                log.Warn("WebBackEnd:dispatchAction {0} does not have the TileAction attribute", t);
            }

            string command     = null;
            string commandArgs = null;

            if (actionString.StartsWith("http://") || actionString.StartsWith("file://"))
            {
                command     = "gnome-open";
                commandArgs = "'" + actionString + "'";
            }
            else if (actionString.StartsWith("mailto:"))
            {
                command     = "evolution";
                commandArgs = actionString;
            }

            if (command != null)
            {
                Process p = new Process();
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.FileName        = command;
                if (commandArgs != null)
                {
                    //if (args != null)
                    p.StartInfo.Arguments = commandArgs;
                }
                try {
                    p.Start();
                }
                catch { }
            }
        }