-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dev time tracker when user is idle for more than 5 mins #3861
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
using Amdocs.Ginger.Repository; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows.Threading; | ||
using amdocs.ginger.GingerCoreNET; | ||
using Amdocs.Ginger.Common; | ||
|
||
namespace Ginger | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add documentation for this class |
||
{ | ||
public class DevTimeTrackerIdle | ||
{ | ||
private readonly DispatcherTimer idleTimer; | ||
private DateTime lastActivity; | ||
private bool isPaused; | ||
|
||
|
||
public DevTimeTrackerIdle() | ||
{ | ||
idleTimer = new DispatcherTimer(); | ||
idleTimer.Interval = TimeSpan.FromMinutes(1); // Check every minute | ||
idleTimer.Tick += IdleTimer_Tick; | ||
idleTimer.Start(); | ||
|
||
lastActivity = DateTime.Now; | ||
isPaused = false; | ||
} | ||
|
||
public void AttachActivityHandlers(UIElement element) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a destructor method which will remove the attached events. |
||
element.MouseMove += OnActivity; | ||
element.KeyDown += OnActivity; | ||
element.MouseDown += OnActivity; | ||
} | ||
|
||
|
||
private void IdleTimer_Tick(object sender, EventArgs e) | ||
{ | ||
if (DateTime.Now - lastActivity > TimeSpan.FromMinutes(5) && !isPaused) | ||
{ | ||
PauseDevelopmentTimeTracker(); | ||
} | ||
} | ||
|
||
private void OnActivity(object sender, EventArgs e) | ||
{ | ||
if (isPaused) | ||
{ | ||
ResumeDevelopmentTimeTracker(); | ||
} | ||
|
||
lastActivity = DateTime.Now; | ||
|
||
} | ||
private List<RepositoryItemBase> _itemsWithPausedDevelopmentTimeTracker = []; | ||
AmanPrasad43 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// Pauses the development time tracker for modified files in the solution. | ||
/// </summary> | ||
public void PauseDevelopmentTimeTracker() | ||
{ | ||
if (WorkSpace.Instance == null || | ||
WorkSpace.Instance.SolutionRepository == null || | ||
WorkSpace.Instance.SolutionRepository.ModifiedFiles == null) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
_itemsWithPausedDevelopmentTimeTracker.Clear(); | ||
List<RepositoryItemBase> modifiedFiles = new(WorkSpace.Instance.SolutionRepository.ModifiedFiles); | ||
|
||
foreach (RepositoryItemBase modifiedFile in modifiedFiles) | ||
{ | ||
if (modifiedFile is GingerCore.BusinessFlow bf && bf.IsTimerRunning()) | ||
{ | ||
bf.StopTimer(); | ||
_itemsWithPausedDevelopmentTimeTracker.Add(bf); | ||
|
||
foreach (GingerCore.Activity bfActivity in bf.Activities) | ||
{ | ||
if (bfActivity.IsTimerRunning()) | ||
{ | ||
bfActivity.StopTimer(); | ||
_itemsWithPausedDevelopmentTimeTracker.Add(bfActivity); | ||
} | ||
} | ||
} | ||
else if (modifiedFile is GingerCore.Activity activity && activity.IsTimerRunning()) | ||
{ | ||
activity.StopTimer(); | ||
_itemsWithPausedDevelopmentTimeTracker.Add(activity); | ||
} | ||
else if (modifiedFile is Amdocs.Ginger.Repository.ApplicationPOMModel applicationPOMModel && applicationPOMModel.IsTimerRunning()) | ||
{ | ||
applicationPOMModel.StopTimer(); | ||
_itemsWithPausedDevelopmentTimeTracker.Add(applicationPOMModel); | ||
} | ||
} | ||
|
||
//Setting flag to true | ||
if (_itemsWithPausedDevelopmentTimeTracker.Count > 0) | ||
{ | ||
isPaused = true; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Reporter.ToLog(eLogLevel.DEBUG, "error while pausing development tracker", ex); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Resumes the development time tracker for paused items. | ||
/// </summary> | ||
public void ResumeDevelopmentTimeTracker() | ||
{ | ||
try | ||
{ | ||
List<RepositoryItemBase> items = new(_itemsWithPausedDevelopmentTimeTracker); | ||
_itemsWithPausedDevelopmentTimeTracker.Clear(); | ||
|
||
foreach (RepositoryItemBase item in items) | ||
{ | ||
if (item is GingerCore.BusinessFlow bf) | ||
{ | ||
bf.StartTimer(); | ||
} | ||
else if (item is GingerCore.Activity activity) | ||
{ | ||
activity.StartTimer(); | ||
} | ||
else if (item is Amdocs.Ginger.Repository.ApplicationPOMModel applicationPOMModel) | ||
{ | ||
applicationPOMModel.StartTimer(); | ||
} | ||
} | ||
|
||
//Setting flag to false | ||
if (_itemsWithPausedDevelopmentTimeTracker.Count == 0) | ||
{ | ||
isPaused = false; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Reporter.ToLog(eLogLevel.DEBUG, "error while resuming development tracker", ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add license part at top of the class