/// <summary>
        /// This method gets invoked when the command is called.
        /// </summary>
        protected override void InternalProcessRecord()
        {
            SPServiceApplicationProxy        resolvedProxy = null;
            ClubCloudServiceApplicationProxy castedProxy   = null;

            resolvedProxy = this.Identity.Read();

            if (resolvedProxy == null)
            {
                this.ThrowTerminatingError(new InvalidOperationException("No service application proxy was found."), ErrorCategory.InvalidOperation, this);
            }

            castedProxy = resolvedProxy as ClubCloudServiceApplicationProxy;

            if (castedProxy == null)
            {
                this.ThrowTerminatingError(new InvalidOperationException("The service application proxy was not of the correct type."), ErrorCategory.InvalidOperation, this);
            }

            if (this.ShouldProcess(castedProxy.Name))
            {
                if (!string.IsNullOrEmpty(this.Name) && (!string.Equals(this.Name.Trim(), castedProxy.Name, StringComparison.OrdinalIgnoreCase)))
                {
                    // Get the service proxy and check for duplicate name
                    ClubCloudServiceProxy     serviceProxy   = SPFarm.Local.ServiceProxies.GetValue <ClubCloudServiceProxy>();
                    SPServiceApplicationProxy duplicateProxy = serviceProxy.ApplicationProxies[this.Name.Trim()];

                    if (duplicateProxy != null)
                    {
                        this.ThrowTerminatingError(new InvalidOperationException("There is already a service application proxy with that name."), ErrorCategory.InvalidOperation, this);
                    }

                    castedProxy.Name = this.Name.Trim();
                    castedProxy.Update();
                }

                if (this.DefaultProxyGroup.IsPresent)
                {
                    SPServiceApplicationProxyGroup group = SPServiceApplicationProxyGroup.Default;

                    if (this.DefaultProxyGroup.ToBool())
                    {
                        group.Add(castedProxy);
                    }
                    else
                    {
                        group.Remove(castedProxy.Id);
                    }
                }
            }
        }
        public static void SetDefaultServiceApplicationProxy(ParagoServiceApplicationProxy serviceApplicationProxy)
        {
            if (serviceApplicationProxy != null)
            {
                SPServiceApplicationProxyGroup proxyGroup = SPServiceApplicationProxyGroup.Default;

                if (proxyGroup != null)
                {
                    // Remove all existing service application proxies available
                    foreach (ParagoServiceApplicationProxy proxy in proxyGroup.DefaultProxies.OfType <ParagoServiceApplicationProxy>().ToList())
                    {
                        proxyGroup.Remove(proxy.Id);
                    }

                    proxyGroup.Add(serviceApplicationProxy);
                    proxyGroup.Update(true);
                }
            }
        }