private void DeployDefinition(object modelHost, SPFarm spFarm, DiagnosticsServiceBaseDefinition definition)
        {
            var currentObject = GetCurrentObject(spFarm, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = currentObject,
                ObjectType = typeof(SPDiagnosticsServiceBase),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });

            if (currentObject == null)
                currentObject = CreateObject(spFarm, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioned,
                Object = currentObject,
                ObjectType = typeof(SPDiagnosticsServiceBase),
                ObjectDefinition = definition,
                ModelHost = modelHost
            });
        }
        private SPDiagnosticsServiceBase CreateObject(SPFarm spFarm, DiagnosticsServiceBaseDefinition definition)
        {
            var serviceType = Type.GetType(definition.AssemblyQualifiedName);
            var serviceInstance = Activator.CreateInstance(serviceType) as SPDiagnosticsServiceBase;

            spFarm.Services.Add(serviceInstance);
            spFarm.Update();

            return GetCurrentObject(spFarm, definition);
        }
 public static ModelNode AddDiagnosticsServiceBase(this ModelNode model, DiagnosticsServiceBaseDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddDiagnosticsServiceBase(this ModelNode model, DiagnosticsServiceBaseDefinition definition)
 {
     return AddDiagnosticsServiceBase(model, definition, null);
 }
 private SPDiagnosticsServiceBase GetCurrentObject(SPFarm spFarm, DiagnosticsServiceBaseDefinition definition)
 {
     return spFarm.Services.FirstOrDefault(s => s.TypeName.ToUpper() == definition.AssemblyQualifiedName.ToUpper()) as SPDiagnosticsServiceBase;
 }