예제 #1
0
        public void Dequeue(Data.Person dPerson)
        {
            if (dPerson == null)
            {
                throw new Exception.DequeueException(Exception.DequeueException.ResponseCodes.InvalidPerson);
            }

            lock ( ms_oSync )
            {
                System.Xml.Linq.XElement xWaitList = m_oXmlFilePersister.Load(mc_sStorageName) ?? new System.Xml.Linq.XElement("Waitlist");

                System.Xml.Linq.XElement xPersons = GetPersons(xWaitList);

                System.Xml.Linq.XElement xPerson = xPersons
                                                   .Elements("Person")
                                                   .Where(xPersonSearch => xPersonSearch.Attribute("Id").GetValue(Guid.Empty, s => new Guid(s)) == dPerson.Id)
                                                   .FirstOrDefault( );

                if (xPerson == null)
                {
                    throw new Exception.DequeueException(Exception.DequeueException.ResponseCodes.PersonNotFound);
                }
                else
                {
                    xPerson.Remove( );
                    m_oXmlFilePersister.Save(mc_sStorageName, xWaitList);
                }
            }
        }
예제 #2
0
        public Data.Person Queue(string sName, string sPhone)
        {
            Data.Person dPerson = new Data.Person( )
            {
                Id    = Guid.NewGuid( ),
                Name  = sName,
                Phone = sPhone
            };

            // normally this logic would exist on the server side.
            if (string.IsNullOrEmpty(sName))
            {
                throw new Exception.QueueException(Exception.QueueException.ResponseCodes.InvalidName);
            }
            else if (string.IsNullOrEmpty(sPhone))
            {
                throw new Exception.QueueException(Exception.QueueException.ResponseCodes.InvalidPhone);
            }

            lock ( ms_oSync )
            {
                System.Xml.Linq.XElement xWaitList = m_oXmlFilePersister.Load(mc_sStorageName) ?? new System.Xml.Linq.XElement("Waitlist");

                System.Xml.Linq.XElement xPersons = GetPersons(xWaitList);

                if (xPersons.Elements("Person")
                    .Select(xPerson => m_adpPersonFromXml.Adapt(xPerson))
                    .Any(dPersonSearch => dPersonSearch == dPerson))
                {
                    throw new Exception.QueueException(Exception.QueueException.ResponseCodes.PersonExists);
                }

                xPersons.Add(m_adpPersonToXml.Adapt(dPerson));

                m_oXmlFilePersister.Save(mc_sStorageName, xWaitList);
            }

            return(dPerson);
        }