protected override void ProcessRecord() { try { var dllPath = ModuleHelper.InstallDir + "ServiceBroker\\" + ServiceTypeAssembly; var brokerClass = _managementServer.GetRegisterableServices() .Where(service => service.Value == dllPath) .Select(p => p.Key).FirstOrDefault(); if (_managementServer.GetServiceType(_serviceTypeGuid) != null) { WriteVerbose($"Updating existing Service Type {SystemName}"); _managementServer.UpdateServiceType(_serviceTypeGuid, SystemName, DisplayName, Description, dllPath, brokerClass); } else { WriteVerbose("Registering the following Service Type:"); WriteVerbose($"System Name - {SystemName}"); WriteVerbose($"Display Name - {DisplayName}"); WriteVerbose($"Guid - {_serviceTypeGuid}"); _managementServer.RegisterServiceType(_serviceTypeGuid, SystemName, DisplayName, Description, brokerClass); } } catch (Exception ex) { ErrorHelper.Write(ex); } }
/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { bool result; int currentStep = 0; LogHelper.LogMessage("\n\n***** BEGIN *******\n"); LogHelper.LogSubStepInfo("K2 Server: " + K2Server); LogHelper.LogSubStepInfo("K2 HostServer Port: " + K2HostServerPort.ToString()); LogHelper.LogSubStepInfo("Service Type Guid: " + ServiceTypeGuid); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeSystemName); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeDisplayName); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeDescription); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeAssemblyPath); LogHelper.LogSubStepInfo("Service Type : " + serviceTypeClassName); try { LogHelper.LogStep(++currentStep, "Validating"); if (!GuidHelper.IsGuid(ServiceTypeGuid)) throw new ArgumentException("Invalid Service Type Guid"); if(!File.Exists(ServiceTypeAssemblyPath)) throw new ArgumentException("Service Type Assembly Path is not valid."); // Create the Guid Guid svcGuid = new Guid(ServiceTypeGuid); LogHelper.LogStep(++currentStep, "Getting K2 Service Manager"); LogHelper.LogSubStep("Create K2 Service Manager"); ServiceManagementServer svcMng = new ServiceManagementServer(); using (svcMng.CreateConnection()) { LogHelper.LogSubStep("Opening Connection to K2 Server"); svcMng.Connection.Open(ConnectionString); LogHelper.LogSubStepInfo("Connection State: " + (svcMng.Connection.IsConnected ? "Connected" : "Disconnected")); LogHelper.LogStep(++currentStep, "Registering Service Type"); LogHelper.LogSubStep("Determining if Service Type already exists"); // Check if this Service Type is already registered if (String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) { LogHelper.LogSubStepInfo("Service Type does not exist"); LogHelper.LogSubStep("Getting Service Type Definition"); // NOTE: Registering the Service Type without this Service Type definition // results in incorrect registration string svcTypeDefinition = K2Helper.GetK2ServiceTypeDefinition( svcGuid, ServiceTypeSystemName, ServiceTypeDisplayName, ServiceTypeDescription, ServiceTypeAssemblyPath, ServiceTypeClassName); LogHelper.LogSubStepInfo(svcTypeDefinition); LogHelper.LogSubStep("Registering new Service Type"); svcMng.RegisterServiceType(svcGuid, svcTypeDefinition); if(String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) throw new Exception("Registration of Service Type Unsuccessful"); else LogHelper.LogSubStepInfo("Registration of Service Type was Successful"); } else { LogHelper.LogSubStepInfo("Service Type already exists"); LogHelper.LogSubStep("Updating existing Service Type"); svcMng.UpdateServiceType( svcGuid, ServiceTypeSystemName, ServiceTypeDisplayName, ServiceTypeDescription, ServiceTypeAssemblyPath, ServiceTypeClassName); if (String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) throw new Exception("Update of Service Type Unsuccessful"); else LogHelper.LogSubStepInfo("Update of Service Type was Successful"); } } result = true; } catch { throw; } finally { LogHelper.LogMessage("\n***** END *******\n\n"); } return result; }
internal virtual bool RegisterServiceType(Guid ServiceTypeGuid, string SystemName, string DisplayName, string Description, string Path, string Class) { return(_serviceManagementServer.RegisterServiceType(ServiceTypeGuid, SystemName, DisplayName, Description, Path, Class)); }
/// <summary> /// When overridden in a derived class, executes the task. /// </summary> /// <returns> /// true if the task successfully executed; otherwise, false. /// </returns> public override bool Execute() { bool result; int currentStep = 0; LogHelper.LogMessage("\n\n***** BEGIN *******\n"); LogHelper.LogSubStepInfo("K2 Server: " + K2Server); LogHelper.LogSubStepInfo("K2 HostServer Port: " + K2HostServerPort.ToString()); LogHelper.LogSubStepInfo("Service Type Guid: " + ServiceTypeGuid); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeSystemName); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeDisplayName); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeDescription); LogHelper.LogSubStepInfo("Service Type : " + ServiceTypeAssemblyPath); LogHelper.LogSubStepInfo("Service Type : " + serviceTypeClassName); try { LogHelper.LogStep(++currentStep, "Validating"); if (!GuidHelper.IsGuid(ServiceTypeGuid)) { throw new ArgumentException("Invalid Service Type Guid"); } if (!File.Exists(ServiceTypeAssemblyPath)) { throw new ArgumentException("Service Type Assembly Path is not valid."); } // Create the Guid Guid svcGuid = new Guid(ServiceTypeGuid); LogHelper.LogStep(++currentStep, "Getting K2 Service Manager"); LogHelper.LogSubStep("Create K2 Service Manager"); ServiceManagementServer svcMng = new ServiceManagementServer(); using (svcMng.CreateConnection()) { LogHelper.LogSubStep("Opening Connection to K2 Server"); svcMng.Connection.Open(ConnectionString); LogHelper.LogSubStepInfo("Connection State: " + (svcMng.Connection.IsConnected ? "Connected" : "Disconnected")); LogHelper.LogStep(++currentStep, "Registering Service Type"); LogHelper.LogSubStep("Determining if Service Type already exists"); // Check if this Service Type is already registered if (String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) { LogHelper.LogSubStepInfo("Service Type does not exist"); LogHelper.LogSubStep("Getting Service Type Definition"); // NOTE: Registering the Service Type without this Service Type definition // results in incorrect registration string svcTypeDefinition = K2Helper.GetK2ServiceTypeDefinition( svcGuid, ServiceTypeSystemName, ServiceTypeDisplayName, ServiceTypeDescription, ServiceTypeAssemblyPath, ServiceTypeClassName); LogHelper.LogSubStepInfo(svcTypeDefinition); LogHelper.LogSubStep("Registering new Service Type"); svcMng.RegisterServiceType(svcGuid, svcTypeDefinition); if (String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) { throw new Exception("Registration of Service Type Unsuccessful"); } else { LogHelper.LogSubStepInfo("Registration of Service Type was Successful"); } } else { LogHelper.LogSubStepInfo("Service Type already exists"); LogHelper.LogSubStep("Updating existing Service Type"); svcMng.UpdateServiceType( svcGuid, ServiceTypeSystemName, ServiceTypeDisplayName, ServiceTypeDescription, ServiceTypeAssemblyPath, ServiceTypeClassName); if (String.IsNullOrEmpty(svcMng.GetServiceType(svcGuid))) { throw new Exception("Update of Service Type Unsuccessful"); } else { LogHelper.LogSubStepInfo("Update of Service Type was Successful"); } } } result = true; } catch { throw; } finally { LogHelper.LogMessage("\n***** END *******\n\n"); } return(result); }