public FromNative ( string pattern, char stringSeparators ) : bool | ||
pattern | string | |
stringSeparators | char | |
리턴 | bool |
public bool FromNative(string pattern, char[] stringSeparators)
{
Debug.AssertNotNull(pattern, "Pattern string is null");
if(pattern.Length == 0) {
return false;
}
string[] components = pattern.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
// there should be at least four components
if(components.Length < 4) {
return false;
}
else {
int patternLength;
if(int.TryParse(components[3], out patternLength) == false) {
Debug.ReportWarning("Couldn't parse pattern length. Length field: {0}", components[0]);
return false;
}
// perform some other validation on the pattern length
if(patternLength < 0 || patternLength > 0x10000) {
Debug.ReportWarning("Invalid pattern length. Length: {0}", patternLength);
return false;
}
if(patternLength > (components.Length - 1)) {
Debug.ReportWarning("Not all pattern components present. Length: {0}, Present: {1}", patternLength, components.Length);
return false;
}
if(patternLength > 0) {
// allocate the pattern
_pattern = new byte[patternLength];
for(int i = 0; i < patternLength; i++) {
if(byte.TryParse(components[4 + i], out _pattern[i]) == false) {
Debug.ReportWarning("Failed to parse pattern component. Component field: {0}", components[4 + i]);
_pattern = null;
return false;
}
}
}
return true;
}
}
private bool HandleStep(string line) { string[] components = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries); if(components.Length < 3) { Debug.ReportWarning("Invalid step. Step data: {0}", line); return false; } // get the number int number; int type; if(int.TryParse(components[1], out number) == false) { Debug.ReportWarning("Invalid step number. Number field: {0}", components[1]); return false; } // validate the number if(number < 0 || number >= stepNumber) { Debug.ReportWarning("Invalid step number. Number: {0}, Max. step: {1}", number, stepNumber); return false; } if(int.TryParse(components[2], out type) == false) { Debug.ReportWarning("Invalid step Type. Type field: {0}", components[2]); return false; } switch(type) { case 0: { PatternWipeStep step = new PatternWipeStep(number); if(step.FromNative(line, splitChars) == true) { wipeSteps.Add(step); } break; } case 1: { wipeSteps.Add(new RandomWipeStep(number)); break; } case 2: { wipeSteps.Add(new RandomByteStep(number)); break; } case 3: { wipeSteps.Add(new ComplementStep(number)); break; } default: { Debug.ReportWarning("Invalid step Type. Type: {0}", type); return false; } } return true; }