protected override void ProcessRecord()
        {
            try
            {
                if (this.GetClusterConnection() == null)
                {
                    throw new Exception("Connection to Cluster is null, Connect to Cluster before invoking the cmdlet");
                }

                Microsoft.ServiceFabric.Powershell.InternalClusterConnection clusterConnection =
                    new Microsoft.ServiceFabric.Powershell.InternalClusterConnection(this.GetClusterConnection());

                var queryResult = clusterConnection.GetTransportBehavioursAsync(
                    this.NodeName,
                    this.GetTimeout(),
                    this.GetCancellationToken()).Result;

                foreach (var item in queryResult)
                {
                    this.WriteObject(this.FormatOutput(item));
                }
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle((ae) =>
                {
                    this.ThrowTerminatingError(
                        ae,
                        ConstantsInternal.GetTransportBehaviorList,
                        this.GetClusterConnection());
                    return(true);
                });
            }
        }
        protected override void ProcessRecord()
        {
            this.WriteObject(string.Format(
                                 "Note:Adding transport behavior causes reliability issues on the cluster.\n" +
                                 "Note: The behavior {0} is applied on the node until it is removed with Remove-ServiceFabricTransportBehavior cmdlet.", BehaviorName));
            if (this.ShouldProcess(this.NodeName))
            {
                if (this.Force || this.ShouldContinue(string.Empty, string.Empty))
                {
                    try
                    {
                        if (this.GetClusterConnection() == null)
                        {
                            throw new Exception("Connection to Cluster is null, Connect to Cluster before invoking the cmdlet");
                        }

                        Microsoft.ServiceFabric.Powershell.InternalClusterConnection clusterConnection =
                            new Microsoft.ServiceFabric.Powershell.InternalClusterConnection(this.GetClusterConnection());
                        ValidateParams();

                        TimeSpan delayInSeconds     = string.IsNullOrEmpty(DelayInSeconds) ? TimeSpan.MaxValue : TimeSpan.FromSeconds(int.Parse(DelayInSeconds));
                        TimeSpan delaySpanInSeconds = string.IsNullOrEmpty(DelaySpanInSeconds) ? TimeSpan.Zero : TimeSpan.FromSeconds(int.Parse(DelaySpanInSeconds));

                        UnreliableTransportBehavior behavior = new UnreliableTransportBehavior(
                            Destination, BehaviorName, double.Parse(ProbabilityToApply),
                            delayInSeconds, delaySpanInSeconds,
                            int.Parse(Priority),
                            int.Parse(ApplyCount));

                        clusterConnection.AddUnreliableTransportAsync(
                            NodeName,
                            BehaviorName,
                            behavior,
                            this.GetTimeout(),
                            this.GetCancellationToken()).Wait();

                        // localization of string not needed, since this cmdlet is an internal use.
                        this.WriteObject(string.Format(
                                             "Added Unreliable transport for behavior: {0}.\n" +
                                             "Note: The behavior is applied on the node until it is removed with Remove-UnreliableTransport cmdlet.", BehaviorName));
                    }
                    catch (AggregateException aggregateException)
                    {
                        aggregateException.Handle((ae) =>
                        {
                            this.ThrowTerminatingError(
                                ae,
                                ConstantsInternal.AddUnreliableTransportId,
                                this.GetClusterConnection());
                            return(true);
                        });
                    }
                }
            }
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            this.WriteObject(string.Format(
                                 "Note:Adding Lease behavior causes reliability issues on the cluster.\n" +
                                 "Note: The behavior {0} is applied on the node until it is removed with Remove-ServiceFabricLeaseBehavior cmdlet.", BehaviorString));

            try
            {
                if (this.GetClusterConnection() == null)
                {
                    throw new Exception("Connection to Cluster is null, Connect to Cluster before invoking the cmdlet");
                }

                Microsoft.ServiceFabric.Powershell.InternalClusterConnection clusterConnection =
                    new Microsoft.ServiceFabric.Powershell.InternalClusterConnection(this.GetClusterConnection());

                clusterConnection.AddUnreliableLeaseAsync(
                    NodeName,
                    BehaviorString,
                    Alias,
                    this.GetTimeout(),
                    this.GetCancellationToken()).Wait();

                // localization of string not needed, since this cmdlet is an internal use.
                this.WriteObject(string.Format(
                                     "Added Unreliable Lease for behavior: {0}.\n" +
                                     "Note: The behavior is applied on the node until it is removed with Remove-UnreliableLease cmdlet.", BehaviorString));
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle((ae) =>
                {
                    this.ThrowTerminatingError(
                        ae,
                        ConstantsInternal.AddUnreliableLeaseId,
                        this.GetClusterConnection());
                    return(true);
                });
            }
        }