Пример #1
0
        private SupervisedAgentViewModel CreateAgentViewModel(agentType agent)
        {
            SupervisedAgentViewModel avm = new SupervisedAgentViewModel(Model);

            avm.DisplayName = agent.displayname;

            Int64 startTime;

            if (Int64.TryParse(agent.statuschangedtime, out startTime))
            {
                avm.StartTime = new DateTime(startTime).ToLocalTime();
            }


            if (agent.mediatypes != null)
            {
                foreach (string m in agent.mediatypes)
                {
                    avm.MediaTypes.Add(m);
                }
            }

            avm.Status = agent.status;
            avm.Uri    = agent.uri;

            return(avm);
        }
Пример #2
0
        private void ModelAgentsChanged(object sender, AgentsChangedEventArgs e)
        {
            foreach (string uri in e.AgentsRemoved)
            {
                Agents.Remove(new SupervisedAgentViewModel(Model)
                {
                    Uri = uri
                });
            }

            foreach (agentType agent in e.AgentsUpdated)
            {
                SupervisedAgentViewModel avm = CreateAgentViewModel(agent);

                int index;

                if ((index = _agents.IndexOf(avm)) != -1)
                {
                    _agents[index].DisplayName = avm.DisplayName;

                    _agents[index].StartTime = avm.StartTime;
                    _agents[index].Status    = avm.Status;

                    _agents[index].MediaTypes.Clear();

                    if (avm.MediaTypes != null)
                    {
                        foreach (string m in avm.MediaTypes)
                        {
                            _agents[index].MediaTypes.Add(m);
                        }
                    }
                }
                else
                {
                    avm.PropertyChanged += AvmPropertyChanged;
                    avm.Monitored       += AvmMonitored;

                    Agents.Add(avm);
                }
            }
        }