Beispiel #1
0
        /// <summary>
        /// 区域属性,所有参数均为0或1值
        /// </summary>
        /// <returns></returns>
        public UInt16 AreaAttribute(AreaAttribute info)
        {
            UInt16 attr = 0;

            attr |= info.accordingTime;
            attr |= (UInt16)(info.limitSpeed << 1);
            attr |= (UInt16)(info.inareaUpDriver << 2);
            attr |= (UInt16)(info.inareaUpPltf << 3);
            attr |= (UInt16)(info.outareaUpDriver << 4);
            attr |= (UInt16)(info.outareaUpPltf << 5);
            attr |= (UInt16)(info.latflag << 6);
            attr |= (UInt16)(info.lngflag << 7);
            attr |= (UInt16)(info.openflag << 8);
            attr |= (UInt16)(info.communicationflag << 14);
            attr |= (UInt16)(info.samplingflag << 15);
            return(attr);
        }
        /// <summary>
        /// 从类型中获取功能的区域信息
        /// </summary>
        private static string GetArea(Type type)
        {
            AreaAttribute attribute = type.GetAttribute <AreaAttribute>(true);

            return(attribute?.RouteValue);
        }
        /// <summary>
        /// 重写以实现从类型中获取功能的区域信息
        /// </summary>
        protected override string GetArea(Type type)
        {
            AreaAttribute attribute = type.GetAttribute <AreaAttribute>(true);

            return(attribute?.RouteValue);
        }
        /// <summary>
        /// 重写以实现从类型中提取模块信息
        /// </summary>
        /// <param name="type">类型信息</param>
        /// <param name="existPaths">已存在的路径集合</param>
        /// <returns>提取到的模块信息</returns>
        protected override ModuleInfo[] GetModules(Type type, string[] existPaths)
        {
            ModuleInfoAttribute infoAttr = type.GetAttribute <ModuleInfoAttribute>();

            if (infoAttr == null)
            {
                return(new ModuleInfo[0]);
            }
            ModuleInfo info = new ModuleInfo()
            {
                Name         = infoAttr.Name ?? GetName(type),
                Code         = infoAttr.Code ?? type.Name.Replace("Controller", ""),
                Order        = infoAttr.Order,
                Position     = GetPosition(type, infoAttr.Position),
                PositionName = infoAttr.PositionName
            };
            List <ModuleInfo> infos = new List <ModuleInfo>()
            {
                info
            };

            //获取中间分类模块
            if (infoAttr.Position != null)
            {
                info = new ModuleInfo()
                {
                    Name     = infoAttr.PositionName ?? infoAttr.Position,
                    Code     = infoAttr.Position,
                    Position = GetPosition(type, null)
                };
                if (!existPaths.Contains($"{info.Position}.{info.Code}"))
                {
                    infos.Insert(0, info);
                }
            }
            //获取区域模块
            string            area, name;
            AreaInfoAttribute areaInfo = type.GetAttribute <AreaInfoAttribute>();

            if (areaInfo != null)
            {
                area = areaInfo.RouteValue;
                name = areaInfo.Display ?? area;
            }
            else
            {
                AreaAttribute areaAttr = type.GetAttribute <AreaAttribute>();
                area = areaAttr?.RouteValue ?? "Site";
                name = area == "Site" ? "站点" : area;
            }
            info = new ModuleInfo()
            {
                Name         = name,
                Code         = area,
                Position     = "Root",
                PositionName = name
            };
            if (!existPaths.Contains($"{info.Position}.{info.Code}"))
            {
                infos.Insert(0, info);
            }

            return(infos.ToArray());
        }
Beispiel #5
0
        /// <summary>
        /// 从类型中获取功能的区域信息
        /// </summary>
        private static string GetArea(MemberInfo type)
        {
            AreaAttribute attribute = type.GetAttribute <AreaAttribute>();

            return(attribute?.RouteValue);
        }
Beispiel #6
0
        public async Task Run()
        {
            // load boundaries.
            var boundaries = this.LoadBoundaries();

            // load areas and index them by id.
            var map   = new Dictionary <long, Area>();
            var areas = _dbContext.Areas
                        .Include(x => x.AreaAttributes);

            foreach (var area in areas)
            {
                var idAttributes = area.AreaAttributes.FirstOrDefault(x => x.Key == "id");
                if (idAttributes == null)
                {
                    continue;
                }
                if (!long.TryParse(idAttributes.Value, out var id))
                {
                    continue;
                }

                map[id] = area;
                boundaries.Remove(id);
            }

            // add all to db.
            var postGisWriter = new PostGisWriter();

            while (boundaries.Count > 0)
            {
                // get boundaries with all parents done.
                var queue = new Queue <long>();
                foreach (var(key, (_, parent)) in boundaries)
                {
                    if (map.ContainsKey(key))
                    {
                        continue;
                    }
                    if (parent != -1 && !map.ContainsKey(parent))
                    {
                        continue;
                    }

                    queue.Enqueue(key);
                }

                // no more items left.
                if (queue.Count == 0)
                {
                    break;
                }

                // convert to areas.
                while (queue.Count > 0)
                {
                    var next      = queue.Dequeue();
                    var nextValue = boundaries[next];
                    boundaries.Remove(next);

                    // get parent area.
                    if (nextValue.parent == -1 ||
                        !map.TryGetValue(nextValue.parent, out var parentArea))
                    {
                        parentArea = null;
                    }

                    // create area and attributes.
                    var geometry = postGisWriter.Write(nextValue.feature.Geometry);
                    var area     = new Area()
                    {
                        Geometry     = geometry,
                        ParentAreaId = parentArea?.AreaId
                    };
                    await _dbContext.Areas.AddAsync(area);

                    await _dbContext.SaveChangesAsync();

                    map[next] = area;

                    foreach (var name in nextValue.feature.Attributes.GetNames())
                    {
                        if (string.IsNullOrWhiteSpace(name))
                        {
                            continue;
                        }
                        if (name == "parents")
                        {
                            continue;
                        }

                        var value = nextValue.feature.Attributes[name];
                        if (!(value is string valueString))
                        {
                            if (value is long l)
                            {
                                valueString = l.ToString();
                            }
                            else
                            {
                                continue;
                            }
                        }

                        var areaAttribute = new AreaAttribute()
                        {
                            Key    = name,
                            AreaId = area.AreaId,
                            Value  = valueString
                        };
                        await _dbContext.AreaAttributes.AddAsync(areaAttribute);
                    }
                    await _dbContext.SaveChangesAsync();
                }
            }
        }
Beispiel #7
0
    /// <summary>
    /// Configure the attributes and upgrades each worker will have.
    /// </summary>
    protected virtual void Configure()
    {
        AreaAttributes = new List <AreaAttribute <decimal> >();

        MovementSpeed = new AreaAttribute <decimal>
        {
            DisplayName        = MovementDisplay,
            Value              = MovementStart,
            StringFormatMethod = StringFormatter.GetMovementString,
            UpgradeMethod      = (x) => { return(x * MovementUpgrade); }
        };

        CollectionSpeed = new AreaAttribute <decimal>
        {
            DisplayName        = CollectionDisplay,
            Value              = CollectionStart,
            StringFormatMethod = StringFormatter.GetCurrencyPerSecondString,
            UpgradeMethod      = (x) => { return(x * CollectionUpgrade); }
        };

        CarryCapacity = new AreaAttribute <decimal>
        {
            DisplayName        = CapacityDisplay,
            Value              = CapacityStart,
            StringFormatMethod = StringFormatter.GetCapacityString,
            UpgradeMethod      = (x) => { return(x * CapacityUpgrade); }
        };

        Workers = new AreaAttribute <int>
        {
            DisplayName        = WorkerDisplay,
            Value              = workerStart,
            StringFormatMethod = StringFormatter.GetWorkersString,
            UpgradeMethod      = (x) => {
                if (ExtraWorkerUpgradeLevel > 0 && CanAddWorkers && x < MaxWorkers)
                {
                    // Every X (ExtraWorkerUpgradeLevel) upgrades add 1 worker
                    return((AreaLevel % ExtraWorkerUpgradeLevel == 0) ? 1 : 0);
                }
                else
                {
                    return(0);
                }
            }
        };

        UpgradeCostMethod = () =>
        {
            return(CurrentUpgradeCost * AreaUpgrade);
        };

        CurrentUpgradeCost = AreaUpgradeStart;


        AreaAttributes.Add(MovementSpeed);
        AreaAttributes.Add(CollectionSpeed);
        AreaAttributes.Add(CarryCapacity);


        // Cycle though and upgrade area if start level is GREATER than 1.
        if (AreaStartLevel > 1)
        {
            for (int i = 0; i < AreaStartLevel - 1; i++)
            {
                UpgradeArea();
            }
        }
    }