コード例 #1
0
        private void InitAddr(ServiceEntity model)
        {
            var cfg = JsonConvert.DeserializeObject <ServiceCfg>(model.RegContent);

            ViewBag.InList  = cfg.InAddr;
            ViewBag.OutList = cfg.OutAddr;
        }
コード例 #2
0
        public ActionResult Edit(ServiceEntity collection)
        {
            var rm = new ReturnMessage(false);

            try
            {
                var model = BusinessContext.ServiceList.GetModel(Convert.ToInt32(Request["_id"]));
                model.ServiceName   = collection.ServiceName;
                model.SecondaryName = collection.SecondaryName;
                model.Host          = collection.Host;
                model.Version       = collection.Version;
                model.Remark        = collection.Remark;
                SetRegContent(model);
                model.ModifyOn = DateTime.Now;
                model.ModifyBy = CurrentHelper.CurrentUser.User.UserName;
                rm.IsSuccess   = BusinessContext.ServiceList.Update(model);
            }
            catch (Exception ex)
            {
                rm.Message = "数据异常,请刷新重试";
                LogManager.Error(ex);
            }

            return(Json(rm, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult Create(ServiceEntity collection, int?type, string isContinue = "1")
        {
            var rm = new ReturnMessage(false);

            try
            {
                if (string.IsNullOrWhiteSpace(collection.ServiceName))
                {
                    rm.Message = "服务名称不能为空";
                    return(Json(rm));
                }

                if (string.IsNullOrWhiteSpace(collection.Host))
                {
                    rm.Message = "部署机器不能为空";
                    return(Json(rm));
                }
                if (string.IsNullOrWhiteSpace(collection.Version))
                {
                    rm.Message = "版本号不能为空";
                    return(Json(rm));
                }

                if (string.IsNullOrWhiteSpace(collection.SecondaryName))
                {
                    rm.Message = "二级服务名称不能为空";
                    return(Json(rm));
                }

                if (BusinessContext.ServiceList.Exists(collection.ServiceName, collection.SecondaryName))
                {
                    rm.Message = "服务已存在";
                    return(Json(rm));
                }
                SetRegContent(collection);
                if (type.HasValue)
                {
                    collection.ServiceType = (ServiceTypeEnum)type.Value;
                }
                collection.CreateOn = DateTime.Now;
                collection.CreateBy = CurrentHelper.CurrentUser.User.UserName;
                rm.IsSuccess        = BusinessContext.ServiceList.Add(collection);
                rm.IsContinue       = isContinue == "1";
            }
            catch (Exception ex)
            {
                LogManager.Error(ex);
            }
            return(Json(rm));
        }
コード例 #4
0
        public bool Update(ServiceEntity model)
        {
            var service =
                DBContext.Mongo.GetMongoDB(DBContext.DbName, true)
                .GetCollection("GroupName")
                .FindAs <GroupName>(Query <GroupName> .EQ(t => t.ServiceName, model.ServiceName))
                .ToList();

            if (service.Any())
            {
                model.PrimaryId = service.First()._id;
            }
            return(DBContext.Mongo.Upsert(DBContext.DbName, Col, model));
        }
コード例 #5
0
        private void SetRegContent(ServiceEntity model)
        {
            var inList   = new List <string>();
            var outList  = new List <string>();
            var inPorts  = new List <string>();
            var outPorts = new List <string>();
            var inStr    = Request["inAddr"];

            if (!string.IsNullOrWhiteSpace(inStr))
            {
                inList = inStr.Split(',').ToList();
            }
            var outStr = Request["outAddr"];

            if (!string.IsNullOrWhiteSpace(outStr))
            {
                outList = outStr.Split(',').ToList();
            }
            var inPortStr = Request["inPort"];

            if (!string.IsNullOrWhiteSpace(inStr))
            {
                inPorts = inPortStr.Split(',').ToList();
            }
            var outPortStr = Request["outPort"];

            if (!string.IsNullOrWhiteSpace(inStr))
            {
                outPorts = outPortStr.Split(',').ToList();
            }
            var cfg = new ServiceCfg
            {
                InAddr  = inList.Zip(inPorts, (t, p) => !string.IsNullOrEmpty(p) ? t + ":" + p : t).ToList(),
                OutAddr = outList.Zip(outPorts, (t, p) => !string.IsNullOrEmpty(p) ? t + ":" + p : t).ToList(),
                Remarks = model.Remark
            };

            model.RegContent = JsonConvert.SerializeObject(cfg);
        }
コード例 #6
0
        public bool Add(ServiceEntity model)
        {
            model._id = Convert.ToInt32(DBContext.Mongo.GetScalar(DBContext.DbName, Col)) + 1;

            var service =
                DBContext.Mongo.GetMongoDB(DBContext.DbName, true)
                .GetCollection("GroupName")
                .FindAs <GroupName>(Query <GroupName> .EQ(t => t.ServiceName, model.ServiceName))
                .ToList();

            if (service.Any())
            {
                model.PrimaryId = service.First()._id;
            }

            var cursor = DBContext.Mongo.GetMongoDB(DBContext.DbName, true).GetCollection(Col).FindAllAs <ServiceEntity>();

            cursor.SetSortOrder(SortBy.Descending("SecondaryId"));
            var first = cursor.FirstOrDefault();

            model.SecondaryId = first != null ? first.SecondaryId + 1 : 1;

            return(DBContext.Mongo.Insert(DBContext.DbName, Col, model));
        }
コード例 #7
0
 public bool Add(ServiceEntity model)
 {
     return(_dal.Add(model));
 }
コード例 #8
0
 public bool Update(ServiceEntity model)
 {
     return(_dal.Update(model));
 }