private static void TraverseFromBottomLeft(this DeviceGroupConfig node, ICollection <DeviceGroupConfig> traversedNodes, Action <DeviceGroupConfig, DeviceGroupConfig> enterAction = null, Action <DeviceGroupConfig, DeviceGroupConfig> exitAction = null) { foreach (var childNode in node.GroupConfigCollection) { if (enterAction != null) { enterAction(childNode, node); } TraverseFromBottomLeft(childNode, traversedNodes, enterAction, exitAction); if (exitAction != null) { exitAction(childNode, node); } } traversedNodes.Add(node); }
public static IEnumerable <DeviceGroupConfig> TraverseFromTopLeft(this DeviceGroupConfig node, Action <DeviceGroupConfig, DeviceGroupConfig> enterAction = null, Action <DeviceGroupConfig, DeviceGroupConfig> exitAction = null) { var nodes = new List <DeviceGroupConfig>(); if (enterAction != null) { enterAction(node, null); } TraverseFromTopLeft(node, nodes, enterAction, exitAction); if (exitAction != null) { enterAction(node, null); } return(nodes); }
public IDeviceGroup Create(DeviceGroupConfig deviceGroupConfig) { var deviceGroup = ServiceLocator.GetInstance <IDeviceGroup>(); deviceGroup.Name = deviceGroupConfig.Name; foreach (var deviceConfig in deviceGroupConfig.DeviceConfigCollection) { var device = DeviceFactory.Create(deviceConfig); deviceGroup.Devices.Add(device); } foreach (var subDeviceGroupConfig in deviceGroupConfig.GroupConfigCollection) { var subDeviceGroup = Create(subDeviceGroupConfig); deviceGroup.DeviceGroups.Add(subDeviceGroup); subDeviceGroup.Parent = deviceGroup; } return(deviceGroup); }
public DeviceGroupConfig GetGroup(DeviceGroupDef def, ConcurrentDictionary <string, int> counters, int globalIndex, int index) { var gc = new DeviceGroupConfig { Name = def.Name, GlobalIndex = globalIndex, Index = index, }; foreach (var group in def.GroupDefCollection) { var groupName = @group.Name; var collectionName = groupName + "Collection"; var childGc = new DeviceGroupConfig() { Name = collectionName }; gc.GroupConfigCollection.Add(childGc); var counter = counters.GetOrAdd(groupName, 0); for (int i = 0; i < group.Total; i++) { var globalIndex2 = counter; var index2 = i; var grandChildGc = GetGroup(group, counters, globalIndex2, index2); childGc.GroupConfigCollection.Add(grandChildGc); counter++; counters[groupName] = counter; } } return(gc); }
private DeviceGroupConfig GetDeviceGroupConfig(DeviceDefSchema deviceDefSchema, int?generationIndex) { DeviceGroupConfig top = GetTopNode(deviceDefSchema); DeviceGroupConfigExtensions.TraverseFromTopLeft( top, (n, p) => { //var deviceDefs = deviceDefSchema.DeviceDefs.Where(x => x.OffsetDefs.Last().GroupName == n.Name); if (!_deviceDefsDic.ContainsKey(n.Name)) { return; } var deviceDefs = _deviceDefsDic[n.Name]; foreach (var deviceDef in deviceDefs) { var offsetE = _deviceOffsetsDic[deviceDef]; offsetE.MoveNext(); var offset = offsetE.Current; var tagIndex = deviceDef.TagIndexPosition + n.GlobalIndex + offset; var path = deviceDef.Path; string tag; if (generationIndex == null) { if (deviceDef.IsArray) { tag = PathFactory.CreateArrayPath(path, tagIndex); } else { tag = PathFactory.Create(path, tagIndex, deviceDef.TagIndexLength); } } else { if (deviceDef.IsArray) { tag = PathFactory.CreateArrayPath(path, tagIndex, generationIndex.Value); } else { tag = PathFactory.Create(path, tagIndex, deviceDef.TagIndexLength, generationIndex.Value); } } var deviceConfig = new DeviceConfig { Name = deviceDef.Name, DataType = deviceDef.DataType, //Path = path, TagIndex = tagIndex, Tag = tag, IsSimulated = deviceDef.IsSimulated, IsConversionEnabled = deviceDef.IsConversionEnabled, ConverterCollection = deviceDef.ConverterCollection.DeepClone(), }; //deviceDef.ConverterCollection.ForEach(c=>deviceConfig.ConverterCollection.Add(c.DeepClone())); n.DeviceConfigCollection.Add(deviceConfig); } }); return(top); }