public string SolveExpressionFromBeginning(int iteration) { string exp = _expression; foreach (Function func in _functions) { switch (func.Type) { case Function.FunctionType.SequentialIntFunction: SequentialIntFunction sif = (SequentialIntFunction)func; exp = exp.Replace(sif.Name, sif.AllVals(iteration).Last <int>().ToString().PadLeft(sif.Padding, '0')); break; case Function.FunctionType.SequentialCharFunction: SequentialCharFunction scf = (SequentialCharFunction)func; exp = exp.Replace(scf.Name, scf.AllVals(iteration).Last <char>().ToString()); break; case Function.FunctionType.ConstantTextFunction: ConstantTextFunction ctf = (ConstantTextFunction)func; exp = exp.Replace(ctf.Name, ctf.Constant); break; case Function.FunctionType.ConstantFileFunction: ConstantFileFunction cff = (ConstantFileFunction)func; exp = exp.Replace(cff.Name, cff.NextVal()); break; case Function.FunctionType.ConstantFileFunctionEx: ConstantFileFunctionEx cffe = (ConstantFileFunctionEx)func; exp = exp.Replace(cffe.Name, cffe.NextVal()); break; case Function.FunctionType.ConstantFileExtFunction: ConstantFileExtFunction cfef = (ConstantFileExtFunction)func; exp = exp.Replace(cfef.Name, cfef.NextVal()); break; } } return(exp); }
private string SolveExpressionPrevValues() { string exp = _expression; foreach (Function func in _functions) { switch (func.Type) { case Function.FunctionType.SequentialIntFunction: SequentialIntFunction sif = (SequentialIntFunction)func; exp = exp.Replace(sif.Name, sif.PrevVal().ToString().PadLeft(sif.Padding, '0')); break; case Function.FunctionType.SequentialCharFunction: SequentialCharFunction scf = (SequentialCharFunction)func; exp = exp.Replace(scf.Name, scf.PrevVal().ToString()); break; case Function.FunctionType.ConstantTextFunction: ConstantTextFunction ctf = (ConstantTextFunction)func; exp = exp.Replace(ctf.Name, ctf.Constant); break; case Function.FunctionType.ConstantFileFunction: ConstantFileFunction cff = (ConstantFileFunction)func; exp = exp.Replace(cff.Name, cff.NextVal()); break; case Function.FunctionType.ConstantFileFunctionEx: ConstantFileFunctionEx cffe = (ConstantFileFunctionEx)func; exp = exp.Replace(cffe.Name, cffe.NextVal()); break; case Function.FunctionType.ConstantFileExtFunction: ConstantFileExtFunction cfef = (ConstantFileExtFunction)func; exp = exp.Replace(cfef.Name, cfef.NextVal()); break; } } return(exp); }
public static bool Generate(string file1, string file2, string folder, string[] extensions, out string expression, out List <ConstantFileFunction> functions) { expression = string.Empty; functions = new List <ConstantFileFunction>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(file1, file2); if (diffs.Count > 0) { string file1_beginning, file1_ending, file2_beginning, file2_ending; string common_beginning, common_ending; int file1_beginning_fpos, file1_ending_ipos, file2_beginning_fpos, file2_ending_ipos; bool has_beginning, has_ending; file1_beginning = file1_ending = file2_beginning = file2_ending = common_beginning = common_ending = string.Empty; file1_beginning_fpos = file1_ending_ipos = file2_beginning_fpos = file2_ending_ipos = -1; has_beginning = has_ending = false; // get the ending positions of the beginning of the file name or the first position of file name's ending if (diffs[0].First.First > 0) { file1_beginning_fpos = diffs[0].First.First - 1; } else { file1_ending_ipos = diffs[diffs.Count - 1].First.First + diffs[diffs.Count - 1].First.Second.Length; } if (diffs[0].Second.First > 0) { file2_beginning_fpos = diffs[0].Second.First - 1; } else { file2_ending_ipos = diffs[diffs.Count - 1].Second.First + diffs[diffs.Count - 1].Second.Second.Length; } // if the final position of the beginning of the file name was found, then try getting te first position of the file name's ending if (file1_beginning_fpos != -1 && diffs.Count > 1) { file1_ending_ipos = diffs[diffs.Count - 1].First.First + diffs[diffs.Count - 1].First.Second.Length; } if (file2_beginning_fpos != -1 && diffs.Count > 1) { file2_ending_ipos = diffs[diffs.Count - 1].Second.First + diffs[diffs.Count - 1].Second.Second.Length; } // generate the beginning and ending tokens if (file1_beginning_fpos != -1) { file1_beginning = file1.Substring(0, file1_beginning_fpos + 1).Trim().ToLower(); } if (file1_ending_ipos != -1) { file1_ending = file1.Substring(file1_ending_ipos, file1.Length - file1_ending_ipos).Trim().ToLower(); } if (file2_beginning_fpos != -1) { file2_beginning = file2.Substring(0, file2_beginning_fpos + 1).Trim().ToLower(); } if (file2_ending_ipos != -1) { file2_ending = file2.Substring(file2_ending_ipos, file2.Length - file2_ending_ipos).Trim().ToLower(); } // check if there is a common file name beginning and ending if (file1_beginning != string.Empty && file1_beginning == file2_beginning) { has_beginning = true; common_beginning = file2_beginning; } if (file1_ending != string.Empty && file1_ending == file2_ending) { has_ending = true; common_ending = file2_ending; } // if there was a beginning or and ending in common, so there's a generalization if (has_beginning || has_ending) { string f_name = "§1"; expression = f_name; ConstantFileFunction cff = new ConstantFileFunction(f_name, common_beginning, common_ending, folder, extensions); functions.Add(cff); } } if (functions.Count > 0) { return(true); } else { return(false); } }
public static Generalization[] Generate(string str1, string str2, TimeSpan time) { List <Generalization> gens = new List <Generalization>(); bool is_file; string folder1, folder2; if (Directory.Exists(str2)) { is_file = false; folder1 = Directory.GetParent(str1).FullName; folder2 = Directory.GetParent(str2).FullName; } else { is_file = true; folder1 = Path.GetDirectoryName(str1); folder2 = Path.GetDirectoryName(str2); } // if both files have the same directory, then there might be a generalization if (folder1 == folder2) { List <ConstantFileFunction> cff = new List <ConstantFileFunction>(); List <ConstantFileFunctionEx> cffe = new List <ConstantFileFunctionEx>(); List <SequentialIntFunction> sifs = new List <SequentialIntFunction>(); List <SequentialCharFunction> scfs = new List <SequentialCharFunction>(); List <ConstantFileExtFunction> cfef = new List <ConstantFileExtFunction>(); List <ConstantTextFunction> ctfs = new List <ConstantTextFunction>(); string expression = string.Empty; string file1 = Path.GetFileNameWithoutExtension(str1); string file2 = Path.GetFileNameWithoutExtension(str2); List <string> extensions = new List <string>(); // detect which file extensions show the operations be applied to if (is_file) { if (Path.GetExtension(str1) == Path.GetExtension(str2) && Path.GetExtension(str1) != string.Empty) { extensions.Add(Path.GetExtension(str2)); } extensions.Add(".*"); } // SequentialIntFunction if (SequentialIntFunction.Generate(file1, file2, out expression, out sifs)) { gens.Add(new FileDeleteGeneralization(expression, sifs.ToArray(), str2, time, 2)); } // SequentialCharFunction if (SequentialCharFunction.Generate(file1, file2, out expression, out scfs)) { gens.Add(new FileDeleteGeneralization(expression, scfs.ToArray(), str2, time, 2)); } // ConstantFileFunction if (ConstantFileFunction.Generate(file1, file2, folder2, extensions.ToArray(), out expression, out cff)) { gens.Add(new FileDeleteGeneralization(expression, cff.ToArray(), str2, time, 2)); } // ConstantFileFunctionEx if (ConstantFileFunctionEx.Generate(file1, file2, folder2, extensions.ToArray(), out expression, out cffe)) { gens.Add(new FileDeleteGeneralization(expression, cffe.ToArray(), str2, time, 2)); } // ConstantFileExtFunction if (ConstantFileExtFunction.Generate(folder2, extensions.ToArray(), out expression, out cfef)) { gens.Add(new FileDeleteGeneralization(expression, cfef.ToArray(), str2, time, 2)); } // ConstantTextFunction if (ConstantTextFunction.Generate(file1, file2, out expression, out ctfs)) { gens.Add(new FileDeleteGeneralization(expression, ctfs.ToArray(), str2, time, 2)); } } return(gens.ToArray()); }