/// <summary> /// Attempts to load the goAbout config file. /// </summary> /// <returns>The load state of the device</returns> public eLoadState LoadFromXML() { this.matches.Clear(); if (!File.Exists(@"goAbout.xml")) { this.serverAddress = defaultServerAddress; loadState = eLoadState.NoLogin; } else { XmlTextReader r = new XmlTextReader(@"goAbout.xml"); while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.LocalName.Equals("MemberID")) { string str = decr(r.ReadString()); memberID = str; } if (r.LocalName.Equals("Password")) { string str = decr(r.ReadString()); password = str; } if (r.LocalName.Equals("MemberID")) { string str = decr(r.ReadString()); serverAddress = str; if (str == "") serverAddress = defaultServerAddress; } if (password != "" && memberID!="") loadState = eLoadState.Loaded; if (r.LocalName == "Options") { while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.LocalName == "Option1") this.option1 = Int32.Parse(r.ReadString()); if (r.LocalName == "Option2") this.option2 = Int32.Parse(r.ReadString()); if (r.LocalName == "Option3") this.option3 = Int32.Parse(r.ReadString()); if (r.LocalName == "Option4") { this.option4 = Int32.Parse(r.ReadString()); break; } } } } if (r.LocalName == "Profile") { while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { //if (r.LocalName == "Age") // Member.Age = Int32.Parse(r.ReadString()); ////if (r.LocalName == "Gender") // // Member.Gender = (eGender)r.ReadString(); //if (r.LocalName == "AgeSeek") // Member.SeekAge = Int32.Parse(r.ReadString()); //if (r.LocalName == "GenderSeek") //{ // Member.SeekGender = (eGender)r.ReadString(); // break; //} } } } if (r.LocalName == "Matches") { while (r.Read()) { if (r.NodeType == XmlNodeType.Element) { if (r.LocalName == "Match") { Match m = null; while (r.Read()) { if (r.LocalName == "MatchName") m = new Match(r.ReadString()); if (r.LocalName == "MAC") m.MACAddress = r.ReadString(); if (r.LocalName == "MatchTime") m.MatchDT = Convert.ToDateTime(r.ReadString()); if (r.LocalName == "ConfirmedByServer") { m.ConfirmedByServer = Convert.ToBoolean(r.ReadString()); matches.Add(m); } } } } } } } } r.Close(); DisplayMatches(); } if (this.loadState == eLoadState.NoLogin) { MainForm.pnlLogin.Visible = true; MainForm.LeftMenu.Text = "Done"; MainForm.pnlLogin.Controls[2].Focus(); } return loadState; }
/// <summary> /// Trys to create a Match object from an incoming bluetooth connection stream /// </summary> /// <returns>A Match object or null if the stream is invalid</returns> private Match ReceiveBTData() { // set bytes read to 0 int bytesRead = 0; // nullify an existing BluetoothClient object BluetoothClient client = null; // create a new stream object for the incoming data System.IO.Stream stream = null; // create a byte array buffer of 128 byte[] Buffer = new byte[128]; // create a null Match object // if the incoming byte stream cannot be successfully converted into a Match // object then m is returned as a null Match m=null; try { // Accept an requested connections client = btListener.AcceptBluetoothClient(); // return the byte stream from the connection stream = client.GetStream(); // place up 128 bytes of data into the buffer and read the number of bytes read bytesRead = stream.Read(Buffer, 0, 128); // convert the byte array into a string string rs = System.Text.Encoding.Unicode.GetString(Buffer, 0, bytesRead); // split the string via the comma delimter string[] str = rs.Split(new char[]{','}); // pass the MemberID into the Match Constructor to create a new instance m = new Match(str[6]); // set the MAC address of the Match from the connections Address object m.MACAddress = ((BluetoothEndPoint)client.Client.RemoteEndPoint).Address.ToString(); // determine if the remote Member has my profile already if (str[8] == "0") m.HasMyProfile = false; else m.HasMyProfile = true; // Close the bluetooth connect as the radio is released stream.Close(); client.Close(); } catch (Exception e) { //throw e; } finally { // upon terminating the try/catch block, make sure the stream and client object // are other incoming connections arent stalled until the connetion times out if ((!(stream == null))) { stream.Close(); } if ((!(client == null))) { client.Close(); } } // return the Match object return m; }
/// <summary> /// Adds a new Bluetooth Match into the system /// </summary> /// <param name="m"></param> public void AddMatch(Match m) { // add the match to the arraylist this.matches.Add(m); // update the display DisplayMatches(); // save the Match to the XML storage file SaveToXML(); }