示例#1
0
        public void DP_AppendDesc_Parse()
        {
            var res = DescriptionParser.ParseDescription("11111-111(+abc)");

            Assert.AreEqual("11111-111", res.BeforeDescription);
            Assert.AreEqual("abc", res.Description);
        }
示例#2
0
        public void DP_AppendWithNormalBrackets_Parse()
        {
            var res = DescriptionParser.ParseDescription("11111-111(+abc(def)ghi)");

            Assert.AreEqual("11111-111", res.BeforeDescription);
            Assert.AreEqual("abc(def)ghi", res.Description);
        }
示例#3
0
        public void DP_NoDesc_Parse()
        {
            var res = DescriptionParser.ParseDescription("11111-111");

            Assert.AreEqual("11111-111", res.BeforeDescription);
            Assert.IsEmpty(res.Description);
        }
示例#4
0
        public void DP_StringEmpty_DoNothing()
        {
            var res = DescriptionParser.ParseDescription(string.Empty);

            Assert.IsEmpty(res.BeforeDescription);
            Assert.IsEmpty(res.Description);
        }
示例#5
0
        public void DP_Null_DoNothing()
        {
            var res = DescriptionParser.ParseDescription(null);

            Assert.IsEmpty(res.BeforeDescription);
            Assert.IsEmpty(res.Description);
        }
示例#6
0
        private void LoadDeviceServices(UPnPDevice device)
        {
            foreach (UPnPService service in device.Services)
            {
                string descriptionXml = DescriptionLoader.LoadDescription(service.BaseUrl + service.ServiceDescriptionUrl).Result;
                DescriptionParser.ParseDescription(service, descriptionXml);
            }

            foreach (UPnPDevice deviceSubDevice in device.SubDevices)
            {
                LoadDeviceServices(deviceSubDevice);
            }
        }
示例#7
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);
        }