Example #1
0
        public void Update(MapPair pair)
        {
            UrlAddressParser inParser = pair.In;

            if (inParser.IsIp)
            {
                throw new Exception("输入地址不能为IP");
            }
            var p = maplist.FirstOrDefault(o => o.Id == pair.Id);

            p.In          = pair.In;
            p.Out         = pair.Out;
            p.Enabled     = pair.Enabled;
            p.UserSetting = pair.UserSetting;
            Save();
        }
Example #2
0
        /// <summary>
        /// 新增一组映射
        /// </summary>
        /// <param name="in"></param>
        /// <param name="out">全局唯一的</param>
        public async Task <bool> Add(string @in, string @out)
        {
            UrlAddressParser inParser  = @in;
            UrlAddressParser outParser = @out;


            if (inParser.IsIp)
            {
                throw new Exception("输入地址不能为IP");
            }

            if (maplist.Where(a => a.In == inParser.Url).Count() > 0)
            {
                var confirm = await jsruntime.InvokeAsync <bool>("confirm", new object[] {
                    "已存在相同的输入地址,是否禁用旧的映射?"
                });

                if (confirm)
                {
                    maplist.Where(a => a.In == inParser.Url && a.Enabled).First().Enabled = false;
                }
                else
                {
                    throw new Exception("已存在相同的输入地址");
                }
            }


            var pair = new MapPair()
            {
                In      = inParser.Url,
                Out     = outParser.Url,
                Id      = Guid.NewGuid().ToString(),
                Enabled = true,
            };

            maplist.Add(pair);

            Save();

            return(true);
        }