예제 #1
0
파일: NetGate.cs 프로젝트: dotnetchris/nfx
        private void setVariable(bool inc, TrafficDirection direction, string address, string varName, int value)
        {
            if (!Running || address.IsNullOrWhiteSpace() || varName.IsNullOrWhiteSpace() || value == 0)
            {
                return;
            }

            var state = this[direction];
            var grp   = state.FindGroupForAddress(address);

            var key = grp == null ? address : grp.Key;

            var nstate = state.NetState.GetOrAdd(key, (k) => grp == null ? new NetSiteState(address) : new NetSiteState(grp));

            lock (nstate)
            {
                if (inc)
                {
                    NetSiteState._value vval;
                    if (!nstate.m_Variables.TryGetValue(varName, out vval))
                    {
                        nstate.m_Variables[varName] = vval = new NetSiteState._value();
                    }
                    vval.Value += value;
                }
                else
                {
                    nstate.m_Variables[varName] = new NetSiteState._value {
                        Value = value
                    }
                };
            }
        }

        #endregion
    }
예제 #2
0
파일: NetGate.cs 프로젝트: itadapter/nfx
        private void setVariable(bool inc, TrafficDirection direction, string address, string varName, int value)
        {
            if (!Running || address.IsNullOrWhiteSpace() || varName.IsNullOrWhiteSpace() || value==0) return;

            var state = this[direction];
            var grp = state.FindGroupForAddress(address);

            var key = grp==null ? address : grp.Key;

            var nstate = state.NetState.GetOrAdd(key, (k) => grp==null ? new NetSiteState(address) : new NetSiteState(grp));

            lock(nstate)
            {
              if (inc)
              {
               NetSiteState._value vval;
               if (!nstate.m_Variables.TryGetValue(varName, out vval))
               {
             nstate.m_Variables[varName] = vval = new NetSiteState._value();
               }
               vval.Value += value;
              }
              else
               nstate.m_Variables[varName] = new NetSiteState._value{Value = value};
            }
        }