Example #1
0
        private IObservable <Tuple <AgentInformation, IObservable <Either <T, Exception> > > > ObserveAllUnsafe <TAgent, T>(string propertyName, ExecutionScopeOptions scope = ExecutionScopeOptions.All, bool ignoreAgentState = false)
            where TAgent : IAgent
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentNullException("propertyName");
            }

            var currentAgents = GetAgentInfos <TAgent>(scope);

            if (!ignoreAgentState)
            {
                currentAgents = currentAgents.Where(a => a.IsReachable && a.LastKnownState == AgentState.Activated);
            }

            var newAgentsSource = this.AgentDataSource
                                  .Where(a =>
                                         (scope.HasFlag(a.IsLocal ? ExecutionScopeOptions.Local : ExecutionScopeOptions.Remote)) &&
                                         a.Contracts.Contains(typeof(TAgent).AssemblyQualifiedName));

            if (!ignoreAgentState)
            {
                newAgentsSource = newAgentsSource.Where(a => a.IsReachable && a.LastKnownState == AgentState.Activated);
            }

            return(Observable
                   .Merge(currentAgents.ToObservable(), newAgentsSource)
                   .Distinct(a => a.AgentId)
                   .Select(a => Tuple.Create(a, ObserveOneUnsafe <T>(a.AgentId, propertyName, ignoreAgentState))));
        }
        internal IEnumerable <AgentInformation> GetAgentInfos <TAgent>(ExecutionScopeOptions scope)
            where TAgent : IAgent
        {
            var agents = Enumerable.Empty <AgentInformation>();

            if (scope.HasFlag(ExecutionScopeOptions.Local))
            {
                agents = agents.Concat(GetLocalAgentInfos <TAgent>());
            }

            if (scope.HasFlag(ExecutionScopeOptions.Remote))
            {
                agents = agents.Concat(GetRemoteAgentInfos <TAgent>());
            }

            return(agents);
        }
        public IEnumerable <Tuple <AgentInformation, TAgent> > GetAgents <TAgent>(ExecutionScopeOptions scope, bool ignoreAgentState = false)
            where TAgent : IAgent
        {
            var agents = Enumerable.Empty <Tuple <AgentInformation, TAgent> >();

            if (scope.HasFlag(ExecutionScopeOptions.Local))
            {
                agents = agents.Concat(GetLocalAgentInfos <TAgent>().Select(info => Tuple.Create((AgentInformation)info, (TAgent)info.Agent)));
            }

            if (scope.HasFlag(ExecutionScopeOptions.Remote))
            {
                agents = agents.Concat(GetRemoteAgentInfos <TAgent>().Select(info => Tuple.Create((AgentInformation)info, (TAgent)info.ServiceClientFactory.CreateServiceClient <TAgent>())));
            }

            if (!ignoreAgentState)
            {
                agents = agents.Where(a => a.Item1.LastKnownState == AgentState.Activated);
            }

            return(agents);
        }