Click or drag to resize

ServerFactoryNewServer Method

Create a new instance of server.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IServer NewServer(
	IContext context,
	string type,
	ConnectionStringType connectionStringType,
	Nullable<Guid> moduleGuid = null
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution.
type
Type: SystemString
Type of the server to create.
connectionStringType
Type: AskiaPortalCmnConnectionStringType
Type of the connection string.
moduleGuid (Optional)
Type: SystemNullableGuid
Guid of the module that manage the server (if null use the CurrentModule).

Return Value

Type: IServer
Return a new instance of server or null if the user in the context doesn't have enough right to create a server.
Examples

Create a new server 'SMTP' server for the `AskiaPortal` module and save it.

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}

Guid askiaPortalGuid = Guid.Parse("5F856C7A-2F60-47C5-A90C-23BC2F179CBC");

var server = ServerFactory.NewServer(context, "smtp", ConnectionStringType.Smtp, askiaPortalGuid);
if (server == null)
{
    Console.Error.WriteLine("Could not create a server.");
    return;
}

server.Name = "MySecondSMTPServer";
server.Description = "Second SMTP server";
var smtpConnectionString = new SmtpConnectionString
{
    Host   = "server.domain.ext", 
    Port   = 25, 
    UseSsl = true, 
    UserName = "myusername", 
    Password = "secret"
};
server.ConnectionString = smtpConnectionString.ToString();

var saveResult = server.Save();
if (saveResult.Success)
{
    Console.WriteLine("The server (Id={0}) was successfully saved",
                                    server.Id);
}
else
{
    Console.Error.Write(saveResult.Exception.Message);
}
See Also