public override void parse(String json)
        {
            // 文件上传返回值
            var raw = (IDictionary <String, Object>)JsonAdapter.JSON.ToObject(json);

            var firstR = get(raw, "r");

            if (firstR == null)
            {
                throw newPaserException(json);
            }

            bool isok = firstR is IDictionary <String, Object>;

            object secondR = null;

            if (isok)
            {
                secondR = get(firstR as IDictionary <String, Object>, "r");
            }

            if (secondR == null || !(secondR is IDictionary || secondR is IDictionary <String, Object>))
            {
                this.exception = new BmobException("文件上传失败!");
                this.data      = default(T);
            }
            else
            {
                this.data = BmobInput.Parse <T>(secondR as IDictionary <String, Object>);
            }
        }
示例#2
0
        public object PostFile([FromBody] Course_View cl)
        {
            String a        = "";
            String objectId = "";
            Course course   = new Course();

            course.id         = BmobInput.Parse <BmobInt>(cl.id);
            course.name       = cl.name;
            course.program    = cl.program;
            course.experiment = cl.experiment;
            course.time       = cl.time;
            var query = new BmobQuery();

            query.WhereEqualTo("id", course.id);
            var f = Bmob.FindTaskAsync <Course>("Course", query);

            try
            {
                objectId = f.Result.results[0].objectId;
                var future = Bmob.UpdateTaskAsync("Course", objectId, course);
                a = future.Result.updatedAt;
            }
            catch
            {
                a = "失败";
            }
            return(a);
        }
        public virtual void parse(String json)
        {
            if (!result.ok())
            {
                this.exception = new BmobException(result.ToString());
                this.data      = default(T);
            }
            else
            {
                var type = typeof(T);
                if (type.IsArray || typeof(IList).IsAssignableFrom(type))
                {
                    // batch or ...
                    var raw = (IList)JsonAdapter.JSON.ToObject(json);
                    this.data = BmobInput.Parse <T>(raw);
                }
                else
                {
                    // 解析[CRUD]的返回值对象
                    var raw = (IDictionary <String, Object>)JsonAdapter.JSON.ToObject(json);

                    this.data = BmobInput.Parse <T>(raw);
                }
            }
        }
示例#4
0
        public object PostFile([FromBody] Resource_View resourceView)
        {
            HttpCookie cookie1  = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String     id       = cookie1["CourseId"];
            int        courseId = int.Parse(id);
            String     a        = "";
            // String objectId = "";
            Resource resource = new Resource();

            resource.id          = BmobInput.Parse <BmobInt>(resourceView.id);
            resource.file        = resourceView.file;
            resource.type        = resourceView.type;
            resource.courseId    = BmobInput.Parse <BmobInt>(courseId);
            resource.unitId      = BmobInput.Parse <BmobInt>(resourceView.unitId);
            resource.knowledgeId = BmobInput.Parse <BmobInt>(resourceView.knowledgeId);
            //var query = new BmobQuery();
            //query.WhereEqualTo("id", course.id);
            var f = Bmob.CreateTaskAsync("Resource", resource);

            try
            {
                a = f.Result.objectId;
            }
            catch
            {
                a = "失败";
            }
            return(a);
        }
示例#5
0
        public virtual void parse(String json)
        {
            if (!result.ok())
            {
                // RestAPI 如果不是200,说明返回内容有“错误”,此时解析内容
                var raw    = (IDictionary <String, Object>)JsonAdapter.JSON.ToObject(json);
                var status = BmobInput.Parse <Status>(raw);

                this.exception = new BmobException(status.code == null ? result : status);
                this.data      = default(T);
            }
            else
            {
                var type = typeof(T);
                if (type.IsArray || typeof(IList).IsAssignableFrom(type))
                {
                    // batch or ...
                    var raw = (IList)JsonAdapter.JSON.ToObject(json);
                    this.data = BmobInput.Parse <T>(raw);
                }
                else
                {
                    // 解析[CRUD]的返回值对象
                    var raw = (IDictionary <String, Object>)JsonAdapter.JSON.ToObject(json);
                    this.data = BmobInput.Parse <T>(raw);
                }
            }
        }
示例#6
0
        public override void readFields(BmobInput input)
        {
            // EndPoint直接返回数据,不像Table返回值有Container的概念!
            var type = typeof(U);

            // 请求正确,返回数据
            Object jsonData = null;
            // 请求失败(如,云端方法不存在), 异常状态
            Object statData = null;

            var rawResp = input.getString("result");

            if (typeof(IList).IsAssignableFrom(type))
            {
                this.data = BmobInput.Parse <U>(JsonAdapter.JSON.ToObject(rawResp));
            }
            else
            {
                var rawRespJson = JsonAdapter.JSON.ToObject(rawResp);
                jsonData = rawRespJson;
                statData = rawRespJson;

                if (statData is IDictionary || statData is IDictionary <String, Object> )
                {
                    // 要么返回数据,要么就是返回状态值
                    EndPointCallbackStat status = BmobInput.Parse <EndPointCallbackStat>(statData);
                    if (status != null && status.sucess != null)
                    {
                        this.exception = new BmobException("请求失败!错误信息为: " + status.message);
                        this.data      = default(U);
                        return;
                    }
                }

                this.data = BmobInput.Parse <U>(rawRespJson);
            }
        }
示例#7
0
        public object PostSavePaper([FromBody] Examination_View examination_View)
        {
            HttpCookie  cookie1     = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String      id          = cookie1["CourseId"];
            int         courseId    = int.Parse(id);
            Examination examination = new Examination();

            examination.id           = BmobInput.Parse <BmobInt> (examination_View.id);
            examination.name         = examination_View.name;
            examination.questionList = examination_View.questionList;
            examination.difficulty   = BmobInput.Parse <BmobDouble>(examination_View.difficulty);
            examination.courseId     = BmobInput.Parse <BmobInt>(courseId);
            var future = Bmob.CreateTaskAsync("Examination", examination);

            try
            {
                String objectId = future.Result.objectId;
                return(objectId);
            }
            catch
            {
                return("获取失败");
            }
        }
示例#8
0
        public object PostAddCourse([FromBody] Course_View cl)
        {
            String     a        = "";
            HttpCookie cookie   = HttpContext.Current.Request.Cookies["UserInfoRemember"];
            String     username = cookie["username"].ToString();
            Course     course   = new Course();

            course.id   = BmobInput.Parse <BmobInt>(cl.id);
            course.name = cl.name;
            course.tId  = username;
            //course.program = cl.program;
            //course.experiment = cl.experiment;
            //course.time = cl.time;
            var future = Bmob.CreateTaskAsync("Course", course);

            try
            {
                a = "success";
            }catch
            {
                a = "fail";
            }
            return(a);
        }
示例#9
0
        public object PostUpdateClass([FromBody] List <Class_View> classInfo)
        {
            HttpCookie cookie1  = HttpContext.Current.Request.Cookies["CurrentCourse"];
            String     Id       = cookie1["CourseId"];
            int        courseId = int.Parse(Id);
            String     result   = "";
            int        count    = 0;
            int        length   = classInfo.Count;
            BmobQuery  query    = new BmobQuery();

            for (int i = 0; i < length; i++)
            {
                query.WhereEqualTo("id", classInfo[i].id);
                var future = Bmob.FindTaskAsync <Class>("Class", query);
                try
                {
                    String objectId = future.Result.results[0].objectId;
                    Class  c        = new Class();
                    c.id       = classInfo[i].id;
                    c.name     = classInfo[i].name;
                    c.courseId = BmobInput.Parse <BmobInt>(courseId);
                    c.schedule = classInfo[i].schedule;
                    c.term     = classInfo[i].term;
                    var future1 = Bmob.UpdateTaskAsync("Class", objectId, c);
                    try
                    {
                        String a = future1.Result.updatedAt;
                        count++;
                        if (count == length)
                        {
                            result = "success";
                        }
                    }
                    catch
                    {
                        result = "fail";
                    }
                }catch
                {
                    result = "fail";
                }
            }
            //for(int i = 0; i < length; i++)
            //{
            //    String objectId = classInfo[i].objectId;
            //    var future = Bmob.UpdateTaskAsync("Class", objectId, classInfo[i]);
            //    try
            //    {
            //        String a = future.Result.updatedAt;
            //        count++;
            //        if(count == length)
            //        {
            //            result = "success";
            //        }
            //    }
            //    catch
            //    {
            //        result = "fail";
            //    }
            //}
            return(result);
        }