public MainViewModel(CoreDispatcher dispatcher) { this.Dispatch = dispatcher; this.NetSoul = null; this.Connected = false; this.LoginBoxEnable = true; this.ContactList = new ObservableCollection <ContactInfo>(); this.LastContactSelection = -1; this.SelectedContact = null; this.ChatBox = String.Empty; this.SendBox = String.Empty; this.AddContactCmd = new MyCommand <string>(new Action <string>(arg => { bool check = false; if (arg != String.Empty) { foreach (ContactInfo c in this.ContactList) { if (c.Login == arg) { check = true; } } if (check == false) { this.ContactList.Add(new ContactInfo(arg)); this.NetSoul.AddContact(arg); this.SaveContactList(); } } string test = String.Empty; //foreach (string s in this.NetSoul.Verif) //{ // test += s; //} //if (this.NetSoul.ShutdownClient == true) // test += "shutdown"; this.ChatBox += test; this.UpdateProperty("ChatBox"); })); this.SendCmd = new MyCommand <string>(new Action <string>(arg => { if (this.SelectedContact.Socket > 0) { this.NetSoul.Send(this.SelectedContact.Socket, arg); // this.NetSoul.Message.Add(this.SelectedContact.Socket.ToString() + ":" + arg); this.ChatBox += ">>> " + arg + "\n"; this.UpdateProperty("ChatBox"); this.SendBox = String.Empty; this.UpdateProperty("SendBox"); } })); }
public async void NetsoulConnection(string Server, string PortStr, string UsernameText, string PasswordText, string LocationText) { this.UserLogin = UsernameText; int Port = -1; Int32.TryParse(PortStr, out Port); if (this.Connected == false && Port != -1) { if (UsernameText.Length == 8 && UsernameText.Contains("_") && PasswordText.Length == 8) { await this.LoadContactList(UsernameText); this.UpdateProperty("ContactList"); this.NetSoul = new NetsoulRT(); //this.NetSoul.OnDataReceived += NetSoul_OnDataReceived; // this.NetSoul.OnContactUpdated += NetSoul_OnContactUpdated; //this.NetSoul.OnErrorRaised += NetSoul_OnErrorRaised; this.NetSoul.Login = UsernameText; this.NetSoul.Password = PasswordText; this.NetSoul.UserData = "WinRT-NetSoul"; if (LocationText != String.Empty) { this.NetSoul.UserLocation = LocationText; } bool ret = await this.NetSoul.ConnectAsync(); if (ret == true) { this.UpdateWatchList(); this.Connected = true; this.UpdateProperty("Connected"); this.LoginBoxEnable = false; this.UpdateProperty("LoginBoxEnable"); //this.NetSoul.StartServer(); } } } }