public override void PurgeAllMessages() { AzureServiceBusHelper.PurgeAllMessages(_monitorQueues.Cast <AzureMessageQueue>()); //List<Task> tasks = new List<Task>(); //for( int i = 0; i < _monitorQueues.Count; i++ ) { // if( AzureServiceBusReceiver.GetAzureQueueCount(_monitorQueues[i].Queue.Name ) > 0 ) { // tasks.Add(Task.Factory.StartNew(() => _monitorQueues[i].Purge())); // Thread.Sleep(200); // } // if( ( ( tasks.Count ) % 15 ) == 0 ) { // Task.WaitAll(tasks.ToArray()); // tasks.Clear(); // } //} //if( tasks.Count > 0 ) // Task.WaitAll(tasks.ToArray()); OnItemsChanged(); }
public Friends(string MyUsername) { if (string.IsNullOrWhiteSpace(MyUsername)) { throw new ArgumentNullException(nameof(MyUsername)); } MyName = MyUsername; FriendsConstructorBaseInput friendsConstructor = new FriendsConstructorBaseInput(); //Get it hash set because of usefull check operation if many invitaions have sent HashSet <string> peoples = friendsConstructor.GetFriendsNames(MyName); FriendsUsernames = peoples; TopicsPaths = AzureServiceBusHelper.TakeAllTopicsForUser(MyUsername); }
public void SendMessage(List <string> TopicNames, string message, string fromuser) { if (string.IsNullOrWhiteSpace(message)) { throw new ArgumentNullException(nameof(message)); } Message = message; foreach (var toUserName in ChatPartisipantsNames) { string TopicName = TopicNames.Find(s => s.Split('1').ToList().Contains(toUserName)); AzureServiceBusHelper.SendMessageTopic(TopicName, toUserName.ToString(), fromuser, message); FriendsConstructorBaseInput.SaveMessage(TopicName, fromuser, message); } Console.WriteLine("\n**Message Sent!**"); }
private void AcceptFriendInvitation(string username, string friendusername) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException(nameof(username)); } if (string.IsNullOrWhiteSpace(friendusername)) { throw new ArgumentNullException(nameof(friendusername)); } using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.OpenAsync(); string topicname = username + "1" + friendusername; string query = $"Update Friends Set Accepted = 'Y' where UserName = '******' and FriendsUsername = '******'"; string query1 = $"INSERT INTO Friends" + $" (UserName,FriendsUsername,Accepted) " + $"VALUES('{username}', '{friendusername}', 'Y')"; string query2 = $"Create table `{topicname}`(messageid int auto_increment not null primary key, SenderName varchar(50) not null, Messege varchar(1000));"; MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); cmd.CommandText = query1; cmd.ExecuteNonQuery(); cmd.CommandText = query2; cmd.ExecuteNonQuery(); connection.CloseAsync(); AzureServiceBusHelper.CreateTopic(topicname); AzureServiceBusHelper.CreateSubscription(topicname, new List <string>() { username, friendusername }); Console.WriteLine("Successfully added new friend"); } }
public static void CreateMultiplechat(string user, string tabletopic) { List <string> topics = AzureServiceBusHelper.TakeAllTopicsForUser(user); string topic = null; bool f = true; foreach (var top in topics.OrderBy(x => x.Length)) { f = true; foreach (var name in (tabletopic + '1' + user).ToString().Split('1').ToList()) { if (top.Split('1').ToList().Contains(name) && top.Split('1').Length == (tabletopic + '1' + user).ToString().Split('1').Length&& f) { topic = top; break; } else { f = false; topic = null; continue; } } } if (topic == null && tabletopic.Contains("1")) { AzureServiceBusHelper.CreateTopic(tabletopic); AzureServiceBusHelper.CreateSubscription(tabletopic, tabletopic.Split('1').ToList()); string query = $"Create table `{tabletopic}`(messageid int auto_increment not null pimary key, SenderName varchar(50) not null, Messege varchar(1000));"; using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.OpenAsync(); MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); connection.CloseAsync(); } Console.WriteLine("New group chat has been successfully created!"); } else { string query = $"SELECT * FROM ChatApp.{topic} order by messageid"; using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.OpenAsync(); //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list int i = 10; while (dataReader.Read()) { Console.WriteLine(dataReader["SenderName"].ToString().ToLowerInvariant() + ": " + dataReader["Messege"].ToString()); i--; if (i < 0) { break; } } //close Data Reader dataReader.Close(); connection.CloseAsync(); } } }