示例#1
0
        public void SetAvailability(bool available)
        {
            var existing = DataItems.FirstOrDefault(i => string.Compare(i.Type, DataItemType.AVAILABILITY.ToString(), StringComparison.OrdinalIgnoreCase) == 0);

            if (existing == null)
            {
                return;
            }

            existing.SetValue(available ? "AVAILABLE" : "UNAVAILABLE");
        }
示例#2
0
        public bool IsPackApplicable()
        {
            var parentPackItem = DataItems.FirstOrDefault(p => !p.FeatureId.HasValue && p.FeaturePackId.HasValue);

            return(parentPackItem != null && !parentPackItem.IsNonApplicableFeatureInGroup);
        }
 public MyCustomSingleData FirstOrDefault()
 {
     return(DataItems.FirstOrDefault());
 }
 public MyCustomSingleData FirstOrDefault(string criteria = null)
 {
     return(DataItems.FirstOrDefault(GetExpression(criteria)));
 }
示例#5
0
文件: Node.cs 项目: mahdiz/mpclib
        public override void Receive(Message msg)
        {
            base.Receive(msg);

            var bnMsg = msg as BnMessage;

            if (bnMsg == null)
            {
                throw new Exception("Invalid message type.");
            }

            switch (bnMsg.Type)
            {
            case BnMessageType.Setup:
                var setupMsg = bnMsg as SetupMessage;
                if (setupMsg == null)
                {
                    throw new Exception("Invalid message type.");
                }

                Initialize(setupMsg);
                break;

            case BnMessageType.Store:
                // TODO: Check duplicate data items
                DataItems.Add(bnMsg.Data as IDataItem <T>);
                if (DataItems == null)
                {
                    throw new Exception("Invalid message payload.");
                }
                break;

            case BnMessageType.Query:
                var query = bnMsg.Data as IDataItem <T>;
                if (query == null)
                {
                    throw new Exception("Invalid message payload.");
                }

                Search(query);
                break;

            case BnMessageType.Data:
                var dataMsg = bnMsg as DataMessage;
                if (dataMsg == null)
                {
                    throw new Exception("Invalid message type.");
                }

                if (dataMsg.Direction == DataMessageDir.Down)
                {
                    var ddMsg = (DataDownMessage)dataMsg;
                    if (ddMsg.NextSupernode >= netWidth * (netHeight - 1))
                    {
                        if (ddMsg.NextSupernode != ddMsg.DestinationSupernode)
                        {
                            throw new Exception("Routing error: unexpected message received at bottom.");
                        }

                        // reached a bottom supernode; send my data item up along the
                        // same path as the query was sent downwards if the titles match.
                        query = dataMsg.Data as IDataItem <T>;
                        if (query == null)
                        {
                            throw new Exception("Invalid query message received in bottom node " + Id);
                        }

                        var dataItem = DataItems.FirstOrDefault(di => di.Title == query.Title);
                        if (dataItem == null)
                        {
                            throw new Exception("Data item not found in node " + Id);
                        }
                        else
                        {
                            var upMsg = new DataMessage(DataMessageDir.Up,
                                                        dataMsg.BackPath, dataItem);
                            ForwardDataUp(upMsg);
                        }
                    }
                    else
                    {
                        ForwardDataDown(ddMsg);
                    }
                }
                else
                {
                    var backConn = dataMsg.BackPath.Pop();
                    if (dataMsg.BackPath.Count == 0)
                    {
                        if (SearchFinished != null)
                        {
                            SearchFinished(this);
                        }

                        Console.WriteLine("Search result received in node " +
                                          Id + " from node " + dataMsg.SenderId + ". Result title is '" +
                                          ((IDataItem <System.Drawing.Image>)dataMsg.Data).Title + "'");
                    }
                    else
                    {
                        if (!ReceivedData.ContainsKey(backConn.FromSupernode))
                        {
                            ReceivedData[backConn.FromSupernode] = new List <IDataItem <T> >();
                            ForwardDataUp(dataMsg);
                        }
                        ReceivedData[backConn.FromSupernode].Add((IDataItem <T>)dataMsg.Data);
                    }
                }
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#6
0
 public void Remove(string dataItemValue)
 {
     DataItems.FirstOrDefault(x => x.Current.Name == dataItemValue).AsSelectionItem().RemoveFromSelection();
 }