/// <summary>
        ///
        /// </summary>
        /// <param name="changedPC"></param>
        /// <param name="client"></param>
        public void updatePC(PCChange changedPC, Client client)
        {
            Site   site = siteList.Find(s => s.Name == client.Site);
            Laptop PCtoEdit;

            if (client.Hotswaps)
            {
                PCtoEdit = site.Hotswaps.Find(pc => pc.Serial == changedPC.Serial);
            }
            else
            {
                PCtoEdit = site.Loaners.Find(pc => pc.Serial == changedPC.Serial);
            }

            string modification = string.Empty;

            if (changedPC.CheckedOut)
            {
                modification = " is checking out ";
            }
            else
            {
                modification = " is checking in ";
            }
            UpdateStatus(">>> User " + client.UserName + modification + PCtoEdit.Serial +
                         " from site " + client.Site);
            Changed = true;
            PCtoEdit.MergeChanges(changedPC);

            UpdateStatus(">> Sending updates to other clients connected to " + client.Site);
            BroadcastUpdateToSite(PCtoEdit, client);
        }
 public void MergeChanges(PCChange changes)
 {
     Serial       = changes.Serial;
     Username     = changes.UserName;
     UserPCSerial = changes.UserPCSerial;
     TicketNumber = changes.Ticket;
     CheckedOut   = changes.CheckedOut;
 }
Esempio n. 3
0
        private void bgwWaitForPCRequests_DoWork(object sender, DoWorkEventArgs e)
        {
            var siht = e.Argument as InventoryServerForm;

            siht.UpdateStatus("> Awaiting requests from " + UserName);
            byte[] inStream = new byte[10025];
            while (true)
            {
                try {
                    ClientSocket.GetStream().Read(inStream, 0, ClientSocket.ReceiveBufferSize);
                    var streamIdentifier = (DataIdentifier)BitConverter.ToInt32(inStream, 0);
                    if (streamIdentifier == DataIdentifier.Request)
                    {
                        RequestPCPacket pcRequest = new RequestPCPacket(inStream);
                        if (pcRequest.Type == "Hotswaps")
                        {
                            Hotswaps = true;
                        }
                        else
                        {
                            Hotswaps = false;
                        }
                        Site = pcRequest.SiteName;
                        siht.SendPCsForSite(this, pcRequest.SiteName, pcRequest.Type);
                    }
                    else if (streamIdentifier == DataIdentifier.Update)
                    {
                        PCChange changedPC = new PCChange(inStream);
                        //siht.BroadcastUpdateToSite("> User " + UserName + " is modifying " + changedPC.Serial, this);
                        siht.updatePC(changedPC, this);
                    }
                    else if (streamIdentifier == DataIdentifier.Laptop)
                    {
                    }
                } catch (Exception ex) {
                    siht.UpdateStatus("<<< " + UserName + " disconnected: " + ex.Message);
                    if (!ClientSocket.Connected)
                    {
                        siht.RemoveClient(this);
                        break;
                    }
                }
            }
        }