Пример #1
0
        private void CreateServiceApplicationProxy(BaristaServiceApplication serviceApp)
        {
            // get reference to the installed service proxy
            var serviceProxy = BaristaHelper.GetBaristaServiceProxy(SPFarm.Local);

            // create service app proxy
            var serviceAppProxy = new BaristaServiceApplicationProxy(
                ServiceAppName.Text + " Proxy",
                serviceProxy,
                serviceApp.Uri);

            serviceAppProxy.Update(true);

            // provision service app proxy
            serviceAppProxy.Provision();

            // start it if it isn't already started
            // ReSharper disable once RedundantCheckBeforeAssignment
            if (serviceAppProxy.Status != SPObjectStatus.Online)
            {
                serviceAppProxy.Status = SPObjectStatus.Online;
            }
            serviceAppProxy.Update(true);

            // add the proxy to the default group if selected
            if (!DefaultServiceApp.Checked)
            {
                return;
            }

            var defaultGroup = SPServiceApplicationProxyGroup.Default;

            defaultGroup.Add(serviceAppProxy);
            defaultGroup.Update(true);
        }
Пример #2
0
        protected override void InternalProcessRecord()
        {
            #region validation stuff
            // ensure can hit farm
            var farm = SPFarm.Local;
            if (farm == null)
            {
                ThrowTerminatingError(new InvalidOperationException("SharePoint farm not found."), ErrorCategory.ResourceUnavailable, this);
                SkipProcessCurrentRecord();
                return;
            }

            // ensure proxy installed
            var serviceProxy = BaristaHelper.GetBaristaServiceProxy(farm);
            if (serviceProxy == null)
            {
                ThrowTerminatingError(new InvalidOperationException("Barista Service Proxy not found (likely not installed)."), ErrorCategory.NotInstalled, this);
                SkipProcessCurrentRecord();
                return;
            }

            // ensure can hit service application
            var existingServiceAppProxy = serviceProxy.ApplicationProxies.GetValue <BaristaServiceApplicationProxy>();
            if (existingServiceAppProxy != null)
            {
                ThrowTerminatingError(new InvalidOperationException("Barista Service Application Proxy already exists."), ErrorCategory.ResourceExists, this);
                SkipProcessCurrentRecord();
                return;
            }
            #endregion

            Uri serviceApplicationAddress = null;
            switch (ParameterSetName)
            {
            case "Uri":
                serviceApplicationAddress = m_uri;
                break;

            case "ServiceApplication":
            {
                // make sure can get a refernce to service app
                var serviceApp = ServiceApplication.Read();
                if (serviceApp == null)
                {
                    WriteError(new InvalidOperationException("Service application not found."), ErrorCategory.ResourceExists, null);
                    SkipProcessCurrentRecord();
                    return;
                }

                // make sure can connect to service app
                var sharedServiceApp = serviceApp as ISharedServiceApplication;
                if (sharedServiceApp == null)
                {
                    WriteError(new InvalidOperationException("Service application not found."), ErrorCategory.ResourceExists, serviceApp);
                    SkipProcessCurrentRecord();
                    return;
                }

                serviceApplicationAddress = sharedServiceApp.Uri;
            }
            break;

            default:
                ThrowTerminatingError(new InvalidOperationException("Invalid parameter set."), ErrorCategory.InvalidArgument, this);
                break;
            }

            // create the service app proxy
            if ((serviceApplicationAddress == null) || !ShouldProcess(Name))
            {
                return;
            }

            var serviceAppProxy = new BaristaServiceApplicationProxy(
                Name,
                serviceProxy,
                serviceApplicationAddress);

            // provision the service app proxy
            serviceAppProxy.Provision();

            // pass service app proxy back to the PowerShell
            WriteObject(serviceAppProxy);
        }