Ejemplo n.º 1
0
        public RequestGroup CreatePartialRequestGroup(IEnumerable <Request> declinedRequests, IEnumerable <Ranking> rankings, DateTimeOffset?newRequestExpiry, DateTimeOffset newRequestCreationTime, bool isTerminalRequest = false)
        {
            var brokersWithRequestGroups = RequestGroups.Select(r => r.Ranking.BrokerId);

            var ranking = rankings.Where(r => !brokersWithRequestGroups.Contains(r.BrokerId)).OrderBy(r => r.Rank).FirstOrDefault();
            var orders  = declinedRequests.GetRequestOrders();

            if (ranking == null)
            {
                // Rejected by all brokers, close all orders
                SetStatus(OrderStatus.NoBrokerAcceptedOrder, false);
                orders.ToList().ForEach(o => o.Status = OrderStatus.NoBrokerAcceptedOrder);
                return(null);
            }
            var requestGroup = new RequestGroup(
                ranking,
                newRequestExpiry,
                newRequestCreationTime,
                orders.Select(o => o.CreateRequest(ranking, newRequestExpiry, newRequestCreationTime, isTerminalRequest)).ToList(),
                isTerminalRequest
                );

            RequestGroups.Add(requestGroup);

            return(requestGroup);
        }
Ejemplo n.º 2
0
        private RequestGroup CreateQuarantinedRequestGroup(Ranking ranking, DateTimeOffset creationTime, Quarantine quarantine)
        {
            var requestGroup = new RequestGroup(ranking, creationTime, Orders.Select(o => o.CreateQuarantinedRequest(ranking, creationTime, quarantine)).ToList(), quarantine);

            RequestGroups.Add(requestGroup);
            return(requestGroup);
        }
Ejemplo n.º 3
0
            public void AddRequest(Request request)
            {
                NewRequests = true;

                foreach (RequestGroup group in RequestGroups)
                {
                    if (group.Push(request))
                    {
                        return;
                    }
                }

                NewGroups = true;
                RequestGroup newGroup = new RequestGroup(request);

                RequestGroups.Add(newGroup);
            }
Ejemplo n.º 4
0
        private Ranking GetNextRanking(IEnumerable <Ranking> rankings, DateTimeOffset newRequestCreationTime)
        {
            var brokersWithRequestGroups = RequestGroups.Select(r => r.Ranking.BrokerId);
            var ranking = rankings.Where(r => !brokersWithRequestGroups.Contains(r.BrokerId)).OrderBy(r => r.Rank).FirstOrDefault();

            if (ranking != null)
            {
                var quarantine = ranking.Quarantines.FirstOrDefault(q => q.CustomerOrganisationId == CustomerOrganisationId &&
                                                                    q.ActiveFrom <= newRequestCreationTime && q.ActiveTo >= newRequestCreationTime);
                if (quarantine != null)
                {
                    //Create a quarantined requestGroup, and get next ranking
                    CreateQuarantinedRequestGroup(ranking, newRequestCreationTime, quarantine);
                    ranking = GetNextRanking(rankings, newRequestCreationTime);
                }
            }
            return(ranking);
        }
Ejemplo n.º 5
0
        ///
        /// ------------------------------------------------------------------------------------------------
        /// Name		AddSearchResult
        ///
        /// <summary>	Adds the contents of the search result to the property data.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// ------------------------------------------------------------------------------------------------
        ///
        public void AddSearchResult(SRiSearchResult result)
        {
            bool requestGroupExists;
            bool recordExists;

            //
            // Figure out if a new request group is required, or if the record can go into an existing one.
            // If the same record is already in memory, do not add the new one.
            foreach (var rg in result.Property.RequestGroups)
            {
                foreach (var r in rg.Records)
                {
                    requestGroupExists = false;
                    foreach (var localGroup in RequestGroups)
                    {
                        if (localGroup.GroupType.Equals(rg.GroupType))
                        {
                            requestGroupExists = true;
                            recordExists       = false;
                            foreach (var localRecord in localGroup.Records)
                            {
                                if (localRecord.ID.Equals(r.ID))
                                {
                                    recordExists = true;
                                    break;
                                }
                            }
                            //
                            if (!recordExists)
                            {
                                localGroup.Records.Add(r);
                            }
                            break;
                        }
                    }
                    //
                    if (!requestGroupExists)
                    {
                        RequestGroups.Add(new SRiRequestGroup(r));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        ///
        /// ------------------------------------------------------------------------------------------------
        /// Name		AddRecord
        ///
        /// <summary>	Adds a record to the request group collection. Putting it in either an existing
        ///             group that has a matching request type or creating a new group.
        /// </summary>
        /// <param name="record">		The record to add.</param>
        ///
        /// <remarks>
        /// </remarks>
        /// ------------------------------------------------------------------------------------------------
        ///
        public void AddRecord(SRiRecordMeta record)
        {
            bool addedToGroup;

            //
            addedToGroup = false;
            foreach (var rg in RequestGroups)
            {
                if (rg.GroupType.Equals(record.Record.RequestType))
                {
                    rg.Records.Add(record);
                    addedToGroup = true;
                    break;
                }
            }
            //
            if (!addedToGroup)
            {
                RequestGroups.Add(new SRiRequestGroup(record));
            }
            //
            // If any of the record fields in the property are missing,
            // take the field from the new record.
            if (string.IsNullOrEmpty(UPRN))
            {
                UPRN = record.Record.UPRN;
            }
            if (string.IsNullOrEmpty(TradeName))
            {
                TradeName = record.Record.TradeName;
            }
            if (string.IsNullOrEmpty(Address.RawAddress))
            {
                Address = new OnSiteAddress(record.Record.Address);
            }
            if (!HasValidCoords)
            {
                Latitude  = record.Record.Latitude;
                Longitude = record.Record.Longitude;
            }
            //Added by Gowtham for getting organisation name in the new property. It has not been in the code given by louis.
            Organisation = record.Organisation;
        }
Ejemplo n.º 7
0
        public RequestGroup CreateRequestGroup(IEnumerable <Ranking> rankings, DateTimeOffset?newRequestExpiry, DateTimeOffset newRequestCreationTime, bool isTerminalRequest = false)
        {
            var ranking = GetNextRanking(rankings, newRequestCreationTime);

            if (ranking == null)
            {
                // Rejected by all brokers, close all orders
                SetStatus(OrderStatus.NoBrokerAcceptedOrder);
                return(null);
            }

            var requestGroup = new RequestGroup(
                ranking,
                newRequestExpiry,
                newRequestCreationTime,
                Orders.Select(o => o.CreateRequest(ranking, newRequestExpiry, newRequestCreationTime, isTerminalRequest)).ToList(),
                isTerminalRequest
                );

            RequestGroups.Add(requestGroup);

            return(requestGroup);
        }
Ejemplo n.º 8
0
            private bool SearchNewCombinations()
            {
                PuzzleBox puzzleBox = new PuzzleBox(MaxPlayerCount, RequestGroups.ToArray());

                return(AddToValidCombinations(puzzleBox.SearchNewCombinations()));
            }