Esempio n. 1
0
 private static void InitUnicomUpload()
 {
     LoadHistoryData();
     _notify = bool.Parse(ConfigurationManager.AppSettings["notify"]);
     if (_dataSource == "web")
     {
         using (var ctx = new UnicomDbContext())
         {
             foreach (var device in ctx.EmsDevices.ToList())
             {
                 if (!device.IsTransfer)
                 {
                     continue;
                 }
                 if (OnTransferDevices.All(d => d != device.Name))
                 {
                     AddMinuteTask(device.Name);
                     OnTransferDevices.Add(device.Name);
                 }
             }
         }
     }
     else
     {
         AddMinuteTask(null);
     }
 }
 private void LoadInfomation(DeviceModel model)
 {
     using (var ctx = new UnicomDbContext())
     {
         model.Projects = ctx.EmsProjects.ToList();
     }
 }
Esempio n. 3
0
        private static bool NeedRandomData(string devId, out EmsAutoDust dust)
        {
            bool need;

            if (_dataSource == "web")
            {
                using (var ctx = new UnicomDbContext())
                {
                    var dev = ctx.EmsDevices.First(d => d.Name == devId);
                    dust = new EmsAutoDust
                    {
                        Id            = 0,
                        DevSystemCode = devId,
                        RangeMaxValue = (long)dev.TpMax,
                        RangeMinValue = (long)dev.TpMin
                    };
                    need = dev.IsHandlerValues;
                }
            }
            else
            {
                var d = _context.AutoDusts.FirstOrDefault(a => a.DevSystemCode == devId);
                dust = d;
                need = d != null;
            }
            return(need);
        }
        public ActionResult AddNewProject(emsProject project, ProjectModel model)
        {
            project.code = model.RegisterCode;
            var result = WebConfig.UniComService.PushProjects(new[] { project });

            if (result.result.Length > 0 && !result.result[0].value.ToString().Contains("ERROR"))
            {
                try
                {
                    model.Code = result.result[0].value.ToString();
                    using (var ctx = new UnicomDbContext())
                    {
                        ctx.EmsProjects.Add(new EmsProject
                        {
                            Code            = model.Code,
                            Name            = model.Name,
                            RegisterCode    = model.RegisterCode,
                            District        = model.District,
                            ProjectType     = model.ProjectType,
                            ProjectCategory = model.ProjectCategory,
                            ProjectPeriod   = model.ProjectPeriod,
                            Region          = model.Region,
                            Street          = model.Street,
                            Longitude       = model.Longitude,
                            Latitude        = model.Latitude,
                            Contractors     = model.Contractors,
                            Superintendent  = model.Superintendent,
                            Telephone       = model.Telephone,
                            Address         = model.Address,
                            SiteArea        = model.SiteArea,
                            BuildingArea    = model.BuildingArea,
                            StartDate       = model.StartDate,
                            EndDate         = model.EndDate,
                            Stage           = model.Stage,
                            IsCompleted     = model.IsCompleted,
                            Status          = model.Status
                        });
                        ctx.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    ModelState.AddModelError("RegisterError", "注册工程信息成功,但保存至服务器时遇到异常,请记录工程信息并提供给管理员手动添加。");
                    LoadInfomation(model);
                    return(View(nameof(Register), model));
                }
                return(View("Success"));
            }

            foreach (var entry in result.result)
            {
                ModelState.AddModelError("RegisterError", entry.value.ToString());
            }
            LoadInfomation(model);
            return(View(nameof(Register), model));
        }
Esempio n. 5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var ctx = new UnicomDbContext())
            {
                if (!ctx.EmsDistricts.Any())
                {
                    var server = WebConfig.UniComService;
                    foreach (var emsDistrict in server.PullDistrict(null))
                    {
                        ctx.EmsDistricts.Add(new EmsDistrict
                        {
                            Code = emsDistrict.code,
                            Name = emsDistrict.name
                        });
                    }
                    foreach (var emsPrjType in server.PullProjectType())
                    {
                        ctx.EmsProjectTypes.Add(new EmsProjectType
                        {
                            Code = emsPrjType.code,
                            Name = emsPrjType.name
                        });
                    }
                    foreach (var emsPrjPeriod in server.PullProjectPeriod())
                    {
                        ctx.EmsProjectPeriods.Add(new EmsProjectPeriod
                        {
                            Code = emsPrjPeriod.code,
                            Name = emsPrjPeriod.name
                        });
                    }
                    foreach (var emsPrjCategory in server.PullProjectCategory())
                    {
                        ctx.EmsProjectCategories.Add(new EmsProjectCategory
                        {
                            Code = emsPrjCategory.code,
                            Name = emsPrjCategory.name
                        });
                    }
                    foreach (var emsRegion in server.PullRegion())
                    {
                        ctx.EmsRegions.Add(new EmsRegion
                        {
                            Code = emsRegion.code,
                            Name = emsRegion.name
                        });
                    }
                    ctx.SaveChanges();
                }
            }
        }
        public ActionResult UpdateProject(emsProject project, ProjectModel model)
        {
            project.code = model.Code;
            var result = WebConfig.UniComService.PushProjectStatus(new[] { project });

            if (result.result.Length <= 0)
            {
                try
                {
                    using (var ctx = new UnicomDbContext())
                    {
                        var prj = ctx.EmsProjects.First(p => p.Code == model.Code);
                        prj.Code            = model.Code;
                        prj.Name            = model.Name;
                        prj.RegisterCode    = model.RegisterCode;
                        prj.District        = model.District;
                        prj.ProjectType     = model.ProjectType;
                        prj.ProjectCategory = model.ProjectCategory;
                        prj.ProjectPeriod   = model.ProjectPeriod;
                        prj.Region          = model.Region;
                        prj.Street          = model.Street;
                        prj.Longitude       = model.Longitude;
                        prj.Latitude        = model.Latitude;
                        prj.Contractors     = model.Contractors;
                        prj.Superintendent  = model.Superintendent;
                        prj.Telephone       = model.Telephone;
                        prj.Address         = model.Address;
                        prj.SiteArea        = model.SiteArea;
                        prj.BuildingArea    = model.BuildingArea;
                        prj.StartDate       = model.StartDate;
                        prj.EndDate         = model.EndDate;
                        prj.Stage           = model.Stage;
                        prj.IsCompleted     = model.IsCompleted;
                        prj.Status          = model.Status;
                        ctx.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    ModelState.AddModelError("RegisterError", "更新工程信息成功,但保存至服务器时遇到异常,请记录工程信息并提供给管理员手动添加。");
                    LoadInfomation(model);
                    return(View(nameof(Register), model));
                }
                return(Redirect("/Project/ProjectManager"));
            }

            foreach (var entry in result.result)
            {
                ModelState.AddModelError("RegisterError", entry.value.ToString());
            }
            LoadInfomation(model);
            return(View(nameof(Register), model));
        }
 private void LoadInfomation(ProjectModel model)
 {
     using (var ctx = new UnicomDbContext())
     {
         model.Districts         = ctx.EmsDistricts.ToList();
         model.ProjectCategories = ctx.EmsProjectCategories.ToList();
         model.ProjectPeriods    = ctx.EmsProjectPeriods.ToList();
         model.ProjectTypes      = ctx.EmsProjectTypes.ToList();
         model.Regions           = ctx.EmsRegions.ToList();
     }
 }
        private ActionResult AddNewDevice(emsDevice emsDevice, DeviceModel model)
        {
            var result = WebConfig.UniComService.PushDevices(new[] { emsDevice });

            if (result.result.Length > 0 && !result.result[0].value.ToString().Contains("ERROR"))
            {
                try
                {
                    model.Code = result.result[0].key.ToString();
                    using (var ctx = new UnicomDbContext())
                    {
                        ctx.EmsDevices.Add(new EmsDevice
                        {
                            Code            = model.Code,
                            Name            = model.Name,
                            UnicomName      = model.UnicomName,
                            IpAddr          = model.IpAddr,
                            MacAddr         = model.MacAddr,
                            Port            = model.Port,
                            Version         = model.Version,
                            ProjectCode     = model.ProjectCode,
                            Longitude       = model.Longitude,
                            Latitude        = model.Latitude,
                            StartDate       = model.StartDate,
                            EndDate         = model.EndDate,
                            InstallDate     = model.InstallDate,
                            OnlineStatus    = model.OnlineStatus,
                            VideoUrl        = model.VideoUrl,
                            IsTransfer      = model.IsTransfer,
                            IsHandlerValues = model.IsHandlerValues,
                            TpMax           = model.TpMax,
                            TpMin           = model.TpMin
                        });
                        ctx.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("RegisterError", "注册设备信息成功,但保存至服务器时遇到异常,请记录工程信息并提供给管理员手动添加。");
                    LoadInfomation(model);
                    return(View(model));
                }
                return(View("Success"));
            }

            foreach (var entry in result.result)
            {
                ModelState.AddModelError("RegisterError", entry.value.ToString());
            }
            LoadInfomation(model);
            return(View(model));
        }
Esempio n. 9
0
        private static DeviceInfomation LoadDevInfo(object taskState)
        {
            DeviceInfomation info;
            var devCode = taskState.ToString();

            if (SystemDevs.ContainsKey(devCode))
            {
                info = SystemDevs[devCode];
                return(info);
            }
            if (_dataSource == "web")
            {
                using (var ctx = new UnicomDbContext())
                {
                    var mtweDev = ctx.EmsDevices.FirstOrDefault(d => d.Name == devCode);
                    if (mtweDev != null)
                    {
                        var prj = ctx.EmsProjects.First(p => p.Code == mtweDev.ProjectCode);
                        info = new DeviceInfomation
                        {
                            DevCode       = taskState.ToString(),
                            UnicomDevCode = mtweDev.Code,
                            StatCode      = prj.Name,
                            ProjectType   = prj.ProjectType
                        };
                        SystemDevs.Add(devCode, info);
                        return(info);
                    }
                }
            }
            else
            {
                if (int.TryParse(devCode, out int devId))
                {
                    var dev  = EsMonitorDataProvider.GetDevs(devId);
                    var stat = EsMonitorDataProvider.GetStatss(int.Parse(dev.StatId));
                    info = new DeviceInfomation
                    {
                        DevCode    = taskState.ToString(),
                        StatCode   = stat.StatCode,
                        StatId     = dev.StatId,
                        Country    = stat.Country.ToString(),
                        StatUpCode = stat.StatCodeUp
                    };
                    SystemDevs.Add(devCode, info);
                    return(info);
                }
            }

            return(null);
        }
Esempio n. 10
0
        private static bool DeviceOnTransfer(string systemDeviceCode)
        {
            if (_dataSource == "web")
            {
                using (var ctx = new UnicomDbContext())
                {
                    var webDevice = ctx.EmsDevices.FirstOrDefault(d => d.Name == systemDeviceCode);
                    return(webDevice == null || webDevice.IsTransfer);
                }
            }
            var device = _context.FirstOrDefault <EmsDevice>($"SystemCode = {systemDeviceCode}");

            return(device == null || device.OnTransfer);
        }
Esempio n. 11
0
        private ActionResult UpdateDevice(emsDevice emsDevice, DeviceModel model)
        {
            var result = WebConfig.UniComService.PushDeviceStatus(new[] { emsDevice });

            if (result.result.Length <= 0)
            {
                try
                {
                    using (var ctx = new UnicomDbContext())
                    {
                        var dev = ctx.EmsDevices.First(d => d.Code == model.Code);
                        dev.Code            = model.Code;
                        dev.Name            = model.Name;
                        dev.IpAddr          = model.IpAddr;
                        dev.MacAddr         = model.MacAddr;
                        dev.Port            = model.Port;
                        dev.Version         = model.Version;
                        dev.ProjectCode     = model.ProjectCode;
                        dev.Longitude       = model.Longitude;
                        dev.Latitude        = model.Latitude;
                        dev.StartDate       = model.StartDate;
                        dev.EndDate         = model.EndDate;
                        dev.InstallDate     = model.InstallDate;
                        dev.OnlineStatus    = model.OnlineStatus;
                        dev.VideoUrl        = model.VideoUrl;
                        dev.IsTransfer      = model.IsTransfer;
                        dev.IsHandlerValues = model.IsHandlerValues;
                        dev.TpMax           = model.TpMax;
                        dev.TpMin           = model.TpMin;
                        ctx.SaveChanges();
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("RegisterError", "更新设备信息成功,但保存至服务器时遇到异常,请记录设备信息并提供给管理员手动添加。");
                    LoadInfomation(model);
                    return(View(model));
                }
                return(Redirect("/Device/DeviceManager"));
            }

            foreach (var entry in result.result)
            {
                ModelState.AddModelError("RegisterError", entry.value.ToString());
            }
            LoadInfomation(model);
            return(View(model));
        }
Esempio n. 12
0
 public ActionResult Stop(string code)
 {
     using (var ctx = new UnicomDbContext())
     {
         var dev = ctx.EmsDevices.First(d => d.Code == code);
         try
         {
             dev.IsTransfer = false;
             ctx.SaveChanges();
             return(Json("停止上传成功!", JsonRequestBehavior.AllowGet));
         }
         catch (Exception)
         {
             return(Json("停止上传操作失败!", JsonRequestBehavior.AllowGet));
         }
     }
 }
        public ActionResult Register(string code)
        {
            ProjectModel model;

            if (string.IsNullOrWhiteSpace(code))
            {
                model = new ProjectModel();
            }
            else
            {
                using (var ctx = new UnicomDbContext())
                {
                    var prj = ctx.EmsProjects.First(d => d.Code == code);
                    model = new ProjectModel
                    {
                        Code            = prj.Code,
                        Name            = prj.Name,
                        RegisterCode    = prj.RegisterCode,
                        District        = prj.District,
                        ProjectType     = prj.ProjectType,
                        ProjectCategory = prj.ProjectCategory,
                        ProjectPeriod   = prj.ProjectPeriod,
                        Longitude       = prj.Longitude,
                        Latitude        = prj.Latitude,
                        StartDate       = prj.StartDate,
                        EndDate         = prj.EndDate,
                        Region          = prj.Region,
                        Street          = prj.Street,
                        Contractors     = prj.Contractors,
                        Superintendent  = prj.Superintendent,
                        Telephone       = prj.Telephone,
                        Address         = prj.Address,
                        SiteArea        = prj.SiteArea,
                        BuildingArea    = prj.BuildingArea,
                        Stage           = prj.Stage,
                        IsCompleted     = prj.IsCompleted,
                        Status          = prj.Status
                    };
                }
            }
            LoadInfomation(model);
            return(View(model));
        }
Esempio n. 14
0
        public ActionResult UnicomProjectTable(BootstraptablePost post)
        {
            var ctx   = new UnicomDbContext();
            var total = ctx.EmsProjects.Count();
            var rows  = ctx.EmsProjects.OrderBy(p => p.Code).Skip(post.offset).Take(post.limit)
                        .Select(prj => new
            {
                prj.Code,
                prj.RegisterCode,
                prj.Name,
                prj.Telephone,
                prj.Superintendent
            }).ToList();

            return(Json(new
            {
                total,
                rows
            }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 15
0
 public ActionResult UnicomDeviceTable(BootstraptablePost post)
 {
     using (var ctx = new UnicomDbContext())
     {
         var total = ctx.EmsDevices.Count();
         var rows  = ctx.EmsDevices.OrderBy(d => d.Code).Skip(post.offset).Take(post.limit)
                     .Select(dev => new
         {
             dev.Code,
             dev.Name,
             dev.Version,
             dev.ProjectCode,
             dev.IsTransfer
         }).ToList();
         return(Json(new
         {
             total,
             rows
         }, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 16
0
        public ActionResult Register(string code)
        {
            DeviceModel model;

            if (string.IsNullOrWhiteSpace(code))
            {
                model = new DeviceModel();
            }
            else
            {
                using (var ctx = new UnicomDbContext())
                {
                    var dev = ctx.EmsDevices.First(d => d.Code == code);
                    model = new DeviceModel
                    {
                        Code         = dev.Code,
                        Name         = dev.Name,
                        UnicomName   = dev.UnicomName,
                        IpAddr       = dev.IpAddr,
                        MacAddr      = dev.MacAddr,
                        Port         = dev.Port,
                        Version      = dev.Version,
                        ProjectCode  = dev.ProjectCode,
                        Longitude    = dev.Longitude,
                        Latitude     = dev.Latitude,
                        StartDate    = dev.StartDate,
                        EndDate      = dev.EndDate,
                        InstallDate  = dev.InstallDate,
                        OnlineStatus = dev.OnlineStatus,
                        VideoUrl     = dev.VideoUrl,
                        IsTransfer   = dev.IsTransfer
                    };
                }
            }
            LoadInfomation(model);
            return(View(model));
        }
Esempio n. 17
0
 private static void RefreashTransfer()
 {
     if (_dataSource == "web")
     {
         using (var ctx = new UnicomDbContext())
         {
             foreach (var device in ctx.EmsDevices.ToList())
             {
                 if (!device.IsTransfer)
                 {
                     if (OnTransferDevices.Any(d => d == device.Name))
                     {
                         OnTransferDevices.Remove(device.Name);
                     }
                     continue;
                 }
                 OnTransferDevices.Add(device.Name);
             }
         }
     }
     else
     {
         foreach (var device in _context.Devices)
         {
             if (!device.OnTransfer)
             {
                 if (OnTransferDevices.Any(d => d == device.SystemCode))
                 {
                     OnTransferDevices.Remove(device.SystemCode);
                 }
                 continue;
             }
             OnTransferDevices.Add(device.SystemCode);
         }
     }
 }
Esempio n. 18
0
        public ActionResult Index()
        {
            var projects = new UnicomDbContext().EmsProjects.ToList();

            return(View(projects));
        }