public ShortCutStatistic(ShortCut sc) : base(sc.Key, sc.Expansion) { this.ID = sc.ID; this.WholeDayExpansion = sc.WholeDayExpansion; this.ValidFrom = sc.ValidFrom; }
public void GetData(ShortCut sc) { this.Key = sc.Key; this.Expansion = sc.Expansion; this.WholeDayExpansion = sc.WholeDayExpansion; this.ValidFrom = sc.ValidFrom; }
public void GetData(ShortCut sc) { this.Key = sc.Key; this.Expansion = sc.Expansion; this.WholeDayExpansion = sc.WholeDayExpansion; this.ValidFrom = sc.ValidFrom; this.Group = sc.Group; }
public ShortCutStatistic(ShortCut sc) : base(sc.Key, sc.Expansion) { this.sourceShortCut = sc; this.ID = sc.ID; this.WholeDayExpansion = sc.WholeDayExpansion; this.ValidFrom = sc.ValidFrom; this.Group = sc.Group; }
public ShortcutViewModel(ShortCut shortCut, WorkWeek workWeek, MoniSettings settings, Action closeAction) { this.viewcloseAction = closeAction; this.moniSettings = settings; this.workWeek = workWeek; this.Model = shortCut ?? new ShortCut(); this.IsNew = shortCut == null; this.ShortCutKey = this.Model.Key; }
public ShortcutViewModel(ShortCut shortCut, WorkWeek workWeek, MoniSettings settings, Action closeAction) { this.viewcloseAction = closeAction; this.MoniSettings = settings; this.workWeek = workWeek; this.Model = shortCut ?? new ShortCut(); this.IsNew = shortCut == null; this.ShortCutKey = this.Model.Key; this.ShortCutGroup = settings.ParserSettings.ShortCutGroups.FirstOrDefault(sg => Equals(sg.Key, this.Model.Group)); this.ShortCutGroupKey = this.Model.Group; }
public void GetValidShortCuts_MultipleKeysInterval_ReturnJustRightShortcuts() { var shortCuts = new List<ShortCut>(); shortCuts.Add(new ShortCut("ctbn", "12345-000")); var findMe = new ShortCut("ctbn", "54321-000", new DateTime(2000,1,1)); shortCuts.Add(findMe); var andMe = new ShortCut("ktln", "25710-420(feature)"); shortCuts.Add(andMe); var matchOnShortcut = new DateTime(2005,1,1); var validShortCuts = WorkDayParserSettings.ValidShortCuts(shortCuts, matchOnShortcut); CollectionAssert.AreEqual(new[] { findMe, andMe }, validShortCuts); }
public void CreatedShortCutShouldShownInNextMonth() { var vm = new MainViewModel(Dispatcher.CurrentDispatcher); var newSc = new ShortCut(); newSc.Key = newSc.ID; newSc.Expansion = "8,8;12345-000"; newSc.ValidFrom = DateTime.Now; vm.EditShortCut = new ShortcutViewModel(newSc, vm.WorkWeek, vm.Settings, null); vm.EditShortCut.SaveShortcut(); var shortCut = vm.WorkWeek.Month.ShortCutStatistic.FirstOrDefault(s => s.Key.Equals(newSc.Key)); Assert.NotNull(shortCut); Assert.AreEqual(newSc.Key, shortCut.Key); vm.SelectDate(vm.WorkWeek.StartDate.AddMonths(1)); shortCut = vm.WorkWeek.Month.ShortCutStatistic.FirstOrDefault(s => s.Key.Equals(newSc.Key)); Assert.NotNull(shortCut); Assert.AreEqual(newSc.Key, shortCut.Key); }
public void AddShortCut(string key, string expansion) { this.ViewModel.PNSearch.IsProjectSearchViewOpen = false; var sc = new ShortCut(key, expansion); this.ViewModel.EditShortCut = new ShortcutViewModel(sc, this.ViewModel.WorkWeek, this.ViewModel.Settings, () => this.ViewModel.EditShortCut = null) { IsNew = true }; }
private string PreProcessWholeDayExpansion(string userInput, DateTime dateTime, out ShortCut wholeDayShortcut) { if (this.settings != null) { var currentShortcuts = this.settings.GetValidShortCuts(dateTime); if (currentShortcuts.Any(sc => sc.WholeDayExpansion)) { var dic = currentShortcuts.Where(sc => sc.WholeDayExpansion).FirstOrDefault(sc => sc.Key == userInput); if (dic != null) { wholeDayShortcut = dic; return dic.Expansion; } } } wholeDayShortcut = null; return userInput; }
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; }
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); }
private string PreProcessWholeDayExpansion(string userInput, DateTime dateTime, out ShortCut wholeDayShortcut) { if (this.settings != null) { var currentShortcuts = this.settings.GetValidShortCuts(dateTime); if (currentShortcuts.Any(sc => sc.WholeDayExpansion)) { var dic = currentShortcuts.Where(sc => sc.WholeDayExpansion).FirstOrDefault(sc => sc.Key == userInput); if (dic != null) { wholeDayShortcut = dic; return(dic.Expansion); } } } wholeDayShortcut = null; return(userInput); }
public void WDParser_ShortcutLinkInWorkItem_WholeDayShortcut() { WorkDay wd = new WorkDay(1, 1, 1, null); var abbr = new List<ShortCut>(); var shortCut = new ShortCut("a", "8,8;11111-111(aa)") { WholeDayExpansion = true }; abbr.Add(shortCut); WorkDayParserSettings workDayParserSettings = new WorkDayParserSettings { ShortCuts = abbr }; WorkDayParser wdp = new WorkDayParser(workDayParserSettings); var workItemParserResult = wdp.Parse("a", ref wd); Assert.IsTrue(workItemParserResult.Success, workItemParserResult.Error); CollectionAssert.IsNotEmpty(wd.Items); CollectionAssert.AreEqual(new[] { new WorkItem(new TimeItem(8), new TimeItem(16), "11111", "111", "aa") }, wd.Items); Assert.IsEmpty(workItemParserResult.Error); Assert.AreEqual(8, wd.HoursDuration); Assert.AreEqual(shortCut, wd.Items.First().ShortCut); }
public void MoveShortcutUp(ShortCut sc) { int idx = this.MonlistSettings.ParserSettings.ShortCuts.IndexOf(sc); if (idx > 0) { this.MonlistSettings.ParserSettings.ShortCuts.Remove(sc); this.MonlistSettings.ParserSettings.ShortCuts.Insert(idx - 1, sc); } this.WorkWeek.Month.ReloadShortcutStatistic(this.MonlistSettings.ParserSettings.GetValidShortCuts(this.WorkWeek.StartDate)); }
public void DeleteShortcut(ShortCut delsc) { this.MonlistSettings.ParserSettings.ShortCuts.Remove(delsc); this.WorkWeek.Month.ReloadShortcutStatistic(this.MonlistSettings.ParserSettings.GetValidShortCuts(this.WorkWeek.StartDate)); this.WorkWeek.Reparse(); }