Esempio n. 1
0
 public ThingCreationParameters(ThingCreationParameters p)
 {
     CreateIfNotExist = p.CreateIfNotExist;
     Hidden           = p.Hidden;
     ReadOnly         = p.ReadOnly;
     InstanceId       = p.InstanceId;
     FriendlyName     = p.FriendlyName;
 }
Esempio n. 2
0
        private async Task <bool> Initialize(OPCUAParameters opcUAParameters, ThingCreationParameters thingCreation)
        {
            if (thingCreation == null)
            {
                thingCreation = new ThingCreationParameters();
            }

            Dictionary <string, object> properties;

            if (opcUAParameters != null)
            {
                try
                {
                    properties = TheCommonUtils.DeserializeJSONStringToObject <Dictionary <string, object> >(TheCommonUtils.SerializeObjectToJSONString(opcUAParameters));
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                properties = new Dictionary <string, object>();
            }

            var tTaskForThing = TheThingRegistry.CreateOwnedThingAsync(new TheThingRegistry.MsgCreateThingRequestV1
            {
                EngineName       = TheOPCUAClientEngines.EngineName,
                DeviceType       = eOPCUAClientDeviceTypes.RemoteServer,
                Address          = ServerAddress,
                CreateIfNotExist = thingCreation.CreateIfNotExist,
                FriendlyName     = thingCreation.FriendlyName,
                Hidden           = thingCreation.Hidden,
                ReadOnly         = thingCreation.ReadOnly,
                InstanceId       = thingCreation.InstanceId,
                OwnerAddress     = OwnerAddress,
                Properties       = properties,
            }, new TheMessageAddress {
                Node = TheBaseAssets.MyServiceHostInfo.MyDeviceInfo.DeviceID
            }, new TimeSpan(0, 0, 30));
            var tThing = await tTaskForThing;

            if (tThing == null)
            {
                return(false);
            }

            OpcThingAddress = tThing;
            _opcThing       = tThing;
            RegisterEvent(eOPCUAClientEvents.ConnectComplete, sinkConnected);
            RegisterEvent(eOPCUAClientEvents.ConnectFailed, sinkConnectFailure);
            RegisterEvent(eOPCUAClientEvents.DisconnectComplete, sinkDisconnected);
            return(true);
        }
Esempio n. 3
0
        public static async Task <TheOPCUAClient> CreateAndInitAsync(TheMessageAddress owner, string serverAddress, OPCUAParameters opcUAParameters = null, OPCUAConnectParameters connectParameters = null, ThingCreationParameters thingCreationParameters = null)
        {
            var client = new TheOPCUAClient(owner, serverAddress, connectParameters);

            if (await client.Initialize(opcUAParameters, thingCreationParameters))
            {
                return(client);
            }
            return(null);
        }