public override object Clone() { TypeTextAction action = new TypeTextAction(new Window(_window), Text); action.Id = this.Id; action.Time = this.Time; return(action); }
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); } TypeTextAction action = (TypeTextAction)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 (this.Text == action.Text) { return(true); } else { return(false); } } }
public override UserAction Merge(UserAction action) { UserAction ret = null; if (action != null) { if (action.ActionType == UserActionType.TypeTextAction) { TypeTextAction t_action = (TypeTextAction)action; if (this.Window.Handle == t_action.Window.Handle) { string c_a = t_action.Text; string c_b = this.Text; ret = new TypeTextAction(t_action.Window, c_a + c_b); ret.Time = this._time; } } } return(ret); }
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.TypeTextAction) { TypeTextAction t_action = (TypeTextAction)action; if (this.Text == t_action.Text) { return(true); } else { return(false); } } else { return(false); } } }
//private static bool _test = false; private void AssignValidId(UserAction action) { // find the last logged action that is of the same kind of the new one UserAction same_kind = null; UserAction regeneralize = null; Generalizations.Generalization[] generalizations = new Generalizations.Generalization[0]; bool break_loop = false; for (int i = UserActions.Count - 1; i >= 0; i--) { //if (UserActions[i].Equals(action)) //{ // same_kind = UserActions[i]; //} if (action.GetType() == UserActions[i].GetType()) { switch (action.ActionType) { case UserAction.UserActionType.KeyPressAction: { KeyPressAction old_action = (KeyPressAction)UserActions[i]; KeyPressAction new_action = (KeyPressAction)action; generalizations = KeyGeneralization.Generate(old_action.QuickDescription, new_action.QuickDescription, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = KeyGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } break; case UserAction.UserActionType.TypeTextAction: { TypeTextAction old_action = (TypeTextAction)UserActions[i]; TypeTextAction new_action = (TypeTextAction)action; //if (new_action.Text == "ola 3 ") // _test = true; //if (_test && new_action.Text == "ola 3") // System.Windows.Forms.MessageBox.Show("test"); generalizations = TextGeneralization.Generate(old_action.Text, new_action.Text, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = TextGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } break; case UserAction.UserActionType.MouseClickAction: { MouseClickAction old_action = (MouseClickAction)UserActions[i]; MouseClickAction new_action = (MouseClickAction)action; if (old_action.Window.Handle == new_action.Window.Handle && old_action.Button == new_action.Button && old_action.Modifiers == new_action.Modifiers) { generalizations = MouseGeneralization.Generate((int)old_action.X, (int)old_action.Y, (int)new_action.X, (int)new_action.Y, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = MouseGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } else if (_generalizations[UserActions[i].Id][0].Occurrences == 2) { regeneralize = UserActions[i]; break_loop = true; } } else { same_kind = UserActions[i]; break_loop = true; } } } } break; case UserAction.UserActionType.MouseDoubleClickAction: { MouseDoubleClickAction old_action = (MouseDoubleClickAction)UserActions[i]; MouseDoubleClickAction new_action = (MouseDoubleClickAction)action; if (old_action.Window.Handle == new_action.Window.Handle && old_action.Button == new_action.Button && old_action.Modifiers == new_action.Modifiers) { generalizations = MouseGeneralization.Generate((int)old_action.X, (int)old_action.Y, (int)new_action.X, (int)new_action.Y, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = MouseGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } else if (_generalizations[UserActions[i].Id][0].Occurrences == 2) { regeneralize = UserActions[i]; break_loop = true; } } else { same_kind = UserActions[i]; break_loop = true; } } } } break; case UserAction.UserActionType.MouseDragAction: { MouseDragAction old_action = (MouseDragAction)UserActions[i]; MouseDragAction new_action = (MouseDragAction)action; if (old_action.Button == new_action.Button) { generalizations = MouseDragGeneralization.Generate((int)old_action.InitialX, (int)old_action.InitialY, (int)new_action.InitialX, (int)new_action.InitialY, (int)old_action.FinalX, (int)old_action.FinalY, (int)new_action.FinalX, (int)new_action.FinalY, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = MouseDragGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } else if (_generalizations[UserActions[i].Id][0].Occurrences == 2) { regeneralize = UserActions[i]; break_loop = true; } } else { same_kind = UserActions[i]; break_loop = true; } } } } break; case UserAction.UserActionType.MouseWheelSpinAction: { MouseWheelSpinAction old_action = (MouseWheelSpinAction)UserActions[i]; MouseWheelSpinAction new_action = (MouseWheelSpinAction)action; if (((old_action.Delta >= 0 && new_action.Delta >= 0) || (old_action.Delta <= 0 && new_action.Delta <= 0)) && old_action.Window.Handle == new_action.Window.Handle && old_action.Modifiers == new_action.Modifiers) { generalizations = MouseGeneralization.Generate((int)old_action.X, (int)old_action.Y, (int)new_action.X, (int)new_action.Y, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = MouseGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } else if (_generalizations[UserActions[i].Id][0].Occurrences == 2) { regeneralize = UserActions[i]; break_loop = true; } } else { same_kind = UserActions[i]; break_loop = true; } } } } break; case UserAction.UserActionType.FileCreatedAction: { FileCreatedAction old_action = (FileCreatedAction)UserActions[i]; FileCreatedAction new_action = (FileCreatedAction)action; generalizations = FileCreateGeneralization.Generate(old_action.FilePath, new_action.FilePath, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = FileCreateGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } break; case UserAction.UserActionType.FileDeletedAction: { FileDeletedAction old_action = (FileDeletedAction)UserActions[i]; FileDeletedAction new_action = (FileDeletedAction)action; generalizations = FileDeleteGeneralization.Generate(old_action.FilePath, new_action.FilePath, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = FileDeleteGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } break; case UserAction.UserActionType.FileMovedAction: { FileMovedAction old_action = (FileMovedAction)UserActions[i]; FileMovedAction new_action = (FileMovedAction)action; if (old_action.Folder == new_action.Folder) { generalizations = FileMoveGeneralization.Generate(old_action.Folder, new_action.Folder, old_action.FileName, new_action.FileName, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = FileMoveGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } } break; case UserAction.UserActionType.FileRenamedAction: { FileRenamedAction old_action = (FileRenamedAction)UserActions[i]; FileRenamedAction new_action = (FileRenamedAction)action; //if (new_action.NewFile == @"D:\Test\other 2\3_hundred_men_attack #1.txt") // System.Windows.Forms.MessageBox.Show("tf?"); generalizations = FileRenameGeneralization.Generate(old_action.OldFile, old_action.NewFile, new_action.OldFile, new_action.NewFile, new_action.Time - old_action.Time); if (generalizations.Length > 0) { if (_generalizations[UserActions[i].Id].Count > 0) { Generalizations.Generalization[] merged_gens = FileRenameGeneralization.Merge(_generalizations[UserActions[i].Id].ToArray(), generalizations); if (merged_gens.Length > 0) { same_kind = UserActions[i]; break_loop = true; generalizations = merged_gens; } } else { same_kind = UserActions[i]; break_loop = true; } } } break; default: if (UserActions[i].Equals(action)) { //generalizations = TextGeneralization.Generate(((TypeTextAction)UserActions[i]).Text, ((TypeTextAction)action).Text); same_kind = UserActions[i]; break_loop = true; } break; } } if (break_loop) { break; } } if (same_kind != null) // if an action of the same kind exists, get its ID { action.Id = same_kind.Id; if (generalizations.Length == 0) { System.Windows.Forms.MessageBox.Show("A zero length generalization was accepted. This should NEVER happen..."); } _generalizations[action.Id] = new List <ContextLib.DataContainers.Monitoring.Generalizations.Generalization>(generalizations); } else if (regeneralize != null) // there an action to regeneralize { action.Id = GenerateValidId(); _counter_reference[regeneralize.Id]--; regeneralize.Id = action.Id; _counter_reference[action.Id]++; _generalizations[action.Id] = new List <ContextLib.DataContainers.Monitoring.Generalizations.Generalization>(generalizations); } else // else, get a new one { action.Id = GenerateValidId(); } _counter_reference[action.Id]++; }
public override UserAction Merge(UserAction action) { UserAction ret = null; //if (action != null) //{ // if (action.ActionType == UserActionType.KeyPressAction) // { // KeyPressAction k_action = (KeyPressAction)action; // if (this.Window.Handle == k_action.Window.Handle && // ((this.Modifiers == Modifiers.None) || (this.Modifiers == Modifiers.Shift) || (this.Modifiers == Modifiers.CapsLock) || (this.Modifiers == (Modifiers.Alt | Modifiers.Ctrl))) && // ((k_action.Modifiers == Modifiers.None) || (k_action.Modifiers == Modifiers.Shift) || (k_action.Modifiers == Modifiers.CapsLock) || (k_action.Modifiers == (Modifiers.Alt | Modifiers.Ctrl)))) // { // if (this.Key != Keys.Escape && k_action.Key != Keys.Escape) // { // char c_a = k_action.KeyChar; // char c_b = this.KeyChar; // if (c_a != char.MinValue && c_a != '\r' && c_a != '\b' && // c_b != char.MinValue && c_b != '\r' && c_b != '\b') // { // ret = new TypeTextAction(k_action.Window, new string( new char[] { c_a , c_b } )); // ret.Time = this._time; // } // } // } // } // else if (action.ActionType == UserActionType.TypeTextAction) // { // TypeTextAction t_action = (TypeTextAction)action; // if (this.Window.Handle == t_action.Window.Handle && // (this.Modifiers == Modifiers.None) || (this.Modifiers == Modifiers.Shift) || (this.Modifiers == Modifiers.CapsLock) || (this.Modifiers == (Modifiers.Alt | Modifiers.Ctrl))) // { // if (this.Key == Keys.Back) // { // string c_a = t_action.Text; // if (c_a.Length > 1) // { // ret = new TypeTextAction(t_action.Window, c_a.Substring(0, c_a.Length - 1)); // ret.Time = this._time; // } // else // ret = this; // } // else if (this.Key != Keys.Escape) // { // string c_a = t_action.Text; // char c_b = this.KeyChar; // //string c_b = "A"; // if (c_b != char.MinValue && c_b != '\r' && c_b != '\b') // { // ret = new TypeTextAction(t_action.Window, c_a + c_b); // ret.Time = this._time; // } // } // } // } //} if (action.ActionType == UserActionType.TypeTextAction) { TypeTextAction t_action = (TypeTextAction)action; if (this.Window.Handle == t_action.Window.Handle && ((_modifiers == ContextLib.DataContainers.Monitoring.UserAction.Modifiers.None) || (_modifiers == ContextLib.DataContainers.Monitoring.UserAction.Modifiers.Shift) || (_modifiers == ContextLib.DataContainers.Monitoring.UserAction.Modifiers.CapsLock) || (_modifiers == (ContextLib.DataContainers.Monitoring.UserAction.Modifiers.Shift | ContextLib.DataContainers.Monitoring.UserAction.Modifiers.CapsLock)) || (_modifiers == (ContextLib.DataContainers.Monitoring.UserAction.Modifiers.Alt | ContextLib.DataContainers.Monitoring.UserAction.Modifiers.Ctrl)))) { if (this.Key == Keys.Back) { string c_a = t_action.Text; if (c_a.Length > 1) { ret = new TypeTextAction(t_action.Window, c_a.Substring(0, c_a.Length - 1)); ret.Time = this._time; } else { ret = this; } } } } return(ret); }