Для одного из проектов, которые я делаю для работы, я должен сделать отчет, который получает список супервизоров из компонента сценария SSIS. К сожалению, эта функция дает мне проблемы, и я не могу понять, почему. Функция ниже получает строку из входного буфера SSIS и проверяет переменную списка, называемую супервизорами, чтобы узнать, находится ли это имя в указанном экземпляре уже в списке, называемом супервизорами, и если нет, то помещает имя из строки ввода-буфера в список. По какой-то причине он просто добавляет всех, кто идет через буфер ввода, и я действительно не знаю, почему!Группа не работает с регулярным выражением
, например, я должен у меня есть список сотрудников с их именем контролеров:
- Фред Flintstones | печенье монстр
- john Doe | кули монстр
- willy wonka | резина Даки
результат я хочу получить что-то вроде группы by..cookie монстра, резиновые Даки
вместо этого, я получаю это ... печенье монстра, печенье монстра, резиновые Даки
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;
}
}
Попробуйте 'выражение строка = String.Format (" ({0} * {1} |.. {1} * { 0}) ", Row.FirstName, Row.LastName);' и затем 'if (lookup.IsMatch (person))' ... –
да, не работает. ни один человек не появляется –
Если вы можете сузить свою проблему и предоставить некоторые примеры ввода и выборки, вам будет легче помочь. –