Exemple #1
0
        /// <summary>
        /// Gets the orchard tenants which satisfy the current cmdlet parameters.
        /// </summary>
        /// <returns>Sequence of <see cref="OrchardTenant"/> objects.</returns>
        private IEnumerable <OrchardTenant> GetTenantsFromParameters()
        {
            if (!string.IsNullOrEmpty(this.Name))
            {
                OrchardTenant tenant = this.tenantAgent.GetTenant(this.Name);
                if (tenant != null)
                {
                    yield return(tenant);
                }
            }
            else
            {
                IEnumerable <OrchardTenant> tenants = this.tenantAgent.GetTenants();

                if (this.Enabled.ToBool())
                {
                    tenants = tenants.Where(t => t.State == TenantState.Running);
                }

                if (this.Disabled.ToBool())
                {
                    tenants = tenants.Where(t => t.State == TenantState.Disabled);
                }

                foreach (OrchardTenant tenant in tenants)
                {
                    yield return(tenant);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets a list of Orchard tenants from which features should be returned.
        /// </summary>
        /// <returns>A sequence of <see cref="OrchardTenant"/> objects.</returns>
        private IEnumerable <OrchardTenant> GetTenantsFromParameters()
        {
            var tenants = new List <OrchardTenant>();

            if (this.FromAllTenants.ToBool())
            {
                tenants.AddRange(this.allTenants);
            }
            else if (!string.IsNullOrEmpty(this.Tenant))
            {
                OrchardTenant namedTenant = this.allTenants.SingleOrDefault(
                    s => s.Name.Equals(this.Tenant, StringComparison.OrdinalIgnoreCase));

                if (namedTenant != null)
                {
                    tenants.Add(namedTenant);
                }
                else
                {
                    var ex = new ArgumentException("Failed to find tenant with name '" + this.Tenant + "'.");
                    this.WriteError(ex, "FailedToFindTenant", ErrorCategory.InvalidArgument);
                }
            }
            else if (this.TenantObject != null)
            {
                tenants.Add(this.TenantObject);
            }
            else
            {
                OrchardTenant tenant = this.GetCurrentTenant();
                if (tenant != null)
                {
                    tenants.Add(tenant);
                }
                else
                {
                    OrchardTenant defaultTenant = this.allTenants.SingleOrDefault(
                        s => s.Name.Equals("Default", StringComparison.OrdinalIgnoreCase));

                    if (defaultTenant != null)
                    {
                        tenants.Add(defaultTenant);
                    }
                    else
                    {
                        var ex = new ArgumentException("Failed to find tenant with name 'Default'.");
                        this.WriteError(ex, "FailedToFindTenant", ErrorCategory.InvalidArgument);
                    }
                }
            }

            return(tenants);
        }
Exemple #3
0
        /// <summary>
        /// Provides a record-by-record processing functionality for the cmdlet.
        /// </summary>
        protected override void ProcessRecord()
        {
            string tenantName = null;

            if ((this.ParameterSetName != "FeatureObject") && string.IsNullOrEmpty(this.Tenant))
            {
                // Get feature for current tenant if tenant name not specified
                OrchardTenant tenant = this.GetCurrentTenant();
                tenantName = tenant != null ? tenant.Name : "Default";
            }

            if (!string.IsNullOrEmpty(this.Tenant))
            {
                tenantName = this.Tenant;
            }

            OrchardFeature feature = null;

            if (this.ParameterSetName == "Default")
            {
                feature = this.GetOrchardFeature(tenantName, this.Name);
                if (feature == null)
                {
                    this.WriteError(
                        new ArgumentException("Failed to find feature with name '" + this.Name + "'."),
                        "FailedToFindFeature",
                        ErrorCategory.InvalidArgument);
                }
            }
            else if (this.ParameterSetName == "FeatureObject")
            {
                feature    = this.Feature;
                tenantName = this.Feature.TenantName;
            }

            if (feature != null)
            {
                if (this.ShouldProcess("Feature: " + feature.Id + ", Tenant: " + tenantName, "Enable Feature"))
                {
                    this.modulesAgent.EnableFeature(tenantName, feature.Id, !this.WithoutDependencies.ToBool());
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Provides a record-by-record processing functionality for the cmdlet.
        /// </summary>
        protected override void ProcessRecord()
        {
            OrchardTenant tenant     = this.GetCurrentTenant();
            string        tenantName = tenant != null ? tenant.Name : "Default";

            string output = null;

            switch (this.ParameterSetName)
            {
            case "Default":
                output = this.InvokeDefault(tenantName, this.Name, this.Parameters, this.DirectConsole);
                break;

            case "CommandObject":
                output = this.InvokeCommandObject(tenantName, this.Command, this.Parameters, this.DirectConsole);
                break;
            }

            if (!this.DirectConsole)
            {
                this.WriteObject(output);
            }
        }
Exemple #5
0
 public TenantNode(IPowerShellVfs vfs, OrchardTenant tenant)
     : base(vfs, tenant.Name)
 {
     this.Item = tenant;
 }