Beispiel #1
0
        private static void Register()
        {
            string Key = Guid.NewGuid().ToString().Replace("-", string.Empty);

            // For info on tag names, see: http://xmpp.org/extensions/xep-0347.html#tags
            MetaDataTag[] MetaData = new MetaDataTag[]
            {
                new MetaDataStringTag("KEY", Key),
                new MetaDataStringTag("CLASS", "PC"),
                new MetaDataStringTag("MAN", "waher.se"),
                new MetaDataStringTag("MODEL", "Waher.Service.PcSensor"),
                new MetaDataStringTag("PURL", "https://github.com/PeterWaher/IoTGateway/tree/master/Services/Waher.Service.PcSensor"),
                new MetaDataNumericTag("V", 1.0)
            };

            thingRegistryClient.RegisterThing(MetaData, (sender2, e2) =>
            {
                if (e2.Ok)
                {
                    registered = true;

                    if (e2.IsClaimed)
                    {
                        ownerJid = e2.OwnerJid;
                    }
                    else
                    {
                        ownerJid = string.Empty;
                        SimpleXmppConfiguration.PrintQRCode(thingRegistryClient.EncodeAsIoTDiscoURI(MetaData));
                    }
                }

                return(Task.CompletedTask);
            }, null);
        }
Beispiel #2
0
        internal static Task RegistrationSuccessfulAsConsole(MetaDataTag[] MetaData, RegistrationEventArgs e)
        {
            if (!e.IsClaimed && Types.TryGetModuleParameter("Registry", out object Obj) && Obj is ThingRegistryClient ThingRegistryClient)
            {
                SimpleXmppConfiguration.PrintQRCode(ThingRegistryClient.EncodeAsIoTDiscoURI(MetaData));
            }

            return(RegistrationSuccessfulAsService(MetaData, e));
        }
Beispiel #3
0
        private static async Task RegistrationSuccessful(MetaDataTag[] MetaData, RegistrationEventArgs e)
        {
            if (!e.IsClaimed && Types.TryGetModuleParameter("Registry", out object Obj) && Obj is ThingRegistryClient ThingRegistryClient)
            {
                string ClaimUrl = ThingRegistryClient.EncodeAsIoTDiscoURI(MetaData);
                string FilePath = Path.Combine(Gateway.AppDataFolder, "Gateway.iotdisco");

                SimpleXmppConfiguration.PrintQRCode(ClaimUrl);

                Log.Informational("Registration successful.");
                Log.Informational(ClaimUrl, new KeyValuePair <string, object>("Path", FilePath));

                await File.WriteAllTextAsync(FilePath, ClaimUrl);
            }
        }