private void SetupDayNamerServiceApp() { // create a long running op.. using (SPLongOperation op = new SPLongOperation(this)) { op.Begin(); try { // get reference to the installed service DayNamerService service = SPFarm.Local.Services.GetValue <DayNamerService>(); // create the service application DayNamerServiceApplication serviceApp = CreateServiceApplication(service); // if the service instance isn't running, start it up StartServiceInstances(); // create service app proxy CreateServiceApplicationProxy(serviceApp); } catch (Exception e) { throw new SPException("Error creating Day Namer service application.", e); } } }
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); }
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 DayNamerServiceApplication CreateServiceApplication(DayNamerService service) { // create service app DayNamerServiceApplication serviceApp = DayNamerServiceApplication.Create( ServiceAppName.Text, service, ApplicationPoolSelection.GetOrCreateApplicationPool()); serviceApp.Update(); // start it if it isn't already started if (serviceApp.Status != SPObjectStatus.Online) { serviceApp.Status = SPObjectStatus.Online; } // configure service app endpoint serviceApp.AddServiceEndpoint(string.Empty, SPIisWebServiceBindingType.Http); serviceApp.Update(true); // now provision the service app serviceApp.Provision(); return(serviceApp); }
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 can hit local server SPServer server = SPServer.Local; if (server == null) { ThrowTerminatingError(new InvalidOperationException("SharePoint local server not found."), ErrorCategory.ResourceUnavailable, this); SkipProcessCurrentRecord(); } // ensure can hit service application DayNamerService service = farm.Services.GetValue <DayNamerService>(); if (service == null) { ThrowTerminatingError(new InvalidOperationException("Day Namer Service not found."), ErrorCategory.ResourceUnavailable, this); SkipProcessCurrentRecord(); } // ensure can hit app pool SPIisWebServiceApplicationPool appPool = this.ApplicationPool.Read(); if (appPool == null) { ThrowTerminatingError(new InvalidOperationException("Application pool not found."), ErrorCategory.ResourceUnavailable, this); SkipProcessCurrentRecord(); } #endregion // Check a service app doesn't already exist DayNamerServiceApplication existingServiceApp = service.Applications.GetValue <DayNamerServiceApplication>(); if (existingServiceApp != null) { WriteError(new InvalidOperationException("Day Namer Service Application already exists."), ErrorCategory.ResourceExists, existingServiceApp); SkipProcessCurrentRecord(); } // Create & provision the service application if (ShouldProcess(this.Name)) { DayNamerServiceApplication serviceApp = DayNamerServiceApplication.Create( this.Name, service, appPool); // provision the service app serviceApp.Provision(); // pass service app back to the PowerShell WriteObject(serviceApp); } }