Пример #1
0
        internal void UpdateInternalState(IEnumerable <string> vars)
        {
            using (var guard = new UpgradeableGuard(_bindingLock))
            {
                if (AddObject(PlcObject, Variables, vars))
                {
                    var bindings = new Dictionary <string, PlcObjectBinding>();
                    foreach (var rawDataBlock in _mapper.Optimizer.CreateRawReadOperations(PlcObject.Selector, Variables, ReadDataBlockSize))
                    {
                        if (rawDataBlock.References.Any())
                        {
                            foreach (var reference in rawDataBlock.References)
                            {
                                bindings.Add(reference.Key, new PlcObjectBinding(rawDataBlock, reference.Value.Item2, reference.Value.Item1, ValidationTimeMs));
                            }
                        }
                    }

                    if (bindings.Any())
                    {
                        using (var writeGuard = guard.UpgradeToWriterLock())
                        {
                            //extend bindings with the new created ones
                            _bindings = _bindings != null
                                            ? _bindings.Union(bindings
                                                              .Where(kvp => !_bindings.ContainsKey(kvp.Key))
                                                              ).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
                                            : bindings;
                        }
                    }
                }
            }
        }
Пример #2
0
 public UpgradedGuard(UpgradeableGuard parentGuard)
 {
     _parentGuard = parentGuard;
     _writerLock  = new WriterGuard(_parentGuard._readerWriterLock);
 }