2

사용자 지정 활동 및 사용자 지정 디자이너 (WPF)가있는 WF 서비스가 있습니다. web.config 파일에 일부 값이 있는지 확인하는 유효성 검사를 추가하고 싶습니다.WF4 워크 플로 서비스의 사용자 지정 활동 디자이너에서 Web.Config 파일을 읽는 방법

런타임시 나는 void CacheMetadata(ActivityMetadata metadata)을 오버로드 할 수 있습니다. 따라서 System.Configuration.ConfigurationManager을 사용하여 구성 파일을 읽으면 행복하게 유효성 검사를 수행 할 수 있습니다.

디자인 타임에이 작업을 수행하고 싶으므로 디자이너에서이 작업을 수행 할 방법을 찾고있었습니다.

답변

3

좋아 나는이 하나의 솔루션 :

string GetWebConfigXml() { 

     string configXml = null; 

     Window window = null; 
     ProjectItem project = null; 
     ProjectItem configFile = null; 

     try { 
      EnvDTE.DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE)) as DTE; 
      if(dte == null) return null; 

      project = dte.Solution.FindProjectItem(dte.ActiveDocument.FullName); 
      configFile = (from ProjectItem childItem in project.ProjectItems 
          where childItem.Name.Equals("web.config", StringComparison.OrdinalIgnoreCase) 
          select childItem).FirstOrDefault(); 

      if (configFile == null) return null; 

      if (!configFile.IsOpen) window = configFile.Open(); 
      var selection = (TextSelection)configFile.Document.Selection; 
      selection.SelectAll(); 
      configXml = selection.Text; 
     } finally { 

      //Clean up the COM stuff 

      if (window != null) { 
       window.Close(vsSaveChanges.vsSaveChangesNo); 
       window = null; 
      } 

      if (configFile != null) { 
       configFile = null; 
      } 

      if (project != null) { 
       project = null; 
      } 
     } 
    } 
    return configXml; 
} 

참고 : 당신은 아마

여기에 시도 어획량의 보트로드가 필요합니다 잊지 마세요
관련 문제