私が仕事をしているプロジェクトの1つとして、SSISスクリプトコンポーネントからスーパーバイザのリストを取得するレポートを作成する必要があります。この1つの機能は私に不幸にも問題を与えているのですが、なぜその理由が分かりません。以下の関数は、SSIS入力バッファから行を取得し、スーパーバイザと呼ばれるリスト変数をチェックして、そのインスタンス内のその名前がすでにスーパーバイザと呼ばれるリスト内にあるかどうかを確認し、そうでない場合は入力バッファ行の名前をリスト。なんらかの理由で、入力バッファを通過してくるすべての人が追加され、私は実際にその理由を知りません! |正規表現で間違っているグループ
- フレッド・フリントストーン:私は上司の名前を持つ従業員のリストを持っているに例えば
私が持っていますクッキーモンスター
- john Doe |クーリーモンスター
- willy wonka |ゴムduckie
は、私が取得したい結果ではなく、私はこの...クッキーモンスター、クッキーモンスター、ゴムduckie
を取得し、グループby..cookieモンスターのようなもの、ゴムduckieです
public void check(Input0Buffer Row)
{
bool flag = true;
string expression = String.Format("({0}|{1})", Row.FirstName, Row.LastName);
Regex lookup = new Regex(expression,RegexOptions.IgnoreCase);
if (supervisors.Count > 0)
{
foreach (string person in supervisors)
{
if (lookup.Matches(person).Count >= 2)
{
flag = false;
break;
}
}
if (flag)
supervisors.Add(Row.ReportsToName);
}
else
supervisors.Add(Row.ReportsToName);
}
ここには、SSISスクリプトのすべてのコードがあります。
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
/// <summary>
/// This is the class to which to add your code. Do not change the name, attributes, or parent
/// of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public List<Dictionary<string, string>> Employees;
public List<string> supervisors;
string temp;
/// <summary>
/// This method is called once, before rows begin to be processed in the data flow.
///
/// You can remove this method if you don't need to do anything here.
/// </summary>
public override void PreExecute()
{
base.PreExecute();
Employees = new List<Dictionary<string, string>>();
supervisors = new List<string>();
temp = "First Name\tLast Name\tEXT\tUsername\n";
}
/// <summary>
/// This method is called after all the rows have passed through this component.
///
/// You can delete this method if you don't need to do anything here.
/// </summary>
public override void PostExecute()
{
base.PostExecute();
foreach (string supervisor in supervisors)
{
foreach (Dictionary<string, string> employee in Employees)
{
if(match(supervisor,employee))
{
temp+= String.Format("{0}\t{1}\t{2}\t{3}\n",employee["First"],employee["last"],employee["EXT"],employee["Username"]);
break;
}
}
}
File.WriteAllLines(@"blahvlajsdlfh", (string[])temp.Split('\n'));
File.AppendAllLines(@"Q:gfdhdfghdfgh", supervisors.ToArray());
}
/// <summary>
/// This method is called once for every row that passes through the component from Input0.
///
/// Example of reading a value from a column in the the row:
/// string zipCode = Row.ZipCode
///
/// Example of writing a value to a column in the row:
/// Row.ZipCode = zipCode
/// </summary>
/// <param name="Row">The row that is currently passing through the component</param>
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
Dictionary<string, string> temp_dict = new Dictionary<string, string>();
temp_dict.Add("First", Row.FirstName);
temp_dict.Add("last", Row.LastName);
if (Row.ext_IsNull)
temp_dict.Add("EXT", "0000");
else
temp_dict.Add("EXT", Row.ext);
if (Row.OEEUSERNAME_IsNull)
temp_dict.Add("Username", "not available");
else
temp_dict.Add("Username", Row.OEEUSERNAME);
Employees.Add(temp_dict);
check(Row);
}
/// <summary>
/// checks to see if a person is the supervisor list.
/// </summary>
/// <param name="Row"></param>
public void check(Input0Buffer Row)
{
bool flag = true;
string expression = String.Format("({0}|{1})", Row.FirstName, Row.LastName);
Regex lookup = new Regex(expression,RegexOptions.IgnoreCase);
if (supervisors.Count > 0)
{
foreach (string person in supervisors)
{
if (lookup.Matches(person).Count >= 2)
{
flag = false;
break;
}
}
if (flag)
supervisors.Add(Row.ReportsToName);
}
else
supervisors.Add(Row.ReportsToName);
}
/// <summary>
/// used to match supervisors to all of there information
/// </summary>
/// <param name="supervisor"></param>
/// <param name="employees"></param>
/// <returns></returns>
public bool match(string supervisor, Dictionary<string, string> employees)
{
string expression = String.Format("({0}|{1})", employees["First"], employees["last"]);
Regex lookup = new Regex(expression, RegexOptions.IgnoreCase);
if (lookup.Matches(supervisor).Count >= 2)
return true;
return false;
}
}
({0} "(=' String.Formatのを文字列式を試してみてください* {1} |。{1} * {。 0}) "、Row.FirstName、Row.LastName);'次に 'if(lookup.IsMatch(person))' ... –
うん、うまくいきませんでした。一人ではない –
問題を絞り込み、サンプル入力とサンプル出力を提供することができれば、より簡単にお手伝いできます。 –