ServiceDefinitionBuilder

We found 10 examples in language CSharp for this search. You will see 35 fragments of code.

        /// <summary>
        /// Changes the name of the service.
        /// </summary>
        /// <param name="serviceName">New name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithServiceName(string serviceName)
        {
            ServiceName = serviceName;
            return this;
        }

        /// <summary>
        /// Changes the display name of the service.
        /// </summary>
        /// <param name="displayName">The new display name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDisplayName(string displayName)
        {
            DisplayName = displayName;
            return this;
        }

        /// <summary>
        /// Changes the service description.
        /// </summary>
        /// <param name="description">The new service description.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDescription(string description)
        {
            Description = description;
            return this;
        }

        /// <summary>
        /// Changes the credentials for the account the service shall run as.
        /// </summary>
        /// <param name="credentials">The new credentials for the account the service shall run as.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithCredentials(Win32ServiceCredentials credentials)
        {
            Credentials = credentials;
            return this;
        }

        /// <summary>
        /// Changes the failure actions of the service.
        /// </summary>
        /// <param name="failureActions">The new failure actions of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithFailureActions(ServiceFailureActions failureActions)
        {
            FailureActions = failureActions;
            return this;
        }

        /// <summary>
        /// Changes the error severity of service failures.
        /// </summary>
        /// <param name="errorSeverity">The new error severity of service failures.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithErrorSeverity(ErrorSeverity errorSeverity)
        {
            ErrorSeverity = errorSeverity;
            return this;
        }


        /// <summary>
        /// Changes the name of the service.
        /// </summary>
        /// <param name="serviceName">New name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithServiceName(string serviceName)
        {
            ServiceName = serviceName;
            return this;
        }

        /// <summary>
        /// Changes the display name of the service.
        /// </summary>
        /// <param name="displayName">The new display name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDisplayName(string displayName)
        {
            DisplayName = displayName;
            return this;
        }

        /// <summary>
        /// Changes the service description.
        /// </summary>
        /// <param name="description">The new service description.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDescription(string description)
        {
            Description = description;
            return this;
        }

        /// <summary>
        /// Changes the credentials for the account the service shall run as.
        /// </summary>
        /// <param name="credentials">The new credentials for the account the service shall run as.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithCredentials(Win32ServiceCredentials credentials)
        {
            Credentials = credentials;
            return this;
        }

        /// <summary>
        /// Changes the failure actions of the service.
        /// </summary>
        /// <param name="failureActions">The new failure actions of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithFailureActions(ServiceFailureActions failureActions)
        {
            FailureActions = failureActions;
            return this;
        }

        /// <summary>
        /// Changes the error severity of service failures.
        /// </summary>
        /// <param name="errorSeverity">The new error severity of service failures.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithErrorSeverity(ErrorSeverity errorSeverity)
        {
            ErrorSeverity = errorSeverity;
            return this;
        }

        public static ServiceDefinitionBuilder CreateByImplementationType(
            Type serviceImplementationType, IMutableServiceDefinition serviceDefinition) =>
            (ServiceDefinitionBuilder)Activator.CreateInstance(
                typeof(ServiceDefinitionBuilder<>).MakeGenericType(serviceImplementationType),
                new object[] { serviceDefinition });

        public ServiceDefinitionBuilder Name(string serviceName)
        {
            ServiceDefinition.Name = serviceName;
            return this;
        }

        public ServiceDefinitionBuilder AlternateName(params string[] alternateServiceNames)
        {
            foreach (var altName in alternateServiceNames)
                ServiceDefinition.AddAlternateName(altName);
            return this;
        }

        public ServiceDefinitionBuilder Method(string methodName, Action<MethodDefinitionBuilder> buildAction)
        {
            buildAction(Method(methodName));
            return this;
        }

        public ServiceDefinitionBuilder Command(string methodName, Action<CommandDefinitionBuilder> buildAction)
        {
            buildAction(Command(methodName));
            return this;
        }

        public ServiceDefinitionBuilder Query(string methodName, Action<QueryDefinitionBuilder> buildAction)
        {
            buildAction(Query(methodName));
            return this;
        }


        public CommunicationModelBuilder Service(Type implementationType, Action<ServiceDefinitionBuilder> buildAction)
        {
            var serviceBuilder = Service(implementationType);
            buildAction(serviceBuilder);
            return this;
        }

        public CommunicationModelBuilder Service(Type interfaceType, Type implementationType, Action<ServiceDefinitionBuilder> buildAction)
        {
            var serviceBuilder = Service(interfaceType, implementationType);
            buildAction(serviceBuilder);
            return this;
        }


        /// <summary>
        /// Changes the name of the service.
        /// </summary>
        /// <param name="serviceName">New name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithServiceName(string serviceName)
        {
            ServiceName = serviceName;
            return this;
        }

        /// <summary>
        /// Changes the display name of the service.
        /// </summary>
        /// <param name="displayName">The new display name of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDisplayName(string displayName)
        {
            DisplayName = displayName;
            return this;
        }

        /// <summary>
        /// Changes the service description.
        /// </summary>
        /// <param name="description">The new service description.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithDescription(string description)
        {
            Description = description;
            return this;
        }

        /// <summary>
        /// Changes the credentials for the account the service shall run as.
        /// </summary>
        /// <param name="credentials">The new credentials for the account the service shall run as.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithCredentials(Win32ServiceCredentials credentials)
        {
            Credentials = credentials;
            return this;
        }

        /// <summary>
        /// Changes the failure actions of the service.
        /// </summary>
        /// <param name="failureActions">The new failure actions of the service.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithFailureActions(ServiceFailureActions failureActions)
        {
            FailureActions = failureActions;
            return this;
        }

        /// <summary>
        /// Changes the error severity of service failures.
        /// </summary>
        /// <param name="errorSeverity">The new error severity of service failures.</param>
        /// <returns>Returns the current instance</returns>
        public ServiceDefinitionBuilder WithErrorSeverity(ErrorSeverity errorSeverity)
        {
            ErrorSeverity = errorSeverity;
            return this;
        }

        
        private static ServiceDefinitionBuilder CreateTestServiceDefinitionBuilder()
            => new ServiceDefinitionBuilder(TestServiceName)
                .WithDisplayName(TestDisplayName)
                .WithDescription(TestDescription)
                .WithBinaryPath(TestBinaryPath)
                .WithCredentials(Win32ServiceCredentials.LocalService);

using System.IO;
using AspNetSkeleton.Base;
using AspNetSkeleton.Core.Hosting;
using AspNetSkeleton.Core.Hosting.Operations;
using DasMulli.Win32.ServiceUtils;

namespace AspNetSkeleton.UI.Hosting
{
    public class HostWindowsService : HostWindowsServiceBase
    {
        const string name = "AspNetSkeleton.UI";
        const string description = "AspNetSkeleton UI component implemented as an ASP.NET Core application.";

        public HostWindowsService(IHost host, IAppEnvironment environment) : base(host)
        {
            Definition = new ServiceDefinitionBuilder()
                .WithServiceName(name)
                .WithDisplayName(name)
                .WithDescription(description)
                .WithBinaryPath($"dotnet.exe \"{Path.Combine(environment.AppBasePath, environment.AppName + ".dll")}\" {ServiceOperation.Name}")
                .WithCredentials(Win32ServiceCredentials.LocalSystem)
                .WithAutoStart(true)
                .Build();
        }

        public override ServiceDefinition Definition { get; }
    }
}

using System.IO;
using AspNetSkeleton.Base;
using AspNetSkeleton.Core.Hosting;
using AspNetSkeleton.Core.Hosting.Operations;
using DasMulli.Win32.ServiceUtils;

namespace AspNetSkeleton.Api.Hosting
{
    public class HostWindowsService : HostWindowsServiceBase
    {
        const string name = "AspNetSkeleton.Api";
        const string description = "AspNetSkeleton API component implemented as an ASP.NET Core application.";

        public HostWindowsService(IHost host, IAppEnvironment environment) : base(host)
        {
            Definition = new ServiceDefinitionBuilder()
                .WithServiceName(name)
                .WithDisplayName(name)
                .WithDescription(description)
                .WithBinaryPath($"dotnet.exe \"{Path.Combine(environment.AppBasePath, environment.AppName + ".dll")}\" {ServiceOperation.Name}")
                .WithCredentials(Win32ServiceCredentials.LocalSystem)
                .WithAutoStart(true)
                .Build();
        }

        public override ServiceDefinition Definition { get; }
    }
}

using System.IO;
using AspNetSkeleton.Base;
using AspNetSkeleton.Core.Hosting;
using AspNetSkeleton.Core.Hosting.Operations;
using DasMulli.Win32.ServiceUtils;

namespace AspNetSkeleton.Service.Host.Hosting
{
    public class HostWindowsService : HostWindowsServiceBase
    {
        const string name = "AspNetSkeleton.Service";
        const string description = "AspNetSkeleton logic layer component implemented as an ASP.NET Core application.";

        public HostWindowsService(IHost host, IAppEnvironment environment) : base(host)
        {
            Definition = new ServiceDefinitionBuilder()
                .WithServiceName(name)
                .WithDisplayName(name)
                .WithDescription(description)
                .WithBinaryPath($"dotnet.exe \"{Path.Combine(environment.AppBasePath, environment.AppName + ".dll")}\" {ServiceOperation.Name}")
                .WithCredentials(Win32ServiceCredentials.LocalSystem)
                .WithAutoStart(true)
                .Build();
        }

        public override ServiceDefinition Definition { get; }
    }
}


        public void AppendServiceDefinition(Stream stream)
        {
            var streamPosition = stream.Position;

            var serializer = new XmlSerializer(typeof(ApisRoot));
            var reader = new StreamReader(stream);
            var root = (ApisRoot)serializer.Deserialize(reader);

            if (stream.CanSeek)
                stream.Seek(streamPosition, SeekOrigin.Begin);

            this.AppendRoot(root);
        }

        public void AppendServiceDefinition(ServiceDefinition serviceDefinition)
        {
            this.AppendRoot(serviceDefinition.Root);
        }

        private void AppendRoot(ApisRoot tree)
        {
            this.isDirty = true;

            if (this.root == null)
            {
                this.root = tree;
            }
            else
            {
                foreach (var apiGroup in tree.ApiGroups)
                {
                    var matchGroup = this.root.ApiGroups.SingleOrDefault(g => g.Name == apiGroup.Name);
                    if (matchGroup != null)
                    {
                        matchGroup.Methods.AddRange(apiGroup.Methods);
                        matchGroup.ReturnTypes.AddRange(apiGroup.ReturnTypes);
                    }
                    else
                    {
                        this.root.ApiGroups.Add(apiGroup);
                    }
                }
            }
        }

        private void Sanitize()
        {
            this.isDirty = false;
            this.warnings = new List<string>();
            this.infos = new List<string>();

            this.definition = this.definition ?? (this.definition = new ServiceDefinition(this.root));

            this.VerifyFieldNames();

            {
                foreach (var apiGroup in this.root.ApiGroups)
                {
                    // generate implicit return types
                    foreach (var returnType in apiGroup.ReturnTypes.ToArray())
                    {
                        foreach (var item in returnType.Fields.ToArray())
                        {
                            var parts = item.Name.Split(new char[] { ':', '/', }, 2);
                            var mainPart = parts.Length == 1 ? parts[0] : parts[0];
                            var subPart = parts.Length == 2 ? parts[1] : null;

                            if (parts.Length > 1)
                            {
                                var subReturnType = definition.FindReturnType(mainPart, apiGroup.Name, subPart: subPart, typeName: item.Type);
                            }
                        }
                    }
                }
            }

            this.VerifyFieldNames();
        }

        private void VerifyFieldNames()
        {
            foreach (var apiGroup in this.root.ApiGroups)
            {
                // fill optional stuff
                foreach (var returnType in apiGroup.ReturnTypes.ToArray())
                {
                    returnType.ApiGroup = apiGroup.Name;

                    foreach (var item in returnType.Fields)
                    {
                        // field name stuff
                        if (string.IsNullOrEmpty(item.Name))
                        {
                            this.warnings.Add("Field " + apiGroup.Name + "/" + returnType.Name + "/" + returnType.Fields.IndexOf(item) + " has en empty name.");
                        }

                        var nameParts = item.GetNameParts();
                        item.FieldName = nameParts[0];
                        if (item.Type != null && item.FieldName.ClassName == null)
                            item.FieldName.ClassName = item.Type;

                        if (string.IsNullOrEmpty(item.PropertyName))
                        {
                            item.PropertyName = item.FieldName.PropertyName;
                            this.infos.Add("Set property name of " + apiGroup.Name + "/" + returnType.Name + "/" + returnType.Fields.IndexOf(item) + "-" + item.Name + " to " + item.PropertyName + ".");
                        }
                    }

                    if (returnType.Headers != null)
                    {
                        foreach (var item in returnType.Headers)
                        {
                            // field name stuff
                            if (string.IsNullOrEmpty(item.Name))
                            {
                                this.warnings.Add("Header " + apiGroup.Name + "/" + returnType.Name + "/" + returnType.Headers.IndexOf(item) + " has en empty name.");
                            }

                            var nameParts = item.GetNameParts();
                            item.FieldName = nameParts[0];
                            if (item.Type != null && item.FieldName.ClassName == null)
                                item.FieldName.ClassName = item.Type;

                            if (string.IsNullOrEmpty(item.PropertyName))
                            {
                                item.PropertyName = item.FieldName.PropertyName;
                                this.infos.Add("Set property name of " + apiGroup.Name + "/" + returnType.Name + "/" + returnType.Fields.IndexOf(item) + "-" + item.Name + " to " + item.PropertyName + ".");
                            }
                        }
                    }
                }
            }
        }

DasMulli.Win32.ServiceUtils.ServiceDefinitionBuilder : Object

Constructors :

public ServiceDefinitionBuilder()
public ServiceDefinitionBuilder(String serviceName = )
public ServiceDefinitionBuilder(ServiceDefinition definition = )
public ServiceDefinitionBuilder(ServiceDefinitionBuilder definitionBuilder = )

Methods :

public String get_ServiceName()
public Void set_ServiceName(String value = )
public String get_DisplayName()
public Void set_DisplayName(String value = )
public String get_Description()
public Void set_Description(String value = )
public String get_BinaryPath()
public Void set_BinaryPath(String value = )
public Win32ServiceCredentials get_Credentials()
public Void set_Credentials(Win32ServiceCredentials value = )
public ServiceFailureActions get_FailureActions()
public Void set_FailureActions(ServiceFailureActions value = )
public Boolean get_FailureActionsOnNonCrashFailures()
public Void set_FailureActionsOnNonCrashFailures(Boolean value = )
public Boolean get_AutoStart()
public Void set_AutoStart(Boolean value = )
public ErrorSeverity get_ErrorSeverity()
public Void set_ErrorSeverity(ErrorSeverity value = )
public Boolean get_DelayedAutoStart()
public Void set_DelayedAutoStart(Boolean value = )
public ServiceDefinition Build()
public ServiceDefinitionBuilder WithServiceName(String serviceName = )
public ServiceDefinitionBuilder WithDisplayName(String displayName = )
public ServiceDefinitionBuilder WithDescription(String description = )
public ServiceDefinitionBuilder WithBinaryPath(String binaryPath = )
public ServiceDefinitionBuilder WithCredentials(Win32ServiceCredentials credentials = )
public ServiceDefinitionBuilder WithFailureActions(ServiceFailureActions failureActions = )
public ServiceDefinitionBuilder WithFailureActionsOnNonCrashFailures(Boolean failureActionsOnNonCrashFailures = )
public ServiceDefinitionBuilder WithAutoStart(Boolean autoStart = )
public ServiceDefinitionBuilder WithErrorSeverity(ErrorSeverity errorSeverity = )
public ServiceDefinitionBuilder WithDelayedAutoStart(Boolean delayedAutoStart = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()