Ejemplo n.º 1
0
        internal override string RegisterInHostThing()
        {
            string error = null;

            string   propertyName = DisplayName;
            TheThing targetThing  = null;

            if (this.IsSubscribedAsThing)
            {
                // Dedicated event thing
                targetThing = MyBaseThing;
            }
            if (this.IsSubscribedAsProperty)
            {
                // This is an external, multi-event thing: use the browsepath to avoid collisions with properties from multiple events
                targetThing = this.GetHostThing().GetBaseThing();
            }
            if (targetThing != null)
            {
                var prop       = targetThing.GetProperty(propertyName, true);
                var sensorMeta = prop.GetSensorMeta();
                prop = targetThing.DeclareSensorProperty(propertyName, ePropertyTypes.NOCHANGE, sensorMeta);
                if (prop != null)
                {
                    var opcSubscriptionInfo = new TheOPCSensorSubscription
                    {
                        SampleRate    = this.SampleRate,
                        SensorId      = this.NodeIdName,
                        ChangeTrigger = this.ChangeTrigger,
                        DeadbandValue = this.DeadbandFilterValue,
                        EventInfo     = this.EventInfo,
                    };

                    var providerInfo = new cdeP.TheProviderInfo(this.MyOPCServer.GetBaseThing(), opcSubscriptionInfo);
                    prop.SetSensorProviderInfo(providerInfo);
                }
                else
                {
                    error = "ERROR: Property not found";
                }
            }
            else
            {
                error = "ERROR: Thing not found";
            }
            return(error);
        }
Ejemplo n.º 2
0
        internal static List <TheOPCSensorSubscription> GetHostThingOPCProperties(TheThing tHostThing, TheThing tProviderThing)
        {
            string prefix      = "OPCUA";
            var    legacyProps = tHostThing.GetPropertiesMetaStartingWith(prefix, true);

            if (legacyProps.Any())
            {
                foreach (var prop in legacyProps)
                {
                    if (ParseOpcUaMetaString(prop.cdeM, out var propKind, out var nodeIdName, out var serverId, out var changeTrigger, out var deadBandValue, out var structTypeInfo, out var historyStartTime, out var eventFilter))
                    {
                        if (serverId == tProviderThing.ID)
                        {
                            // TODO log migration start
                            var opcSubscriptionInfo = new TheOPCSensorSubscription
                            {
                                SampleRate     = (int)prop.cdeEXP,
                                SensorId       = nodeIdName,
                                ChangeTrigger  = changeTrigger,
                                DeadbandValue  = deadBandValue,
                                EventInfo      = eventFilter,
                                StructTypeInfo = structTypeInfo,
                                //HistoryStartTime = historyStartTime, // TODO
                            };

                            var providerInfo = new cdeP.TheProviderInfo(tProviderThing, opcSubscriptionInfo);
                            prop.SetSensorProviderInfo(providerInfo);
                            prop.cdeM = null;
                            // TODO Log migration finish
                        }
                        else
                        {
                            // tag from a different opc client
                        }
                    }
                    else
                    {
                        // Log migration error
                    }
                }