Example #1
0
        public CommonResponse PostStudyStatus([FromBody] StudyStatusRequest inputRequest)
        {
            try
            {
                if (inputRequest == null)
                {
                    return(new CommonResponse {
                        StatusCode = "100002", Description = "请求错误,请检查请求参数!"
                    });
                }
                Log.Info("PostStudyStatus input:" + JsonConvert.SerializeObject(inputRequest));

                return(new CommonResponse
                {
                    StatusCode = "100000",
                    Description = "ok",
                });
            }
            catch (Exception ex)
            {
                Log.Error("PostStudyStatus", ex);
                return(new CommonResponse {
                    StatusCode = "100003", Description = ex.Message
                });
            }
        }
Example #2
0
        public CommonResponse InspectPostStudyStatus([FromBody] StudyStatusRequest inputRequest)
        {
            try
            {
                if (inputRequest == null)
                {
                    return(new CommonResponse {
                        StatusCode = "100002", Description = "请求错误,请检查请求参数!"
                    });
                }
                var found    = false;
                var identity = string.Empty;
                foreach (var a in tokens)
                {
                    if (a.Token == inputRequest.Token)
                    {
                        identity = a.Identity;
                        found    = true;
                        break;
                    }
                }
                if (!found)
                {
                    return(new CommonResponse {
                        StatusCode = "100001", Description = "error token"
                    });
                }
                var theuser = _db1.User.FirstOrDefault(async => async.Identity == identity);
                if (theuser == null)
                {
                    return(new GetLearnerInfoResponse {
                        StatusCode = "100004", Description = "error identity"
                    });
                }

                if (theuser.Startdate == null)
                {
                    theuser.Startdate = DateTime.Now;
                }
                //    Console.WriteLine("startdate,{0}", theuser.Startdate);
                theuser.Studylog += JsonConvert.SerializeObject(inputRequest);
                _db1.SaveChanges();
                return(new CommonResponse
                {
                    StatusCode = "100000",
                    Description = "ok",
                });
            }
            catch (Exception ex)
            {
                //  Log.Error("PostStudyStatus", ex);
                return(new CommonResponse {
                    StatusCode = "100003", Description = ex.Message
                });
            }
        }
Example #3
0
        public async Task <CommonResponse> InspectPostStudyStatus([FromBody] StudyStatusRequest inputRequest)
        {
            try
            {
                var input = JsonConvert.SerializeObject(inputRequest);
                await Task.Run(() => LogRequest(input, "InspectPostStudyStatus", Request.HttpContext.Connection.RemoteIpAddress.ToString()));

                if (inputRequest == null)
                {
                    Log.Error("InspectPostStudyStatus,{0}", Global.Status[responseCode.RequestError].Description);
                    return(new CommonResponse
                    {
                        StatusCode = Global.Status[responseCode.RequestError].StatusCode,
                        Description = Global.Status[responseCode.RequestError].Description
                    });
                }
                Log.Information("InspectPostStudyStatus,input ={0},from ip={1}",
                                input, Request.HttpContext.Connection.RemoteIpAddress);
                var found    = false;
                var identity = string.Empty;
                foreach (var a in tokens)
                {
                    if (a.Token == inputRequest.Token)
                    {
                        identity = a.Identity;
                        found    = true;
                        break;
                    }
                }
                if (!found)
                {
                    Log.Error("InspectPostStudyStatus,{0},token={1}",
                              Global.Status[responseCode.TokenError].Description, inputRequest.Token);
                    return(new CommonResponse
                    {
                        StatusCode = Global.Status[responseCode.TokenError].StatusCode,
                        Description = Global.Status[responseCode.TokenError].Description
                    });
                }
                var cryptographicid = CryptographyHelpers.StudyEncrypt(identity);
                var theuser         = _db1.User.FirstOrDefault(async => async.Identity == identity || async.Identity == cryptographicid);
                //  var theuser = _db1.User.FirstOrDefault(async => async.Identity == identity);
                if (theuser == null)
                {
                    Log.Error("InspectPostStudyStatus,{0},identity={1}",
                              Global.Status[responseCode.InvalidIdentiy].Description, identity);
                    return(new CommonResponse
                    {
                        StatusCode = Global.Status[responseCode.InvalidIdentiy].StatusCode,
                        Description = Global.Status[responseCode.InvalidIdentiy].Description
                    });
                }

                var studylog = string.Format("{0},{1},{2}", inputRequest.CourseTitle, inputRequest.StartTime, inputRequest.EndTime);

                if (theuser.Startdate == null)
                {
                    theuser.Startdate = DateTime.Now;
                    theuser.Studylog  = studylog;
                    Log.Information("InspectPostStudyStatus,Startdate ={0},from ip={1}",
                                    "uninitiated", Request.HttpContext.Connection.RemoteIpAddress);
                    //  theuser.Studylog = string.Format("{0},{1},{2}", inputRequest.CourseTitle, inputRequest.StartTime, inputRequest.EndTime);
                }
                else
                {
                    //  var slog=string.Format("-{0}", studylog);
                    if (!string.IsNullOrEmpty(theuser.Studylog))
                    {
                        if (!theuser.Studylog.Contains(studylog))
                        {
                            theuser.Studylog += string.Format("-{0}", studylog);
                        }
                        else
                        {
                            Log.Information("InspectPostStudyStatus,duplicate submit, discarded ={0},from ip={1}",
                                            "", Request.HttpContext.Connection.RemoteIpAddress);
                        }
                    }
                    else
                    {
                        theuser.Studylog = studylog;
                    }
                }

                if (theuser.Studylog.Length < 500)
                {
                    theuser.Syncdate = DateTime.Now;
                    _db1.SaveChanges();
                }
                if (!string.IsNullOrEmpty(inputRequest.CourseTitle))
                {
                    if (inputRequest.Pictures != null)
                    {
                        var date = DateTime.Today;
                        //   var dir = string.Format("{0}{1}{2}", date.Year, date.Month, date.Day);
                        var subfpath = identity;
                        if (!string.IsNullOrEmpty(theuser.Photofile))
                        {
                            subfpath = theuser.Photofile;
                        }
                        var fpath = Path.Combine(Global.LogPhotoPath, subfpath);
                        if (!Directory.Exists(fpath))
                        {
                            Directory.CreateDirectory(fpath);
                        }

                        var fname = Path.Combine(fpath, inputRequest.StartTime.ToString() + inputRequest.EndTime.ToString() + ".zip");
                        //     Log.Information("filename is: {0}", fname);
                        System.IO.File.WriteAllBytes(fname, inputRequest.Pictures);
                    }
                }

                return(new CommonResponse
                {
                    StatusCode = Global.Status[responseCode.ok].StatusCode,
                    Description = Global.Status[responseCode.ok].Description,
                });
            }
            catch (Exception ex)
            {
                Log.Error("InspectPostStudyStatus,{0},exception={1}",
                          Global.Status[responseCode.ProgramError].Description, ex);
                return(new CommonResponse
                {
                    StatusCode = Global.Status[responseCode.ProgramError].StatusCode,
                    Description = Global.Status[responseCode.ProgramError].Description
                });
            }
        }