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); } MouseDoubleClickAction action = (MouseDoubleClickAction)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.MouseDoubleClickAction) { MouseDoubleClickAction m_action = (MouseDoubleClickAction)action; if (m_action._button == this._button) { if (this._x <= (int)(m_action._x + MAX_X_OFFSET) && this._x >= (int)(m_action._x - MAX_X_OFFSET) && this._y <= (int)(m_action._y + MAX_Y_OFFSET) && this._y >= (int)(m_action._y - MAX_Y_OFFSET)) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }
public override object Clone() { MouseDoubleClickAction action = new MouseDoubleClickAction(new Window(_window), _button, _x, _y, _modifiers); action.Id = this.Id; action.Time = this.Time; return(action); }
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.MouseDoubleClickAction) { MouseDoubleClickAction m_action = (MouseDoubleClickAction)action; if (m_action._button == this._button) { if (this._x <= (int)(m_action._x + MAX_X_OFFSET) && this._x >= (int)(m_action._x - MAX_X_OFFSET) && this._y <= (int)(m_action._y + MAX_Y_OFFSET) && this._y >= (int)(m_action._y - MAX_Y_OFFSET)) { return(true); } else { return(false); } } else { return(false); } } else { return(false); } } }
public override UserAction Merge(UserAction action) { UserAction ret = null; if (action != null && action.ActionType == UserActionType.MouseClickAction) { MouseClickAction m_action = (MouseClickAction)action; if (this.Window.Handle == m_action.Window.Handle && this.Button == m_action.Button && this.Modifiers == m_action.Modifiers && this.X <= m_action.X + MAX_X_OFFSET && this.X >= m_action.X - MAX_X_OFFSET && this.Y <= m_action.Y + MAX_Y_OFFSET && this.Y >= m_action.Y - MAX_Y_OFFSET) { if ((this.Time - action.Time) <= new TimeSpan(MAX_DOUBLE_CLICK_DELAY * TimeSpan.TicksPerMillisecond)) { ret = new MouseDoubleClickAction(m_action.Window, m_action.Button, m_action.X, m_action.Y, m_action.Modifiers); ret.Time = this._time; } } } return(ret); }
//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]++; }