public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // install the service
            var service = BaristaHelper.GetBaristaService(SPFarm.Local);

            if (service == null)
            {
                service = new BaristaService(SPFarm.Local);
                service.Update(true);
            }


            // install the service proxy
            var serviceProxy = BaristaHelper.GetBaristaServiceProxy(SPFarm.Local);

            if (serviceProxy == null)
            {
                serviceProxy = new BaristaServiceProxy(SPFarm.Local);
                serviceProxy.Update(true);
            }


            // with service added to the farm, install instance
            var serviceInstance = new BaristaServiceInstance(SPServer.Local, service);

            serviceInstance.Update(true);
        }
        private BaristaServiceApplication CreateServiceApplication(BaristaService service)
        {
            // create service app
            var serviceApp = BaristaServiceApplication.Create(
                ServiceAppName.Text,
                service,
                ApplicationPoolSelection.GetOrCreateApplicationPool());

            serviceApp.Update();

            // start it if it isn't already started
            // ReSharper disable once RedundantCheckBeforeAssignment
            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);
        }