示例#1
0
        /// <summary>
        /// Determines if a service instance exists.
        /// </summary>
        /// <param name="svcMng">ServiceManagementServer object.</param>
        /// <param name="ServiceInstanceGuid">The service instance GUID.</param>
        /// <returns>true if the the service instance already exists; otherwise, false.</returns>
        public static bool DetermineIfServiceInstanceExists(ServiceManagementServer svcMng, Guid ServiceInstanceGuid)
        {
            bool result = false;

            // Check if this Service Instance is already registered
            try
            {
                string _svcInstanceName = svcMng.GetServiceInstance(ServiceInstanceGuid);
                result = true;
            }
            catch
            {
                result = false;
            }

            return(result);
        }
        /// <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;

            // clean up some values
            char token = '"';

            K2Server = K2Helper.StripLeadingAndTailing(K2Server, token);
            ServiceInstanceGuid = K2Helper.StripLeadingAndTailing(ServiceInstanceGuid, token);
            ServiceInstanceSystemName = K2Helper.StripLeadingAndTailing(ServiceInstanceSystemName, token);
            ServiceInstanceDisplayName = K2Helper.StripLeadingAndTailing(ServiceInstanceDisplayName, token);
            ServiceInstanceDescription = K2Helper.StripLeadingAndTailing(ServiceInstanceDescription, token);
            ConfigKeyNames = K2Helper.StripLeadingAndTailing(configKeyNames, token);
            ConfigKeyValues = K2Helper.StripLeadingAndTailing(ConfigKeyValues, token);
            ConfigKeysRequired = K2Helper.StripLeadingAndTailing(ConfigKeysRequired, token);
            ConfigKeyDelimiter = K2Helper.StripLeadingAndTailing(ConfigKeyDelimiter, token);

            LogHelper.LogMessage("\n\n*****     BEGIN     *******\n");

            LogHelper.LogSubStepInfo("K2 Server: " + K2Server);
            LogHelper.LogSubStepInfo("K2 HostServer Port: " + K2HostServerPort.ToString());
            LogHelper.LogSubStepInfo("Service Instance Guid: " + ServiceInstanceGuid);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceSystemName);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceDisplayName);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceDescription);
            LogHelper.LogSubStepInfo("Config Key Names : " + ConfigKeyNames);
            LogHelper.LogSubStepInfo("Config Key Values : " + ConfigKeyValues);
            LogHelper.LogSubStepInfo("Config Key Reqds : " + ConfigKeysRequired);
            LogHelper.LogSubStepInfo("Config Delimiter : " + ConfigKeyDelimiter);

            try
            {
                LogHelper.LogStep(++currentStep, "Validating");

                if (!GuidHelper.IsGuid(ServiceTypeGuid))
                    throw new ArgumentException("Invalid Service Type Guid");

                if (!GuidHelper.IsGuid(ServiceInstanceGuid))
                    throw new ArgumentException("Invalid Service Instance Guid");

                // Create the Service Type Guid
                Guid svcTypeGuid = new Guid(ServiceTypeGuid);

                // Create the Service Instance Guid
                Guid svcInstanceGuid = new Guid(ServiceInstanceGuid);

                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"));

                    char delim = ',';
                    if (ConfigKeyDelimiter.Length == 1)
                    {
                        delim = ConfigKeyDelimiter.ToCharArray()[0];
                    }

                    LogHelper.LogSubStep("Getting Service Instance Configuration");
                    string svcInstanceConfig = K2Helper.GetK2ServiceInstanceConfig(
                        ConfigImpersonate, ConfigKeyNames, ConfigKeyValues,
                        ConfigKeysRequired, delim);

                    LogHelper.LogSubStepInfo("Service Instance Config = ");
                    LogHelper.LogSubStepInfo(svcInstanceConfig);

                    LogHelper.LogStep(++currentStep, "Registering Service Instance");
                    LogHelper.LogSubStep("Determining if Service Instance already exists");

                    // Check if this Service Instance is already registered
                    if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                    {
                        LogHelper.LogSubStepInfo("Service Instance does not exist");

                        LogHelper.LogSubStep("Registering new Service Instance");
                        svcMng.RegisterServiceInstance(
                            svcTypeGuid, svcInstanceGuid, ServiceInstanceSystemName,
                            ServiceInstanceDisplayName, ServiceInstanceDescription, svcInstanceConfig);

                        if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                            throw new Exception("Registration of Service Instance Unsuccessful");
                        else
                            LogHelper.LogSubStepInfo("Registration of Service Instance was Successful");
                    }
                    else
                    {
                        LogHelper.LogSubStepInfo("Service Instance already exists");

                        LogHelper.LogSubStep("Updating existing Service Instance");

                        svcMng.UpdateServiceInstance(
                            svcTypeGuid, svcInstanceGuid, ServiceInstanceSystemName,
                            ServiceInstanceDisplayName, ServiceInstanceDescription, svcInstanceConfig);

                        if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                            throw new Exception("Update of Service Instance Unsuccessful");
                        else
                            LogHelper.LogSubStepInfo("Update of Service Instance was Successful");
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
                //LogHelper.LogSubStepInfo(string.Format("Got an error:{0}{1}", ex.Message, ex.StackTrace));
                //result = false;
            }
            finally
            {
                LogHelper.LogMessage("\n*****       END       *******\n\n");
            }

            return result;
        }
示例#3
0
        public ServiceManagementServerWrapper(ServiceManagementServer serviceManagementServer)
        {
            serviceManagementServer.ThrowIfNull(nameof(serviceManagementServer));

            _serviceManagementServer = serviceManagementServer;
        }
        /// <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;
        }
        /// <summary>
        /// Determines if a service instance exists.
        /// </summary>
        /// <param name="svcMng">ServiceManagementServer object.</param>
        /// <param name="ServiceInstanceGuid">The service instance GUID.</param>
        /// <returns>true if the the service instance already exists; otherwise, false.</returns>
        public static bool DetermineIfServiceInstanceExists(ServiceManagementServer svcMng, Guid ServiceInstanceGuid)
        {
            bool result = false;

            // Check if this Service Instance is already registered
            try
            {
                string _svcInstanceName = svcMng.GetServiceInstance(ServiceInstanceGuid);
                result = true;
            }
            catch
            {
                result = false;
            }

            return result;
        }
 public static void DeleteServiceInstance(this ServiceManagementServer server, Guid serviceInstanceGuid)
 {
     WrapperFactory.Instance.GetServiceManagementServerWrapper(server).DeleteServiceInstance(serviceInstanceGuid);
 }
示例#7
0
        /// <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);
        }
示例#8
0
        internal virtual ServiceManagementServerWrapper GetServiceManagementServerWrapper(ServiceManagementServer server)
        {
            if (server == null)
            {
                server = ConnectionHelper.GetServer <ServiceManagementServer>();
            }

            return(new ServiceManagementServerWrapper(server));
        }
        /// <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;

            // clean up some values
            char token = '"';

            K2Server                   = K2Helper.StripLeadingAndTailing(K2Server, token);
            ServiceInstanceGuid        = K2Helper.StripLeadingAndTailing(ServiceInstanceGuid, token);
            ServiceInstanceSystemName  = K2Helper.StripLeadingAndTailing(ServiceInstanceSystemName, token);
            ServiceInstanceDisplayName = K2Helper.StripLeadingAndTailing(ServiceInstanceDisplayName, token);
            ServiceInstanceDescription = K2Helper.StripLeadingAndTailing(ServiceInstanceDescription, token);
            ConfigKeyNames             = K2Helper.StripLeadingAndTailing(configKeyNames, token);
            ConfigKeyValues            = K2Helper.StripLeadingAndTailing(ConfigKeyValues, token);
            ConfigKeysRequired         = K2Helper.StripLeadingAndTailing(ConfigKeysRequired, token);
            ConfigKeyDelimiter         = K2Helper.StripLeadingAndTailing(ConfigKeyDelimiter, token);


            LogHelper.LogMessage("\n\n*****     BEGIN     *******\n");

            LogHelper.LogSubStepInfo("K2 Server: " + K2Server);
            LogHelper.LogSubStepInfo("K2 HostServer Port: " + K2HostServerPort.ToString());
            LogHelper.LogSubStepInfo("Service Instance Guid: " + ServiceInstanceGuid);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceSystemName);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceDisplayName);
            LogHelper.LogSubStepInfo("Service Instance : " + ServiceInstanceDescription);
            LogHelper.LogSubStepInfo("Config Key Names : " + ConfigKeyNames);
            LogHelper.LogSubStepInfo("Config Key Values : " + ConfigKeyValues);
            LogHelper.LogSubStepInfo("Config Key Reqds : " + ConfigKeysRequired);
            LogHelper.LogSubStepInfo("Config Delimiter : " + ConfigKeyDelimiter);

            try
            {
                LogHelper.LogStep(++currentStep, "Validating");

                if (!GuidHelper.IsGuid(ServiceTypeGuid))
                {
                    throw new ArgumentException("Invalid Service Type Guid");
                }

                if (!GuidHelper.IsGuid(ServiceInstanceGuid))
                {
                    throw new ArgumentException("Invalid Service Instance Guid");
                }

                // Create the Service Type Guid
                Guid svcTypeGuid = new Guid(ServiceTypeGuid);

                // Create the Service Instance Guid
                Guid svcInstanceGuid = new Guid(ServiceInstanceGuid);

                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"));

                    char delim = ',';
                    if (ConfigKeyDelimiter.Length == 1)
                    {
                        delim = ConfigKeyDelimiter.ToCharArray()[0];
                    }

                    LogHelper.LogSubStep("Getting Service Instance Configuration");
                    string svcInstanceConfig = K2Helper.GetK2ServiceInstanceConfig(
                        ConfigImpersonate, ConfigKeyNames, ConfigKeyValues,
                        ConfigKeysRequired, delim);

                    LogHelper.LogSubStepInfo("Service Instance Config = ");
                    LogHelper.LogSubStepInfo(svcInstanceConfig);

                    LogHelper.LogStep(++currentStep, "Registering Service Instance");
                    LogHelper.LogSubStep("Determining if Service Instance already exists");

                    // Check if this Service Instance is already registered
                    if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                    {
                        LogHelper.LogSubStepInfo("Service Instance does not exist");

                        LogHelper.LogSubStep("Registering new Service Instance");
                        svcMng.RegisterServiceInstance(
                            svcTypeGuid, svcInstanceGuid, ServiceInstanceSystemName,
                            ServiceInstanceDisplayName, ServiceInstanceDescription, svcInstanceConfig);

                        if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                        {
                            throw new Exception("Registration of Service Instance Unsuccessful");
                        }
                        else
                        {
                            LogHelper.LogSubStepInfo("Registration of Service Instance was Successful");
                        }
                    }
                    else
                    {
                        LogHelper.LogSubStepInfo("Service Instance already exists");

                        LogHelper.LogSubStep("Updating existing Service Instance");

                        svcMng.UpdateServiceInstance(
                            svcTypeGuid, svcInstanceGuid, ServiceInstanceSystemName,
                            ServiceInstanceDisplayName, ServiceInstanceDescription, svcInstanceConfig);

                        if (!K2Helper.DetermineIfServiceInstanceExists(svcMng, svcInstanceGuid))
                        {
                            throw new Exception("Update of Service Instance Unsuccessful");
                        }
                        else
                        {
                            LogHelper.LogSubStepInfo("Update of Service Instance was Successful");
                        }
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
                //LogHelper.LogSubStepInfo(string.Format("Got an error:{0}{1}", ex.Message, ex.StackTrace));
                //result = false;
            }
            finally
            {
                LogHelper.LogMessage("\n*****       END       *******\n\n");
            }


            return(result);
        }