コード例 #1
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            string botSkypeId = ConfigurationManager.AppSettings["botskypeid"];

            List<SkypeContact> contacts = chat.Contacts.Where(s => s.Id != botSkypeId).ToList();
            return contacts[(new Random()).Next(contacts.Count)].Id;
        }
コード例 #2
0
        public void WriteSkypeContact()
        {
            string       exceptionMes = string.Empty;
            Contact      skypeContact = new SkypeContact();
            Contact      standard     = new SkypeContact("Denchik", "Den4ik_Wi_n_e_r");
            StreamWriter streamWriter = new StreamWriter("../../SkypeContactOutput.txt");

            try
            {
                standard.Write(streamWriter);
                streamWriter.Close();
                streamWriter.Dispose();

                StreamReader streamReader = new StreamReader("../../SkypeContactOutput.txt");
                skypeContact.Read(streamReader);
                streamReader.Close();
                streamReader.Dispose();
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(skypeContact.Name, standard.Name);
            Assert.AreEqual(skypeContact.Data, standard.Data);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
コード例 #3
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string argument = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            try
            {
                if (!string.IsNullOrEmpty(argument))
                {
                    if (argument.Length > MaxFeedbackLength)
                    {
                        return
                            (string.Format(
                                 "The feedback message is too long. The maximum allowed length is 500. Your's is {0}",
                                 argument.Length));
                    }

                    this.dataManager.AddFeedback(contact.Id, argument);
                }
                else
                {
                    return("Please use feedback command with argument");
                }
            }
            catch (Exception)
            {
                return("Sorry, couldn't process your feedback");
            }

            return("Got your message. We will try to take a look at it asap. Thanks!");
        }
コード例 #4
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string argument = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            string result = string.Empty;

            if (!string.IsNullOrWhiteSpace(argument))
            {
                Thread thread = new Thread(
                    () =>
                {
                    try
                    {
                        result = new Engine().Execute(argument).GetCompletionValue().ToString();
                    }
                    catch (Exception)
                    {
                        result = "Sorry, couldn't parse.";
                    }
                });

                thread.Start();

                if (!thread.Join(Timeout))
                {
                    thread.Abort();
                    result = "Sorry, your code took too long and has been aborted.";
                }
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            string botSkypeId = ConfigurationManager.AppSettings["botskypeid"];

            List <SkypeContact> contacts = chat.Contacts.Where(s => s.Id != botSkypeId).ToList();

            return(contacts[(new Random()).Next(contacts.Count)].Id);
        }
コード例 #6
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string args)
        {
            if (this.dataManager.IsChatEnabled(chat.Id))
            {
                return(AlreadyListeningMessage);
            }

            this.dataManager.EnabledChat(chat.Id);
            return(HelloMessage);
        }
コード例 #7
0
ファイル: Settings.cs プロジェクト: vhytyk/skype-notifier
        private void buttonAddContact_Click(object sender, EventArgs e)
        {
            SkypeContact selectedContact = listBoxAllContacts.SelectedItem as SkypeContact;

            if (selectedContact != null && SkypeNotifier.Instance.Settings.SubscribedContacts.Find(contact => contact.ID == selectedContact.ID) == null)
            {
                SkypeNotifier.Instance.Settings.SubscribedContacts.Add(selectedContact);
                listBoxSelectedContacts.Items.Add(selectedContact);
                RefreshListBox(listBoxSelectedContacts, SkypeNotifier.Instance.Settings.SubscribedContacts);
                buttonSave.Enabled = true;
            }
        }
コード例 #8
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            try
            {
                this.dataManager.UnsubscribeChat(chat.Id);
            }
            catch (Exception)
            {
                return("Oops, something went wrong with unsubscribing");
            }

            return(string.Format("You've successfully been unsubscribed from any project"));
        }
コード例 #9
0
ファイル: Settings.cs プロジェクト: vhytyk/skype-notifier
        private void buttonRemoveContact_Click(object sender, EventArgs e)
        {
            SkypeContact selectedContact = listBoxSelectedContacts.SelectedItem as SkypeContact;

            if (selectedContact != null)
            {
                SkypeContact contactToRemove = SkypeNotifier.Instance.Settings.SubscribedContacts.Find(contact => contact.ID == selectedContact.ID);
                if (contactToRemove != null)
                {
                    SkypeNotifier.Instance.Settings.SubscribedContacts.Remove(contactToRemove);
                }
                listBoxSelectedContacts.Items.Remove(selectedContact);
                RefreshListBox(listBoxSelectedContacts, SkypeNotifier.Instance.Settings.SubscribedContacts);
                buttonSave.Enabled = true;
            }
        }
コード例 #10
0
        public void TestMethodForClassSkypeContact()
        {
            SkypeContact phone = new SkypeContact("Roman", "joni");
            StreamWriter sw    = new StreamWriter("FileForTest.txt");

            phone.WrtiteToFile(sw);
            sw.Close();
            SkypeContact phone1 = new SkypeContact();

            using (StreamReader sr = new StreamReader("FileForTest.txt"))
            {
                phone1.ReadFromFile(sr);
            }

            Assert.IsTrue(phone1.Name == "Roman," && phone1.NicknameInSkype == "joni" && phone.Name == "Roman" && phone.NicknameInSkype == "joni");
        }
コード例 #11
0
        public void PropertiesSkypeContactInputIncorrectName()
        {
            Contact skypeContact = new SkypeContact();
            string  name         = "Pioner_first";
            string  exceptionMes = string.Empty;

            try
            {
                skypeContact.Name = name;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(skypeContact.Name, string.Empty);
            Assert.AreNotEqual(exceptionMes, string.Empty);
        }
コード例 #12
0
        public void PropertiesSkypeContactInputIncorrectSkype()
        {
            Contact skypeContact = new SkypeContact();
            string  skype        = "MySkype@best";
            string  exceptionMes = string.Empty;

            try
            {
                skypeContact.Data = skype;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(skypeContact.Data, string.Empty);
            Assert.AreNotEqual(exceptionMes, string.Empty);
        }
コード例 #13
0
        public void PropertiesSkypeContactInputCorrectData()
        {
            Contact phoneContact = new SkypeContact();
            string  name         = "Qwerty";
            string  skype        = "qwerty_uiop";
            string  exceptionMes = string.Empty;

            try
            {
                phoneContact.Name = name;
                phoneContact.Data = skype;
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(phoneContact.Name, name);
            Assert.AreEqual(phoneContact.Data, skype);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
コード例 #14
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The args.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact sender, SkypeChat chat, string message)
        {
            string projectName = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);
            int    projectId   = this.dataManager.GetProjectId(projectName);

            if (projectId == 0)
            {
                return("No project with such name was found");
            }

            try
            {
                this.dataManager.SubscribeChat(chat.Id, projectId);
            }
            catch (Exception)
            {
                return("Oops, something went wrong with subscribing");
            }

            return(string.Format("You've successfully been subscribed to project {0}", projectName));
        }
コード例 #15
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (string.IsNullOrWhiteSpace(args))
            {
                var sb = new StringBuilder();
                sb.AppendLine("The commands supported by this bot:");
                sb.AppendLine("help - displays this help message");

                foreach (AbstractDirectCommand command in this.commands)
                {
                    sb.AppendLine(string.Format("{0} - {1}", command.Name, command.Help));
                }

                sb.AppendLine();
                sb.Append("To get more commands, you should be subscribed to some project.");
                sb.Append("To get detailed help for a certain command, type a command ");
                sb.AppendLine("name after the 'help' command. For example:");
                sb.AppendLine("help on");

                return(sb.ToString());
            }

            if (string.Equals(args, "help", StringComparison.CurrentCultureIgnoreCase))
            {
                return("Displays the main help page");
            }

            AbstractDirectCommand directCommand =
                this.commands.FirstOrDefault(c => string.Equals(c.Name, args, StringComparison.OrdinalIgnoreCase));

            if (directCommand != null)
            {
                return(directCommand.Usage);
            }

            return("The command is not found. Please type 'help' to see available commands");
        }
コード例 #16
0
        public void ReadSkypeContact()
        {
            string       exceptionMes = string.Empty;
            Contact      skypeContact = new SkypeContact();
            Contact      standard     = new SkypeContact("Vasia", "pupkin_vasia1");
            StreamReader stream       = new StreamReader("../../SkypeContactInput.txt");

            try
            {
                skypeContact.Read(stream);
                stream.Close();
                stream.Dispose();
            }
            catch (ArgumentException mes)
            {
                exceptionMes = mes.Message;
            }

            Assert.AreEqual(skypeContact.Name, standard.Name);
            Assert.AreEqual(skypeContact.Data, standard.Data);
            Assert.AreEqual(exceptionMes, string.Empty);
        }
コード例 #17
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            IEnumerable <ProjectStatus> statuses = this.client.GetProjectStatus();

            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (!string.IsNullOrEmpty(args))
            {
                statuses = statuses.Where(s => string.Equals(s.Name, args, StringComparison.CurrentCultureIgnoreCase));
            }

            var sb = new StringBuilder();

            foreach (ProjectStatus status in statuses)
            {
                if (this.buildNames.Contains(status.Name))
                {
                    sb.AppendLine(string.Format("{0}: {1}", status.Name, status.BuildStatus));
                }
            }

            return(sb.ToString());
        }
コード例 #18
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string json = string.Empty;

            string argument = this.regex.Match(message).Value;

            try
            {
                var request = WebRequest.Create(this.url + "rest/api/latest/issue/" + argument) as HttpWebRequest;
                request.ContentType = "application/json";
                request.Method      = "GET";

                string base64Credentials = this.GetEncodedCredentials();
                request.Headers.Add("Authorization", "Basic " + base64Credentials);

                var response = request.GetResponse() as HttpWebResponse;

                using (var reader = new StreamReader(response.GetResponseStream()))
                {
                    json = reader.ReadToEnd();
                }
            }
            catch (Exception)
            {
                return(string.Empty);
            }

            if (!string.IsNullOrEmpty(json))
            {
                JObject jsonObj = JObject.Parse(json);
                string  key     = jsonObj["key"].ToString().ToUpper();
                string  summary = jsonObj["fields"]["summary"].ToString();
                string  status;
                string  assignee;

                if (summary[0] == '{')
                {
                    summary  = jsonObj["fields"]["summary"]["value"].ToString();
                    status   = jsonObj["fields"]["status"]["value"]["name"].ToString();
                    assignee = jsonObj["fields"]["assignee"]["value"]["displayName"].ToString();
                }
                else
                {
                    status   = jsonObj["fields"]["status"]["name"].ToString();
                    assignee = jsonObj["fields"]["assignee"].HasValues
                                   ? jsonObj["fields"]["assignee"]["displayName"].ToString()
                                   : "Unassigned";
                }

                var sb = new StringBuilder();

                if (!message.StartsWith("http"))
                {
                    sb.AppendLine(this.url + "browse/" + key);
                }

                sb.AppendLine('"' + summary + '"');
                sb.AppendLine(string.Format("Status: {0}", status));
                sb.AppendLine(string.Format("Assignee: {0}", assignee));
                return(sb.ToString());
            }

            return(string.Empty);
        }
コード例 #19
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (string.IsNullOrWhiteSpace(args))
            {
                var sb = new StringBuilder();
                sb.AppendLine("The commands supported by this bot:");
                sb.AppendLine("help - displays this help message");

                foreach (AbstractDirectCommand command in this.commands)
                {
                    sb.AppendLine(string.Format("{0} - {1}", command.Name, command.Help));
                }

                sb.AppendLine();
                sb.Append("To get more commands, you should be subscribed to some project.");
                sb.Append("To get detailed help for a certain command, type a command ");
                sb.AppendLine("name after the 'help' command. For example:");
                sb.AppendLine("help on");

                return sb.ToString();
            }

            if (string.Equals(args, "help", StringComparison.CurrentCultureIgnoreCase))
            {
                return "Displays the main help page";
            }

            AbstractDirectCommand directCommand =
                this.commands.FirstOrDefault(c => string.Equals(c.Name, args, StringComparison.OrdinalIgnoreCase));
            if (directCommand != null)
            {
                return directCommand.Usage;
            }

            return "The command is not found. Please type 'help' to see available commands";
        }
コード例 #20
0
 /// <summary>
 /// Executes the command on answer to the specified chat name.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <returns>
 /// The result string to send back as the answer.
 /// </returns>
 public override string Execute(SkypeContact contact, SkypeChat chat, string args)
 {
     this.dataManager.DisableChat(chat.Id);
     return(GoodbyeMessage);
 }
コード例 #21
0
        /// <summary>
        /// Executes the command on answer to the specified chat name.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The result string to send back as the answer.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            IEnumerable<ProjectStatus> statuses = this.client.GetProjectStatus();

            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);
            if (!string.IsNullOrEmpty(args))
            {
                statuses = statuses.Where(s => string.Equals(s.Name, args, StringComparison.CurrentCultureIgnoreCase));
            }

            var sb = new StringBuilder();
            foreach (ProjectStatus status in statuses)
            {
                if (this.buildNames.Contains(status.Name))
                {
                    sb.AppendLine(string.Format("{0}: {1}", status.Name, status.BuildStatus));
                }
            }

            return sb.ToString();
        }
コード例 #22
0
 /// <summary>
 /// The execute.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <returns>
 /// The <see cref="string"/>.
 /// </returns>
 public abstract string Execute(SkypeContact contact, SkypeChat chat, string message);
コード例 #23
0
 /// <summary>
 /// Executes the command on answer to the specified chat name.
 /// </summary>
 /// <param name="contact">
 /// The contact.
 /// </param>
 /// <param name="chat">
 /// The chat.
 /// </param>
 /// <param name="args">
 /// The args.
 /// </param>
 /// <returns>
 /// The result string to send back as the answer.
 /// </returns>
 public override string Execute(SkypeContact contact, SkypeChat chat, string args)
 {
     this.dataManager.DisableChat(chat.Id);
     return GoodbyeMessage;
 }