/// <summary> /// Handles changes to properties on the settings service. /// In particular, whether the clipboard timer is enabled. /// </summary> /// <param name="sender">The settings service whose property changed.</param> /// <param name="e">Event args for the property change.</param> private void OnSettingsServicePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(this.settingsService.EnableClipboardTimer)) { OnPropertyChanged(nameof(UserNameClearEnabled)); OnPropertyChanged(nameof(PasswordClearEnabled)); OnPropertyChanged(nameof(OtherClearEnabled)); // If the timer has been disabled, kill any existing timers. if (!this.settingsService.EnableClipboardTimer) { if (this.currentTimer != null) { this.currentTimer.Tick -= OnTimerTick; this.currentTimer.Stop(); this.currentTimer = null; this.currentTimerType = ClipboardOperationType.None; NormalizedUserNameTimeRemaining = 0; NormalizedPasswordTimeRemaining = 0; NormalizedOtherTimeRemaining = 0; OnPropertyChanged(nameof(NormalizedTimeRemaining)); OnPropertyChanged(nameof(TimeRemainingInSeconds)); } } } }
/// <summary> /// Sets the data object. /// </summary> /// <param name="pData">The parent data.</param> /// <param name="pOperation">The parent operation.</param> public void SetDataObject(TreeNode pData, ClipboardOperationType pOperation) { RemoveCutMark(); data = pData; operationType = pOperation; if (pOperation == ClipboardOperationType.Cut) { data.ForeColor = Color.LightGray; } }
/// <summary> /// Helper to handle the case where the timer is at 0. /// </summary> private void CheckTimerCompletion() { // Check to see if the timer is done. if (this.currentTimer != null && NormalizedTimeRemaining == 0) { this.currentTimer.Tick -= OnTimerTick; this.currentTimer.Stop(); this.currentTimer = null; this.syncContext.Post(FireTimerComplete); this.currentTimerType = ClipboardOperationType.None; } }
/// <summary> /// Copies sensitive data to the clipboard. /// </summary> /// <param name="credential">The data to copy.</param> /// <param name="copyType">The type of data being copied.</param> public void CopyCredential(string credential, ClipboardOperationType copyType) { if (String.IsNullOrEmpty(credential)) { this.clipboard.SetContent(null); } else { this.clipboard.SetContent(credential); FireCredentialCopied(copyType); } }
/// <summary> /// Initializes the ViewModel. /// </summary> /// <param name="settingsService">A service for retrieving app settings.</param> public SettingsBasedClipboardClearViewModel( ITimerFactory timerFactory, ISyncContext syncContext, IAppSettingsService settingsService ) { this.timerFactory = timerFactory; this.syncContext = syncContext; this.settingsService = settingsService; this.currentTimerType = ClipboardOperationType.None; this.durationOfCurrentTimerInSeconds = 0; this.elapsedTimeInSeconds = 0; NormalizedUserNameTimeRemaining = 0; NormalizedPasswordTimeRemaining = 0; NormalizedOtherTimeRemaining = 0; }
/// <summary> /// Initializes the EventArgs instance. /// </summary> /// <param name="timerType">The type of timer (e.g., username, password) associated with this event.</param> public ClipboardTimerCompleteEventArgs(ClipboardOperationType timerType) { TimerType = timerType; Handled = false; }
/// <summary> /// Starts the clipboard clear timer, resetting any existing timers. /// If the specified timer is not enabled, this call is ignored. /// </summary> /// <param name="timerType">The type of clipboard timer being started.</param> public void StartTimer(ClipboardOperationType timerType) { if (timerType == ClipboardOperationType.None) { throw new ArgumentException("cannot start a timer with no type", nameof(timerType)); } bool timerEnabled = false; switch (timerType) { case ClipboardOperationType.UserName: timerEnabled = UserNameClearEnabled; break; case ClipboardOperationType.Password: timerEnabled = PasswordClearEnabled; break; case ClipboardOperationType.Other: timerEnabled = OtherClearEnabled; break; default: throw new InvalidOperationException(); } if (!timerEnabled) { return; } // If we have an existing timer, kill it. if (this.currentTimer != null) { this.currentTimer.Tick -= OnTimerTick; this.currentTimer.Stop(); } // Set up the new timer. this.currentTimerType = timerType; switch (timerType) { case ClipboardOperationType.UserName: NormalizedUserNameTimeRemaining = 1; NormalizedPasswordTimeRemaining = 0; NormalizedOtherTimeRemaining = 0; break; case ClipboardOperationType.Password: NormalizedUserNameTimeRemaining = 0; NormalizedPasswordTimeRemaining = 1; NormalizedOtherTimeRemaining = 0; break; case ClipboardOperationType.Other: NormalizedUserNameTimeRemaining = 0; NormalizedPasswordTimeRemaining = 0; NormalizedOtherTimeRemaining = 1; break; default: throw new InvalidOperationException(); } this.durationOfCurrentTimerInSeconds = this.settingsService.ClearClipboardOnTimer; this.elapsedTimeInSeconds = 0; this.currentTimer = this.timerFactory.Assemble(TimeSpan.FromSeconds(TimerIntervalInSeconds)); this.currentTimer.Tick += OnTimerTick; this.currentTimer.Start(); }
public ClipboardData(IEnumerable<Uri> paths, ClipboardOperationType oper) { Paths = paths.ToList(); Operation = oper; }
public ClipboardData(List<Uri> paths, ClipboardOperationType oper) { Paths = paths; Operation = oper; }
/// <summary> /// Starts the clipboard timer. /// </summary> /// <param name="sender">The ClipboardService.</param> /// <param name="args">The type of copy operation.</param> private void ClipboardService_CredentialCopied(ISensitiveClipboardService sender, ClipboardOperationType args) { ClipboardClearViewModel.StartTimer(args); }
public ClipboardBufferData(GroupType groupType, ClipboardOperationType opType, IList <ProjectElementBase> elements) { this.groupType = groupType; this.opType = opType; this.elements = new List <ProjectElementBase>(elements); }
public ClipboardBufferData(GroupType groupType, ClipboardOperationType opType, params ProjectElementBase[] elements) : this(groupType, opType, new List <ProjectElementBase>(elements)) { }
public ClipboardBufferData(ClipboardOperationType opType, IList <ProjectElementBase> elements) : this(CheckGroupValid(elements), opType, new List <ProjectElementBase>(elements)) { }
/// <summary> /// Fires the <see cref="CredentialCopied"/> event. /// </summary> /// <param name="copyType"></param> private void FireCredentialCopied(ClipboardOperationType copyType) { CredentialCopied?.Invoke(this, copyType); }
/// <summary> /// Creates an instance with the specified type of copy operation. /// </summary> /// <param name="type">The type of copy being performed (name vs password).</param> public CopyRequestedEventArgs(IKeePassEntry entry, ClipboardOperationType type) { Entry = entry; CopyType = type; }