public static ParagoService CreateParagoServiceWithServiceInstance() { SPFarm farm = SPFarm.Local; SPServer server = SPServer.Local; if (farm == null) { throw new InvalidOperationException("No farm object available"); } if (server == null) { throw new InvalidOperationException("No server object available"); } ParagoService service = ParagoService.Local; ParagoServiceInstance serviceInstance = null; ParagoServiceProxy serviceProxy = null; if (service == null) { // NOTE: There cases when service class got not detected, but is still avialable. // --- service = new ParagoService(farm); try { service.Unprovision(); } catch { } try { service.Delete(); } catch { } // --- // NOTE: Must be set new after Delete is called! service = new ParagoService(farm); try { service.Update(); if (service.Status != SPObjectStatus.Online) { service.Provision(); } serviceInstance = server.ServiceInstances.GetValue <ParagoServiceInstance>(ParagoServiceInstance.DefaultName); if (serviceInstance == null) { serviceInstance = new ParagoServiceInstance(server, service); serviceInstance.Update(); } // NOTE: Provisioning the service instance will create the IIS web service, when first service // appliation will be created, otherwise it will not work! if (serviceInstance.Status != SPObjectStatus.Online) { serviceInstance.Provision(); } serviceProxy = farm.ServiceProxies.GetValue <ParagoServiceProxy>(ParagoServiceProxy.DefaultName); if (serviceProxy == null) { serviceProxy = new ParagoServiceProxy(farm); serviceProxy.Update(); } if (serviceProxy.Status != SPObjectStatus.Online) { serviceProxy.Provision(); } } catch { try { if (serviceProxy != null) { if (serviceProxy.Status == SPObjectStatus.Online) { serviceProxy.Unprovision(); } serviceProxy.Delete(); } if (serviceInstance != null) { if (serviceInstance.Status == SPObjectStatus.Online) { serviceInstance.Unprovision(); } serviceInstance.Delete(); } if (service != null) { if (service.Status == SPObjectStatus.Online) { service.Unprovision(); } service.Delete(); } } catch { } throw; } } return(service); }
public static void RemoveParagoServiceAndAllDependentObjects() { if (SPFarm.Local == null) { throw new InvalidOperationException("No farm object available"); } ParagoService service = ParagoService.Local; if (service == null) { throw new InvalidOperationException("No service object available"); } foreach (SPServiceProxy serviceProxy in SPFarm.Local.ServiceProxies) { if (serviceProxy is ParagoServiceProxy) { foreach (SPServiceApplicationProxy serviceApplicationProxy in serviceProxy.ApplicationProxies) { if (serviceApplicationProxy is ParagoServiceApplicationProxy) { if (serviceApplicationProxy.Status == SPObjectStatus.Online) { serviceApplicationProxy.Unprovision(); } serviceApplicationProxy.Delete(); } } if (serviceProxy.Status == SPObjectStatus.Online) { serviceProxy.Unprovision(); } serviceProxy.Delete(); } } foreach (SPServiceInstance serviceInstance in service.Instances) { if (serviceInstance is ParagoServiceInstance) { if (serviceInstance.Status == SPObjectStatus.Online) { serviceInstance.Unprovision(); } serviceInstance.Delete(); } } foreach (SPServiceApplication serviceApplication in service.Applications) { if (serviceApplication is ParagoServiceApplication) { if (serviceApplication.Status == SPObjectStatus.Online) { serviceApplication.Unprovision(); } serviceApplication.Delete(); } } if (service.Status == SPObjectStatus.Online) { service.Unprovision(); } service.Delete(); }