private DeviceGroupConfig Get(DeviceGroupDef deviceGroupDef, int globalIndex, int index)
        {
            /*            var deviceDefs = DeviceDefSchemaProvider.Schema.DeviceDefs
             *              .Where(x => x.OffsetDefs.Last().GroupName == deviceGroupDef.Name);*/

            //            throw new NotImplementedException();
            return(new DeviceGroupConfig()
            {
                Name = deviceGroupDef.Name,
                GlobalIndex = globalIndex,
                Index = index
            });
        }
        private void InitDeviceDefsDict(DeviceDefSchema deviceDefSchema)
        {
//init deviceDef map
            _deviceDefsDic = new Dictionary <string, IEnumerable <DeviceDef> >();

            var groups = deviceDefSchema.RootGroupDef.TraverseFromTopLeft();

            foreach (var deviceGroupDef in groups)
            {
                DeviceGroupDef def        = deviceGroupDef;
                var            deviceDefs = deviceDefSchema.DeviceDefCollection.Where(x => x.GroupName == def.Name);
                _deviceDefsDic.Add(def.Name, deviceDefs);
            }
        }
        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);
        }
Пример #4
0
        public static DeviceGroupDef AddGroup(this DeviceGroupDef group, DeviceGroupDef childGroup)
        {
            group.GroupDefCollection.Add(childGroup);
//            childGroup.ParentName = group.Name;
            return(group);
        }
Пример #5
0
 public static IList <DeviceGroupDef> TraverseFromTopLeft(this DeviceGroupDef group)
 {
     return(group.TraverseFromTopLeft(x => x.GroupDefCollection).ToList());
 }
Пример #6
0
 public static DeviceGroupDef AddAndGetGroup(this DeviceGroupDef group, DeviceGroupDef childGroup)
 {
     return(group.AddGroup(childGroup).GetGroup(childGroup.Name));
 }
Пример #7
0
 public static DeviceGroupDef GetGroup(this DeviceGroupDef group, string childGroupName)
 {
     return(group.GroupDefCollection.SingleOrDefault(gd => gd.Name == childGroupName));
 }