/// <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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Read all unread messages into the scratchpad.
        /// </summary>
        /// <param name="buffer">The I/O buffer</param>
        private static void ReadScratchpad(LineBuffer buffer)
        {
            WebRequest wrGeturl = APIRequest.Get("user/cixtelnetd/65535/0/scratchpad", APIRequest.APIFormat.XML);

            try
            {
                Stream objStream = wrGeturl.GetResponse().GetResponseStream();
                if (objStream != null)
                {
                    using (XmlReader reader = XmlReader.Create(objStream))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Scratchpad));
                        Scratchpad    scratchpad = (Scratchpad)serializer.Deserialize(reader);

                        buffer.WriteRedirectableLine("Checking for conference activity.");

                        Dictionary <string, List <ScratchpadMessagesMsg> > allMessages = new Dictionary <string, List <ScratchpadMessagesMsg> >();

                        foreach (ScratchpadMessagesMsg message in scratchpad.Messages)
                        {
                            string thisTopic = string.Format("{0}/{1}", message.Forum, message.Topic);
                            List <ScratchpadMessagesMsg> topicList;

                            if (!allMessages.TryGetValue(thisTopic, out topicList))
                            {
                                topicList = new List <ScratchpadMessagesMsg>();
                                allMessages[thisTopic] = topicList;
                            }
                            topicList.Add(message);
                        }

                        foreach (string thisTopic in allMessages.Keys)
                        {
                            List <ScratchpadMessagesMsg> topicList = allMessages[thisTopic];
                            buffer.WriteRedirectableLine(string.Format("Joining {0} {1} new message(s).", thisTopic, topicList.Count));

                            foreach (ScratchpadMessagesMsg message in topicList)
                            {
                                string [] monthString = { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };

                                StringBuilder messageHeader = new StringBuilder();
                                messageHeader.AppendFormat(">>>{0} {1} {2}({3})", thisTopic, message.ID, message.Author, message.Body.Length);

                                DateTime messageDate = DateTime.Parse(message.DateTime);

                                messageHeader.AppendFormat("{0}{1}{2} ", messageDate.Day, monthString[messageDate.Month - 1], messageDate.Year - 2000);
                                messageHeader.AppendFormat("{0}:{1}", messageDate.Hour, messageDate.Minute);
                                if (message.ReplyTo != "0")
                                {
                                    messageHeader.AppendFormat(" c{0}", message.ReplyTo);
                                }
                                buffer.WriteRedirectableLine(messageHeader.ToString());
                                buffer.WriteRedirectableLine(message.Body);
                            }
                        }

                        buffer.WriteRedirectableLine("No unread messages");
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Message.Contains("401"))
                {
                    throw new AuthenticationException("Authentication Failed", e);
                }
            }
        }
        /// <summary>
        /// Read all unread messages into the scratchpad.
        /// </summary>
        /// <param name="buffer">The I/O buffer</param>
        private static void ReadScratchpad(LineBuffer buffer)
        {
            WebRequest wrGeturl = WebRequest.Create(CIXOAuth.GetUri("cix.svc/user/cixtelnetd/65535/0/scratchpad.xml"));
            wrGeturl.Method = "GET";

            try
            {
                Stream objStream = wrGeturl.GetResponse().GetResponseStream();
                if (objStream != null)
                {
                    using (XmlReader reader = XmlReader.Create(objStream))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(Scratchpad));
                        Scratchpad scratchpad = (Scratchpad)serializer.Deserialize(reader);

                        buffer.WriteRedirectableLine("Checking for conference activity.");

                        Dictionary<string, List<ScratchpadMessagesMsg> > allMessages = new Dictionary<string, List<ScratchpadMessagesMsg> >();

                        foreach (ScratchpadMessagesMsg message in scratchpad.Messages)
                        {
                            string thisTopic = string.Format("{0}/{1}", message.Forum, message.Topic);
                            List<ScratchpadMessagesMsg> topicList;

                            if (!allMessages.TryGetValue(thisTopic, out topicList))
                            {
                                topicList = new List<ScratchpadMessagesMsg>();
                                allMessages[thisTopic] = topicList;
                            }
                            topicList.Add(message);
                        }

                        foreach (string thisTopic in allMessages.Keys)
                        {
                            List<ScratchpadMessagesMsg> topicList = allMessages[thisTopic];
                            buffer.WriteRedirectableLine(string.Format("Joining {0} {1} new message(s).", thisTopic, topicList.Count));

                            foreach (ScratchpadMessagesMsg message in topicList)
                            {
                                string [] monthString = new[] { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};

                                StringBuilder messageHeader = new StringBuilder();
                                messageHeader.AppendFormat(">>>{0} {1} {2}({3})", thisTopic, message.ID, message.Author, message.Body.Length);

                                DateTime messageDate = DateTime.Parse(message.DateTime);

                                messageHeader.AppendFormat("{0}{1}{2} ", messageDate.Day, monthString[messageDate.Month - 1], messageDate.Year - 2000);
                                messageHeader.AppendFormat("{0}:{1}", messageDate.Hour, messageDate.Minute);
                                if (message.ReplyTo != "0")
                                {
                                    messageHeader.AppendFormat(" c{0}", message.ReplyTo);
                                }
                                buffer.WriteRedirectableLine(messageHeader.ToString());
                                buffer.WriteRedirectableLine(message.Body);
                            }
                        }

                        buffer.WriteRedirectableLine("No unread messages");
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Message.Contains("401"))
                {
                    throw new AuthenticationException("Authentication Failed", e);
                }
            }
        }
Beispiel #4
0
        /// <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);
            }
        }