Example #1
0
        private async Task CreateNewPlanAsync(DomainState state, DomainState goalState, CancellationToken token)
        {
            var actionSet = GetActionSet();

            try
            {
                _logger.Debug("Starting planning to reach goal `{0}`.", CurrentGoal.GoalName);

                var result = await Task.Run(() => _planner.GetPlan(state, goalState, actionSet), token);

                if (!result.Success)
                {
                    return;
                }

                foreach (var action in result.Plan)
                {
                    _actionQueue.Enqueue(action);
                }
            }
            catch (OperationCanceledException)
            {
                _logger.Debug("Planning was canceled.");
            }
        }
Example #2
0
 public DomainEventArgs(Authentication authentication, IDomain domain)
 {
     this.domain = domain;
     this.domainInfo = domain.DomainInfo;
     this.domainState = domain.DomainState;
     this.signatureDate = authentication.SignatureDate;
 }
Example #3
0
        private DomainState WaitWhilePendingState(DomainState pendingState, LocalizedString pendingMessage, LiveFederationProvision.GetDomainStateDelegate getDomainState)
        {
            int         num         = 20;
            int         num2        = (int)((double)(100 - num) / (LiveFederationProvision.PendingStateWait.TotalSeconds / LiveFederationProvision.PendingStateWaitInterval.TotalSeconds));
            DateTime    t           = DateTime.UtcNow + LiveFederationProvision.PendingStateWait;
            DomainState domainState = DomainState.Unknown;

            for (;;)
            {
                this.WriteProgress(pendingMessage, pendingMessage, num);
                try
                {
                    domainState = getDomainState();
                }
                catch (LiveDomainServicesException)
                {
                    domainState = DomainState.Unknown;
                }
                if (domainState != pendingState || DateTime.UtcNow > t)
                {
                    break;
                }
                Thread.Sleep(LiveFederationProvision.PendingStateWaitInterval);
                num += num2;
            }
            return(domainState);
        }
Example #4
0
        protected void ReserveDomain(string domain, string applicationIdentifier, ManageDelegationClient client, LocalizedString errorProofDomainOwnership, LiveFederationProvision.GetDomainStateDelegate getDomainState)
        {
            LocalizedString localizedString = Strings.SetLiveFedDomainReserveRequest(domain);

            this.WriteVerbose(localizedString);
            this.WriteProgress(localizedString, localizedString, 0);
            try
            {
                client.ReserveDomain(applicationIdentifier, domain, "ExchangeConnector");
            }
            catch (LiveDomainServicesException ex)
            {
                if (ex.DomainError != null && ex.DomainError.Value == DomainError.ProofOfOwnershipNotValid)
                {
                    throw new DomainProofOwnershipException(errorProofDomainOwnership, ex);
                }
                throw new UnableToReserveDomainException(domain, applicationIdentifier, ex.Message, ex);
            }
            this.WriteVerbose(Strings.SetLiveFedDomainReserveResponse(domain));
            DomainState domainState = this.WaitWhilePendingState(DomainState.PendingActivation, localizedString, getDomainState);

            this.WriteProgress(localizedString, localizedString, 100);
            if (domainState == DomainState.Unknown)
            {
                this.WriteVerbose(Strings.ErrorCannotGetDomainStatusFromPartnerSTS(domain, applicationIdentifier, string.Empty));
                return;
            }
            if (DomainState.PendingRelease == domainState)
            {
                throw new UnableToReserveDomainException(domain, applicationIdentifier, DomainState.PendingRelease.ToString());
            }
        }
Example #5
0
        private static bool TryApplyEffects(IDomainAction action, DomainState goalState, out DomainState newState)
        {
            newState = goalState;

            foreach (var pair in action.Effects)
            {
                var worldVar = pair.Key;

                // Preconditions aren't violated, so we just ignore this
                if (!goalState.TryGet(worldVar, out object value))
                {
                    continue;
                }

                // If any effect clashes with the goal state, the plan node is invalid
                if (!Equals(value, pair.Value))
                {
                    return(false);
                }

                // If the goal is fulfilled, we can remove it from the search
                newState = newState.Remove(worldVar);
            }

            return(true);
        }
Example #6
0
        public Task RegisterAsync(RegisterCommand command)
        {
            DomainState.Register(this.GetActorId().GetGuidId(), command.Name,
                                 command.Address.ToDomainModel(), command.Subject.ToDomainModel());

            return(Task.FromResult(true));
        }
Example #7
0
 public override async Task<bool> ExecuteAsync(DomainState currentState, CancellationToken token)
 {
     var source = new TaskCompletionSource<bool>();
     token.Register(() => source.SetResult(true));
     await source.Task;
     
     return true;
 }
Example #8
0
        private void StartNotActiveState()
        {
            this.domainState = DomainState.NOT_ACTIVE;

            Color newColor = this.TargetedColor;

            newColor.A         = 0;
            this.TargetedColor = newColor;
        }
Example #9
0
        private void StartActiveState()
        {
            this.domainState = DomainState.ACTIVE;

            Color newColor = this.TargetedColor;

            newColor.A         = 255;
            this.TargetedColor = newColor;
        }
Example #10
0
        public override PlanningResult GetPlan(DomainState startState, DomainState goalState, ActionSet actions)
        {
            Plan GetOptions(IPlanNode node) => RegressivePlanner.GetOptions(node, actions, startState);

            var start = new PlanNode(goalState, null, null, 0);

            var(path, graph) = FindPlan(start, startState.IsSuperstateOf, GetOptions);

            return(new PlanningResult
            {
                Plan = GetActions(path),
                SearchTree = graph
            });
        }
Example #11
0
        private static Plan GetOptions(IPlanNode node, ActionSet actions, DomainState startState)
        {
            var goalState       = node.State;
            var expandedActions = new HashSet <IDomainAction>();

            foreach (var(worldVar, targetValue) in goalState.GetAll())
            {
                if (!actions.TryGetOut(worldVar, out var matchingActions))
                {
                    continue;
                }

                // TODO create path for numeric values
                foreach (var(action, effectValue) in matchingActions)
                {
                    if (expandedActions.Contains(action))
                    {
                        continue;
                    }
                    if (!Equals(effectValue, targetValue))
                    {
                        continue;
                    }

                    // Discard actions with effects that don't overlap with goal state
                    if (!TryApplyEffects(action, goalState, out var nextStateToFind))
                    {
                        continue;
                    }

                    // Check if precondition violates search
                    if (AnyPreconditionConflictsWithGoal(action.Preconditions, nextStateToFind))
                    {
                        continue;
                    }

                    // And inject new preconditions into new search state
                    nextStateToFind = nextStateToFind.SetRange(action.Preconditions);

                    // No need to expand action again
                    expandedActions.Add(action);

                    yield return(new PlanNode(nextStateToFind, action, node, nextStateToFind.DistanceTo(startState)));
                }
            }
        }
Example #12
0
        public float GetGoalWeight(DomainState currentState)
        {
            if (Considerations.Count == 0)
            {
                return(Weight);
            }

            var score = 1.0f;

            foreach (var consideration in Considerations)
            {
                score *= consideration.GetValue(currentState);
            }

            var modFactor          = 1 - 1 / Considerations.Count;
            var makeUpFactor       = (1 - score) * modFactor;
            var considerationScore = score + makeUpFactor * score;

            return(considerationScore * Weight);
        }
Example #13
0
        private async Task <DomainState> ReplanAsync(DomainState state, CancellationToken token)
        {
            var goalState = SetNextGoal(ref state);

            if (goalState == null)
            {
                throw new InvalidOperationException("Agent could not find goal to fulfill!");
            }

            await CreateNewPlanAsync(state, goalState, token);

            if (_actionQueue.Count == 0)
            {
                throw new InvalidOperationException("ActionQueue of agent could not be filled!");
            }

            OnNewPlanCreated(_actionQueue.ToList());

            return(state);
        }
Example #14
0
        private IAgentGoal FindBestRatedGoal(DomainState currentState)
        {
            _logger.Debug("Searching goal for next plan, was `{0}`.", CurrentGoal?.GoalName ?? "None");

            var        currentMax = float.MinValue;
            IAgentGoal bestGoal   = null;

            foreach (var goal in Goals)
            {
                var goalScore = goal.GetGoalWeight(currentState);
                if (!(goalScore > currentMax))
                {
                    continue;
                }

                currentMax = goalScore;
                bestGoal   = goal;
            }

            return(bestGoal);
        }
Example #15
0
        /// <summary>
        /// To the entity state.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns>The entity state.</returns>
        public static EntityState ToEntityState(this DomainState state)
        {
            switch (state)
            {
            case DomainState.Added:
                return(EntityState.Added);

            case DomainState.Deleted:
                return(EntityState.Deleted);

            case DomainState.Detached:
                return(EntityState.Detached);

            case DomainState.Modified:
                return(EntityState.Modified);

            case DomainState.Unchanged:
            default:
                return(EntityState.Unchanged);
            }
        }
Example #16
0
        private DomainState SetNextGoal(ref DomainState state)
        {
            var goal = FindBestRatedGoal(state);

            if (goal == null)
            {
                var fallBack = OnNoGoalFound(ref state);
                if (fallBack == null)
                {
                    return(null);
                }

                goal = fallBack;
            }

            var goalState = DomainState.Empty;

            CurrentGoal = OnNewGoalSelected(goal);

            goal.OnActivation(ref state, ref goalState);

            return(goalState);
        }
Example #17
0
        private async Task ExecuteAction(IAsyncExecutableAction action, DomainState currentState, CancellationToken token)
        {
            OnActionStarting(action);
            CurrentAction = action;

            try
            {
                var actionSucceeded = await action.ExecuteAsync(currentState, token);

                if (actionSucceeded)
                {
                    OnActionCompleted(action);
                }
                else
                {
                    OnActionFailed(action);
                }
            }
            catch (OperationCanceledException)
            {
                CurrentAction = null;
            }
        }
Example #18
0
        public DomainDescriptor(Authentication authentication, IDomain domain, DescriptorTypes descriptorTypes, object owner)
            : base(authentication, domain, descriptorTypes)
        {
            this.domain = domain;
            this.owner  = owner ?? this;
            this.domain.Dispatcher.VerifyAccess();
            this.domainInfo  = domain.DomainInfo;
            this.domainState = domain.DomainState;

            this.domainUsersReadonly = new ReadOnlyObservableCollection <DomainUserDescriptor>(this.domainUsers);

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
            {
                this.domain.Deleted            += Domain_Deleted;
                this.domain.RowAdded           += Domain_RowAdded;
                this.domain.RowChanged         += Domain_RowChanged;
                this.domain.RowRemoved         += Domain_RowRemoved;
                this.domain.PropertyChanged    += Domain_PropertyChanged;
                this.domain.DomainInfoChanged  += Domain_DomainInfoChanged;
                this.domain.DomainStateChanged += Domain_DomainStateChanged;
            }

            if (this.descriptorTypes.HasFlag(DescriptorTypes.IsRecursive) == true)
            {
                if (this.descriptorTypes.HasFlag(DescriptorTypes.IsSubscriptable) == true)
                {
                    this.domain.UserAdded   += Domain_UserAdded;
                    this.domain.UserRemoved += Domain_UserRemoved;
                }

                foreach (var item in this.domain.Users)
                {
                    this.domainUsers.Add(new DomainUserDescriptor(authentication, item, this.descriptorTypes, this.owner));
                }
            }
        }
Example #19
0
 private async void Domain_RowRemoved(object sender, DomainRowEventArgs e)
 {
     this.domainInfo  = this.domain.DomainInfo;
     this.domainState = this.domain.DomainState;
     await this.RefreshAsync();
 }
 public float GetValue(DomainState currentState)
 {
     return(_getValue(currentState));
 }
Example #21
0
 private void DomainNameState_StateChanged(object sender, DomainState e)
 {
     StateHasChanged();
 }
Example #22
0
 public virtual float GetCost(DomainState currentState) => StaticCost;
Example #23
0
 public static DomainState ReduceFetchDomainAction(DomainState state, FetchDomainNameAction _) =>
 new DomainState(null, state.ClusterDomains, null, true, null);
Example #24
0
 public static DomainState ReduceFetchClusterDomainFailureAction(DomainState state, FetchClusterDomainNameFailureAction action) =>
 new DomainState(state.Domains, null, null, false, action.ErrorMessage);
Example #25
0
 public static DomainState ReduceFetchClusterDomainSuccessAction(DomainState state, FetchClusterDomainNameSuccessAction action) =>
 new DomainState(state.Domains, action.DomainNames, null, false, null);
Example #26
0
 private async void Domain_DomainStateChanged(object sender, EventArgs e)
 {
     this.domainState = this.domain.DomainState;
     await this.RefreshAsync();
 }
Example #27
0
 private async void Domain_PropertyChanged(object sender, DomainPropertyEventArgs e)
 {
     this.domainInfo  = this.domain.DomainInfo;
     this.domainState = this.domain.DomainState;
     await this.RefreshAsync();
 }
Example #28
0
        protected virtual void OnActionHasUnsatisfiedPreconditions(IDomainAction action, DomainState state)
        {
            var unsatisfiedConditions = action.Preconditions
                                        .Where(cond => !state.Fulfills(cond.Key, cond.Value))
                                        .Select(cond => $"({cond.Key}, {cond.Value} != {state.GetValueOrDefault<object>(cond.Key)})");

            var conditionString = string.Join(", ", unsatisfiedConditions);

            _logger.Warn("Action `{0}` has unsatisfied preconditions [{1}]. Flushing ActionQueue.", action.ActionName, conditionString);

            _actionQueue.Clear();
        }
Example #29
0
        private FederatedOrganizationIdWithDomainStatus CreatePresentationObject(FederatedOrganizationId fedOrgId, bool includeExtendedDomainInfo)
        {
            FederatedOrganizationIdWithDomainStatus federatedOrganizationIdWithDomainStatus = new FederatedOrganizationIdWithDomainStatus(fedOrgId);

            if (fedOrgId.DelegationTrustLink == null)
            {
                return(federatedOrganizationIdWithDomainStatus);
            }
            FederationTrust federationTrust = this.ConfigurationSession.Read <FederationTrust>(fedOrgId.DelegationTrustLink);

            if (federationTrust == null)
            {
                fedOrgId.DelegationTrustLink = ADObjectIdResolutionHelper.ResolveDN(fedOrgId.DelegationTrustLink);
                ADSessionSettings             sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), OrganizationId.ForestWideOrgId, null, false);
                ITopologyConfigurationSession topologyConfigurationSession = DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 147, "CreatePresentationObject", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\SystemConfigurationTasks\\Federation\\GetFederatedOrganizationIdentifier.cs");
                federationTrust = topologyConfigurationSession.Read <FederationTrust>(fedOrgId.DelegationTrustLink);
                if (federationTrust == null)
                {
                    return(federatedOrganizationIdWithDomainStatus);
                }
            }
            List <AcceptedDomain> allFederatedDomains = this.GetAllFederatedDomains(fedOrgId);

            if (allFederatedDomains.Count == 0)
            {
                return(federatedOrganizationIdWithDomainStatus);
            }
            foreach (AcceptedDomain acceptedDomain in allFederatedDomains)
            {
                if (acceptedDomain.IsDefaultFederatedDomain)
                {
                    federatedOrganizationIdWithDomainStatus.DefaultDomain = new SmtpDomain(acceptedDomain.DomainName.Domain);
                    break;
                }
            }
            MultiValuedProperty <FederatedDomain> multiValuedProperty = new MultiValuedProperty <FederatedDomain>();

            if (!includeExtendedDomainInfo)
            {
                foreach (AcceptedDomain acceptedDomain2 in allFederatedDomains)
                {
                    multiValuedProperty.Add(new FederatedDomain(new SmtpDomain(acceptedDomain2.DomainName.Domain)));
                }
                federatedOrganizationIdWithDomainStatus.Domains = multiValuedProperty;
                return(federatedOrganizationIdWithDomainStatus);
            }
            FederationProvision federationProvision = FederationProvision.Create(federationTrust, this);

            base.WriteVerbose(Strings.GetFedDomainStatusInfo(FederatedOrganizationId.AddHybridConfigurationWellKnownSubDomain(fedOrgId.AccountNamespace.Domain)));
            DomainState state = DomainState.Unknown;

            try
            {
                state = federationProvision.GetDomainState(FederatedOrganizationId.AddHybridConfigurationWellKnownSubDomain(fedOrgId.AccountNamespace.Domain));
            }
            catch (LocalizedException ex)
            {
                this.WriteError(new CannotGetDomainStatusFromPartnerSTSException(fedOrgId.AccountNamespace.ToString(), federationTrust.ApplicationIdentifier, ex.Message), ErrorCategory.ResourceUnavailable, null, false);
            }
            multiValuedProperty.Add(new FederatedDomain(fedOrgId.AccountNamespace, state));
            foreach (AcceptedDomain acceptedDomain3 in allFederatedDomains)
            {
                SmtpDomain smtpDomain = new SmtpDomain(acceptedDomain3.DomainName.Domain);
                if (!smtpDomain.Equals(fedOrgId.AccountNamespace))
                {
                    multiValuedProperty.Add(new FederatedDomain(smtpDomain));
                }
            }
            federatedOrganizationIdWithDomainStatus.Domains = multiValuedProperty;
            return(federatedOrganizationIdWithDomainStatus);
        }
Example #30
0
 protected virtual IAgentGoal OnNoGoalFound(ref DomainState state)
 {
     _logger.Error("Could not find a new goal for planning!");
     return(null);
 }