2012-07-11 1 views
2

C#에서 사용자 지정 컨트롤 흐름 SSIS 작업을 처음 작성했습니다. 내 작업 UI 편집기에서 속성 표가 있고 옵션 중 하나에서 사용 가능한 모든 작업 변수의 드롭 다운 목록을 채우고 사용자에게 새 옵션을 만들 수있는 옵션을 제공 할 수 있기를 바랍니다. 나는 며칠 동안 연구를 해왔고 포럼에서 좋은 예를 발견했지만 지금은 조금 잃어버린다. 내 코드는 다음과 같이 컴파일되고 편집기는 드롭 다운 목록을 표시하지만 비어 있습니다. 단계별로 살펴보면 다음과 같이 표시됩니다.C# SSIS 사용자 지정 컨트롤 흐름 작업 목록 속성 드롭 다운 목록의 변수 목록

taskHostProperty = context.Instance.GetType().GetProperty("TransferTask", typeof(TaskHost));The "TransferTask" being the name of my control flow task. I'm wondering if this is correct? 

내 전체 코드는 다음과 같습니다.

//Property Grid Property 
    [Category("General"), 
      Description("Specifies the local Path for this task"), 
      Browsable(true), 
      ReadOnly(false), 
      DesignOnly(false), 
      TypeConverter(typeof(VariableConverter)), 
      DisplayName("Local Path")]    
      public string LocalPath 
      { 
       get 
       { 
        return this.stLocalPath; 
       } 
       set 
       {      
        dtsVariableService = serviceProvider.GetService(typeof(IDtsVariableService)) as IDtsVariableService; 
        dtsVariableService.PromptAndCreateVariable(parentWindow, dtsContainer,"Local Path","User",typeof(string)); 
        this.stLocalPath = value; 
       } 
      } 
//Variable Converter 
internal class VariableConverter : TypeConverter 
     { 
      StandardValuesCollection svc = new StandardValuesCollection(new ArrayList()); 
      public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
      { 
       return true; 
      } 
      public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
      { 
       TaskHost taskHost = null; 
       PropertyInfo taskHostProperty = null; 
       List<string> values = new List<string>(); 
       values.Add(NEW_VARIABLE); 
       if (context == null) 
       { 
        return svc; 
       } 
       if (context.Instance == null) 
       { 
        return svc; 
       } 
       taskHostProperty = context.Instance.GetType().GetProperty("TransferTask", typeof(TaskHost)); 
       if (taskHostProperty == null) 
       { 
        return svc; 
       } 
       taskHost = taskHostProperty.GetValue(context.Instance, null) as TaskHost; 

       foreach(Variable v in taskHost.Variables) 
       { 
        if (!v.SystemVariable && v.DataType == TypeCode.String) 
        { 
         values.Add(v.QualifiedName); 
        } 
       } 
       values.Sort(); 
       return new StandardValuesCollection(values); 
    } 

답변

1

결국 나는 변수 그리드에 변수를 추가하려고 시도하지 않고 방금 내 양식을 만들었습니다. 콤보 상자를 채우고 사용자가 새 SSIS 변수를 추가 할 수있게 한 후 다음 코드를 사용했습니다. 데이터 소스를 새로 고쳤습니다. 나는 아직도 이것을 제대로하는 법을 알고 싶지만 앉아서 일할 시간이 없다. 필자는 다음과 같이 필요한 SSIS 변수를 먼저 얻었습니다. 새 SSIS 변수를 추가 할 수 있고 새로 생성 된 변수를 선택할 수 있습니다. 이렇게하는 더 좋은 방법이있을 것이라고 확신하지만, 지금은 효과가 있습니다.

public ObservableCollection<string> FillVariableList() 
     { 
      ObservableCollection<string> variables = new ObservableCollection<string>(); 

      variables.Add(string.Empty); 
      variables.Add(New_Variable);   

      foreach (Variable v in thetaskHost.Variables) 
      { 
       if (!v.SystemVariable && v.DataType == TypeCode.String && !variables.Contains(v.Name)) 
       { 
        variables.Add(v.Name);     
       } 
      } 

      return variables; 
     } 

그리고

는 내가 새로운 SSIS 변수를 추가하거나 기존 SSIS 변수를 선택하고 SSIS 변수 콤보 상자를 새로 고침 할 수있는 사용자 수 있도록 다음과 같은 사용.

private void cmbxVariables_SelectionChangeCommitted(object sender, EventArgs e) 
    { 
     if (cmbxVariables.Text == New_Variable) 
     { 
      try 
      { 
       DtsContainer dtsContainer = null; 
       dtsVariableServie = serviceProvider.GetService(typeof(IDtsVariableService)) as IDtsVariableService; 
       Variable var = dtsVariableServie.PromptAndCreateVariable(null, dtsContainer, "VariableName", "User", typeof(string)); 
       if (!var.IsNull()) 
       { 
        cmbxVariables.DataSource = null; 
        cmbxVariables.DataSource = FillVariableList(); 
       } 
      } 
      catch (Exception exe) 
      { 
       MessageBox.Show(exe.ToString()); 
      } 
     } 
     else 
     { 
      foreach (Variable v in thetaskHost.Variables) 
      { 
       if (v.Name == cmbxVariables.Text) 
       { 
        //Do something with the variable selected 
        break; 
       } 
      } 
     }   
    }