Example #1
0
        /// <summary>
        /// Removes the service and components from the farm.
        /// </summary>
        internal static void RemoveService()
        {
            ClubCloudService      service      = SPFarm.Local.Services.GetValue <ClubCloudService>();
            ClubCloudServiceProxy serviceProxy = SPFarm.Local.ServiceProxies.GetValue <ClubCloudServiceProxy>();

            // Uninstall any service applications
            if (service != null)
            {
                foreach (SPServiceApplication app in service.Applications)
                {
                    app.Unprovision(true);
                    app.Delete();
                }
            }

            // Uninstall any remaining service application proxies (e.g. any connections to other farms)
            if (serviceProxy != null)
            {
                foreach (SPServiceApplicationProxy proxy in serviceProxy.ApplicationProxies)
                {
                    proxy.Unprovision(true);
                    proxy.Delete();
                }
            }

            // Uninstall the instances
            foreach (SPServer server in SPFarm.Local.Servers)
            {
                ClubCloudServiceInstance serviceInstance = server.ServiceInstances.GetValue <ClubCloudServiceInstance>();
                while (serviceInstance != null)
                {
                    server.ServiceInstances.Remove(serviceInstance.Id);
                    serviceInstance = server.ServiceInstances.GetValue <ClubCloudServiceInstance>();
                }
            }

            // Uninstall the service proxy
            if (serviceProxy != null)
            {
                SPFarm.Local.ServiceProxies.Remove(serviceProxy.Id);
            }

            // Uninstall the service
            if (service != null)
            {
                SPFarm.Local.Services.Remove(service.Id);
            }
        }
        /// <summary>
        /// Installs the service instances on servers in the farm (does not start them).
        /// </summary>
        /// <param name="service">The service associated with these instances.</param>
        internal static void CreateServiceInstances(ClubCloudService service)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service");
            }

            foreach (SPServer server in SPFarm.Local.Servers)
            {
                if (server.Role == SPServerRole.Application || server.Role == SPServerRole.SingleServer || server.Role == SPServerRole.WebFrontEnd)
                {
                    ClubCloudServiceInstance instance = server.ServiceInstances.GetValue <ClubCloudServiceInstance>();
                    if (instance == null)
                    {
                        instance = new ClubCloudServiceInstance(server, service);
                        instance.Update();
                    }
                }
            }
        }