Пример #1
0
        /// <summary>
        /// Creates the service application proxy during the farm configuration wizard, and when you attempt to create a connection to a cross-farm service application.
        /// </summary>
        /// <param name="serviceApplicationProxyType">The <see cref="System.Type" /> of the service application proxy.</param>
        /// <param name="name">The name of the service application proxy.</param>
        /// <param name="serviceApplicationUri">The service application uri.</param>
        /// <param name="provisioningContext">The <see cref="Microsoft.SharePoint.Administration.SPServiceProvisioningContext" />.</param>
        /// <returns>An <see cref="Microsoft.SharePoint.Administration.SPServiceApplicationProxy" />.</returns>
        public SPServiceApplicationProxy CreateProxy(System.Type serviceApplicationProxyType, string name, System.Uri serviceApplicationUri, SPServiceProvisioningContext provisioningContext)
        {
            if (serviceApplicationProxyType != typeof(ConfigServiceApplicationProxy))
            {
                throw new NotSupportedException();
            }

            // First create the new proxy.
            ConfigServiceApplicationProxy proxy = new ConfigServiceApplicationProxy(name, this, serviceApplicationUri);

            // You must call Update() to get the object into the persisted store before you can provision.
            proxy.Update();

            // Provision (install) the proxy.
            proxy.Provision();

            return proxy;
        }
        /// <summary>
        /// This method gets invoked when the command is called
        /// </summary>
        protected override void InternalProcessRecord()
        {
            Uri applicationUri = null;
            SPServiceApplication resolvedApplication = null;
            ConfigServiceApplication castedApplication = null;

            if (this.ServiceApplication == null && string.IsNullOrEmpty(this.Uri))
            {
                this.ThrowTerminatingError(new InvalidOperationException("No service application or Uri was provided."), ErrorCategory.InvalidOperation, this);
            }

            if (this.ServiceApplication != null)
            {
                resolvedApplication = this.ServiceApplication.Read();

                if (resolvedApplication == null)
                {
                    this.ThrowTerminatingError(new InvalidOperationException("Service application not found."), ErrorCategory.InvalidOperation, this);
                }

                castedApplication = resolvedApplication as ConfigServiceApplication;

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

                applicationUri = castedApplication.Uri;

                if (string.IsNullOrEmpty(this.Name))
                {
                    this.Name = castedApplication.Name + " Proxy";
                }
            }
            else
            {
                applicationUri = new Uri(this.Uri);
            }

            if (this.ShouldProcess(this.Name))
            {
                // Ensure the service exists
                NVRConfigService.GetOrCreateService();

                // Ensure the proxy exists
                ConfigServiceProxy serviceProxy = ConfigServiceProxy.GetOrCreateServiceProxy();

                // Create the service application proxy
                ConfigServiceApplicationProxy proxy = new ConfigServiceApplicationProxy(this.Name, serviceProxy, applicationUri);
                proxy.Update();
                proxy.Provision();

                if (this.DefaultProxyGroup.ToBool())
                {
                    SPServiceApplicationProxyGroup group = SPServiceApplicationProxyGroup.Default;
                    group.Add(proxy);
                    group.Update();
                }

                this.WriteObject(proxy);
            }
        }
Пример #3
0
        /// <summary>
        /// Creates the service application.
        /// </summary>
        private void CreateApplication()
        {
            using (SPLongOperation operation = new SPLongOperation(this))
            {
                operation.LeadingHTML = HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "CreateOperationLeadingHtml", CultureInfo.CurrentCulture).ToString();
                operation.TrailingHTML = HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "CreateOperationTrailingHtml", CultureInfo.CurrentCulture).ToString();
                operation.Begin();

                try
                {
                    NVRConfigService service = NVRConfigService.GetOrCreateService();
                    ConfigServiceProxy serviceProxy = ConfigServiceProxy.GetOrCreateServiceProxy();

                    // Create the application pool
                    IisWebServiceApplicationPoolSection applicationPoolSectionCasted = this.applicationPoolSection as IisWebServiceApplicationPoolSection;
                    SPIisWebServiceApplicationPool applicationPool = applicationPoolSectionCasted.GetOrCreateApplicationPool();

                    // Create the service application
                    ConfigServiceApplication application = new ConfigServiceApplication(
                        this.textBoxServiceName.Text.Trim(),
                        service,
                        applicationPool);
                    application.Update();
                    application.Provision();

                    // Create the service application proxy
                    ConfigServiceApplicationProxy proxy = new ConfigServiceApplicationProxy(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            HttpContext.GetGlobalResourceObject("NVRConfigService.ServiceAdminResources", "ServiceApplicationProxyNameTemplate", CultureInfo.CurrentCulture).ToString(),
                            this.textBoxServiceName.Text.Trim()),
                        serviceProxy,
                        application.Uri);
                    proxy.Update();
                    proxy.Provision();

                    if (this.checkBoxIncludeInDefaultProxy.Checked)
                    {
                        SPServiceApplicationProxyGroup group = SPServiceApplicationProxyGroup.Default;
                        group.Add(proxy);
                        group.Update();
                    }

                    operation.EndScript("window.frameElement.commitPopup();");
                }
                catch (Exception ex)
                {
                    SPUtility.TransferToErrorPage(ex.ToString());
                }
            }
        }