//This method creates the service application proxy public SPServiceApplicationProxy CreateProxy(string name, SPServiceApplication serviceApplication, SPServiceProvisioningContext provisioningContext) { #region validation if (serviceApplication.GetType() != typeof(DayNamerServiceApplication)) { throw new NotSupportedException(); } if (serviceApplication == null) { throw new ArgumentNullException("serviceApplication"); } #endregion // verify the service proxy exists DayNamerServiceProxy serviceProxy = (DayNamerServiceProxy)this.Farm.GetObject(name, this.Farm.Id, typeof(DayNamerServiceProxy)); if (serviceProxy == null) { throw new InvalidOperationException("DayNamerServiceProxy does not exist in the farm."); } // if the app proxy doesn't exist, create it DayNamerServiceApplicationProxy applicationProxy = serviceProxy.ApplicationProxies.GetValue <DayNamerServiceApplicationProxy>(name); if (applicationProxy == null) { Uri serviceAppAddress = ((DayNamerServiceApplication)serviceApplication).Uri; applicationProxy = new DayNamerServiceApplicationProxy(name, serviceProxy, serviceAppAddress); } return(applicationProxy); }
public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { // uninstall the instance DayNamerServiceInstance serviceInstance = SPFarm.Local.Services.GetValue <DayNamerServiceInstance>(); if (serviceInstance != null) { SPServer.Local.ServiceInstances.Remove(serviceInstance.Id); } // uninstall the service proxy DayNamerServiceProxy serviceProxy = SPFarm.Local.ServiceProxies.GetValue <DayNamerServiceProxy>(); if (serviceProxy != null) { SPFarm.Local.ServiceProxies.Remove(serviceProxy.Id); } // uninstall the service DayNamerService service = SPFarm.Local.Services.GetValue <DayNamerService>(); if (service != null) { SPFarm.Local.Services.Remove(service.Id); } }
private void CreateServiceApplicationProxy(DayNamerServiceApplication serviceApp) { // get reference to the installed service proxy DayNamerServiceProxy serviceProxy = SPFarm.Local.ServiceProxies.GetValue <DayNamerServiceProxy>(); // create service app proxy DayNamerServiceApplicationProxy serviceAppProxy = new DayNamerServiceApplicationProxy( ServiceAppName.Text + " Proxy", serviceProxy, serviceApp.Uri); serviceAppProxy.Update(true); // provision service app proxy serviceAppProxy.Provision(); // start it if it isn't already started if (serviceAppProxy.Status != SPObjectStatus.Online) { serviceAppProxy.Status = SPObjectStatus.Online; } serviceAppProxy.Update(true); // add the proxy to the default group if selected if (DefaultServiceApp.Checked) { SPServiceApplicationProxyGroup defaultGroup = SPServiceApplicationProxyGroup.Default; defaultGroup.Add(serviceAppProxy); defaultGroup.Update(true); } }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { // install the service DayNamerService service = SPFarm.Local.Services.GetValue <DayNamerService>(); if (service == null) { service = new DayNamerService(SPFarm.Local); service.Update(); } // install the service proxy DayNamerServiceProxy serviceProxy = SPFarm.Local.ServiceProxies.GetValue <DayNamerServiceProxy>(); if (serviceProxy == null) { serviceProxy = new DayNamerServiceProxy(SPFarm.Local); serviceProxy.Update(true); } // with service added to the farm, install instance DayNamerServiceInstance serviceInstance = new DayNamerServiceInstance(SPServer.Local, service); serviceInstance.Update(true); }
protected override void InternalProcessRecord() { #region validation checks // ensure can hit farm SPFarm farm = SPFarm.Local; if (farm == null) { ThrowTerminatingError(new InvalidOperationException("SharePoint farm not found."), ErrorCategory.ResourceUnavailable, this); SkipProcessCurrentRecord(); } // ensure proxy installed DayNamerServiceProxy serviceProxy = farm.ServiceProxies.GetValue <DayNamerServiceProxy>(); if (serviceProxy == null) { ThrowTerminatingError(new InvalidOperationException("Day Namer Service Proxy not found."), ErrorCategory.NotInstalled, this); SkipProcessCurrentRecord(); } // ensure can hit service application DayNamerServiceApplicationProxy existingServiceAppProxy = serviceProxy.ApplicationProxies.GetValue <DayNamerServiceApplicationProxy>(); if (existingServiceAppProxy != null) { ThrowTerminatingError(new InvalidOperationException("Day Namer Service Application Proxy already exists."), ErrorCategory.ResourceExists, this); SkipProcessCurrentRecord(); } #endregion Uri serviceApplicationAddress = null; if (ParameterSetName == "Uri") { serviceApplicationAddress = _uri; } else if (ParameterSetName == "ServiceApplication") { // make sure can get a reference to service app SPServiceApplication serviceApp = ServiceApplication.Read(); if (serviceApp == null) { WriteError(new InvalidOperationException("Service application not found."), ErrorCategory.ResourceExists, serviceApp); SkipProcessCurrentRecord(); } // make sure can connect to service app ISharedServiceApplication sharedServiceApp = serviceApp as ISharedServiceApplication; if (sharedServiceApp == null) { WriteError(new InvalidOperationException("Service application not found."), ErrorCategory.ResourceExists, serviceApp); SkipProcessCurrentRecord(); } serviceApplicationAddress = sharedServiceApp.Uri; } else { ThrowTerminatingError(new InvalidOperationException("Invalid parameter set."), ErrorCategory.InvalidArgument, this); } // create the service app proxy if ((serviceApplicationAddress != null) && ShouldProcess(this.Name)) { DayNamerServiceApplicationProxy serviceAppProxy = new DayNamerServiceApplicationProxy( this.Name, serviceProxy, serviceApplicationAddress); // provision the service app proxy serviceAppProxy.Provision(); // pass service app proxy back to the PowerShell WriteObject(serviceAppProxy); } }