Beispiel #1
0
    public static string SetOp(string left, string right)
    {
        if (XString.Eq(left
                       , "Server.Id"
                       ))
        {
            ServerWindow.Text = right;
        }
        else if (XString.Eq(left, "Logfile"))
        {
            if (XString.Eq(right, "Delete"))
            {
                XLog.DeleteLogfile();
            }
        }

        //else if (XString.Eq(left
        //    , "test"
        //    ))
        //{
        //    var doc = Dte.ActiveDocument as Document;
        //    var selection = doc.Selection as TextSelection;
        //    selection.MoveToAbsoluteOffset(1, false);
        //    selection.MoveToAbsoluteOffset(5, true);
        //}



        return("");
    }
Beispiel #2
0
    private void RunButton_Click(object sender, EventArgs e)
    {
        var command = RequestText.Text;
        var code    = "";

        if (XString.Eq(command, "1"))
        {
            code = IdexLab.MainResource.Request_1;
        }
        else if (XString.Eq(command, "2"))
        {
            code = IdexLab.MainResource.Request_2;
        }
        else if (XString.Eq(command, "all"))
        {
            code = IdexLab.MainResource.Request_All;
        }
        else
        {
            XMB.Info("Command is unknown.", ProductInfo.Name);
        }
        RequestText.Text = code;
    }
Beispiel #3
0
    public static object GetOp(string right)
    {
        if (XString.Eq(right
                       , "NL"
                       , "NewLine"
                       ))
        {
            var result = "\r\n";
            return(result);
        }
        else if (XString.Eq(right
                            , "CR"
                            , "CarriageReturn"
                            ))
        {
            var result = "\r";
            return(result);
        }
        else if (XString.Eq(right
                            , "LF"
                            , "LineFeed"
                            ))
        {
            var result = "\n";
            return(result);
        }
        else if (XString.Eq(right
                            , "HT"
                            , "Tab"
                            ))
        {
            var result = "\t";
            return(result);
        }
        else if (XString.Eq(right
                            , "SP"
                            , "Space"
                            ))
        {
            var result = " ";
            return(result);
        }
        else if (XString.Eq(right
                            , "CO"
                            , "Comma"
                            ))
        {
            var result = ",";
            return(result);
        }
        else if (XString.Eq(right
                            , "SC"
                            , "SemiColon"
                            ))
        {
            var result = ";";
            return(result);
        }
        else if (XString.Eq(right
                            , "FS"
                            , "FullStop"
                            ))
        {
            var result = ".";
            return(result);
        }
        else if (XString.Eq(right
                            , "SO"
                            , "Solidus"
                            ))
        {
            var result = "/";
            return(result);
        }
        else if (XString.Eq(right
                            , "RS"
                            , "ReverseSolidus"
                            ))
        {
            var result = "\\";
            return(result);
        }
        else if (XString.Eq(right
                            , "a.text"
                            , "ActiveDocument.Selection.Text"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.Text);
        }
        else if (XString.Eq(right
                            , "a.line"
                            , "ActiveDocument.Selection.CurrentLine"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.CurrentLine.ToString());
        }
        else if (XString.Eq(right
                            , "a.col"
                            , "ActiveDocument.Selection.CurrentColumn"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.CurrentColumn.ToString());
        }
        else if (XString.Eq(right
                            , "a.topline"
                            , "ActiveDocument.Selection.TopLine"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.TopLine.ToString());
        }
        else if (XString.Eq(right
                            , "a.bottomline"
                            , "ActiveDocument.Selection.BottomLine"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.BottomLine.ToString());
        }
        else if (XString.Eq(right
                            , "a.rangecount"
                            , "ActiveDocument.Selection.TextRangesCount"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.TextRanges.Count.ToString());
        }
        else if (XString.Eq(right
                            , "a.topchar"
                            , "ActiveDocument.Selection.TopCharOffset"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.TopPoint.AbsoluteCharOffset.ToString());
        }
        else if (XString.Eq(right
                            , "a.bottomchar"
                            , "ActiveDocument.Selection.BottomCharOffset"
                            ))
        {
            var selection = ActiveDocument_GetSelection();
            return(selection.BottomPoint.AbsoluteCharOffset.ToString());
        }

        //else if (XString.Eq(right
        //, "test"
        //, "Line_GetLineIndexByCharIndex"
        //))
        //{
        //    var tdoc2 = Dte.ActiveDocument.Object("TextDocument") as TextDocument;
        //    var ep2 = tdoc2.CreateEditPoint();
        //    ep2.MoveToAbsoluteOffset(1);
        //    var line = ep2.Line;
        //}

        else if (XString.Eq(right
                            , "s.items"
                            , "SolutionExplorer.Selection.Items"
                            ))
        {
            var result = Ide.SolutionExplorer_GetItems();
            return(result);
        }
        else if (XString.Eq(right
                            , "s.itemcount"
                            , "SolutionExplorer.Selection.ItemCount"
                            ))
        {
            var result = Ide.SolutionExplorer_GetItemCount();
            return(result);
        }
        else if (XString.Eq(right
                            , "docs"
                            , "Editor.OpenDocuments"))
        {
            var result = OpenDocuments_Get();
            return(result);
        }
        else if (XString.Eq(right
                            , "doccount"
                            , "Editor.OpenDocumentCount"))
        {
            var result = OpenDocumentCount_Get();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.Id"
                            ))
        {
            return(ServerWindow.Text);
        }
        else if (XString.Eq(right
                            , "Server.State"
                            ))
        {
            var result = ServerManager.ServerState.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.Handle"
                            ))
        {
            var result = ServerWindow.Handle.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.Class"
                            ))
        {
            var result = ServerWindow.GetWindowClassName();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.LogEnabled"
                            ))
        {
            var result = XLog.Enabled ? "1" : "0";
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.LogfileExists"
                            ))
        {
            var result = XLog.Exists ? "1" : "0";
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.LogFile"
                            ))
        {
            var result = XLog.LogFile.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.Marker"
                            ))
        {
            var result = Persistence.Marker.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.Version"
                            ))
        {
            var result = Persistence.Version.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.SupportGetOps"
                            ))
        {
            var result = Persistence.SupportGetOps ? "1" : "0";
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.SupportSetOps"
                            ))
        {
            var result = Persistence.SupportSetOps ? "1" : "0";
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.RequestEncoding"
                            ))
        {
            var result = Persistence.RequestEncoding.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.ResponseEncoding"
                            ))
        {
            var result = Persistence.ResponseEncoding.ToString();
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.ClaimMarkerInRequest"
                            ))
        {
            var result = Persistence.ClaimMarkerInRequest ? "1" : "0";
            return(result);
        }
        else if (XString.Eq(right
                            , "Server.IncludeMarkerInResponse"
                            ))
        {
            var result = Persistence.IncludeMarkerInResponse ? "1" : "0";
            return(result);
        }
        return("");
    }
Beispiel #4
0
    public void Handle_CopyData(ref Message m)
    {
        XLog.Log($"Begin Request: {RequestNumber}");
        RequestNumber++;
        var cdsRequest = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT));

        var request         = "";
        var requestEncoding = Persistence.RequestEncoding;

        XLog.Log($"RequestEncoding: {requestEncoding}");
        if (requestEncoding == IdexEncoding.Ansi)
        {
            request = Marshal.PtrToStringAnsi(cdsRequest.lpData);
        }
        else
        {
            request = Marshal.PtrToStringUni(cdsRequest.lpData);
        }

        XLog.Log($"ClaimMarkerInRequest: {Persistence.ClaimMarkerInRequest}");
        if (Persistence.ClaimMarkerInRequest)
        {
            if (XString.StartsWith(request, Marker))
            {
                XLog.Log($"Eliminate Marker: {Marker}");
                request = request.Substring(Marker.Length).Trim();
            }
            else
            {
                XLog.Log($"Marker is expected but not present. Request is denied.");
                return;
            }
        }

        XLog.Log($"Parse Request");
        string requestServerId = "";
        string requestClientId = "";
        var    requestLines    = XString.SplitIntoLines(request);

        if (requestLines.Length >= 3)
        {
            for (int i = 0; i < 3; i++)
            {
                string requestLine = requestLines[i];
                string left, right;
                XString.ParseAssoc(requestLine, out left, out right);
                if (XString.Eq(left, "ServerId") || XString.Eq(left, "sid"))
                {
                    requestServerId = right;
                }
                else if (XString.Eq(left, "ClientId") || XString.Eq(left, "cid"))
                {
                    requestClientId = right;
                }
            }
        }

        XLog.Log($"Identify client");
        IntPtr clientHandle = IntPtr.Zero;

        if (requestClientId != "")
        {
            XLog.Log($"ClientId: {requestClientId}");
            clientHandle = Native.FindWindow(null, requestClientId);
        }
        if (clientHandle == IntPtr.Zero)
        {
            XLog.Log($"Cannot find client");
            return;
        }
        XLog.Log($"ClientHandle: {clientHandle}");

        var response = "";

        foreach (var actionLine in requestLines)
        {
            if (XString.StartsWith(actionLine, "o ", "g ", "s "))
            {
                var actionPrefix = actionLine.Substring(0, 2).Trim();
                var actionBody   = actionLine.Substring(2).Trim();
                if (XString.Eq(actionPrefix, "o"))
                {
                    XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                    response += actionBody;
                }
                else if (XString.Eq(actionPrefix, "g"))
                {
                    if (Persistence.SupportGetOps)
                    {
                        XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                        var result = Ide.TryGetOp(actionBody);
                        response += result;
                    }
                }
                else if (XString.Eq(actionPrefix, "s"))
                {
                    if (Persistence.SupportSetOps)
                    {
                        XLog.Log($"Execute action: {actionPrefix} {actionBody}");
                        string left, right;
                        XString.ParseAssoc(actionBody, out left, out right);
                        Ide.TrySetOp(left, right);
                    }
                }
            }
            else if (XString.StartsWith(actionLine, "Document."))
            {
                string rest         = actionLine.Substring(9);
                int    openBracket  = rest.IndexOf('(');
                string functionName = rest.Substring(0, openBracket);
                rest = rest.Substring(openBracket + 1);
                int closingBracket = rest.IndexOf(')');
                rest = rest.Substring(0, closingBracket);
                var args = rest.Split(',');
                if (XString.Eq(functionName
                               , "SetSelectedRange"))
                {
                    int startIndex = int.Parse(args[0]);
                    int endIndex   = int.Parse(args[1]);
                    Ide.Document_SetSelectedRange(startIndex, endIndex);
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedRange"))
                {
                    int startIndex = 0;
                    int endIndex   = 0;
                    Ide.Document_GetSelectedRange(out startIndex, out endIndex);
                    response += startIndex + "," + endIndex;
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedText"))
                {
                    string text = Ide.Document_GetSelectedText();
                    response += text;
                }
                else if (XString.Eq(functionName
                                    , "ReplaceSelectedText"))
                {
                    Ide.Document_ReplaceSelectedText();
                }
                else if (XString.Eq(functionName
                                    , "DeleteSelectedText"))
                {
                    Ide.Document_DeleteSelectedText();
                }
                else if (XString.Eq(functionName
                                    , "GetLineIndexByChar"
                                    ))
                {
                    int charIndex = int.Parse(args[0]);
                    int lineIndex = Ide.Document_GetLineIndexByChar(charIndex);
                    response += lineIndex.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetLine"
                                    ))
                {
                    int    lineIndex   = int.Parse(args[0]);
                    string lineContent = Ide.Document_GetLine(lineIndex);
                    response += lineContent.ToString();
                }
                else if (XString.Eq(functionName
                                    , "SelectLine"
                                    ))
                {
                    int lineIndex = int.Parse(args[0]);
                    Ide.Document_SelectLine(lineIndex);
                }
                else if (XString.Eq(functionName
                                    , "GetLineLength"
                                    ))
                {
                    int charIndex = int.Parse(args[0]);
                    int charCount = Ide.Document_GetLineLength(charIndex);
                    response += charCount.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetCharIndexByLine"
                                    ))
                {
                    int lineIndex = int.Parse(args[0]);
                    int charIndex = Ide.Document_GetCharIndexByLine(lineIndex);
                    response += charIndex.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetTextLength"
                                    ))
                {
                    int charCount = Ide.Document_GetTextLength();
                    response += charCount.ToString();
                }
                else if (XString.Eq(functionName
                                    , "GetText"
                                    ))
                {
                    string chars = Ide.Document_GetText();
                    response += chars;
                }
                else if (XString.Eq(functionName
                                    , "ScrollToEnd"
                                    ))
                {
                    Ide.Document_ScrollToEnd();
                }
                else if (XString.Eq(functionName
                                    , "GetCaretLineIndex"
                                    ))
                {
                    response += Ide.Document_GetCaretLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetCaretColumnIndex"
                                    ))
                {
                    response += Ide.Document_GetCaretColumnIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedStartLineIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedStartLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedEndLineIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedEndLineIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedRangeCount"
                                    ))
                {
                    response += Ide.Document_GetSelectedRangeCount();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedStartCharIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedStartCharIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedEndCharIndex"
                                    ))
                {
                    response += Ide.Document_GetSelectedEndCharIndex();
                }
                else if (XString.Eq(functionName
                                    , "GetOpenDocuments"
                                    ))
                {
                    response += Ide.Document_GetOpenDocuments();
                }
            }
            else if (XString.StartsWith(actionLine, "SolutionExplorer."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "SolutionExplorer.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "GetSelectedItems"
                               ))
                {
                    response += Ide.SolutionExplorer_GetSelectedItems();
                }
                else if (XString.Eq(functionName
                                    , "GetSelectedItemCount"
                                    ))
                {
                    response += Ide.SolutionExplorer_GetSelectedItemCount();
                }
            }
            else if (XString.StartsWith(actionLine, "Base."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "Base.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "GetServerId"
                               ))
                {
                    response += Ide.Base_GetServerId();
                }
                else if (XString.Eq(functionName
                                    , "SetServerId"
                                    ))
                {
                    string serverId = args[0];
                    Ide.Base_SetServerId(serverId);
                }
                else if (XString.Eq(functionName
                                    , "GetServerHandle"
                                    ))
                {
                    response += Ide.Base_GetServerHandle();
                }
            }
            else if (XString.StartsWith(actionLine, "Output."))
            {
                string   functionName = null;
                string[] args         = null;
                ParseActionLine(actionLine, "Output.",
                                out functionName, out args);

                if (XString.Eq(functionName
                               , "WriteCR"
                               ))
                {
                    response += Ide.Output_WriteCR();
                }
                else if (XString.Eq(functionName
                                    , "WriteLF"
                                    ))
                {
                    response += Ide.Output_WriteLF();
                }
                else if (XString.Eq(functionName
                                    , "WriteCRLF"
                                    ))
                {
                    response += Ide.Output_WriteCRLF();
                }
                else if (XString.Eq(functionName
                                    , "WriteHT"
                                    ))
                {
                    response += Ide.Output_WriteHT();
                }
                else if (XString.Eq(functionName
                                    , "WriteSP"
                                    ))
                {
                    response += Ide.Output_WriteSP();
                }
                else if (XString.Eq(functionName
                                    , "Write"
                                    ))
                {
                    string text = args[0].Trim('"');
                    response += Ide.Output_Write(text);
                }
            }
        }

        XLog.Log($"IncludeMarkerInResponse: {Persistence.IncludeMarkerInResponse}");
        if (Persistence.IncludeMarkerInResponse)
        {
            response += Marker + "\r\n";
        }

        var responseEncoding = Persistence.ResponseEncoding;

        XLog.Log($"ResponseEncoding: {responseEncoding}");
        var sizeInBytes     = (response.Length + 1) * 2;
        var responsePointer = IntPtr.Zero;

        try
        {
            if (responseEncoding == IdexEncoding.Ansi)
            {
                responsePointer = Marshal.StringToCoTaskMemAnsi(response);
            }
            else
            {
                responsePointer = Marshal.StringToCoTaskMemUni(response);
            }

            var cds = new COPYDATASTRUCT();
            cds.cbData = sizeInBytes;
            cds.lpData = responsePointer;
            Native.SendMessage(clientHandle, WM_COPYDATA, IntPtr.Zero, ref cds);
            int errorCode = Marshal.GetLastWin32Error();
            if (errorCode != 0)
            {
                XLog.Log($"SendMessage Code: {errorCode}");
            }
        }
        finally
        {
            XLog.Log($"Free native objects");
            if (responseEncoding == IdexEncoding.Ansi)
            {
                Marshal.ZeroFreeCoTaskMemAnsi(responsePointer);
            }
            else
            {
                Marshal.ZeroFreeCoTaskMemUnicode(responsePointer);
            }
        }
        XLog.Log($"End Request");
    }