Example #1
0
 /// <summary>
 /// 获取组件信息
 /// </summary>
 /// <param name="componentId"></param>
 /// <returns></returns>
 public static SmartWeb.Models.Component GetComponentById(string componentId)
 {
     using (var context = new MyContext())
     {
         SmartWeb.Models.Component component = context.Component.FirstOrDefault(c => c.Cid == componentId);
         return(component);
     }
 }
Example #2
0
 /// <summary>
 /// 新增组件
 /// </summary>
 /// <param name="cid"></param>
 /// <param name="shipId"></param>
 /// <returns></returns>
 public static int ComponentAdd(string cid)
 {
     using (var context = new MyContext())
     {
         var component = context.Component.FirstOrDefault(c => c.Id == ManagerHelp.ComponentId);
         if (component != null)
         {
             if (string.IsNullOrEmpty(component.Cid))
             {
                 component.Cid = cid;
                 context.Update(component);
                 context.SaveChanges();
             }
         }
         else
         {
             string shipId = "";
             if (ManagerHelp.IsShipPort)
             {
                 var ship = context.Ship.FirstOrDefault();
                 shipId = ship != null ? ship.Id : "";
             }
             component = new SmartWeb.Models.Component()
             {
                 Cid    = cid,
                 Id     = ManagerHelp.ComponentId,
                 Line   = 0,
                 Name   = "WEB",
                 Type   = ComponentType.WEB,
                 ShipId = shipId
             };
             context.Add(component);
             context.SaveChanges();
         }
         ManagerHelp.Cid = cid;
     }
     return(0);
 }
Example #3
0
        /// <summary>
        /// 陆地端修改组件信息
        /// </summary>
        /// <param name="components"></param>
        public static void ComponentUpdateRange(List <ComponentInfo> components)
        {
            if (components != null)
            {
                using (var context = new MyContext())
                {
                    var list = context.Component.Where(c => c.Type != ComponentType.WEB).ToList();
                    //保存已在数据库在存在的组件ID
                    List <string> str = new List <string>();
                    //List<SmartWeb.Models.Component> comList = new List<SmartWeb.Models.Component>();

                    //判断流媒体是否启动
                    bool isMed = false;
                    if (components.Where(c => c.type.Equals(ComponentInfo.Type.MED)).Any())
                    {
                        isMed = true;
                    }
                    foreach (var item in components)
                    {
                        if (item.componentid == ManagerHelp.ComponentId)
                        {
                            continue;
                        }
                        if (item.type == ComponentInfo.Type.WEB)
                        {
                            continue;
                        }
                        if (list.Where(c => c.Cid == item.componentid).Any())
                        {
                            #region 组件上线
                            var component = list.FirstOrDefault(c => c.Cid == item.componentid);
                            if (component.Line == 1)
                            {
                                component.Line = 0;
                                context.Component.Update(component);
                                context.SaveChanges();
                                if (isMed)
                                {
                                    SendInitData(item);
                                }
                            }
                            str.Add(item.componentid);
                            #endregion
                        }
                        //陆地端添加组件
                        else if (item.type == ComponentInfo.Type.XMQ)
                        {
                            #region 陆地端添加组件
                            string shipId = Guid.NewGuid().ToString();
                            Random rn     = new Random();
                            rn.Next(1, 9999);
                            Ship ship = new Ship()
                            {
                                Coordinate = "",
                                CrewNum    = 0,
                                Flag       = false,
                                Id         = shipId,
                                Name       = string.IsNullOrEmpty(item.cname) ? "船" + rn : item.cname,
                                type       = Ship.Type.AUTO
                            };
                            context.Ship.Add(ship);
                            SmartWeb.Models.Component component = new SmartWeb.Models.Component()
                            {
                                Id     = Guid.NewGuid().ToString(),
                                Cid    = item.componentid,
                                Line   = 0,
                                Name   = item.cname,
                                Type   = (ComponentType)item.type,
                                ShipId = shipId
                            };
                            context.Component.Add(component);
                            context.SaveChanges();
                            #endregion
                        }
                        else if (ManagerHelp.IsShipPort)
                        {
                            #region 船舶端添加组件
                            SmartWeb.Models.Component component = new SmartWeb.Models.Component()
                            {
                                Id     = Guid.NewGuid().ToString(),
                                Cid    = item.componentid,
                                Line   = 0,
                                Name   = item.cname,
                                Type   = (ComponentType)item.type,
                                ShipId = ""
                            };
                            context.Component.Add(component);
                            context.SaveChanges();
                            if (isMed)
                            {
                                SendInitData(item);
                            }
                            #endregion
                        }
                    }
                    if (list.Count != str.Count)
                    {
                        //组件下线
                        ComponentOnline(components, list, str);
                    }
                }
            }
        }