Ejemplo n.º 1
0
        public TimeSpan GetCurrentLoggedTimeForDate(DateTime date, User user)
        {
            var loggedTime = new TimeSpan();

            foreach (var worklog in fields.worklog.worklogs.Where(worklog => worklog.started.Date == date.Date && worklog.author.name.ToLower() == user.key.ToLower()))
            {
                try
                {
                    loggedTime = loggedTime.Add(new TimeSpan(0, 0, (int)worklog.timeSpentSeconds));    
                }
                catch (OverflowException)
                {
                    //If overflow just omit that value
                }
            }

            return loggedTime;
        }
Ejemplo n.º 2
0
        public void RefreshFromJira(Issue jiraIssue, User currentUser)
        {
            if (jiraIssue == null) return;

            SetJiraExportedTime(jiraIssue.GetCurrentLoggedTimeForDate(DateStarted, currentUser));
            JiraReference = jiraIssue.key;
            JiraProjectName = jiraIssue.fields.project.key;
            JiraName = jiraIssue.fields.summary;
            if (jiraIssue.fields.parent != null)
            {
                JiraParentReference = jiraIssue.fields.parent.key;
                JiraParentName = jiraIssue.fields.parent.fields.summary;
            }
            else
            {
                JiraParentReference = string.Empty;
                JiraParentName = string.Empty;
            }

            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("ExactCurrentTime"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("TimeToExport"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("JiraReference"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("JiraProjectName"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("JiraName"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("JiraParentReference"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("JiraParentName"));
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("HasParent"));
        }
Ejemplo n.º 3
0
        private void CheckAndConnectJira()
        {
            if (jira == null)
            {
                try
                {
                    jira = JiraClientFactory.BuildJiraClient(jiraConnectionSettings.JiraUrl, jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword);

                    CurrentUser = jira.GetCurrentUser();
                    LoggedIn?.Invoke(this, null);

                    TrackingType trackingType;
                    if (jira.GetType() == typeof(JiraRestClient))
                    {
                        trackingType = jiraConnectionSettings.JiraUrl.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudRest : TrackingType.JiraConnectSelfhostRest;
                    }
                    else
                    {
                        trackingType = jiraConnectionSettings.JiraUrl.Contains(".atlassian.net") ? TrackingType.JiraConnectCloudSoap : TrackingType.JiraConnectSelfhostSoap;
                    }

                    trackUsage.TrackAppUsage(trackingType);

                }
                catch (InvalidCredentialException)
                {
                    throw new MissingJiraConfigException("Required settings to create connection to jira are missing");
                }
                catch (Exception ex)
                {
                    throw new JiraConnectionException("Error creating instance of Jira", ex);
                }
            }
        }
Ejemplo n.º 4
0
 public void RefreshFromJira(Guid uniqueId, Issue jiraIssue, User currentUser)
 {
     var timer = GetTimer(uniqueId);
     if (timer != null)
     {
         timer.RefreshFromJira(jiraIssue);
         timer.UpdateExportTimeFromJira(jiraIssue, currentUser);
         SaveTimers();
     }
 }
Ejemplo n.º 5
0
 public void RefreshFromJira(Guid uniqueId, Issue jiraIssue, User currentUser)
 {
     var timer = GetTimer(uniqueId);
     timer.RefreshFromJira(jiraIssue, currentUser);
     SaveTimers();
 }
Ejemplo n.º 6
0
        private void CheckAndConnectJira(bool useRestApi = true)
        {
            if (jira == null)
            {
                if (string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraUrl) ||
                    string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraUsername) ||
                    string.IsNullOrWhiteSpace(jiraConnectionSettings.JiraPassword))
                {
                    throw new MissingJiraConfigException("Required settings to create connection to jira are missing");
                }

                try
                {
                    if (useRestApi)
                    {
                        jira = new JiraRestClient(jiraConnectionSettings.JiraUrl.Replace("/secure/Dashboard.jspa", ""), jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword);
                    }
                    else
                    {
                        jira = new JiraSoapClient(jiraConnectionSettings.JiraUrl.Replace("/secure/Dashboard.jspa", ""), jiraConnectionSettings.JiraUsername, jiraConnectionSettings.JiraPassword);
                    }

                    CurrentUser = jira.GetCurrentUser();
                }
                catch (Exception ex)
                {
                    jira = null;
                    if (useRestApi)
                    {
                        CheckAndConnectJira(false);
                    }
                    else
                    {
                        throw new JiraConnectionException("Error creating instance of Jira", ex);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void UpdateExportTimeFromJira(Issue jiraIssue, User currentUser)
        {
            if (jiraIssue == null) return;

            LocalTimer = false;

            SetJiraExportedTime(jiraIssue.GetCurrentLoggedTimeForDate(DateStarted, currentUser));

            LastJiraTimeCheck = DateTime.UtcNow;

            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ExactCurrentTime"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("TimeToExport"));
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LastJiraTimeCheck"));
        }