Example #1
0
        private bool GetWDTempItem(string wdItemString, out WorkItemTemp workItem, out string error, DateTime dateTime, ShortCut wholeDayShortcut)
        {
            bool success = false;

            workItem = null;
            error    = string.Empty;
            // check for pause item
            if (wdItemString.EndsWith(pauseChar.ToString()))
            {
                if (wdItemString.StartsWith(endTimeStartChar.ToString()))
                {
                    TimeItem ti;
                    var      parsePart          = wdItemString.Substring(1, wdItemString.Length - 2);
                    var      parsePartNoComment = parsePart.TokenReturnInputIfFail("(", 1);
                    if (TimeItem.TryParse(parsePartNoComment, out ti))
                    {
                        workItem = new WorkItemTemp(wdItemString);
                        workItem.DesiredEndtime = ti;
                        workItem.IsPause        = true;
                        success = true;
                    }
                }
                else
                {
                    double pauseDuration;
                    var    parsePart          = wdItemString.Substring(0, wdItemString.Length - 1);
                    var    parsePartNoComment = parsePart.TokenReturnInputIfFail("(", 1);
                    if (double.TryParse(parsePartNoComment, NumberStyles.Float, CultureInfo.InvariantCulture, out pauseDuration))
                    {
                        workItem           = new WorkItemTemp(wdItemString);
                        workItem.HourCount = pauseDuration;
                        workItem.IsPause   = true;
                        success            = true;
                    }
                }
            }
            else
            {
                // workitem: <count of hours|-endtime>;<projectnumber>-<positionnumber>[(<description>)]
                var timeString = wdItemString.Token(hourProjectInfoSeparator.ToString(), 1, wdItemString).Trim();
                if (!string.IsNullOrEmpty(timeString))
                {
                    if (timeString.StartsWith(endTimeStartChar.ToString()))
                    {
                        TimeItem ti;
                        if (TimeItem.TryParse(timeString.Substring(1), out ti))
                        {
                            workItem = new WorkItemTemp(wdItemString);
                            workItem.DesiredEndtime = ti;
                        }
                        else
                        {
                            error = string.Format("Die Endzeit kann nicht erkannt werden: {0}", timeString);
                        }
                    }
                    else
                    {
                        double hours;
                        if (double.TryParse(timeString, NumberStyles.Float, CultureInfo.InvariantCulture, out hours))
                        {
                            workItem           = new WorkItemTemp(wdItemString);
                            workItem.HourCount = hours;
                        }
                        else
                        {
                            error = string.Format("Die Stundeninfo kann nicht erkannt werden: {0}", timeString);
                        }
                    }
                    if (workItem != null)
                    {
                        var projectPosDescString = wdItemString.Substring(wdItemString.IndexOf(hourProjectInfoSeparator) + 1).Trim();
                        if (!string.IsNullOrEmpty(projectPosDescString))
                        {
                            // expand abbreviations
                            if (this.settings != null)
                            {
                                var      abbrevStringNoComment = projectPosDescString.TokenReturnInputIfFail("(", 1).Trim();
                                var      abbrevString          = abbrevStringNoComment.TokenReturnInputIfFail("-", 1).Trim();
                                var      posReplaceString      = abbrevStringNoComment.Token("-", 2).Trim();
                                ShortCut shortCut = this.settings.GetValidShortCuts(dateTime).Where(s => !s.WholeDayExpansion).FirstOrDefault(s => s.Key == abbrevString);
                                if (shortCut != null)
                                {
                                    workItem.ShortCut = shortCut;
                                    var expanded = shortCut.Expansion;
                                    // if there is an desc given use its value instead of the one in the abbrev
                                    var desc         = DescriptionParser.ParseDescription(projectPosDescString);
                                    var descExpanded = DescriptionParser.ParseDescription(expanded);
                                    if (!string.IsNullOrWhiteSpace(desc.Description) && desc.UsedAppendDelimiter)
                                    {
                                        // append description in expanded
                                        expanded = string.Format("{0}({1}{2})", this.replacePosIfNecessary(descExpanded.BeforeDescription, posReplaceString), descExpanded.Description, desc.Description);
                                    }
                                    else if (!string.IsNullOrWhiteSpace(desc.Description))
                                    {
                                        // replace to description in expanded
                                        expanded = string.Format("{0}({1})", this.replacePosIfNecessary(descExpanded.BeforeDescription, posReplaceString), desc.Description);
                                    }
                                    else
                                    {
                                        expanded = this.replacePosIfNecessary(expanded, posReplaceString);
                                    }
                                    projectPosDescString = expanded;
                                }
                                else if (wholeDayShortcut != null)
                                {
                                    workItem.ShortCut = wholeDayShortcut;
                                }
                            }

                            var projectPosString = projectPosDescString.TokenReturnInputIfFail("(", 1);
                            var parts            = projectPosString.Split(projectPositionSeparator).Select(s => s.Trim()).ToList();
                            if (parts.Any())
                            {
                                workItem.ProjectString = parts.ElementAtOrDefault(0);
                                workItem.PosString     = parts.ElementAtOrDefault(1) ?? string.Empty;
                                success = true;
                            }
                            else
                            {
                                error = string.Format("Projektnummer kann nicht erkannt werden: {0}", projectPosDescString);
                            }
                            var descNoExpand = DescriptionParser.ParseDescription(projectPosDescString);
                            if (!string.IsNullOrWhiteSpace(descNoExpand.Description))
                            {
                                workItem.Description = descNoExpand.Description;
                            }
                        }
                        else
                        {
                            error = string.Format("Projektnummer ist leer: {0}", wdItemString);
                        }
                    }
                }
                else
                {
                    error = string.Format("Stundenanzahl kann nicht erkannt werden: {0}", wdItemString);
                }
            }
            return(success);
        }
Example #2
0
        private bool ProcessTempWorkItems(TimeItem dayStartTime, IEnumerable <WorkItemTemp> tmpList, bool ignoreBreakSettings, out IEnumerable <WorkItem> resultList, out string error)
        {
            bool success = false;

            error = string.Empty;
            List <WorkItem> resultListTmp = new List <WorkItem>();
            TimeItem        lastTime      = dayStartTime;

            foreach (var workItemTemp in tmpList)
            {
                try
                {
                    // check for pause
                    if (workItemTemp.IsPause)
                    {
                        if (workItemTemp.DesiredEndtime != null)
                        {
                            lastTime = workItemTemp.DesiredEndtime;
                        }
                        else
                        {
                            lastTime += workItemTemp.HourCount;
                        }
                    }
                    else
                    {
                        bool     endTimeMode = false; // if endTimeMode do not add, but substract break!
                        TimeItem currentEndTime;
                        if (workItemTemp.DesiredEndtime != null)
                        {
                            currentEndTime = workItemTemp.DesiredEndtime;
                            endTimeMode    = true;
                        }
                        else
                        {
                            currentEndTime = lastTime + workItemTemp.HourCount;
                        }
                        // check for split
                        if (this.settings != null && this.settings.InsertDayBreak && !ignoreBreakSettings)
                        {
                            if (endTimeMode && currentEndTime.IsBetween(this.settings.DayBreakTime, this.settings.DayBreakTime + this.settings.DayBreakDurationInMinutes / 60d))
                            {
                                success = false;
                                error   = string.Format("Der Eintrag {0} hat eine absolute Endzeit und endet in der automatischen Tagespause( {1} + {2}min ). Das ist nicht auflösbar.", workItemTemp.OriginalString, this.settings.DayBreakTime, this.settings.DayBreakDurationInMinutes);
                                break;
                            }
                            // the break is in an item
                            if (this.settings.DayBreakTime.IsBetween(lastTime, currentEndTime))
                            {
                                // insert new item
                                resultListTmp.Add(new WorkItem(lastTime, this.settings.DayBreakTime, workItemTemp.ProjectString, workItemTemp.PosString, workItemTemp.Description, workItemTemp.ShortCut, workItemTemp.OriginalString));
                                lastTime = this.settings.DayBreakTime + this.settings.DayBreakDurationInMinutes / 60d;
                                if (!endTimeMode)
                                {
                                    // fixup currentEndTime, need to add the dayshiftbreak
                                    currentEndTime = currentEndTime + this.settings.DayBreakDurationInMinutes / 60d;
                                }
                            }
                            else if (this.settings.DayBreakTime.Equals(lastTime))
                            {
                                lastTime = lastTime + this.settings.DayBreakDurationInMinutes / 60d;
                                if (!endTimeMode)
                                {
                                    currentEndTime = currentEndTime + this.settings.DayBreakDurationInMinutes / 60d;
                                }
                            }
                        }
                        resultListTmp.Add(new WorkItem(lastTime, currentEndTime, workItemTemp.ProjectString, workItemTemp.PosString, workItemTemp.Description, workItemTemp.ShortCut, workItemTemp.OriginalString));
                        lastTime = currentEndTime;
                        success  = true;
                    }
                }
                catch (Exception exception)
                {
                    error   = string.Format("Beim Verarbeiten von \"{0}\" ist dieser Fehler aufgetreten: \"{1}\"", workItemTemp.OriginalString, exception.Message);
                    success = false;
                }
            }
            resultList = resultListTmp;
            return(success);
        }