public override bool Equals(UserAction action) { if ((object)action == null) { return(false); } if (this.Id > -1 && action.Id > -1) // id already specified { if (this.Id == action.Id) { return(true); } else { return(false); } } else { if (action.ActionType == UserActionType.FileCreatedAction) { FileCreatedAction f_action = (FileCreatedAction)action; if (Path.GetDirectoryName(this._file) == Path.GetDirectoryName(f_action._file) && Path.GetExtension(this._file) == Path.GetExtension(f_action._file) && (Path.GetFileNameWithoutExtension(this._file) == Path.GetFileNameWithoutExtension(f_action._file) || Diff.IsDiffNumerical(Diff.DiffString(Path.GetFileNameWithoutExtension(this._file), Path.GetFileNameWithoutExtension(f_action._file))))) { return(true); } else { return(false); } } //else if (action.ActionType == UserActionType.FileDeletedAction) //{ // FileDeletedAction f_action = (FileDeletedAction)action; // if (Path.GetDirectoryName(this._file).Length > Path.GetDirectoryName(f_action.FileName).Length && // Path.GetFileName(this._file) == Path.GetFileName(f_action.FileName)) // return true; // else // return false; //} else { return(false); } } }
public override bool Equals(UserAction action) { if ((object)action == null) { return(false); } if (this.Id > -1 && action.Id > -1) // id already specified { if (this.Id == action.Id) { return(true); } else { return(false); } } else { if (action.ActionType == UserActionType.FileRenamedAction) { FileRenamedAction f_action = (FileRenamedAction)action; if (Path.GetDirectoryName(this._old_path) == Path.GetDirectoryName(f_action._old_path) && ((Path.GetDirectoryName(this._old_path) != Path.GetDirectoryName(this._new_path) && Path.GetDirectoryName(f_action._old_path) != Path.GetDirectoryName(f_action._new_path)) || (Path.GetDirectoryName(this._old_path) == Path.GetDirectoryName(this._new_path) && Path.GetDirectoryName(f_action._old_path) == Path.GetDirectoryName(f_action._new_path)))) { if (Diff.IsDiffIdentical(Diff.DiffString(Path.GetFileName(this._old_path), Path.GetFileName(this._new_path)), Diff.DiffString(Path.GetFileName(f_action._old_path), Path.GetFileName(f_action._new_path)))) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }
public static bool Generate(string old_file_name1, string new_file_name1, string old_file_name2, string new_file_name2, string folder, string[] extensions, out string expression, out List <ConstantFileDiffFunction> functions) { expression = string.Empty; functions = new List <ConstantFileDiffFunction>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs1 = Diff.DiffString(old_file_name1, new_file_name1); List <Pair <Pair <int, string>, Pair <int, string> > > diffs2 = Diff.DiffString(old_file_name2, new_file_name2); // if all diffs are identical, between the old and new names... if (Diff.IsDiffIdentical(diffs1, diffs2) && diffs1.Count > 0) { List <int> original_positions = new List <int>(); List <int> replacement_positions = new List <int>(); List <string> original_tokens = new List <string>(); List <string> replacement_tokens = new List <string>(); // store them as they can be reproduced and there is a generalization for (int i = 0; i < diffs2.Count; i++) { Pair <Pair <int, string>, Pair <int, string> > diff = diffs2[i]; original_positions.Add(diff.First.First); replacement_positions.Add(diff.Second.First); original_tokens.Add(diff.First.Second); replacement_tokens.Add(diff.Second.Second); } if (original_positions.Count > 0) // doh, of course it is... xD { string f_name = "§1"; expression = f_name; ConstantFileDiffFunction cfdf = new ConstantFileDiffFunction(f_name, original_positions.ToArray(), replacement_positions.ToArray(), original_tokens.ToArray(), replacement_tokens.ToArray(), folder, extensions); functions.Add(cfdf); } } if (functions.Count > 0) { return(true); } else { return(false); } }
public static bool Generate(string str1, string str2, out string expression, out List <SequentialCharFunction> functions) { expression = string.Empty; functions = new List <SequentialCharFunction>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(str1, str2); if (diffs.Count > 0 && Diff.IsDiffChar(diffs)) { expression = str2; int val1, val2, pos1, pos2; string f_name = string.Empty; List <int> positions_to_replace = new List <int>(); Dictionary <int, int> fpositions_to_replace = new Dictionary <int, int>(); Dictionary <int, string> tokens_to_replace = new Dictionary <int, string>(); Dictionary <int, SequentialCharFunction> funcs_to_add = new Dictionary <int, SequentialCharFunction>(); for (int i = 1; i <= diffs.Count; i++) { Pair <Pair <int, string>, Pair <int, string> > diff = diffs[i - 1]; f_name = diff.Second.Second.Substring(0, diff.Second.Second.Length - 1) + "§" + i.ToString(); val1 = (int)diff.First.Second[diff.First.Second.Length - 1]; pos1 = diff.First.First; val2 = (int)diff.Second.Second[diff.Second.Second.Length - 1]; pos2 = diff.Second.First; if (pos1 == pos2) { //expression = expression.Replace(diff.Second.Second, f_name); SequentialCharFunction func = new SequentialCharFunction(f_name, (char)val2, val2 - val1, 0, 2); //functions.Add(new SequentialCharFunction(f_name, (char)val2, val2 - val1, 0, 2)); if (!positions_to_replace.Contains(pos2)) { positions_to_replace.Add(pos2); fpositions_to_replace.Add(pos2, pos2); tokens_to_replace.Add(pos2, f_name); funcs_to_add.Add(pos2, func); } } } // add functions by its correct order positions_to_replace.Sort(); foreach (int pos in positions_to_replace) { functions.Add(funcs_to_add[pos]); } // replace text beginning from the end of the string positions_to_replace.Reverse(); foreach (int pos in positions_to_replace) { expression = SystemCore.SystemAbstraction.StringUtilities.StringUtility.ReplaceBetweenPositions(expression, pos, fpositions_to_replace[pos], tokens_to_replace[pos]); } } if (functions.Count > 0) { return(true); } else { return(false); } }
public static bool Generate(string str1, string str2, string folder, string extensions, out string expression, out List <SequentialIntFunction> functions) { expression = string.Empty; functions = new List <SequentialIntFunction>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(str1, str2); if (diffs.Count > 0 /*&& Diff.IsDiffNumerical(diffs)*/) { //if (diffs[0].Second.Second == "2") // System.Windows.Forms.MessageBox.Show("woot"); Regex regex = new Regex(@"[0-9]+"); MatchCollection mcol1 = regex.Matches(str1); MatchCollection mcol2 = regex.Matches(str2); if (mcol1.Count != mcol2.Count) { return(false); } expression = str2; int val1, val2, padding, pos1, pos2; string f_name = string.Empty, to_replace = string.Empty; List <int> positions_to_replace = new List <int>(); Dictionary <int, int> fpositions_to_replace = new Dictionary <int, int>(); Dictionary <int, string> tokens_to_replace = new Dictionary <int, string>(); Dictionary <int, SequentialIntFunction> funcs_to_add = new Dictionary <int, SequentialIntFunction>(); for (int i = 1; i <= diffs.Count; i++) { Pair <Pair <int, string>, Pair <int, string> > diff = diffs[i - 1]; f_name = "§" + i.ToString(); //to_replace = diff.Second.Second; //val1 = Int32.Parse(diff.First.Second); //pos1 = diff.First.First; //val2 = Int32.Parse(diff.Second.Second); //pos2 = diff.Second.First; //padding = 0; val1 = val2 = pos1 = pos2 = padding = 0; to_replace = string.Empty; for (int n = 0; n < mcol2.Count; n++) { Match match = mcol2[n]; padding = match.Length; if (diff.Second.First >= match.Index && diff.Second.First <= (match.Index + match.Length - 1)) { val1 = Int32.Parse(mcol1[n].Value); pos1 = mcol1[n].Index; val2 = Int32.Parse(match.Value); pos2 = match.Index; to_replace = match.Value; break; } } if (pos1 == pos2 && to_replace != string.Empty) { //expression = expression.Replace(to_replace, f_name); SequentialIntFunction func = new SequentialIntFunction(f_name, val2, val2 - val1, padding, 0, 2, folder, extensions); //if (!functions.Contains(func)) // functions.Add(func); if (!positions_to_replace.Contains(pos2)) { positions_to_replace.Add(pos2); fpositions_to_replace.Add(pos2, pos2 + to_replace.Length - 1); tokens_to_replace.Add(pos2, f_name); funcs_to_add.Add(pos2, func); } } } // add functions by its correct order positions_to_replace.Sort(); foreach (int pos in positions_to_replace) { functions.Add(funcs_to_add[pos]); } // replace text beginning from the end of the string positions_to_replace.Reverse(); foreach (int pos in positions_to_replace) { expression = SystemCore.SystemAbstraction.StringUtilities.StringUtility.ReplaceBetweenPositions(expression, pos, fpositions_to_replace[pos], tokens_to_replace[pos]); } } if (functions.Count > 0) { return(true); } else { return(false); } }
public override bool Equals(object obj) { if (obj == null) // check if its null { return(false); } if (this.GetType() != obj.GetType()) // check if the type is the same { return(false); } UserAction action = (UserAction)obj; if (action == null) // check if it can be casted { return(false); } //UserAction action; //try //{ // action = (UserAction)obj; // if (action == null) // check if it can be casted // return false; //} //catch //{ // return false; //} if (this.Id > -1 && action.Id > -1) // id already specified { if (this.Id == action.Id) { return(true); } else { return(false); } } else { if (action.ActionType == UserActionType.FileCreatedAction) { FileCreatedAction f_action = (FileCreatedAction)action; if (Path.GetDirectoryName(this._file) == Path.GetDirectoryName(f_action._file) && Path.GetExtension(this._file) == Path.GetExtension(f_action._file) && (Path.GetFileNameWithoutExtension(this._file) == Path.GetFileNameWithoutExtension(f_action._file) || Diff.IsDiffNumerical(Diff.DiffString(Path.GetFileNameWithoutExtension(this._file), Path.GetFileNameWithoutExtension(f_action._file))))) { return(true); } else { return(false); } } //else if (action.ActionType == UserActionType.FileDeletedAction) //{ // FileDeletedAction f_action = (FileDeletedAction)action; // if (Path.GetDirectoryName(this._file).Length > Path.GetDirectoryName(f_action.FileName).Length && // Path.GetFileName(this._file) == Path.GetFileName(f_action.FileName)) // return true; // else // return false; //} else { return(false); } } }
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 bool Generate(string file1, string file2, string folder, string[] extensions, out string expression, out List <ConstantFileFunctionEx> functions) { expression = string.Empty; functions = new List <ConstantFileFunctionEx>(); List <Pair <Pair <int, string>, Pair <int, string> > > diffs = Diff.DiffString(file1, file2); if (diffs.Count > 0) { //int file1_last_token_beginning = 0, file2_last_token_beginning = 0; string token = string.Empty; HashSet <string> file1_tokens = new HashSet <string>(); HashSet <string> file2_tokens = new HashSet <string>(); HashSet <string> common_tokens = new HashSet <string>(); char[] splitter = new char[] { ' ', '_', '-', '.', '\'', ',' }; //// grab the constant tokens //for (int i = 0; i < diffs.Count; i++) //{ // Pair<Pair<int, string>, Pair<int, string>> diff = diffs[i]; // if (diff.First.First > file1_last_token_beginning) // { // token = file1.Substring(file1_last_token_beginning, diff.First.First - file1_last_token_beginning); // file1_tokens.Add(token); // } // file1_last_token_beginning = diff.First.First + diff.First.Second.Length; // if (diff.Second.First > file2_last_token_beginning) // { // token = file2.Substring(file2_last_token_beginning, diff.Second.First - file2_last_token_beginning); // file2_tokens.Add(token); // } // file2_last_token_beginning = diff.Second.First + diff.Second.Second.Length; //} //if (file1_last_token_beginning < file1.Length) //{ // token = file1.Substring(file1_last_token_beginning, file1.Length - file1_last_token_beginning); // file1_tokens.Add(token); //} //if (file2_last_token_beginning < file2.Length) //{ // token = file2.Substring(file2_last_token_beginning, file2.Length - file2_last_token_beginning); // file2_tokens.Add(token); //} //// refine file1 tokens //HashSet<string> refined_tokens = new HashSet<string>(); //foreach (string t in file1_tokens) //{ // string[] ref_ts = t.Trim().Split(new char[] { ' ' }); // foreach (string ref_t in ref_ts) // if (ref_t.Trim() != string.Empty) // refined_tokens.Add(ref_t.ToLower()); //} //file1_tokens = refined_tokens; //// refine file2 tokens //refined_tokens.Clear(); //foreach (string t in file2_tokens) //{ // string[] ref_ts = t.Trim().Split(new char[] { ' ' }); // foreach (string ref_t in ref_ts) // if (ref_t.Trim() != string.Empty) // refined_tokens.Add(ref_t.ToLower()); //} //file2_tokens = refined_tokens; file1_tokens = new HashSet <string>(file1.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); file2_tokens = new HashSet <string>(file2.Split(splitter, StringSplitOptions.RemoveEmptyEntries)); foreach (string token1 in file1_tokens) { foreach (string token2 in file2_tokens) { if (token1.ToLower() == token2.ToLower()) { if (token1.Length > 1) { common_tokens.Add(token1.ToLower()); break; } } } } // if there is more than one common token, there's a generalization if (common_tokens.Count > 0) { string f_name = "§1"; expression = f_name; ConstantFileFunctionEx cffe = new ConstantFileFunctionEx(f_name, common_tokens.ToArray <string>(), folder, extensions); functions.Add(cffe); } } if (functions.Count > 0) { return(true); } else { return(false); } }
public override bool Equals(object obj) { if (obj == null) // check if its null { return(false); } if (this.GetType() != obj.GetType()) // check if the type is the same { return(false); } FileRenamedAction action = (FileRenamedAction)obj; if (action == null) // check if it can be casted { return(false); } if (this.Id > -1 && action.Id > -1) // id already specified { if (this.Id == action.Id) { return(true); } else { return(false); } } else { if (action.ActionType == UserActionType.FileRenamedAction) { if (Path.GetDirectoryName(this._old_path) == Path.GetDirectoryName(action._old_path) && ((Path.GetDirectoryName(this._old_path) != Path.GetDirectoryName(this._new_path) && Path.GetDirectoryName(action._old_path) != Path.GetDirectoryName(action._new_path)) || (Path.GetDirectoryName(this._old_path) == Path.GetDirectoryName(this._new_path) && Path.GetDirectoryName(action._old_path) == Path.GetDirectoryName(action._new_path)))) { if (Diff.IsDiffIdentical(Diff.DiffString(Path.GetFileName(this._old_path), Path.GetFileName(this._new_path)), Diff.DiffString(Path.GetFileName(action._old_path), Path.GetFileName(action._new_path)))) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }