public Agent GetFullCopy() { var result = new Agent(ID, new List<KVP>() { }, _imageDictionary, _uiDispatcher); //result.Background = this.Background.CloneCurrentValue(); result.IsPresent = IsPresent; result.Status = Status; result.Source = Source.CloneCurrentValue(); result.LastStep = LastStep; result.FirstStep = FirstStep; result.IsExpanded = IsExpanded; result.IsPaneExpanded = IsPaneExpanded; result.IsPresent = IsPresent; result.Minimized = Minimized; result.Account = Account; ObservableCollection<Item> ti = new ObservableCollection<Item>(); foreach (var item in Items) { ti.Add(item.GetFullCopy()); } result.Items = ti; return result; }
public Agent GetNeutralCopy() { var result = new Agent(ID, new List<KVP>(){}, _imageDictionary, _uiDispatcher ); result.Background = new SolidColorBrush(Colors.White); result.IsPresent = true; result.Status = ElementStatus.Unchanged; result.Source = Source; result.LastStep = LastStep; result.FirstStep = FirstStep; result.IsExpanded = IsExpanded; result.IsPaneExpanded = IsPaneExpanded; result.IsPresent = IsPresent; result.Minimized = Minimized; result.Account = Account; return result; }
private static void UpdateAgentItems(Agent oldAgent, Agent newAgent, Dispatcher uiThread) { var ItemsToRemove = new List<Item>(); foreach (var item in oldAgent.Items) { if (item.Status == ElementStatus.Deleted) { ItemsToRemove.Add(item); } else { Item newI = GetItemByKey(newAgent.Items, item.Key); if (newI == null) { item.Status = ElementStatus.Deleted; } else { ElementStatus st = Item.Compare(item, newI); if (st != ElementStatus.Unchanged) { UpdateItem(item, newI); } item.Status = st; } } } foreach (var item1 in ItemsToRemove) { uiThread.Invoke(() => { oldAgent.Items.Remove(item1); }); } foreach (var item in newAgent.Items) { if (!ContainsItem(oldAgent.Items, item.Key)) { Item item1 = item; item1.Status = ElementStatus.New; ObservableCollection<Item> nIt = oldAgent.Items; nIt.Add(item1); uiThread.Invoke(() => oldAgent.itms = nIt); //Vik -- kostyl'!!!!!!! } } oldAgent.Account = newAgent.Account; }
public static EnvironmentState MapState(KVP root, AgentDataDictionary _agentDataDictionary, Dispatcher uiThread) { ObservableCollection<Agent> agList = new ObservableCollection <Agent>(); ObservableCollection<Item> aucList = new ObservableCollection<Item>(); ObservableCollection<Item> comList = new ObservableCollection<Item>(); Dictionary<String, List<KVP>> agts = new Dictionary<string, List<KVP>>(); EnvironmentState state = new EnvironmentState(); foreach (var kvp in root.ListOfItems) { if (kvp.Key.Equals("clock")) { state.Clock = new Clock(kvp); } Item tItem = Item.KvpToItem(kvp, _agentDataDictionary, uiThread); if (AgentDataDictionary.IsSpecialItem(tItem.InstanceOf)) { aucList.Add(tItem); } if (kvp.Key.StartsWith("event")) { //VIK - for future use //Vik -- the future has come. 2014-08-25 state.Event = new SystemEvent(kvp, _agentDataDictionary); } else { foreach (var elt in kvp.ListOfItems) { if (elt.Key.Equals("held_by")) { if (!agts.ContainsKey(elt.Value)) { agts.Add(elt.Value, new List<KVP> {kvp}); } else { List<KVP> tl; if (agts.TryGetValue(elt.Value, out tl)) { tl.Add(kvp); } } } if (elt.Key.Equals("owned_by")) { if (!agts.ContainsKey(elt.Value)) { agts.Add(elt.Value, new List<KVP> {}); } } } } } foreach (var agt in agts) { if (!agt.Key.StartsWith("_")) { Agent malagent = new Agent(agt.Key, agt.Value, _agentDataDictionary, uiThread); agList.Add(new Agent(agt.Key, agt.Value, _agentDataDictionary, uiThread)); } else { ObservableCollection<Item> tRights = Item.KvpToItems(agt.Value, _agentDataDictionary, uiThread); foreach (var tRight in tRights) { comList.Add(tRight); } } } if (!agts.ContainsKey("god")) { agList.Add(new Agent("god", new List<KVP>(), _agentDataDictionary, uiThread)); } state.Agents = agList; //foreach (var ag in state.AllAgents) //{ // if (!StateObjectMapper.ContainsAgent(state.Agents, ag.ID)) // { // ag.Status = ElementStatus.Deleted; // } // else // { // ag.Status = ElementStatus.Unchanged; // } //} state.Auctions = aucList; state.CommonRights = comList; return state; }