퇴근5분전

 

## 실행할때 ...

textDoc.DTE.ExecuteCommand("Query.Execute");

실행은 안해봤고...  SendKeys.Send( ... ) 로 하면 된다.

 

## 현재 로그인정보 ... ( 추후에 직접 sql 쿼리나 시스템 뷰를 이용해서 뭔가 만들때 필요할 듯 하다. )

 

VSIntergration.dll삭제,  SqlPackageBase.dll이 4.0 런타임 이므로 프로젝트 자체를 4.0으로 변경.
var conn = ServiceCache.ScriptFactory

                                .CurrentlyActiveWndConnectionInfo

                                .UIConnectionGroupInfo;

 

textDoc.Selection.NewLine();
textDoc.Selection.Insert( string.Format("S:{0},U:{1},P:{2},D:{3}",

                                                 conn[0].ServerName,

                                                 conn[0].UserName,

                                                 conn[0].Password,

                                                 conn[0].AdvancedOptions[6] ), 0);

 
## 솔루션과 선택된 노드와 에디터 연계 ...

/*
// Nuget 패키지관리자 ( 콘솔 ) : Install-Package VSSDK.Shell.10
// Shell.10.dll이 필요해서 구글링.
// : ServiceProvider
*/
IObjectExplorerService objExplorer = ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService)) as IObjectExplorerService;

 

// 솔루션 탐색기에서 선택된 것 ...
int selectedNodeCount = 0;
INodeInformation[] selectedNodes = null ;
objExplorer.GetSelectedNodes( out selectedNodeCount, out selectedNodes );


// DB정보 : Server[@Name='DB-SVR']/Database[@Name='TabeName']
//  테이블 : Server[@Name='DB-SVR']/Database[@Name='DBName']/Table[@Name='TabeName' and @Schema='dbo']
INodeInformation findNode = objExplorer.FindNode(

                      "Server[@Name='DB-SVR']/Database[@Name='DBName']/Table[@Name='TabeName' and @Schema='dbo']");


// 테스트 아직 로딩 안된 객체 선택! ( 찾아감 )
objExplorer.SynchronizeTree( findNode );

 

*** 이거 쉽지 않더라.

 우선 SQL Server 버젼이 2014! AddIn 만드는것은 VS2013 Community로 .Net 4.0, SqlFormatter는 .NET 3.5

 

 구글링을 해도 대부분 2008버젼, 또는 2012가 있긴한데... 영어해석이 안되서 그런건지... 번역기돌려서 그런지...

참조된 dll경로도 인터넷 글과 조금씩... ( 많이 다르면 다른 글을 봤을텐데... ) 다르다.

 

 참고사항으로 아래 project파일의 참조 링크경로를 복사해둔다.

 

<Reference Include="Extensibility, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <EmbedInteropTypes>False</EmbedInteropTypes>
    </Reference>
    <Reference Include="Microsoft.SqlServer.RegSvrEnum, Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\120\SDK\Assemblies\Microsoft.SqlServer.RegSvrEnum.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <HintPath>..\packages\VSSDK.OLE.Interop.7.0.4\lib\net20\Microsoft.VisualStudio.OLE.Interop.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Microsoft.VisualStudio.Shell.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\VSSDK.Shell.10.10.0.4\lib\net40\Microsoft.VisualStudio.Shell.10.0.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="ObjectExplorer">
      <HintPath>..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\ObjectExplorer.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="SQLEditors">
      <HintPath>..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Extensions\Application\SQLEditors.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="SqlPackageBase, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\SqlPackageBase.dll</HintPath>
      <SpecificVersion>False</SpecificVersion>
      <Private>False</Private>
    </Reference>
    <Reference Include="SqlWorkbench.Interfaces">
      <HintPath>..\..\..\..\..\..\..\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\SqlWorkbench.Interfaces.dll</HintPath>
      <Private>True</Private>
    </Reference>

 

 

  구글링해도 자세한건 대부분 영어라 찾기 어렵다. 한글이 없네...

 

# VS AddIns 만들면서

 - 솔루션탐색기에서 프로젝트에 Context Menu를 띄울때.

      CommandBars cBars = (CommandBars)_applicationObject.CommandBars;

      CommandBar vsBarProject = cBars["Project"];

      commandProjectSettings.AddControl(vsBarProject, 1);

 

- 솔루션탐색기에서 특정 파일에 대해 Context Menu를 띄울때

      CommandBar vsBarFile = cBars["Item"];

    * Status 설정할때

                    UIHierarchy UIH = _applicationObject.ToolWindows.SolutionExplorer;
                    SelectedItem SelectItem = _applicationObject.SelectedItems.Item(1);
                    if (SelectItem != null)
                    {
                        if (Path.GetExtension(SelectItem.Name) == ".xaml")  //확장자가 .xaml일때 메뉴가 뜸.
                        {

                             Status = 지원, 활성화;

                        }

                   }

 

 - 솔루션 탐색기에서 선택된 항목에 대한 실제 파일 경로를 가져올때.

 

                    UIHierarchy UIH = _applicationObject.ToolWindows.SolutionExplorer;
                    Array SelectItems = (Array)UIH.SelectedItems;
                    if (SelectItems != null)
                    {
                        foreach (UIHierarchyItem item in SelectItems)
                        {                      
                            ProjectItem prj = item.Object as ProjectItem;
                            string projectName = prj.ContainingProject.Name;
                            string projectPath = "" + prj.Properties.Item("FullPath").Value;  // 경로

                        }

                    }