Ejemplo n.º 1
0
        public static HarshServerProvisioner ToServerProvisioner(this HarshProvisionerBase provisioner)
        {
            if (provisioner == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(provisioner));
            }

            var clientProvisioner = (provisioner as HarshProvisioner);
            var serverProvisioner = (provisioner as HarshServerProvisioner);

            if (clientProvisioner != null)
            {
                serverProvisioner = new ClientProvisionerWrapper(clientProvisioner);
            }

            if (serverProvisioner == null)
            {
                throw Logger.Fatal.ArgumentFormat(
                          nameof(provisioner),
                          SR.HarshServerProvisionerConverter_CannotConvert,
                          provisioner.GetType().FullName
                          );
            }

            return(serverProvisioner);
        }
Ejemplo n.º 2
0
        internal static void AddChild <TContext>(HarshProvisionerBase <TContext> parent, Object child)
            where TContext : HarshProvisionerContextBase
        {
            if (parent == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(parent));
            }

            if (child == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(child));
            }

            var provisioner           = (child as HarshProvisionerBase);
            var defaultFromContextTag = (child as IDefaultFromContextTag);

            if (provisioner != null)
            {
                parent.Children.Add(provisioner);
            }
            else if (defaultFromContextTag != null)
            {
                parent.ModifyChildrenContextState(defaultFromContextTag);
            }
            else
            {
                throw Logger.Fatal.ArgumentNotAssignableTo(
                          nameof(child),
                          child,
                          typeof(HarshProvisionerBase),
                          typeof(IDefaultFromContextTag)
                          );
            }
        }
Ejemplo n.º 3
0
        internal static void AddChildren <TContext>(HarshProvisionerBase <TContext> parent, Object children)
            where TContext : HarshProvisionerContextBase
        {
            if (children == null)
            {
                return;
            }

            if ((children is HarshProvisionerBase) || (children is IDefaultFromContextTag))
            {
                AddChild(parent, children);
            }

            var scriptBlock = children as ScriptBlock;

            if (scriptBlock != null)
            {
                children = scriptBlock.Invoke()
                           .Select(c => c.BaseObject);
            }

            var enumerable = children as IEnumerable;

            if (children != null)
            {
                AddChildren(parent, children);
            }

            AddChild(parent, children);
        }
Ejemplo n.º 4
0
 internal static void AddChildren <TContext>(HarshProvisionerBase <TContext> parent, IEnumerable <Object> children)
     where TContext : HarshProvisionerContextBase
 {
     foreach (var child in children)
     {
         AddChild(parent, child);
     }
 }
Ejemplo n.º 5
0
        protected sealed override Task UnprovisionChild(HarshProvisionerBase provisioner, HarshProvisionerContext context)
        {
            if (provisioner == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(provisioner));
            }

            return(((HarshProvisioner)(provisioner)).UnprovisionAsync(context));
        }
Ejemplo n.º 6
0
        protected sealed override async Task UnprovisionChild(HarshProvisionerBase provisioner, HarshServerProvisionerContext context)
        {
            if (provisioner == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(provisioner));
            }

            var serverProvisioner = provisioner.ToServerProvisioner();

            if (ShouldUnprovisionChild(serverProvisioner))
            {
                await serverProvisioner.UnprovisionAsync(context);
            }
        }