Ejemplo n.º 1
0
        public void AddWorkLog(WorkLogEntry entry)
        {
            var timeSpentSeconds = (int)entry.RoundedDuration.TotalSeconds;

            _jira.CreateWorklog(new IssueRef {
                id = entry.IssueKey
            }, timeSpentSeconds, "", entry.Start);
        }
Ejemplo n.º 2
0
 public static OperationResult Success(WorkLogEntry arg)
 {
     return(new OperationResult()
     {
         Status = Status.Success,
         OperationArgument = arg
     });
 }
Ejemplo n.º 3
0
 public static OperationResult Error(string message, WorkLogEntry arg)
 {
     return(new OperationResult()
     {
         Status = Status.Error,
         Message = message,
         OperationArgument = arg
     });
 }
        public void Syncronize(WorkLogEntry workLogEntry)
        {
            if (workLogEntry == null)
            {
                return;
            }

            this.Start           = workLogEntry.Start;
            this.Stop            = workLogEntry.Stop;
            this.Description     = workLogEntry.Description;
            this.RoundedDuration = workLogEntry.RoundedDuration;
            //do not update id, because it uniquely identifies the entry
        }
Ejemplo n.º 5
0
 public OperationResult AddWorkLog(WorkLogEntry entry)
 {
     try
     {
         var timeSpentSeconds = (int)entry.RoundedDuration.TotalSeconds;
         _jira.CreateWorklog(new IssueRef {
             id = entry.IssueKey
         }, timeSpentSeconds, entry.Description, entry.Start);
         return(OperationResult.Success(entry));
     }
     catch (Exception ex)
     {
         return(OperationResult.Error(ex.Message, entry));
     }
 }
Ejemplo n.º 6
0
 public OperationResult DeleteWorkLog(WorkLogEntry entry)
 {
     try
     {
         _jira.DeleteWorklog(new IssueRef()
         {
             id = entry.IssueKey
         }, new Worklog()
         {
             id = entry.Id
         });
         return(OperationResult.Success(entry));
     }
     catch (Exception ex)
     {
         return(OperationResult.Error(ex.Message, entry));
     }
 }
Ejemplo n.º 7
0
 public OperationResult UpdateWorkLog(WorkLogEntry entry)
 {
     try
     {
         _jira.UpdateWorklog(
             new IssueRef()
         {
             id = entry.IssueKey
         },
             new Worklog()
         {
             id               = entry.Id,
             comment          = entry.Description,
             started          = entry.Start,
             timeSpentSeconds = (int)entry.RoundedDuration.TotalSeconds
         });
         return(OperationResult.Success(entry));
     }
     catch (Exception ex)
     {
         return(OperationResult.Error(ex.Message, entry));
     }
 }
Ejemplo n.º 8
0
        public static SyncPlan CreateSyncPlan(WorkLogEntry[] sourceEntries, WorkLogEntry[] targetEntries, bool doPurge)
        {
            if (sourceEntries == null)
            {
                sourceEntries = new WorkLogEntry[0];
            }

            if (targetEntries == null)
            {
                targetEntries = new WorkLogEntry[0];
            }

            var syncPlan = new SyncPlan();

            if (!doPurge)
            {
                syncPlan.ToAdd.AddRange(sourceEntries);
                return(syncPlan);
            }

            var withoutSourceId = targetEntries.Where(e => string.IsNullOrEmpty(e.SourceId)).ToArray();

            syncPlan.ToDeleteOrphaned.AddRange(withoutSourceId);
            targetEntries = targetEntries.Except(withoutSourceId).ToArray();

            var duplicates = targetEntries
                             .GroupBy(e => e.SourceId)
                             .Where(g => g.Count() > 1)
                             .SelectMany(g => g.ToList())
                             .ToList();

            syncPlan.ToDeleteDuplicates.AddRange(duplicates);
            targetEntries = targetEntries.Except(duplicates).ToArray();

            var orphaned =
                targetEntries.Where(target => !sourceEntries.Any(source => source.SourceId == target.SourceId && source.IssueKey == target.IssueKey)).ToArray();

            syncPlan.ToDeleteOrphaned.AddRange(orphaned);
            targetEntries = targetEntries.Except(orphaned).ToArray();

            var newSourceEntries =
                sourceEntries.Where(source => targetEntries.All(target => target.SourceId != source.SourceId)).ToArray();

            syncPlan.ToAdd.AddRange(newSourceEntries);
            sourceEntries = sourceEntries.Except(newSourceEntries).ToArray();

            var sourceLookup          = sourceEntries.ToDictionary(s => s.SourceId);
            var toUpdateTargetEntries = targetEntries
                                        .Where(target => sourceLookup.ContainsKey(target.SourceId) && target.DifferentFrom(sourceLookup[target.SourceId]))
                                        .Select(target => { target.Syncronize(sourceLookup[target.SourceId]); return(target); }).ToList();

            syncPlan.ToUpdate.AddRange(toUpdateTargetEntries);
            targetEntries = targetEntries.Except(toUpdateTargetEntries).ToArray();
            sourceEntries = sourceEntries.Except(sourceEntries.Where(source => toUpdateTargetEntries.Any(e => e.SourceId == source.SourceId))).ToArray();

            var entriesWithNoChanges = targetEntries
                                       .Where(target => sourceLookup.ContainsKey(target.SourceId) && !target.DifferentFrom(sourceLookup[target.SourceId])).ToArray();

            syncPlan.NoChanges.AddRange(entriesWithNoChanges);
            targetEntries = targetEntries.Except(entriesWithNoChanges).ToArray();
            sourceEntries = sourceEntries.Except(sourceEntries.Where(source => entriesWithNoChanges.Any(e => e.SourceId == source.SourceId))).ToArray();

            //at this point only new source entries left
            syncPlan.ToAdd.AddRange(sourceEntries);

            return(syncPlan);
        }
Ejemplo n.º 9
0
 public void AddWorkLog(WorkLogEntry entry)
 {
     _target.AddWorkLog(entry);
 }
 public bool DifferentFrom(WorkLogEntry workLogEntry)
 {
     return(this.Start != workLogEntry.Start ||
            this.Description != workLogEntry.Description ||
            this.RoundedDuration != workLogEntry.RoundedDuration);
 }