/// <summary> /// Deletes an item from the ggList as specified by the user /// </summary> /// <param name="userCommand">The command issued by the user</param> /// <param name="ggList">The list of task items</param> public override GGResult Execute(string userCommand, GGList list) { Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty)); this.SetGGList(list); if (InvalidInput(userCommand)) { string errorMsg = "Error: Please specify an item id to remove\n"; Debug.WriteLine(errorMsg); return CreateErrorResultInstance(errorMsg); } int itemIndexToShow = GetItemIndexFromUserCommand(userCommand); itemIndex = itemIndexToShow - 1; if (IndexOutOfBounds(itemIndex)) { string errorMsg = string.Format("Error: There is no list item of index {0}\n", itemIndexToShow); Debug.WriteLine(errorMsg); return CreateErrorResultInstance(errorMsg); } GGList ggList = this.GetGGList(); removedGgItem = ggList.GetGGItemAt(itemIndex); ggList.RemoveGGItemAt(itemIndex); this.SetIsSuccessful(true); string successMsg = string.Format(MESSAGE_REMOVE_SUCCESS, removedGgItem.GetDescription()); Debug.WriteLine(successMsg); result = new GGResult(string.Empty, successMsg, itemIndex, GGResult.RESULT_TYPE.RESULT_REMOVE, removedGgItem.GetTag()); //useless to return itemindex since item does not exist return result; }
public override GGResult Execute(string userCommand, GGList ggList) { Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty)); Debug.Assert(ggList != null); this.SetGGList(ggList); userCommand = StripAddCommandFromUserCommand(userCommand).Trim(); try { ThrowExceptionIfIsEmptyInput(userCommand); newGgItem = QuickParser.Parse(userCommand); ggList.AddGGItem(newGgItem); this.SetIsSuccessful(true); string successMsg = string.Format(MESSAGE_ADD_SUCCESS, newGgItem.GetDescription()); Debug.WriteLine(successMsg, "info"); result = CreateResultInstance(successMsg, GGResult.RESULT_TYPE.RESULT_ADD, ggList.IndexOfGGItem(newGgItem),newGgItem.GetTag()); } catch (Exception e) { error = e.Message; string errorMsg = string.Format(MESSAGE_ERROR, error); Debug.WriteLine(errorMsg, "error"); result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); } return result; }
/// <summary> /// Pins path to an item in ggList. /// </summary> /// <param name="ggList">The full list (ggList from GGLogic)</param> /// <param name="itemIndex">The index of the list item</param> /// <param name="updateTo">The new info of the list item</param> /// <returns>The status of the operation</returns> public override GGResult Execute(String userCommand, GGList ggList) { this.SetGGList(ggList); Regex rgx = new Regex("\\s+"); string[] userCommandArray = rgx.Split(userCommand, 2); if (userCommandArray.Count() != 2) { String errorMsg = "Error: Incorrect input"; result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } else { string itemIndexString = userCommandArray[1]; if (!int.TryParse(itemIndexString, out itemIndex)) { String errorMsg = "Error: Incorrect input"; result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } else if (IndexOutOfBounds(itemIndex)) { String errorMsg = String.Format("Error: There is no list item of index {0}\n", itemIndex); result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } else { GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1); string path = itemToChange.GetPath(); if (path.Equals("")) { String errorMsg = String.Format("Error: There is no path pinned to index {0}\n", itemIndex); result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } try { runpath(path); } catch (Exception e) { String errorMsg = String.Format("Error: Invalid path pinned to index {0}\n", itemIndex); result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } String successMsg = String.Format(MESSAGE_ACT_SUCCESS, itemIndex); result = new GGResult(String.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_ACT, itemToChange.GetTag()); return result; } } }
/// <summary> /// Gives a string representation of all the items in the list. /// </summary> /// <returns>A string of all items in ggList</returns> private GGResult DisplayAll() { GGList ggList = this.GetGGList(); string toDisplay = ""; for (int i = 0; i < ggList.CountGGList(); i++) { string toAdd = (i + 1) + ". " + ggList.GetGGItemAt(i).ToString() + "\n"; toDisplay = toDisplay + toAdd; } GGResult result = new GGResult(toDisplay, string.Empty, -1, GGResult.RESULT_TYPE.RESULT_LIST); return result; }
public override GGResult Execute(string userCommand, GGList list) { Invoker invoker = Invoker.GetInstance(); string msg = string.Empty; if (invoker.PopAndUndo()) { msg = successMsg; } else { msg = errorMsg; } GGResult result = new GGResult(string.Empty, msg, -1, GGResult.RESULT_TYPE.RESULT_UNDO); return result; }
/// <summary> /// Updates the description of the indicated item in ggList. /// </summary> /// <param name="ggList">The full list (ggList from GGLogic)</param> /// <param name="itemIndex">The index of the list item</param> /// <param name="updateTo">The new info of the list item</param> /// <returns>The status of the operation</returns> public override GGResult Execute(string userCommand, GGList ggList) { this.SetGGList(ggList); Regex regex = new Regex("\\s+"); string[] userCommandArray = regex.Split(userCommand, 3); if (userCommandArray.Count() < 3) { string errorMsg = "Error: Incorrect input"; // "ch", itemIndex, newInfo result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } string itemIndexString = userCommandArray[1]; string newInfo = userCommandArray[2]; if (NewInfoIsEmpty(newInfo)) { string errorMsg = "Error: What do you want to change to?"; result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } int.TryParse(itemIndexString, out itemIndex); if (IndexOutOfBounds(itemIndex)) { string errorMsg = string.Format("Error: There is no list item of index {0}\n", itemIndex); result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } try { string oldtag = ggList.GetGGItemAt(itemIndex - 1).GetTag(); GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1); ggList.RemoveGGItemAt(itemIndex - 1); GGItem changedItem = DetermineFieldAndChange(newInfo, itemToChange); ggList.InsertGGItem(itemIndex - 1, changedItem); string successMsg = string.Format(MESSAGE_CHANGE_SUCCESS, itemIndex); result = new GGResult(string.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_UPDATE, oldtag); return result; } catch (Exception e) { string errorMsg = "Error: Invalid Input"; result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } }
public override GGResult Execute(string userCommand, GGList list) { string username = string.Empty; string password = string.Empty; try { GetLoginCredentialsFromUserCommand(userCommand, out username, out password); GGSync sync = new GGSync(username, password); bool IsSuccessfulSync = sync.SyncWithGoogleCalendar(list); if (IsSuccessfulSync) result = CreateResultInstance(MESSAGE_SYNC_SUCCESS, GGResult.RESULT_TYPE.RESULT_SYNC); else { result = CreateResultInstance("Sync Error!", GGResult.RESULT_TYPE.RESULT_INVALID); } } catch (FormatException e) { result = CreateResultInstance(e.Message, GGResult.RESULT_TYPE.RESULT_INVALID); } return result; }
/// <summary> /// Loops through GGList and displays relevant items to the user in the console. /// </summary> /// <param name="ggList">The main list</param> /// <param name="userCommand">ls, followed by an empty string, a tag query, or a search query</param> /// <returns> The list of items (in string form) to display to the user.</returns> public override GGResult Execute(string userCommand, GGList ggList) { this.SetGGList(ggList); ggList.SortGGList(); string pattern = "ls\\s*"; Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase); string parameter = rgx.Replace(userCommand, "", 1); // strip "ls" if (IsDisplayAll(parameter)) { result = DisplayAll(); } else if (isDisplayTag(parameter)) { result = DisplayByTag(parameter); } else // search in descriptions { result = DisplayBySearch(parameter); } return result; }
private void HandleAddDelete(GGResult result) { // RefreshContents(nowindex); if (result.GetResultType() == GGResult.RESULT_TYPE.RESULT_ADD) { if (CmdInvoker.GetTagCount(result.GetTag()) == 1) { TEXTBOX_NO++; TagList.Add(result.GetTag()); DeletedTagLists.Add(false); NewRichTextBox(); } } else if(result.GetResultType() == GGResult.RESULT_TYPE.RESULT_REMOVE) //delete { if (CmdInvoker.GetTagCount(result.GetTag()) == -1) { TEXTBOX_NO--; int index = GetTagIndex(result.GetTag()); DeletedTagLists[index] = true; TagList.RemoveAt(index); RTBIndex = GetPrevIndex(); RTBIndex = GetNextIndex(); } } }
private GGResult CreateErrorResultInstance(string errorMsg) { result = new GGResult(string.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; }
public GGResult CreateResultInstance(string message, GGResult.RESULT_TYPE resultType, int itemindex,string tag = "") { Debug.Assert(message != null && !message.Equals(string.Empty)); return new GGResult(string.Empty, message, itemindex, resultType, tag); }
public override GGResult Execute(string userCommand, GGList list) { string errorMsg = "Error: Invalid Input\n"; GGResult result = new GGResult(string.Empty, errorMsg, -1,GGResult.RESULT_TYPE.RESULT_INVALID); return result; }
private GGResult ReturnErrorMessageInResult() { GGResult result = new GGResult(string.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; }
private void HandleUpdate(GGResult result) { // RefreshContents(nowindex); string oldtag = result.GetTag(); string newtag = CmdInvoker.GetGGList().GetGGItemAt(result.GetItemIndex()).GetTag(); if (CmdInvoker.GetTagCount(newtag) == 1) { TEXTBOX_NO++; TagList.Add(newtag); DeletedTagLists.Add(false); NewRichTextBox(); } if (CmdInvoker.GetTagCount(oldtag) == -1) { TEXTBOX_NO--; int index = GetTagIndex(result.GetTag()); DeletedTagLists[index] = true; TagList.RemoveAt(index); RTBIndex = GetPrevIndex(); RTBIndex = GetNextIndex(); } }
private void HandleList(GGResult result) { // command returns something Table t = new Table(); t.Columns.Add(new TableColumn()); t.Columns.Add(new TableColumn()); t.Columns.Add(new TableColumn()); double tablewidth = RTBWidth * (13.2 / 16.0); t.Columns[0].Width = new GridLength(tablewidth / 2); t.Columns[1].Width = new GridLength(tablewidth / 4); t.Columns[2].Width = new GridLength(tablewidth / 4); t.BorderThickness = new Thickness(RTBWidth / 16, 50, 0, 0); t.CellSpacing = 10; t.RowGroups.Add(AddTextChunkToTable(result.GetMainResult())); RTBNow.Document.Blocks.Add(t); }
/// <summary> /// Gives a string representation of all items that match the search word in /// userCommand. /// </summary> /// <param name="searchWord">The word to search for</param> /// <param name="ggList">The main list</param> /// <returns>A string of all items in ggList that contain the word(s) in the search query in their descriptions</returns> private GGResult DisplayBySearch(string searchWord) { GGList ggList = this.GetGGList(); string toDisplay = ""; for (int i = 0; i < ggList.CountGGList(); i++) { GGItem currentItem = ggList.GetGGItemAt(i); string checkDescription = currentItem.GetDescription(); if (FoundWord(checkDescription, searchWord)) { string toAdd = (i + 1) + ". " + currentItem.ToString() + "\n"; toDisplay = toDisplay + toAdd; } } if (toDisplay.Length == 0) { string emptySearchMsg = string.Format(MESSAGE_EMPTY_SEARCH, searchWord); GGResult result = new GGResult(string.Empty, emptySearchMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } else { GGResult result = new GGResult(toDisplay, string.Empty, -1, GGResult.RESULT_TYPE.RESULT_LIST); return result; } }
public void HandleCmd(GGResult result) { txtError.Clear(); RTBNow.Document.Blocks.Clear(); if (result.GetResultType() == GGResult.RESULT_TYPE.RESULT_LIST) { HandleList(result); } else if (result.GetResultType() == GGResult.RESULT_TYPE.RESULT_ADD || result.GetResultType() == GGResult.RESULT_TYPE.RESULT_REMOVE) { HandleAddDelete(result); } else if (result.GetResultType() == GGResult.RESULT_TYPE.RESULT_UPDATE) { HandleUpdate(result); } else if (result.GetResultType() == GGResult.RESULT_TYPE.RESULT_SYNC) { HandleSync(); } if (result.GetResultType() != GGResult.RESULT_TYPE.RESULT_LIST) RefreshContents(RTBIndex); txtError.Text = result.GetNotice(); if (result.GetNotice() != String.Empty) FadeInAndOut(txtError); HistoryList.Add(txtCmdLine.Text); if (HistoryList.Count > 10) HistoryList.RemoveAt(0); HistoryListIndex = 0; txtCmdLine.Text = ""; }
/// <summary> /// Pins path to an item in ggList. /// </summary> /// <param name="ggList">The full list (ggList from GGLogic)</param> /// <param name="itemIndex">The index of the list item</param> /// <param name="updateTo">The new info of the list item</param> /// <returns>The status of the operation</returns> public override GGResult Execute(String userCommand, GGList ggList) { this.SetGGList(ggList); Regex rgx = new Regex("\\s+"); string[] userCommandArray = rgx.Split(userCommand, 3); if (userCommandArray.Count() < 3) { String errorMsg = "Error: Incorrect input"; // "ch", itemIndex, newInfo result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } else { string itemIndexString = userCommandArray[1]; string path = userCommandArray[2].Equals("none") ? "" : userCommandArray[2]; int.TryParse(itemIndexString, out itemIndex); if (IndexOutOfBounds(itemIndex)) { String errorMsg = String.Format("Error: There is no list item of index {0}\n", itemIndex); result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } if (path.Equals("file")) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); if (dlg.ShowDialog() == true) { path = dlg.FileName; } else { String errorMsg = "Error: No File Selected"; // "ch", itemIndex, newInfo result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } } else if (path.Equals("folder")) { System.Windows.Forms.FolderBrowserDialog fb= new System.Windows.Forms.FolderBrowserDialog(); fb.ShowNewFolderButton = true; fb.Description = "Select folder to pin to your item."; if (fb.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = fb.SelectedPath; } else { String errorMsg = "Error: No Folder Selected"; // "ch", itemIndex, newInfo result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID); return result; } } GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1); itemToChange.SetPath(path); String successMsg = path.Equals("") ? String.Format(MESSAGE_PIN_REMOVED,itemIndex) : String.Format(MESSAGE_PIN_SUCCESS, path, itemIndex); result = new GGResult(String.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_PIN, itemToChange.GetTag()); return result; } }