Ejemplo n.º 1
0
 public WorkDayParserResult Parse(string userInput, ref WorkDay wdToFill)
 {
     // remove newlines
       userInput = userInput.Replace(Environment.NewLine, "");
       ShortCut wholeDayShortcut;
       userInput = this.PreProcessWholeDayExpansion(userInput, wdToFill.DateTime, out wholeDayShortcut);
       bool ignoreBreakSettings = userInput.StartsWith(automaticPauseDeactivation);
       if (ignoreBreakSettings) {
     userInput = userInput.Substring(2);
       }
       WorkDayParserResult ret = new WorkDayParserResult();
       if (!String.IsNullOrEmpty(userInput)) {
     TimeItem dayStartTime;
     string remainingString;
     string error;
     // should be like "<daystarttime>,..."
     // eg 7,... or 7:30,...
     if (this.GetDayStartTime(userInput, out dayStartTime, out remainingString, out error)) {
       // proceed with parsing items
       var parts = remainingString.SplitWithIgnoreRegions(new[]{itemSeparator}, new IgnoreRegion('(',')'));
       var wdItemsAsString = parts.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
       if (wdItemsAsString.Any()) {
     List<WorkItemTemp> tmpList = new List<WorkItemTemp>();
     foreach (var wdItemString in wdItemsAsString) {
       WorkItemTemp workItem;
       if (this.GetWDTempItem(wdItemString, out workItem, out error, wdToFill.DateTime, wholeDayShortcut)) {
         tmpList.Add(workItem);
       } else {
         ret.Error = error;
         ret.Success = false;
         // todo: fail fast??
       }
     }
     IEnumerable<WorkItem> resultList;
     if (this.ProcessTempWorkItems(dayStartTime, tmpList, ignoreBreakSettings, out resultList, out error)) {
       wdToFill.Clear();
       foreach (var workItem in resultList) {
         wdToFill.AddWorkItem(workItem);
       }
       ret.Success = true;
     } else {
       ret.Error = error;
     }
       } else {
     // this is no error for now
     ret.Success = true;
     ret.Error = "Noch keine Einträge gemacht";
       }
     } else {
       ret.Error = error;
     }
       } else {
     ret.Error = "Noch keine Eingabe";
       }
       return ret;
 }
Ejemplo n.º 2
0
 private void ParseData(string value)
 {
     // do parsing
     if (WorkDayParser.Instance != null)
     {
         WorkDay wd = this;
         this.lastParseResult = WorkDayParser.Instance.Parse(value, ref wd);
         if (!this.LastParseResult.Success)
         {
             // todo what now?
         }
         this.ImportantStuffChanged();
     }
 }
Ejemplo n.º 3
0
 private void ParseData(string value)
 {
     // do parsing
     if (WorkDayParser.Instance != null)
     {
         WorkDay wd = this;
         this.lastParseResult = WorkDayParser.Instance.Parse(value, ref wd); // todo why is this a ref?
         if (this.LastParseResult.Success)
         {
             this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("HoursDuration"));
         }
         else
         {
             // todo what now?
             logger.Error($"Error while parsing the string: {value}");
         }
     }
 }
Ejemplo n.º 4
0
 private void ParseData(string value)
 {
     // do parsing
       if (WorkDayParser.Instance != null) {
     WorkDay wd = this;
     this.lastParseResult = WorkDayParser.Instance.Parse(value, ref wd);
     if (!this.LastParseResult.Success) {
       // todo what now?
     }
     this.ImportantStuffChanged();
       }
 }
Ejemplo n.º 5
0
        public WorkDayParserResult Parse(string userInput, ref WorkDay wdToFill)
        {
            // remove newlines
            userInput = userInput.Replace(Environment.NewLine, "");
            ShortCut wholeDayShortcut;

            userInput = this.PreProcessWholeDayExpansion(userInput, wdToFill.DateTime, out wholeDayShortcut);
            bool ignoreBreakSettings = userInput.StartsWith(automaticPauseDeactivation);

            if (ignoreBreakSettings)
            {
                userInput = userInput.Substring(2);
            }
            WorkDayParserResult ret = new WorkDayParserResult();

            if (!String.IsNullOrEmpty(userInput))
            {
                TimeItem dayStartTime;
                string   remainingString;
                string   error;
                // should be like "<daystarttime>,..."
                // eg 7,... or 7:30,...

                if (this.ForceDurationToZero(userInput))
                {
                    ret.Success = true;
                }
                else if (this.GetDayStartTime(userInput, out dayStartTime, out remainingString, out error))
                {
                    // proceed with parsing items
                    var parts           = remainingString.SplitWithIgnoreRegions(new[] { itemSeparator }, new IgnoreRegion('(', ')'));
                    var wdItemsAsString = parts.Where(p => !string.IsNullOrWhiteSpace(p)).ToList();
                    if (wdItemsAsString.Any())
                    {
                        List <WorkItemTemp> tmpList = new List <WorkItemTemp>();
                        foreach (var wdItemString in wdItemsAsString)
                        {
                            WorkItemTemp workItem;
                            if (this.GetWDTempItem(wdItemString, out workItem, out error, wdToFill.DateTime, wholeDayShortcut))
                            {
                                tmpList.Add(workItem);
                            }
                            else
                            {
                                ret.Error   = error;
                                ret.Success = false;
                                // todo: fail fast??
                            }
                        }
                        IEnumerable <WorkItem> resultList;
                        if (this.ProcessTempWorkItems(dayStartTime, tmpList, ignoreBreakSettings, out resultList, out error))
                        {
                            wdToFill.Clear();
                            foreach (var workItem in resultList)
                            {
                                wdToFill.AddWorkItem(workItem);
                            }
                            ret.Success = true;
                        }
                        else
                        {
                            ret.Error = error;
                        }
                    }
                    else
                    {
                        // this is no error for now
                        ret.Success = true;
                        ret.Error   = "Noch keine Einträge gemacht";
                    }
                }
                else
                {
                    ret.Error = error;
                }
            }
            else
            {
                ret.Error = "Noch keine Eingabe";
            }
            return(ret);
        }