public void ClearAllFields(IsbnItem item) { // race.Brand = ""; // race.Comments = ""; // race.Description = ""; // race.Price = ""; // race.PriceNonSpecial = ""; // race.MainBarcode = ""; // race.ProductImage = ""; // race.ProductImageLg = ""; // race.ProductInstructions = ""; // race.SavedAmount = ""; // race.TagLine = ""; // race.URL = ""; // race.UnitOfMeasure = ""; // race.StoreName = ""; // race.ListingAge = ""; // race.isPosted = false; // race.isSaved = false; // // race.InsertDate = DateTime.Now; // race.PostDate = DateTime.Now; // // race.WebsiteID = 0; // race.StoreName = ""; // race.JobID = JobID; // race.InShopID = InShopID; }
// HH - Make StartListening() return void public static void StartListening(Thread childThread) { // Establish the local endpoint for the socket. // The DNS name of the computer // running the listener is "host.contoso.com". IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); // IPAddress ipAddress = ipHostInfo.AddressList[2]; // IPAddress ipAddress = ipHostInfo.AddressList[0]; IPAddress ipAddress = ipHostInfo.AddressList[3]; IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 51968); // Create a TCP/IP socket. Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); // Bind the socket to the local endpoint and listen for incoming connections. try { listener.Bind(localEndPoint); listener.Listen(100); while (true) { // Set the event to nonsignaled state. allDone.Reset(); // Start an asynchronous socket to listen for connections. Console.WriteLine("Waiting for a connection..."); listener.BeginAccept( new AsyncCallback(AcceptCallback), listener); Thread.Sleep(5000); Console.WriteLine(data.Length); // TODO extend data to include the deviceID if (data != "") { item = new IsbnItem(); userItem = new UserItem(); da = new DataAccess(); string[] arrISBN = data.Split(';'); string isbn = arrISBN[0].Trim(); string deviceID = arrISBN[1].Trim(); // set the fields to populate DB and transport over socket connection // In future the user will populate this field so this will be // conditional userItem.DeviceID = deviceID; userItem.Email = null; userItem.UserName = null; userItem.FirstName = null; userItem.LastName = null; // save to database // TODO parse userID user = da.RegisterUser(userItem, deviceID, user); int userID = 0; // Slowing it down for testing Thread.Sleep(2000); // Get the UserID foreach (UserItem userr in user) { userID = userr.UserID; } item.ISBN = isbn; item.UserID = userID; // Check if the ISBN exists while saving if exists, //return that reference = da.SaveSingleISBN(item, isbn, reference); // return the reference from above method // this breaks out of processing - change ISBN if (reference != null) { // Get the book reference // Return reference // Notify client via socket? // Already in db // return reference.ToString(); } // We send the userID along so that we can link the user that created the reference to it. childThread = new Thread(() => GetReference(isbn, userID)); childThread.SetApartmentState(ApartmentState.STA); childThread.Start(); // return data; } // Wait until a connection is made before continuing. allDone.WaitOne(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine("\nPress ENTER to continue..."); //Console.Read(); // return data; }