public bool addSource(IChatSource newSource) { if (!chatSources.ContainsKey(newSource.SourceName)) { chatSources.Add(newSource.SourceName.ToUpper(), newSource); newSource.IncomingMessage += new IncomingMessageEventHandler(newSource_IncomingMessage); if (MainUser != null) { //Assume that either there is only either none or at least one user account if (MainUser.retrieve(newSource) == null) { UserAccount masterAccount; if (MainUser.Profile != null) { masterAccount = newSource.createUser(MainUser.Profile.Name); } else { masterAccount = newSource.createUser("Boss"); } } else { newSource.setup(MainUser.retrieve(newSource)[0]); } } return(true); } else { return(false); } }
private void addChatSource(IChatSource newSource) { if (chatController.addSource(newSource)) { chatComboBox.Items.Add(newSource.SourceName.ToUpper()); if (newSource is IChatFormPlugin) { TabPage tabPage = new TabPage(); tabPage.SuspendLayout(); tabPage.Controls.Add((IChatFormPlugin)newSource); tabPage.Location = new System.Drawing.Point(4, 22); tabPage.Padding = new System.Windows.Forms.Padding(3); tabPage.Size = new System.Drawing.Size(405, 319); tabPage.Text = newSource.SourceName.ToUpper(); tabPage.UseVisualStyleBackColor = true; tabControl.Controls.Add(tabPage); if (newSource is IChatFormPlugin) { ((IChatFormPlugin)newSource).StatusChanged += new PropertyChangedEventHandler(newSource_StatusChanged); } } else //if (newSource is IChatWPFPlugin) { } } }
/// <summary> /// Allocate and initialize a ChatMessage with the following parameters. /// </summary> /// <param name="source">Chat source that this chat message belongs to.</param> /// <param name="sender">User account that this chat message originates from.</param> /// <param name="recipient">User account that this chat message is send to.</param> /// <param name="content">Content of this chat message.</param> public ChatMessage(IChatSource source, UserAccount sender, UserAccount recipient, TextMessage content) { Source = source; Sender = sender; Recipient = recipient; Content = content; Hidden = false; }
public IList <UserAccount> retrieve(IChatSource source) { //Currently, handling one account per chat source. List <UserAccount> list = new List <UserAccount>(); list.Add(accounts[source.SourceName]); return(list); }
public void join(IChatSource source) { if (!Sources.ContainsKey(source.SourceName)) { if (PSource == null) { PSource = source; } Sources.Add(source.SourceName, source); } }
public IList <UserAccount> retrieve(IChatSource source) { if (accounts.ContainsKey(source.SourceName)) { return(accounts[source.SourceName]); } else { return(null); } }
public IList <UserAccount> retrieve(IChatSource source) { if (account == null || !account.SourceName.Equals(source.SourceName)) { return(null); } else { return new List <UserAccount>() { account } }; }
private void sendMessage() { if (sendButton.Enabled) { string name; if (chatController.MainUser.Profile != null) { name = chatController.MainUser.Profile.Name; } else { name = "User"; } IChatSource source = chatController.getSource(chatComboBox.SelectedItem.ToString()); int row = allDataGridView.Rows.Add(); allDataGridView.Rows[row].DefaultCellStyle.ForeColor = source.TextColor; allDataGridView.Rows[row].Cells["NameColumn"].Value = name; allDataGridView.Rows[row].Cells["MessageColumn"].Value = textBox.Text; string username; IList <UserAccount> accounts = chatController.MainUser.retrieve(source); if (accounts != null && accounts.Count > 0) { username = accounts[0].Username; } else { //Need to randomize username for other user username = "******"; } chatController.send(new ChatSourceMessage(source, username, textBox.Text)); textBox.Text = ""; //Autoscroll down int displayed = allDataGridView.DisplayedRowCount(true); if (allDataGridView.FirstDisplayedScrollingRowIndex >= 0 && displayed < allDataGridView.RowCount) { allDataGridView.FirstDisplayedScrollingRowIndex = allDataGridView.RowCount - displayed; } } }
public ChatSourceMessage(IChatSource source, string sender, string message) { Source = source; Sender = sender; Message = message; }
public VisualMessage(IChatSource Source, SmilesDataDase Db, ChatMessage Data) { this.Data = Data; List <Uri> Urls = new List <Uri>(); string UserText = Data.Text;// HttpUtility.HtmlDecode(Data.Text.Replace(":s:", " :s:").Replace(" ", " ")); UserText = UriDetector.Replace( UserText, new MatchEvaluator((m) => { Urls.Add(new Uri(m.Value, UriKind.RelativeOrAbsolute)); return(LinkReplacer + " "); }) ); // parse text WrapPanel wp = new WrapPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal, }; List <string> ttt = new List <string>(); // Тоже странный кусок: int nxd = UserText.IndexOf("<b>"); if (nxd >= 0) { int nxd2 = UserText.IndexOf("</b>"); TalkTo = UserText.Substring(nxd + 3, nxd2 - nxd - 3); if (UserText.Length <= (nxd2 + 6)) { UserText = ""; } else { UserText = UserText.Substring(nxd2 + 6); } this.ToMe = TalkTo == Source.StreamerNick; if (this.ToMe) { wp.SetResourceReference(WrapPanel.StyleProperty, "StreamerContainer"); } else { wp.SetResourceReference(WrapPanel.StyleProperty, "NormalTextContainer"); } ttt.Add(TalkTo + ","); } else { TalkTo = ""; } ttt.AddRange(UserText.Split(' ')); // if (UseLabel) { Label name = new Label() { Content = Data.Name + ": " }; name.SetResourceReference(Label.StyleProperty, "LabelNameStyle"); wp.Children.Add(name); int linkIndex = 0; ISmileCreator creator = Source as ISmileCreator; for (int j = 0; j < ttt.Count; ++j) { if (ttt[j] == LinkReplacer) { Label link = new Label() { Content = "link ", Cursor = Cursors.Hand, ToolTip = Urls[linkIndex], Tag = Urls[linkIndex] }; link.SetResourceReference(Label.StyleProperty, "LabelLinkStyle"); link.MouseLeftButtonUp += (sender, b) => { Uri u = ((Label)sender).Tag as Uri; System.Diagnostics.Process.Start(u.ToString()); }; wp.Children.Add(link); linkIndex++; } else { if (creator != null) { if (!creator.CreateSmile(ttt[j], wp)) { ttt[j] += ' '; AddWord(wp, ttt, j); } } else { ttt[j] += ' '; if (!CreateSmile(Db, ttt[j], wp)) { AddWord(wp, ttt, j); } } } } //} else { // TextBlock name = new TextBlock() { Text = Data.Name + ": " }; // name.SetResourceReference(TextBlock.StyleProperty, "NameStyle"); // wp.Children.Add(name); // int linkIndex = 0; // for (int j = 0; j < ttt.Count; ++j) { // if (ttt[j] == LinkReplacer) { // TextBlock link = new TextBlock() { // Text = "link ", // Cursor = Cursors.Hand, // ToolTip = Urls[linkIndex], // Tag = Urls[linkIndex] // }; // link.SetResourceReference(TextBlock.StyleProperty, "LinkStyle"); // link.MouseLeftButtonUp += ( sender, b ) => { // Uri u = ((TextBlock)sender).Tag as Uri; // System.Diagnostics.Process.Start(u.ToString()); // }; // wp.Children.Add(link); // linkIndex++; // } else { // //if (j != (ttt.Count - 1)) // ttt[j] += ' '; // if (CreateSmile(Db, ttt[j], wp)) { // // Ура смайл ебать есть // } else { // TextBlock txt = new TextBlock() { Text = ttt[j] }; // if (TalkTo + ", " == ttt[j]) { // txt.SetResourceReference(TextBlock.StyleProperty, "NameTextStyle"); // } else { // txt.SetResourceReference(TextBlock.StyleProperty, "TextStyle"); // } // wp.Children.Add(txt); // } // } // } //} Text = wp; }
public VisualMessage( IChatSource Source, SmilesDataDase Db, ChatMessage Data ) { this.Data = Data; List<Uri> Urls = new List<Uri>(); string UserText = Data.Text;// HttpUtility.HtmlDecode(Data.Text.Replace(":s:", " :s:").Replace(" ", " ")); UserText = UriDetector.Replace( UserText, new MatchEvaluator(( m ) => { Urls.Add(new Uri(m.Value, UriKind.RelativeOrAbsolute)); return LinkReplacer + " "; }) ); // parse text WrapPanel wp = new WrapPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal, }; List<string> ttt = new List<string>(); // Тоже странный кусок: int nxd = UserText.IndexOf("<b>"); if (nxd >= 0) { int nxd2 = UserText.IndexOf("</b>"); TalkTo = UserText.Substring(nxd + 3, nxd2 - nxd - 3); if (UserText.Length <= (nxd2 + 6)) { UserText = ""; } else { UserText = UserText.Substring(nxd2 + 6); } this.ToMe = TalkTo == Source.StreamerNick; if (this.ToMe) { wp.SetResourceReference(WrapPanel.StyleProperty, "StreamerContainer"); } else { wp.SetResourceReference(WrapPanel.StyleProperty, "NormalTextContainer"); } ttt.Add(TalkTo + ","); } else { TalkTo = ""; } ttt.AddRange(UserText.Split(' ')); // if (UseLabel) { Label name = new Label() { Content = Data.Name + ": " }; name.SetResourceReference(Label.StyleProperty, "LabelNameStyle"); wp.Children.Add(name); int linkIndex = 0; ISmileCreator creator = Source as ISmileCreator; for (int j = 0; j < ttt.Count; ++j) { if (ttt[j] == LinkReplacer) { Label link = new Label() { Content = "link ", Cursor = Cursors.Hand, ToolTip = Urls[linkIndex], Tag = Urls[linkIndex] }; link.SetResourceReference(Label.StyleProperty, "LabelLinkStyle"); link.MouseLeftButtonUp += ( sender, b ) => { Uri u = ((Label)sender).Tag as Uri; System.Diagnostics.Process.Start(u.ToString()); }; wp.Children.Add(link); linkIndex++; } else { if (creator != null) { if (!creator.CreateSmile(ttt[j], wp)) { ttt[j] += ' '; AddWord(wp, ttt, j); } } else { ttt[j] += ' '; if ( !CreateSmile(Db, ttt[j], wp)) { AddWord(wp, ttt, j); } } } } //} else { // TextBlock name = new TextBlock() { Text = Data.Name + ": " }; // name.SetResourceReference(TextBlock.StyleProperty, "NameStyle"); // wp.Children.Add(name); // int linkIndex = 0; // for (int j = 0; j < ttt.Count; ++j) { // if (ttt[j] == LinkReplacer) { // TextBlock link = new TextBlock() { // Text = "link ", // Cursor = Cursors.Hand, // ToolTip = Urls[linkIndex], // Tag = Urls[linkIndex] // }; // link.SetResourceReference(TextBlock.StyleProperty, "LinkStyle"); // link.MouseLeftButtonUp += ( sender, b ) => { // Uri u = ((TextBlock)sender).Tag as Uri; // System.Diagnostics.Process.Start(u.ToString()); // }; // wp.Children.Add(link); // linkIndex++; // } else { // //if (j != (ttt.Count - 1)) // ttt[j] += ' '; // if (CreateSmile(Db, ttt[j], wp)) { // // Ура смайл ебать есть // } else { // TextBlock txt = new TextBlock() { Text = ttt[j] }; // if (TalkTo + ", " == ttt[j]) { // txt.SetResourceReference(TextBlock.StyleProperty, "NameTextStyle"); // } else { // txt.SetResourceReference(TextBlock.StyleProperty, "TextStyle"); // } // wp.Children.Add(txt); // } // } // } //} Text = wp; }
public override bool execute(ICommand command) { if (command is ChatCommand) { ChatCommandType type = ((ChatCommand)command).Type; IChatSource source = ChatManager.getSource(((ChatCommand)command).SourceName); string username = ((ChatCommand)command).Username; if (type == ChatCommandType.Create) { if (source.findUser(username) != null) { MessageLogger.log("Cannot create account. Username \"" + username + "\" already existed."); command.Status = CommandStatus.FAILED; return(true); } UserAccount account = source.createUser(username); source.addUser(account); } else //if command is either log in, log off, or remove account { UserAccount account = source.findUser(username); if (account == null) { MessageLogger.log("No account found with username \"" + username + "\"."); command.Status = CommandStatus.FAILED; return(true); } if (type == ChatCommandType.Setup) { source.setup(account); } else if (source is IChatSourceAccountManager) { if (command is ChatModifyCommand) { account.Password = ((ChatModifyCommand)command).Password; ((IChatSourceAccountManager)source).modifyAccount(account); } else if (type == ChatCommandType.Login) { ((IChatSourceAccountManager)source).login(account); } else if (type == ChatCommandType.Logout) { ((IChatSourceAccountManager)source).logoff(account); } else if (type == ChatCommandType.Remove) { ((IChatSourceAccountManager)source).removeAccount(account); } else { MessageLogger.log("Chat command type is not supported."); command.Status = CommandStatus.FAILED; return(true); } } else { MessageLogger.log("Account modification is unavailable for this source.", MessageType.WARNING); command.Status = CommandStatus.FAILED; return(true); } } //Command Successfully Executed command.Status = CommandStatus.COMPLETED; return(true); } else { return(false); } }
public void join(IChatSource source) { this.source = source; }