Ejemplo n.º 1
0
#pragma warning restore xUnit1010 // The value is not convertible to the method parameter type
        public void RotateLeftCommand_ValidPlateauValidRoverAndValidInstructions_ShouldBeEqualGivenResult(int width, int height, int xPosition, int yPosition, Directions direction, Directions result)
        {
            _plateauService = new PlateauService();
            _roverService   = new RoverService(_explorationFactoryMock);

            BaseModels <PlateauModel> basePlateauModel = _plateauService.Create(width, height);

            basePlateauModel.Data.Width.Should().Equals(width);
            basePlateauModel.Data.Height.Should().Equals(height);

            RoverLocationModel roverLocation = new RoverLocationModel()
            {
                Direction = direction,
                XPosition = xPosition,
                YPosition = yPosition
            };

            BaseModels <RoverModel> baseRoverModel = _roverService.Initalize(basePlateauModel.Data, roverLocation);

            _explorationCommandMock = new RotateLeftCommand();

            _explorationCommandMock.Explore(_roverService.GetCurrentRover().Data.Location);

            _roverService.GetCurrentRover().Data.Location.Direction.Should().Be(result);
            Console.WriteLine(result);
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public ActionResult SavePartFunc(int id, string funcIds)
        {
            if (string.IsNullOrEmpty(funcIds))
            {
                return(Json(BaseModels.Error("成功!")));
            }

            SysPartFuncBll bll = new SysPartFuncBll();

            List <SYS_PART_FUNC> allPF = bll.Query(t => t.PF_PART_ID == id).ToList();

            foreach (var pf in allPF)
            {
                bll.Delete(pf);
            }
            //bll.SaverChanges();

            string[] ids = funcIds.Split(',');
            foreach (var item in ids)
            {
                SYS_PART_FUNC model = new SYS_PART_FUNC();

                model.PF_PART_ID = id;
                model.PF_FN_ID   = item.ToInt();

                bll.Add(model, false);
            }
            bll.SaverChanges();

            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 3
0
        public void EditUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            string token = Request("token");

            string loginName = Request("loginName");
            string password  = Request("password");
            string mobile    = Request("mobile");
            string province  = Request("province");

            if (string.IsNullOrEmpty(token))
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("登录已失效!")));
                return;
            }

            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("账号和密码不能为空!")));
                return;
            }

            context.Response.Write(js.Serialize(BaseModels.OK("修改成功!")));
            return;
        }
Ejemplo n.º 4
0
        public ActionResult AdminPwd()
        {
            UrUsersBll bll  = new UrUsersBll();
            UR_USERS   user = BaseModels.CurrentUser();

            return(View(user));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="context"></param>
        public void ListUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            int pageCount = string.IsNullOrEmpty(Request("pageCount")) ? 10 : Request("pageCount").ToInt();
            int pageIndex = string.IsNullOrEmpty(Request("pageIndex")) ? 1 : Request("pageIndex").ToInt();
            int total     = 0;

            string loginName = Request("loginName");

            List <Hashtable> ret = new List <Hashtable>();

            for (int i = 0; i < 10; i++)
            {
                Hashtable ht = new Hashtable();
                ht["id"]        = (pageIndex - 1) * pageCount + i + 1;
                ht["loginName"] = string.IsNullOrEmpty(loginName) ? "张三" : loginName;
                ht["password"]  = "******";
                ht["mobile"]    = "15888888888";
                ht["province"]  = "杭州";
                ret.Add(ht);
            }

            Pager pager = new Pager();

            pager.total     = 88;
            pager.pageCount = pageCount;
            pager.pageIndex = pageIndex;
            context.Response.Write(js.Serialize(BaseModels.OK("查询成功!", ret, pager)));
            return;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public void AddUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";

            string loginName = Request("loginName");
            string password  = Request("password");
            string mobile    = Request("mobile");
            string province  = Request("province");


            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("账号和密码不能为空!")));
                return;
            }

            BLL.TtUsersBll bll  = new BLL.TtUsersBll();
            Model.TT_User  user = new Model.TT_User();

            user.LoginName = loginName;
            user.Password  = password;
            user.Mobile    = mobile;
            user.Province  = province;

            bll.Add(user);

            context.Response.Write(js.Serialize(BaseModels.OK("添加成功!")));
            return;
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public void GetUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";
            string token = Request("token");

            string id = Request("id");


            if (string.IsNullOrEmpty(token))
            {
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("登录已失效!")));
                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("编码不能为空!")));
                return;
            }

            Hashtable ht = new Hashtable();

            ht["Id"]        = id;
            ht["loginName"] = "张双";
            ht["password"]  = "******";
            ht["mobile"]    = "15888888888";
            ht["province"]  = "杭州";

            context.Response.Write(js.Serialize(BaseModels.OK("查询成功!", ht)));
            return;
        }
Ejemplo n.º 8
0
        public override void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            HttpRequest request = context.Request;

            string act = Request("act").ToLower();

            switch (act.ToLower())
            {
            case "login":
                LoginSystem(context);
                break;

            case "add":
                AddUser(context);
                break;

            case "list":
                ListUser(context);
                break;

            default:
                context.Response.Write(js.Serialize(BaseModels.ErrorLogin("未指定具体接口!")));
                return;
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            ServiceProvider serviceProvider = new ServiceCollection()
                                              .AddSingleton <IExplorationFactory, ExplorationFactory>()
                                              .AddSingleton <IExplorationCommand, RotateRightCommand>()
                                              .AddSingleton <IExplorationCommand, RotateLeftCommand>()
                                              .AddSingleton <IExplorationCommand, MoveForwardCommand>()
                                              .AddSingleton <IPlateauService, PlateauService>()
                                              .AddSingleton <IRoverService, RoverService>()
                                              .AddSingleton <IInstructionService, InstructionService>()
                                              .BuildServiceProvider();


            IPlateauService     plateauService     = serviceProvider.GetService <IPlateauService>();
            IRoverService       roverService       = serviceProvider.GetService <IRoverService>();
            IInstructionService instructionService = serviceProvider.GetService <IInstructionService>();

            List <RoverModel> rovers = new List <RoverModel>();

            BaseModels <PlateauModel> basePlateauModel = plateauService.Create(5, 5);

            Console.WriteLine("5 5");
            RoverLocationModel firstRoverLocation = new RoverLocationModel()
            {
                XPosition = 1,
                YPosition = 2,
                Direction = Directions.North
            };

            Console.WriteLine("1 2 N");
            BaseModels <RoverModel> baseRoverModel = roverService.Initalize(basePlateauModel.Data, firstRoverLocation);

            rovers.Add(baseRoverModel.Data);
            Console.WriteLine("LMLMLMLMM");
            BaseModels <List <Instruction> > baseInstructionModel = instructionService.GetInstructions("LMLMLMLMM");

            foreach (Instruction instruction in baseInstructionModel.Data)
            {
                roverService.ExplorePlateau(instruction);
            }
            Console.WriteLine("3 3 E");
            RoverLocationModel secondRoverLocation = new RoverLocationModel()
            {
                XPosition = 3,
                YPosition = 3,
                Direction = Directions.East
            };

            baseRoverModel = roverService.Initalize(basePlateauModel.Data, secondRoverLocation);
            rovers.Add(baseRoverModel.Data);
            Console.WriteLine("MMRMMRMRRM");
            baseInstructionModel = instructionService.GetInstructions("MMRMMRMRRM");

            foreach (Instruction instruction in baseInstructionModel.Data)
            {
                roverService.ExplorePlateau(instruction);
            }
            Console.ReadLine();
        }
Ejemplo n.º 10
0
 protected virtual void AddControlRxModel <T>(T rxMoel, string id)
     where T : class, IRelease
 {
     if (!BaseModels.ContainsKey(id))
     {
         BaseModels.Add(id, rxMoel);
     }
 }
Ejemplo n.º 11
0
        public void GetInstructions_IsNotNullAndValidInstruction_ShouldReturnInstructionList_CountShouldEqualWithInstructionLength(string instruction)
        {
            _instructionService = new InstructionService();

            BaseModels <List <Instruction> > baseInstructionModel = _instructionService.GetInstructions(instruction);

            baseInstructionModel.Data.Count.Should().Equals(instruction.Length);
        }
        private void ReadXMLData()
        {
            try
            {
                var root = XElement.Load("DEVS_Structure.xml");

                foreach (XElement node in root.Elements())
                {
                    if (node.Name == "OutmostModel")
                    {
                        Console.WriteLine("[NOTICE]---- OutmostModel called");
                        OutmostModel = new Module(node.Attribute("name").Value);
                        ParsingXML(node.Elements(), ref OutmostModel, 0);
                    }
                    else if (node.Name == "ModelPool")
                    {
                        Console.WriteLine("[NOTICE]---- ModelPool called");
                        ParsingXML(node.Elements(), 0);
                    }
                    else
                    {
                        Console.WriteLine("[WARNING]---- should not be called");
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("[WARNING]----" + ex.ToString());
            }
            Console.WriteLine("[NOTICE]---- successfully load XML file");

            try
            {
                var root = XElement.Load("DEVS_ModelBase.xml");

                foreach (XElement node in root.Elements())
                {
                    if (node.Name == "BaseModel")
                    {
                        Console.WriteLine("[NOTICE]---- BaseModel called");
                        BaseModel temp_baseModel = new BaseModel(node.Attribute("name").Value, node.Attribute("type").Value);
                        ParsingBaseModelXML(node.Elements(), ref temp_baseModel, 0);

                        // [!@#$] Need to check key existence
                        BaseModels.Add(temp_baseModel.Name, temp_baseModel);
                    }
                    else
                    {
                        Console.WriteLine("[WARNING]---- should not be called");
                    }
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("[WARNING]----" + ex.ToString());
            }
            Console.WriteLine("[NOTICE]---- successfully load XML file");
        }
Ejemplo n.º 13
0
        // GET: Login
        public ActionResult Index()
        {
            if (BaseModels.IsLogin())
            {
                return(Redirect("~/Home/"));
            }

            return(View());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 退出登录,清空cookie
        /// </summary>
        /// <returns></returns>
        public ActionResult Quit()
        {
            HttpCookie cookies = new HttpCookie("UserToken");

            cookies.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(cookies);

            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 15
0
        public T GetControlRxModel <T>(string id)
            where T : class, IRelease
        {
            if (BaseModels.ContainsKey(id))
            {
                return(BaseModels[id] as T);
            }

            return(default(T));
        }
Ejemplo n.º 16
0
        public ActionResult Index()
        {
            if (!BaseModels.IsLogin())
            {
                return(Redirect("~/Login/"));
            }
            UR_USERS user = BaseModels.CurrentUser();

            return(View(user));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// file形式的文件上传
        /// </summary>
        /// <param name="context"></param>
        /// <param name="userid"></param>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        public ReturnData UploadFile(HttpContext context, string timestamp)
        {
            HttpRequest    request = context.Request;
            HttpPostedFile file1   = context.Request.Files["file1"];

            if (file1 == null)
            {
                return(BaseModels.Error("上传文件不存在!"));
            }
            if (file1.ContentLength > 1024 * 1024 * 10)
            {
                return(BaseModels.Error("上传文件不可大于10M!"));
            }

            System.IO.BinaryReader reader = new System.IO.BinaryReader(file1.InputStream);
            string fileclass = "";

            for (int i = 0; i < 2; i++)
            {
                fileclass += reader.ReadByte().ToString();
            }
            if (fileclass != "255216" && fileclass != "13780" && fileclass != "6677" && fileclass != "3780" && fileclass != "8297" && fileclass != "8075")
            {
                return(BaseModels.Error("文件格式不正确!"));
            }
            string ext = ".jpg";

            if (fileclass == "3780")
            {
                ext = ".pdf";
            }
            if (fileclass == "8297")
            {
                ext = ".rar";
            }
            if (fileclass == "8075")
            {
                ext = ".zip";
            }

            string dpath    = "/userfile/trademark/" + DateTime.Now.ToString("yyyyMMdd") + "/";
            string filename = timestamp + ext;

            string msg      = "";
            bool   storeImg = StoreImg(context, file1, dpath, filename, out msg);

            if (storeImg)
            {
                return(BaseModels.OK(msg, new { filename = dpath + filename }));
            }
            else
            {
                return(BaseModels.Error(msg));
            }
        }
Ejemplo n.º 18
0
        public ActionResult KefuDel(int id)
        {
            TtKefuBll bll   = new TtKefuBll();
            TT_Kefu   model = bll.Query(t => t.Id == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 19
0
        public ActionResult TypeDel(int id)
        {
            PdTypeBll bll   = new PdTypeBll();
            PD_TYPE   model = bll.Query(t => t.Id == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> GetBaseModels()
        {
            var baseModels = new BaseModels {
                Dungeons     = _dbContext.Dungeons.ToList(),
                Cpus         = _dbContext.Cpus.ToList(),
                Pools        = _dbContext.Pools.ToList(),
                DefenceItems = _dbContext.DefenceItems.ToList()
            };

            return(Ok(baseModels));
        }
Ejemplo n.º 21
0
        public ActionResult OrganDel(int id)
        {
            SysOrganizationBll bll   = new SysOrganizationBll();
            SYS_ORGANIZATION   model = bll.Query(t => t.ORG_ID == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 22
0
        public ActionResult FuncDel(int id)
        {
            SysFunctionBll bll   = new SysFunctionBll();
            SYS_FUNCTION   model = bll.Query(t => t.FN_ID == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 23
0
        public ActionResult PartDel(int id)
        {
            UrPartBll bll   = new UrPartBll();
            UR_PART   model = bll.Query(t => t.PART_ID == id).FirstOrDefault();

            if (model != null)
            {
                bll.Delete(model, true);
            }
            return(Json(BaseModels.OK("成功!")));
        }
Ejemplo n.º 24
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (!BaseModels.IsLogin())
            {
                if (Method == "json")
                {
                    filterContext.Result = BaseModels.Result.Error("请先登录!");
                    return;
                }
                else
                {
                    filterContext.Result = new RedirectResult("~/Login");
                    return;
                }
            }
            UR_USERS currentAdmin = BaseModels.CurrentUser();

            if (Level > 0)
            {
                //角色
                if (currentAdmin.USER_PART.ToInt() < Level)
                {
                    if (Method == "json")
                    {
                        filterContext.Result = BaseModels.Result.Error("您无权操作!");
                        return;
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult("~/?message=" + filterContext.HttpContext.Server.UrlEncode("您无权操作"));
                        return;
                    }
                }
            }
            if (!string.IsNullOrEmpty(Admins))
            {
                Admins += "sa";
                List <string> adminlist = new List <string>(Admins.Split(','));
                if (!adminlist.Contains(currentAdmin.USER_NAME))
                {
                    if (Method == "json")
                    {
                        filterContext.Result = BaseModels.Result.Error("您无权操作!");
                        return;
                    }
                    else
                    {
                        filterContext.Result = new RedirectResult("~/?message=" + filterContext.HttpContext.Server.UrlEncode("您无权操作"));
                        return;
                    }
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public void ListUser(HttpContext context)
        {
            //context.Response.ContentType = "application/json";

            int pageCount = string.IsNullOrEmpty(Request("pageCount")) ? 10 : Request("pageCount").ToInt();
            int pageIndex = string.IsNullOrEmpty(Request("pageIndex")) ? 1 : Request("pageIndex").ToInt();
            int total     = 0;

            string loginName = Request("loginName");
            string province  = Request("province");


            var predicate = PredicateBuilder.New <Model.TT_User>(true);

            if (!string.IsNullOrEmpty(loginName))
            {
                predicate = predicate.And(t => t.LoginName.Contains(loginName));
            }
            if (!string.IsNullOrEmpty(province))
            {
                predicate = predicate.And(t => t.Province == province);
            }

            BLL.TtUsersBll       bll     = new BLL.TtUsersBll();
            List <Model.TT_User> allUser = bll.QueryByPage(pageIndex, pageCount, out total, predicate, t => t.Id, false);

            List <Hashtable> ret = new List <Hashtable>();

            if (allUser != null)
            {
                Pager pager = new Pager();
                pager.total     = total;
                pager.pageCount = pageCount;
                pager.pageIndex = pageIndex;

                foreach (var user in allUser)
                {
                    Hashtable ht = new Hashtable();
                    ht["id"]        = user.Id;
                    ht["loginName"] = user.LoginName;
                    ht["password"]  = user.Password;
                    ht["mobile"]    = user.Mobile;
                    ht["province"]  = user.Province;
                    ret.Add(ht);
                }

                context.Response.Write(js.Serialize(BaseModels.OK("查询成功!", ret, pager)));
                return;
            }

            context.Response.Write(js.Serialize(BaseModels.Error("查询失败!")));
            return;
        }
Ejemplo n.º 26
0
        public BaseModels <RoverModel> GetCurrentRover()
        {
            BaseModels <RoverModel> model = new BaseModels <RoverModel>();

            if (CurrentRover != null)
            {
                model.Data = CurrentRover;
            }
            else
            {
                model.Errors.Add("Rover not found.");
            }

            return(model);
        }
Ejemplo n.º 27
0
        public BaseModels <bool> Validate(PlateauModel plateau)
        {
            BaseModels <bool> model = new BaseModels <bool>();

            if (plateau != null && plateau.Width > 0 && plateau.Height > 0)
            {
                model.Data = true;
                Console.WriteLine($"Plateau has valid size ({plateau.Width}-{plateau.Height}).");
            }
            else
            {
                ValidatePlateauException exception = new ValidatePlateauException();
                Console.WriteLine(exception.Message);
                throw exception;
            }

            return(model);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 登录系统
        /// </summary>
        /// <param name="context"></param>
        public void LoginSystem(HttpContext context)
        {
            string userName = Request("userName");
            string password = Request("password");

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                context.Response.Write(js.Serialize(BaseModels.Error("账号和密码不能为空!")));
                return;
            }
            Hashtable ht = new Hashtable();

            ht["name"]  = "张三";
            ht["token"] = Guid.NewGuid().ToString("n");

            context.Response.Write(js.Serialize(BaseModels.OK("登录成功!", ht)));
            return;
        }
Ejemplo n.º 29
0
        public BaseModels <RoverModel> Initalize(PlateauModel plateauModel, RoverLocationModel roverLocation)
        {
            BaseModels <RoverModel> model = new BaseModels <RoverModel>();

            BaseModels <bool> validateLocationModel = ValidateLocation(plateauModel, roverLocation);

            if (validateLocationModel.Data)
            {
                model.Data    = new RoverModel();
                model.Data.Id = Guid.NewGuid();
                model.Data.Location.Direction = roverLocation.Direction;
                model.Data.Location.XPosition = roverLocation.XPosition;
                model.Data.Location.YPosition = roverLocation.YPosition;
                CurrentRover = model.Data;
                Console.WriteLine("Rover initialized successfully.");
            }

            return(model);
        }
Ejemplo n.º 30
0
        public App()
        {
            InitializeComponent();

            _user = new User();

            _service         = new NesterService();
            _service.Version = ServiceVersion;

            _target  = new NesterService();
            _storage = new StorageService();
            _storage.Clear();

            _baseModels = new BaseModels(
                new AuthViewModel(),
                new PaymentViewModel(),
                new AppViewModel());
            MainPage = new NavigationPage(
                new WPPodUser.LoginView());
        }