Пример #1
0
        public ActionResult Index(IndexViewModel model)
        {
            if (string.IsNullOrEmpty(model.ClassName))
            {
                //model.Error = true;
                //model.ErrorNo = 1;
                model.ClassName = "RootObject";
            }
            else if (string.IsNullOrEmpty(model.JSON))
            {
                model.Error = true;
                model.ErrorNo = 2;
            }


            if (model.JSON.ToLower().StartsWith("http"))
            {
                try
                {
                    model.JSON = new WebClient().DownloadString(model.JSON);
                }
                catch (Exception ex)
                {
                    model.Error = true;
                    model.ErrorNo = 4;
                }
            }


            if (model.Error)
            {
                return View(model);
            }
            
            try
            {
                if (model.Language != 3)
                {

                    model.CodeObjects =
                        Server.HtmlEncode(Prepare(model.JSON, model.ClassName, model.Language, model.Nest, model.Pascal,
                        model.PropertyAttribute, (model.Language == 5 || model.Language == 6) && model.Properties));
                }
                else
                    model.CodeObjects = "javascript";
            }
            catch (Exception ex)
            {
                model.Error = true;
                model.ErrorNo = 3;               
            }
            
            return View(model);
        }
Пример #2
0
        public ActionResult Index(string url)
        {
            var vm = new IndexViewModel();

            if (!string.IsNullOrEmpty(url))
            {
                try
                {
                    vm.JSON = new WebClient().DownloadString(url);
                }
                catch (Exception ex)
                {
                    vm.Error = true;
                    vm.ErrorNo = 4;
                }
            }

            if (string.IsNullOrEmpty(vm.JSON))
            {
                vm.JSON = @"{""employees"": [
                        {  ""firstName"":""John"" , ""lastName"":""Doe"" }, 
                        {  ""firstName"":""Anna"" , ""lastName"":""Smith"" }, 
                        { ""firstName"": ""Peter"" ,  ""lastName"": ""Jones "" }
                        ]
                        }".Trim();
            }

            vm.ClassName = "Example";
            vm.PropertyAttribute = "None";
            vm.Nest = false;

            try
            {
                vm.CodeObjects = Server.HtmlEncode(Prepare(vm.JSON, vm.ClassName, 1, vm.Nest, false, vm.PropertyAttribute));
            }
            catch (Exception ex)
            {
                vm.Error = true;
                vm.ErrorNo = 3;
            }
            vm.Language = 1;

            return View(vm);
        }