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 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);
        }