示例#1
0
        public static ICommand CreateInstance(ConfigurationAction action)
        {
            log.Debug(m => m("Creating command instance for action '{0}'...", action));
            var command = default(ICommand);

            switch (action)
            {
            case ConfigurationAction.Console:
                command = new ConsoleCommand();
                break;

            case ConfigurationAction.Install:
                command = new InstallCommand();
                break;

            case ConfigurationAction.Uninstall:
                command = new UninstallCommand();
                break;

            case ConfigurationAction.Run:
                command = new RunCommand();
                break;
            }
            log.Debug(m => m("Done creating command instance for action '{0}'.", action));
            return(command);
        }
示例#2
0
        public void ConfigureFor()
        {
            ConfigurationAction configurationAction = s => s.InThreadScope();

            this.testee.ConfigureFor <int>(configurationAction);

            this.conventionBindingBuilderMock.Verify(b => b.ConfigureFor <int>(configurationAction));
        }
 /// <summary>根据约定绑定</summary>
 private void BindByConvention <T>(Assembly assembly, IFromSyntax fromSyntax, Func <Type, bool> filter,
                                   ConfigurationAction configuration)
 {
     fromSyntax.From(assembly)
     .IncludingNonePublicTypes()
     .SelectAllClasses()
     .InheritedFrom <T>()
     .Where(filter)
     .BindDefaultInterfaces()
     .Configure(configuration);
 }
示例#4
0
        public void ConfigureFor <T>(ConfigurationAction configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            var type = typeof(T);

            foreach (var syntax in this.bindingSyntax[type])
            {
                configuration(syntax);
            }
        }
示例#5
0
        /// <summary>
        /// Configures the bindings using the specified configuration.
        /// </summary>
        /// <param name="configuration">The configuration that is applies to the bindings.</param>
        public void Configure(ConfigurationAction configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            foreach (var bindingSyntaxEntry in this.bindingSyntax)
            {
                foreach (var syntax in bindingSyntaxEntry.Value)
                {
                    configuration(syntax);
                }
            }
        }
        public override bool Compatible(ConfigurationAction action)
        {
            if (!action.ModifyingContainer.Name.Equals(this.ConstrainedContainer.Name) || !action.ServerName.Equals(this.ServerName))
            {
                return(true);
            }

            if (Type == LocationConstraintType.Replicate && action.GetType() == typeof(RemoveSecondaryServer))
            {
                return(false);
            }
            else if (Type == LocationConstraintType.DoNotReplicate && (action.GetType() == typeof(AddPrimaryServer) || action.GetType() == typeof(AddSecondaryServer) || action.GetType() == typeof(MakeSoloPrimaryServer)))
            {
                return(false);
            }

            return(true);
        }
示例#7
0
        private static string ReconfigActionText(ConfigurationAction act)
        {
            string text;

            switch (act.GetType().Name)
            {
            case "MakeSoloPrimaryServer": text = "Move the primary site to " + SiteName(act.ServerName); break;

            case "AddPrimaryServer": text = "Add a primary replica in " + SiteName(act.ServerName); break;

            case "AddSecondaryServer": text = "Add a secondary replica in " + SiteName(act.ServerName); break;

            case "AdjustSyncPeriod": text = "Reduce the sync period for site " + SiteName(act.ServerName); break;

            case "DowngradePrimary": text = "Downgrade from primary to secondary site " + SiteName(act.ServerName); break;

            case "RemoveSecondaryServer": text = "Remove the secondary replica in " + SiteName(act.ServerName); break;

            default: text = act.GetType().Name + " " + SiteName(act.ServerName); break;
            }
            return(text);
        }
 public DatabaseBindingGatherer Configure(ConfigurationAction action)
 {
     _options.ConfigurationAction = action;
     return new DatabaseBindingGatherer(_options);
 }
        internal override void Apply(List <ConfigurationAction> newActions, List <ConfigurationConstraint> constraints, SortedSet <ServiceLevelAgreement> SLAs, Dictionary <string, ClientUsageData> clientData)
        {
            if (Type == LocationConstraintType.Replicate)
            {
                //first, we check if the tablet is already replicated in the particular server or not.
                if (Configuration.SecondaryServers.Contains(ServerName) || Configuration.PrimaryServers.Contains(ServerName))
                {
                    //the constraint is already in place. we just have to make sure that no new action in actions list remove it.
                    ConfigurationAction toRemove = null;
                    foreach (ConfigurationAction action in newActions)
                    {
                        if (action.GetType() == typeof(RemoveSecondaryServer) && action.ServerName.Equals(this.ServerName))
                        {
                            toRemove = action;
                            break;
                        }
                    }
                    if (toRemove != null)
                    {
                        newActions.Remove(toRemove);
                        return;
                    }
                }
                else
                {
                    //the constraint is not being enforced. We need to enforce it by creating a new replica.
                    //First we see if the new replica is being created in the new actions
                    foreach (ConfigurationAction action in newActions)
                    {
                        if ((action.GetType() == typeof(AddPrimaryServer) || action.GetType() == typeof(AddSecondaryServer) || action.GetType() == typeof(MakeSoloPrimaryServer)) && action.ServerName.Equals(this.ServerName))
                        {
                            return;
                        }
                    }
                    //we could not find an action enforcing the this constraint.
                    //Hence, we add an action with the minimum cost ourselves. I.e., adding secondary server.
                    newActions.Add(new AddSecondaryServer(Configuration.Name, ServerName, 0, null, ConfigurationActionSource.Constraint));
                }
            }
            else
            {
                //we need to avoid replicating in a particular server.
                //first, we check if the tablet is already replicated in the particular server or not.
                if (Configuration.SecondaryServers.Contains(ServerName) || Configuration.PrimaryServers.Contains(ServerName))
                {
                    //we have to enforce the constraint because it is already being replicated.
                    //We first check to see if there exists a new action removing the container or not.
                    List <ConfigurationAction> toRemove = new List <ConfigurationAction>();
                    foreach (ConfigurationAction action in newActions)
                    {
                        if (action.ModifyingContainer.Name.Equals(ConstrainedContainer.Name) && action.ServerName.Equals(this.ServerName))
                        {
                            toRemove.Add(action);
                        }
                    }
                    //we have to remove all actions on a particular container of this server
                    newActions.RemoveAll(o => toRemove.Contains(o));

                    //we finally add a remove action.
                    if (Configuration.PrimaryServers.Contains(ServerName))
                    {
                        //we first downgrade the primary
                        newActions.Add(new DowngradePrimary(Configuration.Name, ServerName, 0, null, ConfigurationActionSource.Constraint));
                    }
                    //we totally remove the replica
                    newActions.Add(new RemoveSecondaryServer(Configuration.Name, ServerName, 0, null, ConfigurationActionSource.Constraint));
                }
                else
                {
                    //The container is not being replicated in the server.
                    //We just need to make sure that a new action does not replicate it.
                    List <ConfigurationAction> toRemove = new List <ConfigurationAction>();
                    foreach (ConfigurationAction action in newActions)
                    {
                        if (action.ModifyingContainer.Name.Equals(ConstrainedContainer.Name) && action.ServerName.Equals(this.ServerName))
                        {
                            toRemove.Add(action);
                        }
                    }
                    //we have to remove all actions on this container
                    newActions.RemoveAll(o => toRemove.Contains(o));
                }
            }
        }
 /// <summary>
 /// Checks whether the given action is compatible (applicable) with this constraint.
 /// </summary>
 /// <param name="action"></param>
 /// <returns>true if the action is compatible (applicable) with this constraint, false otherwise.</returns>
 public abstract bool Compatible(ConfigurationAction action);
示例#11
0
 public override bool Compatible(ConfigurationAction action)
 {
     // TODO: not implemented.
     return(true);
 }
示例#12
0
 /// <summary>
 /// Configures the bindings with the specified configuration.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <returns>The fluent syntax.</returns>
 public IConfigureForSyntax Configure(ConfigurationAction configuration)
 {
     this.bindingBuilder.Configure(configuration);
     return(this);
 }
示例#13
0
 public override bool Compatible(ConfigurationAction action)
 {
     return(true);
 }
 private void Register(string assemlyMask, string nameEndsWith, ConfigurationAction configurationAction)
 {
     Kernel.Bind(x => x.FromAssembliesMatching(assemlyMask).Select(t => t.FullName.EndsWith(nameEndsWith)).BindDefaultInterface().Configure(configurationAction));
 }
示例#15
0
 private ICommand createCommand(ConfigurationAction action)
 {
     return(CommandFactory.CreateInstance(action));
 }