示例#1
0
文件: Thing.cs 项目: sm6uax/plegma
        public bool IsSameType(Thing thing)
        {
            if (!String.IsNullOrWhiteSpace(Type) && Type != thing.Type)
            {
                return(false);
            }

            if (Ports.Count != thing.Ports.Count)
            {
                return(false);
            }

            foreach (var pkv in thing.Ports)
            {
                // build the right PortKey
                PortKey thingPortKey = PortKey.BuildFromArbitraryString(thing.ThingKey, ((PortKey)pkv.PortKey).PortUID);
                Port    Port         = thing.GetPort(thingPortKey);
                if (Port == null)
                {
                    DebugEx.Assert("could not find Port for pkey: " + thingPortKey);
                }
                if (Port.Type != pkv.Type)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#2
0
        public virtual void Update(Thing incomingThing, bool UpdatePortStates = true)
        {
            DebugEx.Assert(this.ThingKey == incomingThing.ThingKey || ((ThingKey)this.ThingKey).IsInvalid, "Incompatible Things");

            this.ThingKey     = incomingThing.ThingKey;
            this.Name         = incomingThing.Name;
            this.Config       = incomingThing.Config?.ToList();
            this.ReadonlyInfo = incomingThing.ReadonlyInfo?.ToList();
            this.Type         = incomingThing.Type;
            this.BlockType    = incomingThing.BlockType;
            this.Removable    = incomingThing.Removable;
            this.RESTUri      = incomingThing.RESTUri;
            this.UIHints      = incomingThing.UIHints;
            this.Hierarchies  = incomingThing.Hierarchies;

            lock (this)
            {
                //update existing Ports or add the ones that are missing
                foreach (var p in incomingThing.Ports)
                {
                    var port = this.GetPort(p.PortKey);
                    if (port != null)
                    {
                        if (UpdatePortStates)
                        {
                            port.Update(p);
                        }
                        else
                        {
                            port.Update_Except_States(p);
                        }
                    }
                    else
                    {
                        this.Ports.Add(p.DeepClone());
                    }
                }

                //remove the ones that don't exist in incoming Thing
                List <Port> toRemove = new List <Port>();
                foreach (var p in this.Ports)
                {
                    if (incomingThing.GetPort(p.PortKey) == null)
                    {
                        toRemove.Add(p);
                    }
                }
                foreach (var p in toRemove)
                {
                    this.Ports.Remove(p);
                }
            }
        }