Ejemplo n.º 1
0
        void ExecuteAfterTransition(Session session, AppEdge appEdge)
        {
            Process targetProcess = null;

            if (appEdge.Dst.Any)
            {
                Process[] ps = Process.GetProcessesByName(appEdge.Dst.ProcessName).Where(p => !string.IsNullOrWhiteSpace(p.MainWindowTitle)).ToArray();
                if (ps.Length >= 1)
                {
                    targetProcess = ps.First();
                }
            }
            else
            {
                targetProcess = appEdge.Dst.Process;
            }

            if (targetProcess != null)
            {
                ActivateProcess(targetProcess);
            }

            if (appEdge.Dst.Path == "Any" || targetProcess != null)
            {
                session.Execute(appEdge.ActionHandler.dstScript);
            }
        }
Ejemplo n.º 2
0
        void ShowEdgeDetail(AppEdge edge)
        {
            flowLayoutPanel1.Show();
            if (edge == null)
            {
                return;
            }

            allowEditEdgeDetail = false;

            editingEdge = edge;

            srcIconTitle.Image             = edge.Src.Icon;
            srcIconTitle.Text              = edge.Src.ProcessName + ": " + NodeTitle(edge.Src);
            radioContextMenu.Checked       = edge.ActionHandler.TriggerType == TriggerType.ContextMenu;
            textBoxContextMenu.Text        = edge.ActionHandler.ContextMenuText;
            radioHotKey.Checked            = edge.ActionHandler.TriggerType == TriggerType.HotKey;
            CtrlCheckBoxHotKey.Checked     = edge.ActionHandler.Ctrl;
            AltCheckBoxHotKey.Checked      = edge.ActionHandler.Alt;
            WinCheckBoxHotKey.Checked      = edge.ActionHandler.Win;
            ShiftCheckBoxHotKey.Checked    = edge.ActionHandler.Shift;
            FnCheckBoxHotKey.Checked       = edge.ActionHandler.Fn;
            keyComboBoxHotKey.Text         = edge.ActionHandler.Key;
            BlockKeyStrokeCheckBox.Checked = edge.ActionHandler.BlockKeyStroke;
            srcScript.Text = edge.ActionHandler.srcScript;

            dstIconTitle.Image = edge.Dst.Icon;
            dstIconTitle.Text  = edge.Dst.ProcessName + ": " + NodeTitle(edge.Dst);;
            dstScript.Text     = edge.ActionHandler.dstScript;

            allowEditEdgeDetail = true;
        }
Ejemplo n.º 3
0
        //-----------------------------------------------------
        // マウスのフック処理
        //-----------------------------------------------------

        bool IsValidEdge(AppEdge appEdge, TriggerType triggerType)
        {
            if (appEdge.Src.Process == null || appEdge.Dst.Process == null)
            {
                return(false);
            }
            if (appEdge.ActionHandler.TriggerType != triggerType)
            {
                return(false);
            }
            Process activeProcess = GetActiveProcess();

            if (appEdge.Src.Path != "Any")
            {
                //
                if (appEdge.Src.Any)
                {
                    // ソフトの種類のみ見る
                    if (activeProcess.ProcessName != appEdge.Src.ProcessName)
                    {
                        return(false);
                    }
                }
                else
                {
                    // プロセスIDまで見る
                    if (activeProcess.Id != appEdge.Src.Process.Id)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        bool canvas_SetEdgePositions(object sender, MouseEventArgs e)
        {
            AppNode hitNode = GetAppNodeInCanvas(e.Location);

            if (hitNode != null)
            {
                if (appendingEdge == null)
                {
                    appendingEdge     = new AppEdge();
                    appendingEdge.Src = hitNode;
                }
                else
                {
                    appendingEdge.Dst = hitNode;
                    appendingEdge.ActionHandler.TriggerType     = TriggerType.ContextMenu;
                    appendingEdge.ActionHandler.ContextMenuText = "to " + appendingEdge.Dst.ProcessName;
                    appGraph.edges.Add(appendingEdge);
                    ShowEdgeDetail(appendingEdge);
                    appendingEdge = null;
                    canvas.Invalidate();
                }
                return(true);
            }
            else
            {
                appendingEdge = null;
                canvas.Invalidate();
            }
            return(false);
        }
Ejemplo n.º 5
0
 private void newNToolStripMenuItem_Click(object sender, EventArgs e)
 {
     appGraph = new AppGraph();
     canvas.Invalidate();
     ClearEdgeDetail();
     editingEdge = appendingEdge = null;
     editingNode = appendingNode = null;
 }
Ejemplo n.º 6
0
 void ExecuteBeforeTransition(Session session, AppEdge appEdge)
 {
     session.AddReference("System");
     session.AddReference("System.Drawing");
     session.AddReference("System.Windows.Forms");
     session.Execute("using System;");
     session.Execute("using System.Drawing;");
     session.Execute("using System.Collections.Generic;");
     session.Execute("using System.Windows.Forms;");
     session.Execute(appEdge.ActionHandler.srcScript);
 }
Ejemplo n.º 7
0
 //-----------------------------------------------------
 // キーのフック処理
 //-----------------------------------------------------
 int OnKeyLLHook(int code, WM wParam, ref KBDLLHOOKSTRUCT lParam)
 {
     UpdateSysKeyStates(wParam, ref lParam);
     switch (wParam)
     {
     case WM.KEYDOWN:
     case WM.SYSKEYDOWN:
         //                case WM.KEYUP:
         //                case WM.SYSKEYUP:
         for (int i = 0; i < appGraph.edges.Count; i++)
         {
             AppEdge appEdge = appGraph.edges[i];
             if (!IsValidEdge(appEdge, TriggerType.HotKey))
             {
                 continue;
             }
             Keys keyCode;
             if (Enum.TryParse(appEdge.ActionHandler.Key, out keyCode))
             {
                 // TODO: fnなど
                 if (
                     (!appEdge.ActionHandler.Ctrl || onCtrl) &&
                     (!appEdge.ActionHandler.Alt || onAlt) &&
                     (!appEdge.ActionHandler.Shift || onShift) &&
                     (!appEdge.ActionHandler.Win || onWin) &&
                     //                              (!appEdge.ActionHandler.Fn || (lParam.vkCode & MOD_WIN) != 0) &&
                     ((lParam.vkCode & (uint)keyCode) == (uint)keyCode))
                 {
                     try
                     {
                         ExecuteActionHandler(appEdge);
                         if (appEdge.ActionHandler.BlockKeyStroke)
                         {
                             return(1);
                         }
                         else
                         {
                             return(CallNextHookEx(0, code, wParam, ref lParam));
                         }
                     }
                     catch (Exception e)
                     {
                         Console.WriteLine(e);
                     }
                 }
             }
         }
         break;
     }
     return(CallNextHookEx(0, code, wParam, ref lParam));
 }
Ejemplo n.º 8
0
        //------------------------------------------------
        // スクリプトの実行
        //------------------------------------------------

        void ExecuteActionHandler(AppEdge appEdge)
        {
            try
            {
                ScriptEngine engine  = new ScriptEngine();
                Session      session = engine.CreateSession();
                ExecuteBeforeTransition(session, appEdge);
                ExecuteAfterTransition(session, appEdge);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 9
0
        int OnMouseLLHook(int code, WM message, IntPtr state)
        {
            try
            {
                if (message == WM.LBUTTONDOWN)
                {
                    var clientPos = virtualContextMenu.PointToClient(Cursor.Position);
                    if (virtualContextMenu.Visible && virtualContextMenu.ClientRectangle.Contains(clientPos) == false)
                    {
                        virtualContextMenu.Hide();
                    }
                }
                if (message == WM.RBUTTONUP)
                {
                    // コンテキストメニューを表示
                    virtualContextMenu.Items.Clear();

                    for (int i = 0; i < appGraph.edges.Count; i++)
                    {
                        AppEdge appEdge = appGraph.edges[i];
                        if (!IsValidEdge(appEdge, TriggerType.ContextMenu))
                        {
                            continue;
                        }
                        var item = new ToolStripMenuItem(appEdge.ActionHandler.ContextMenuText);
                        item.Click += (s, ee) => ExecuteActionHandler(appEdge);
                        item.Invalidate();
                        virtualContextMenu.Items.Add(item);
                    }

                    if (virtualContextMenu.Items.Count >= 1)
                    {
                        ToolStripMenuItem[] itemList = new ToolStripMenuItem[virtualContextMenu.Items.Count];
                        for (int j = 0; j < virtualContextMenu.Items.Count; j++)
                        {
                            itemList[j] = virtualContextMenu.Items[j] as ToolStripMenuItem;
                        }
                        virtualContextMenu.Show(new Point(Cursor.Position.X, Cursor.Position.Y - 22 * virtualContextMenu.Items.Count));
                    }
                }
                return(CallNextHookEx(mouseHook, code, message, state));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(CallNextHookEx(mouseHook, code, message, state));
            }
        }
Ejemplo n.º 10
0
        bool canvas_checkEdges(object sender, MouseEventArgs e)
        {
            AppEdge hitEdge = null;

            // 各ノードと当たり判定
            for (int i = 0; i < appGraph.edges.Count; i++)
            {
                AppEdge edge = appGraph.edges[i];
                Point   p1, p2, p3, p4;
                EdgePoints(edge.Src, edge.Dst, out p1, out p2, out p3, out p4);

                if (edge.Src == edge.Dst)
                {
                    if (new Rectangle(p1.X, p1.Y - 64, 64, 64).Contains(e.Location))
                    {
                        hitEdge = edge;
                        break;
                    }
                }
                else
                {
                    PointF n = new PointF(
                        p1.Y - p4.Y,
                        p4.X - p1.X);
                    PointF p = new PointF(
                        e.Location.X - p1.X,
                        e.Location.Y - p1.Y);
                    double d = Math.Abs(n.X * p.X + n.Y * p.Y) / Math.Sqrt(n.X * n.X + n.Y * n.Y);
                    if (d <= 4)
                    {
                        hitEdge = edge;
                        break;
                    }
                }
            }

            if (hitEdge != null)
            {
                ShowEdgeDetail(hitEdge);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 11
0
        private void canvas_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.Clear(Color.White);

            // 頂点の描画
            if (appGraph != null)
            {
                // appGraph, appendingNodeの描画
                for (int i = 0; i < appGraph.nodes.Count; i++)
                {
                    AppNode node = appGraph.nodes[i];
                    g.DrawImage(node.Icon, new Rectangle(node.Position, nodeSize));
                    try
                    {
                        if (node.Process != null)
                        {
                            string text = NodeTitle(node);
                            if (text.Length >= AppNodeTitleCharLimit)
                            {
                                text = text.Remove(AppNodeTitleCharLimit - 4) + "...";
                            }
                            SizeF textSize = g.MeasureString(text, fnt);
                            float textX    = node.Position.X + nodeSize.Width / 2 - textSize.Width / 2;
                            float textY    = node.Position.Y + nodeSize.Height;
                            g.DrawString(text, fnt, Brushes.Black, new PointF(textX, textY));
                        }
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine(ee);
                    }
                }
            }

            if (appendingNode != null)
            {
                g.DrawImage(appendingNode.Icon, new Rectangle(appendingNode.Position, nodeSize));
            }

            // 枝の描画
            if (appGraph != null)
            {
                for (int i = 0; i < appGraph.edges.Count; i++)
                {
                    AppEdge edge = appGraph.edges[i];
                    Point   p1, p2, p3, p4;
                    EdgePoints(edge.Src, edge.Dst, out p1, out p2, out p3, out p4);

                    if (edge.Src != edge.Dst)
                    {
                        g.DrawLine(edgePen, p3, p4);
                    }
                    else
                    {
                        g.DrawArc(edgePen, new Rectangle(p1.X, p1.Y - 64, 64, 64), 90, -270);
                    }
                    // TODO
                    string text = "";
                    if (edge.ActionHandler.TriggerType == TriggerType.ContextMenu)
                    {
                        text = "\"" + edge.ActionHandler.ContextMenuText + "\"";
                    }
                    else
                    {
                        text += edge.ActionHandler.Ctrl ? "Ctrl + " : "";
                        text += edge.ActionHandler.Win ? "Ctrl + " : "";
                        text += edge.ActionHandler.Fn ? "Fn + " : "";
                        text += edge.ActionHandler.Shift ? "Sfhift + " : "";
                        text += edge.ActionHandler.Alt ? "Alt + " : "";
                        text += edge.ActionHandler.Key;
                    }
                    g.DrawString(text, fnt, Brushes.Black, new PointF((p1.X + p4.X) / 2, (p1.Y + p4.Y) / 2));
                }
            }

            if (appendingEdge != null)
            {
                Point srcPos = new Point(
                    appendingEdge.Src.Position.X + nodeSize.Width / 2,
                    appendingEdge.Src.Position.Y + nodeSize.Height / 2);
                Point dstPos = canvas.PointToClient(Cursor.Position);
                g.DrawLine(edgePen, srcPos, dstPos);
            }
        }