Vs宏 之 打开URL指定的文件

在自 定义Mvc 项目进行进行调试的过程中,查找文件比较浪费时间。所以我需要一个工具,来完成如下工作:

1.我在 Chrome 上Copy 一个待调试链接。

2.在VS中快速打开该链接所在的 View(ASPX) 和 Controller( CS)

很巧网上也有类似方案:http://www.cnblogs.com/yiyanxiyin/archive/2007/06/26/796238.html

但我需要的是MVC的知定义结构,代码:

   

    'Udi 2012年9月20日
    Sub OpenMvc()

        Dim ClipBoardThread As System.Threading.Thread
        ClipBoardThread = New System.Threading.Thread(AddressOf getClipString_core)
        With ClipBoardThread
            .ApartmentState = ApartmentState.STA
            .IsBackground = True
            .Start()
            '-- Wait for copy to happen
            .Join()
        End With



        ClipBoardThread = Nothing

        Dim url = InputBox("输入 LongFor - PM 网址(IIS 需要配置成应用程序),支持如下格式:" + vbNewLine _
                             + vbNewLine + _
                           "1. http://localhost/pm/Admin/Home/Index.aspx 格式 " + vbNewLine + _
                           "2. /pm/Admin/Home/Index.aspx 格式" + vbNewLine + _
                           "3. ~/Admin/Home/Index.aspx 格式" + vbNewLine + _
                           "4. localhost/pm/Admin/Home/Index.aspx 格式 " + vbNewLine + _
                          "", "直接打开URL小工具", ClipString)

        url = url.Trim()

        If (url.Length = 0) Then Return

        Dim path As String

        path = New FileInfo(DTE.Solution.FullName).DirectoryName


        If (url.StartsWith("http://") = False) Then

            If (url.StartsWith("/")) Then
                url = "http://localhost" + url
            ElseIf (url.StartsWith("~/")) Then
                url = "http://localhost/pm" + url.Substring(1)
            Else
                url = "http://" + url
            End If
        End If

        Dim sect = url.Substring(url.IndexOf("/", "http://".Length + 1) + 1).Split("/")

        Dim area = sect(1)
        Dim controller = sect(2)
        Dim action = sect(3).Split(".")(0)

        Dim cs As String
        Dim aspx As String

        '普通Web
        If ("ReportWeb" = area) Then
            path += "\MyWeb\"

            cs = path + area + "\" + controller + "\" + action + ".aspx.cs"
            aspx = path + area + "\" + controller + "\" + action + ".aspx"

            If (File.Exists(cs)) Then
                DTE.ItemOperations.OpenFile(cs)
                FindWord(action)
            End If

            If (File.Exists(aspx)) Then DTE.ItemOperations.OpenFile(aspx)

        Else
            If (",Admin,cs,Host,".IndexOf("," + area + ",") >= 0) Then
                path += "\MyWeb\Area\"

            Else
                path += "\MyWeb\pm\"

            End If


            cs = path + area + "\Controllers\" + controller + ".cs"
            If (File.Exists(cs) = False) Then cs = path + area + "\Controllers\" + controller + "Controller.cs"

            aspx = path + area + "\Views\" + controller + "\" + action + ".aspx"


            If (File.Exists(cs)) Then
                DTE.ItemOperations.OpenFile(cs)
                FindWord(action)
            End If

            If (File.Exists(aspx)) Then DTE.ItemOperations.OpenFile(aspx)
        End If

    End Sub


    Dim ClipString As String
    'Udi 2012年9月20日
    Sub getClipString_core()
        ClipString = Clipboard.GetDataObject().GetData(System.Windows.Forms.DataFormats.StringFormat)
    End Sub


    Sub FindWord(ByVal word As String)
        DTE.ExecuteCommand("Edit.Find")
        DTE.Find.FindWhat = word
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
        DTE.Find.MatchCase = True
        DTE.Find.MatchWholeWord = True
        DTE.Find.Backwards = False
        DTE.Find.MatchInHiddenText = False
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxLiteral
        DTE.Find.Action = vsFindAction.vsFindActionFind
        If (DTE.Find.Execute() = vsFindResult.vsFindResultNotFound) Then
            Exit Sub
        End If
        DTE.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close()
    End Sub
alarm   作者:NewSea     出处:http://newsea.cnblogs.com/    QQ,MSN:iamnewsea@hotmail.com

  如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。
原文地址:https://www.cnblogs.com/newsea/p/2636480.html