Skip to content
Äkwav edited this page Nov 19, 2019 · 3 revisions

The so called CreationCommands are Commands that create a new Referenceable. They are registered on the active CoflnetCore.

What is it?

Basically they are network Constructors that can be executed from the client to create new objects.

How can I use it?

They can be exectued on the ClientCore via the public Referenceable ClientCore.CreateResource<CreationCommand,Toptions>(Toptions options) method. This instructs the ClientCore to send the CreationCommand to its managing node which creates the resource and returns the newly created id of it. In the meantime it will create a temporary local represenation of the Resource wich is the return value of the function. When the response from the managing node is received by the client, the local id will be updated. All Commands any of the tho ids will eventually reach the managing node and be validated and rolled back if failed.

How to make one

Implement the abstract CreationCommand class found in the Coflnet namespace. For example:

using Coflnet;

public class RegisterDevice : CreationCommand {
	protected override CommandSettings GetSettings () {
		// everyone can register devices
		return new CommandSettings ();
	}

        public override Referenceable CreateResource(MessageData data)
        {
            // check
            //Captcha.CheckToken(data.GetAs<Params>().captchaToken);
            return new Device ();
        }

        public override string Slug => "registerDevice";

        public class Params : CreationParamsBase
        {
                public string captchaToken;
        }
}

And you can use it like this:

var localDevice = ClientCore.CreateResource<RegisterDevice,RegisterDevice.Params>(
        new RegisterDevice.Params(){captchaToken="tokenIgotFromACaptchaProvingThatIamHuman"});

This is/was the method to register Device inside the Coflnet.Client.DeviceService.Setup(). It is likely outdated by now.

Clone this wiki locally