Exemple #1
0
        internal static void DisableNMISubscriptions(Guid NodeID)
        {
            List <TheNMISubscription> tToUnregister = new List <TheNMISubscription>();

            lock (MyNMIElements.MyLock) //This can cause jams of threads here! Highly optimized to get out of lock as fast as possible - could use a reader lock as we dont delete/add to the array- just change a prop
            {
                foreach (var k in MyNMIElements.Keys)
                {
                    TheNMISubscription tSub = null;
                    bool IsOneStillAlive    = false;
                    foreach (var tK in MyNMIElements[k].Keys)
                    {
                        if (MyNMIElements[k][tK].cdeN == NodeID)
                        {
                            MyNMIElements[k][tK].HasLiveSub = false;
                            tSub = MyNMIElements[k][tK];
                            continue;
                        }
                        if (MyNMIElements[k][tK].HasLiveSub == true)
                        {
                            IsOneStillAlive = true;
                            break;
                        }
                    }
                    if (!IsOneStillAlive && tSub != null)
                    {
                        tToUnregister.Add(tSub);
                    }
                }
            }
            if (tToUnregister.Count > 0)
            {
                foreach (var tG in tToUnregister)
                {
                    var tThing = TheThingRegistry.GetThingByMID(tG.cdeO);
                    if (tThing == null)
                    {
                        continue;
                    }
                    var OnUpdateName = tG.DataItem;
                    if (OnUpdateName.StartsWith("MyPropertyBag."))  //TODO: Test this with Prop of Prop
                    {
                        OnUpdateName = OnUpdateName.Split('.')[1];
                    }
                    tThing.GetProperty(OnUpdateName, true).SetPublication(false, Guid.Empty); //Guid.Empty uses PublishCentral - a specific node would use SYSTEMWIDE
                    MyNMIElements.RemoveNoCare(tG.cdeMID);
                    MyAliveThings.RemoveNoCare(tThing.cdeMID);
                }
            }
        }
Exemple #2
0
 internal static TheThing RegisterNMISubscription(TheClientInfo pClientInfo, string pDataItem, TheMetaDataBase tFld)
 {
     if (!string.IsNullOrEmpty(pDataItem))
     {
         TheThing tThing = null;
         lock (MyNMIElements.MyLock) //This can cause jams of threads here! Highly optimized to get out of lock as fast as possible
         {
             if (!MyNMIElements.ContainsKey(tFld.cdeMID))
             {
                 MyNMIElements.TryAdd(tFld.cdeMID, new cdeConcurrentDictionary <Guid, TheNMISubscription>());
             }
             if (!MyNMIElements[tFld.cdeMID].ContainsKey(pClientInfo.NodeID))
             {
                 tThing = TheThingRegistry.GetThingByMID(tFld.cdeO); //Most expensive call in here
                 if (tThing != null)
                 {
                     var tNewEle = new TheNMISubscription()
                     {
                         cdeN = pClientInfo.NodeID, cdeO = tThing.cdeMID, HasLiveSub = true, DataItem = pDataItem, cdeMID = tFld.cdeMID
                     };
                     MyNMIElements[tFld.cdeMID].TryAdd(pClientInfo.NodeID, tNewEle);
                 }
             }
         }
         if (tThing != null)
         {
             if (tFld is TheFieldInfo && (tFld as TheFieldInfo).Type == eFieldType.Table)    //fix for Bug#1195
             {
                 return(tThing);
             }
             RegisterNewNMINode(pClientInfo.NodeID, tFld.cdeMID, tThing.cdeMID, pDataItem, true);
             var OnUpdateName = pDataItem;
             if (OnUpdateName.StartsWith("MyPropertyBag."))  //TODO: Test this with Prop of Prop
             {
                 OnUpdateName = OnUpdateName.Split('.')[1];
             }
             tThing.GetProperty(OnUpdateName, true).SetPublication(true, Guid.Empty); //Guid.Empty uses PublishCentral - a specific node would use SYSTEMWIDE
             return(tThing);
         }
     }
     return(null);
 }
Exemple #3
0
 internal static bool RegisterNewNMINode(Guid pNodeID, Guid pID, Guid pOwner, string pDataItem, bool?pHasLiveSubs)
 {
     if (MyAliveNMINodes.ContainsKey(pNodeID))
     {
         if (pID != Guid.Empty)
         {
             MyAliveNMINodes[pNodeID].cdeMID = pID;
         }
         if (pOwner != Guid.Empty)
         {
             MyAliveNMINodes[pNodeID].cdeO = pOwner;
         }
         if (!string.IsNullOrEmpty(pDataItem))
         {
             MyAliveNMINodes[pNodeID].DataItem = pDataItem;
         }
         if (pHasLiveSubs != null)
         {
             MyAliveNMINodes[pNodeID].HasLiveSub = TheCommonUtils.CBool(pHasLiveSubs);
         }
         return(true);
     }
     else
     {
         var tsub = new TheNMISubscription()
         {
             cdeN = pNodeID, cdeO = pOwner, DataItem = pDataItem, HasLiveSub = TheCommonUtils.CBool(pHasLiveSubs), cdeMID = pID
         };
         MyAliveNMINodes.TryAdd(pNodeID, tsub);
         if (pOwner != Guid.Empty)
         {
             MyAliveThings[pOwner] = tsub;
         }
     }
     return(false);
 }