/// <summary> /// Handle the SCPUT command. /// </summary> /// <param name="parser">Parser</param> private void ScputCommand(Parser parser) { switch (parser.NextArgument()) { case "script": _script = _scratch.ToString(); _scratch.Clear(); break; } }
/// <summary> /// Handle commands at the Option level /// </summary> /// <param name="parser">Parser object</param> private bool OptionCommand(Parser parser) { string optionArgument = parser.NextArgument(); while (optionArgument != "") { switch (optionArgument) { case "q": QuitState(); return(false); case "file": break; case "terse": _isTerse = true; break; } optionArgument = parser.NextArgument(); } return(false); }
/// <summary> /// Handle the BYE command. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">Parser</param> private bool ByeCommand(LineBuffer buffer, Parser parser) { if (parser.NextArgument() != "y" && _scratch.Length > 0) { buffer.WriteString("OK to delete your scratchpad? (y/n/q)? "); string yesNoQuit = buffer.ReadLine(); if (yesNoQuit == "n") { SaveScratchpad(); } if (yesNoQuit == "q") { return(false); } } return(true); }
/// <summary> /// Comment to an existing message in the specified topic. The message body /// follows in the input stream. The command array contains the argument to the /// comment command. /// </summary> /// <param name="buffer">Input stream</param> /// <param name="parser">Buffer</param> private void CommentCommand(LineBuffer buffer, Parser parser) { if (_currentTopic != null) { int replyNumber = _currentTopic.MessageID; string commentArgument = parser.NextArgument(); if (commentArgument != "") { if (!Int32.TryParse(commentArgument, out replyNumber)) { buffer.WriteLine("Invalid comment number"); return; } } SayOrCommentCommand(buffer, replyNumber); } }
/// <summary> /// Handle the RESIGN command. /// </summary> /// <param name="buffer">Input buffer</param> /// <param name="parser">Parser</param> private void ResignCommand(LineBuffer buffer, Parser parser) { string forumName = parser.NextArgument(); string topicName = string.Empty; if (string.IsNullOrEmpty(forumName)) { if (_currentTopic == null) { buffer.WriteString("Conference name? "); forumName = buffer.ReadLine(); } else { forumName = _currentTopic.Forum.Name; } } else { string[] joinParams = forumName.Split(new[] { '/' }); if (joinParams.Length == 2) { forumName = joinParams[0]; topicName = joinParams[1]; } } if (!_forums.IsJoined(forumName)) { buffer.WriteLine(string.Format("You are not a member of conference '{0}'.", forumName)); return; } buffer.WriteLine(string.Format("Resigning from conference '{0}'.", forumName)); _forums.Resign(forumName, topicName); ChangeState(CoSyState.MAIN); }
/// <summary> /// Handle the SCPUT command. /// </summary> /// <param name="parser">Parser</param> private void ScputCommand(Parser parser) { switch (parser.NextArgument()) { case "script": _script = _scratch.ToString(); _scratch.Clear(); break; } }
/// <summary> /// Handle the RESIGN command. /// /// CAUTION: The API currently doesn't support resigning topics within a forum, although /// the web service apparently seems to. Until this is supported, the resign command will /// resign entire forums. For safety, if a topic name is specified in the argument we /// bail out and do nothing. /// </summary> /// <param name="buffer">Input buffer</param> /// <param name="parser">Parser</param> private void ResignCommand(LineBuffer buffer, Parser parser) { string forumName = parser.NextArgument(); if (string.IsNullOrEmpty(forumName)) { if (_currentTopic == null) { buffer.WriteString("Conference name? "); forumName = buffer.ReadLine(); } else { forumName = _currentTopic.Forum.Name; } } else { string[] joinParams = forumName.Split(new[] {'/'}); if (joinParams.Length == 2) { return; // Bail out if a topic name was specified. } } if (!_forums.IsJoined(forumName)) { buffer.WriteLine(string.Format("You are not a member of conference '{0}'.", forumName)); return; } buffer.WriteLine(string.Format("Resigning from conference '{0}'.", forumName)); _forums.Resign(forumName); ChangeState(CoSyState.MAIN); }
/// <summary> /// Handle commands at the Option level /// </summary> /// <param name="parser">Parser object</param> private bool OptionCommand(Parser parser) { string optionArgument = parser.NextArgument(); while (optionArgument != "") { switch (optionArgument) { case "q": QuitState(); return false; case "file": break; case "terse": _isTerse = true; break; } optionArgument = parser.NextArgument(); } return false; }
/// <summary> /// Handle commands at the main level. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">The command parser</param> private bool MainCommand(LineBuffer buffer, Parser parser) { Parser.ParseToken nextCommand = parser.NextCommand(); if (nextCommand == Parser.ParseToken.FILE) { buffer.Output = _scratch; nextCommand = parser.NextCommand(); } switch (nextCommand) { case Parser.ParseToken.DOWNLOAD: DownloadCommand(buffer); break; case Parser.ParseToken.UPLOAD: UploadCommand(buffer); break; case Parser.ParseToken.OPTION: ChangeState(CoSyState.OPT); OptionCommand(parser); break; case Parser.ParseToken.SCPUT: ScputCommand(parser); break; case Parser.ParseToken.SCRIPT: buffer.Script = _script; break; case Parser.ParseToken.JOIN: JoinCommand(buffer, parser); break; case Parser.ParseToken.RESIGN: ResignCommand(buffer, parser); break; case Parser.ParseToken.READ: if (parser.NextArgument() == "all") { buffer.WriteLine("......"); ReadScratchpad(buffer); buffer.WriteLine(""); ShowScratchpadSize(buffer); } break; case Parser.ParseToken.KILLSCRATCH: _scratch.Clear(); buffer.WriteLine("Scratchpad Deleted"); break; case Parser.ParseToken.BYE: return ByeCommand(buffer, parser); } return false; }
/// <summary> /// Handle the JOIN command. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">Parser</param> private void JoinCommand(LineBuffer buffer, Parser parser) { string forumName = parser.NextArgument(); if (!string.IsNullOrEmpty(forumName)) { string topicName = null; string[] joinParams = forumName.Split(new[] {'/'}); if (joinParams.Length == 2) { forumName = joinParams[0]; topicName = joinParams[1]; } if (!_forums.IsJoined(forumName)) { buffer.WriteString(string.Format("You are not registered in '{0}'. ", forumName)); if (Ask(buffer, "Would you like to register (y/n)? ")) { if (!_forums.Join(forumName)) { buffer.WriteRedirectableLine(string.Format("No conference '{0}'.", forumName)); return; } } } Forum thisForum = _forums[forumName]; Topic thisTopic; do { if (topicName != null && !thisForum.Topics.Contains(topicName)) { buffer.WriteLine("Couldn't find topic: No such file or directory"); buffer.WriteLine(string.Format("Topic '{0}' not found.", topicName)); topicName = thisForum.Topics[0].Name; } if (topicName == null) { buffer.WriteString("Topics are:"); for (int c = 0; c < thisForum.Topics.Count; ++c) { string topicString = thisForum.Topics[c].Name; if (c > 0) { buffer.WriteString(","); } buffer.WriteString(string.Format(" '{0}'", topicString)); } buffer.WriteLine(""); buffer.WriteString("Topic? "); topicName = buffer.ReadLine(); if (topicName == "quit") { return; } } thisTopic = thisForum.Topics[topicName]; } while (thisTopic == null); buffer.WriteRedirectableLine(string.Format("Joining conference '{0}', topic '{1}'. {2} new message(s).", forumName, topicName, thisTopic.Unread)); _currentTopic = thisTopic; ChangeState(CoSyState.READ); } }
/// <summary> /// Comment to an existing message in the specified topic. The message body /// follows in the input stream. The command array contains the argument to the /// comment command. /// </summary> /// <param name="buffer">Input stream</param> /// <param name="parser">Buffer</param> private void CommentCommand(LineBuffer buffer, Parser parser) { if (_currentTopic != null) { int replyNumber = _currentTopic.MessageID; string commentArgument = parser.NextArgument(); if (commentArgument != "") { if (!Int32.TryParse(commentArgument, out replyNumber)) { buffer.WriteLine("Invalid comment number"); return; } } SayOrCommentCommand(buffer, replyNumber); } }
/// <summary> /// Handle the BYE command. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">Parser</param> private bool ByeCommand(LineBuffer buffer, Parser parser) { if (parser.NextArgument() != "y" && _scratch.Length > 0) { buffer.WriteString("OK to delete your scratchpad? (y/n/q)? "); string yesNoQuit = buffer.ReadLine(); if (yesNoQuit == "q") { return false; } } return true; }
/// <summary> /// Handle the JOIN command. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">Parser</param> private void JoinCommand(LineBuffer buffer, Parser parser) { string forumName = parser.NextArgument(); if (!string.IsNullOrEmpty(forumName)) { string topicName = null; string[] joinParams = forumName.Split(new[] { '/' }); if (joinParams.Length == 2) { forumName = joinParams[0]; topicName = joinParams[1]; } if (!_forums.IsJoined(forumName)) { buffer.WriteString(string.Format("You are not registered in '{0}'. ", forumName)); if (Ask(buffer, "Would you like to register (y/n)? ")) { if (!_forums.Join(forumName)) { buffer.WriteRedirectableLine(string.Format("No conference '{0}'.", forumName)); return; } } } Forum thisForum = _forums[forumName]; Topic thisTopic; do { if (topicName != null && !thisForum.Topics.Contains(topicName)) { buffer.WriteLine("Couldn't find topic: No such file or directory"); buffer.WriteLine(string.Format("Topic '{0}' not found.", topicName)); topicName = thisForum.Topics[0].Name; } if (topicName == null) { buffer.WriteString("Topics are:"); for (int c = 0; c < thisForum.Topics.Count; ++c) { string topicString = thisForum.Topics[c].Name; if (c > 0) { buffer.WriteString(","); } buffer.WriteString(string.Format(" '{0}'", topicString)); } buffer.WriteLine(""); buffer.WriteString("Topic? "); topicName = buffer.ReadLine(); if (topicName == "quit") { return; } } thisTopic = thisForum.Topics[topicName]; } while (thisTopic == null); buffer.WriteRedirectableLine(string.Format("Joining conference '{0}', topic '{1}'. {2} new message(s).", forumName, topicName, thisTopic.Unread)); _currentTopic = thisTopic; ChangeState(CoSyState.READ); } }
/// <summary> /// Handle commands at the main level. /// </summary> /// <param name="buffer">Line buffer</param> /// <param name="parser">The command parser</param> private bool MainCommand(LineBuffer buffer, Parser parser) { Parser.ParseToken nextCommand = parser.NextCommand(); if (nextCommand == Parser.ParseToken.FILE) { buffer.Output = _scratch; nextCommand = parser.NextCommand(); } switch (nextCommand) { case Parser.ParseToken.DOWNLOAD: DownloadCommand(buffer); break; case Parser.ParseToken.UPLOAD: UploadCommand(buffer); break; case Parser.ParseToken.OPTION: ChangeState(CoSyState.OPT); OptionCommand(parser); break; case Parser.ParseToken.SCPUT: ScputCommand(parser); break; case Parser.ParseToken.SCRIPT: buffer.Script = _script; break; case Parser.ParseToken.JOIN: JoinCommand(buffer, parser); break; case Parser.ParseToken.RESIGN: ResignCommand(buffer, parser); break; case Parser.ParseToken.READ: if (parser.NextArgument() == "all") { buffer.WriteLine("......"); ReadScratchpad(buffer); buffer.WriteLine(""); ShowScratchpadSize(buffer); } break; case Parser.ParseToken.KILLSCRATCH: _scratch.Clear(); buffer.WriteLine("Scratchpad Deleted"); break; case Parser.ParseToken.BYE: return(ByeCommand(buffer, parser)); } return(false); }