コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        public override void ExecuteResult(ControllerContext context)
        {
            context.HttpContext.Response.ContentType = "application/json; charset=utf-8";
            AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(this.SecurityContext, true);

            if (Total > 0)
            {
                var obj = new { items = Query.ToList(), total = Total, merge = true };
                context.HttpContext.Response.Write(js.Serialize(obj));
            }
            else
            {
                var items = Query.ToList();
                context.HttpContext.Response.Write(js.Serialize(items));
            }
        }
コード例 #2
0
        /// <summary>
        /// Send Json filtered with SecurityContext
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        protected ActionResult JsonResult <T>(T model)
        {
            AtomJavaScriptSerializer ajs = new AtomJavaScriptSerializer(Repository.SecurityContext, true);
            string content = ajs.Serialize(model);

            return(Content(content, "application/json"));
        }
コード例 #3
0
        public ActionResult Update(long id)
        {
            if (!User.Identity.IsAuthenticated || User.Identity.AuthenticationType != "WSClient")
            {
                throw new UnauthorizedAccessException();
            }

            using (DB.CreateSecurityScope(null))
            {
                var job = DB.WSJobs.FirstOrDefault(x => x.JobID == id);
                if (job.AssigneeID != User.Identity.Name)
                {
                    throw new UnauthorizedAccessException();
                }
                job.JobStatus = FormValue <string>("JobStatus");
                job.ResultUrl = FormValue <string>("ResultUrl");
                job.EndTime   = DateTime.UtcNow;

                DB.SaveChanges();

                if (!string.IsNullOrWhiteSpace(job.TriggerEmail))
                {
                }

                if (!string.IsNullOrWhiteSpace(job.TriggerUrl))
                {
                    try {
                        using (WebClient client = new WebClient()) {
                            client.Headers[HttpRequestHeader.ContentType] = "application/json";
                            AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(DefaultSecurityContext.Instance);
                            string result = js.Serialize(job);
                            client.UploadString(job.TriggerUrl, "POST", result);
                        }
                    }
                    catch
                    {
                    }
                }

                return(JsonResult(job));
            }
        }
コード例 #4
0
        private static void FetchResult(ControllerContext context)
        {
            TimeSpan ts = TimeSpan.FromSeconds(10);

            var User     = context.HttpContext.User;
            var Response = context.HttpContext.Response;

            string username = User.Identity.Name;

            long jobID;

            AtomJavaScriptSerializer js = new AtomJavaScriptSerializer(null);

            Response.Output.WriteLine("{ 'JobID': 0, 'Message': 'Welcome' }");
            Response.Flush();

            Update();

            do
            {
                if (!Response.IsClientConnected)
                {
                    break;
                }


                if (!Jobs.TryTake(out jobID, ts))
                {
                    Response.Output.WriteLine("{ 'JobID': 0, 'Message':'None' }");
                    Response.Flush();
                    Update();
                    continue;
                }

                using (WSClientModelEntities db = new WSClientModelEntities())
                {
                    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(60)))
                    {
                        DateTime utcNow = DateTime.UtcNow;

                        WSJob job = db.WSJobs.Where(Queued()).FirstOrDefault(x => x.JobID == jobID);
                        if (job == null)
                        {
                            continue;
                        }

                        job.AssigneeID = username;
                        job.JobStatus  = "Assigned";
                        job.EndTime    = DateTime.UtcNow;

                        var s = js.Serialize(new {
                            job.JobID,
                            job.JobStatus,
                            job.WSDLUrl,
                            job.IsDemo,
                            job.OutputType,
                            job.OutputTarget,
                            job.OutputPrefix,
                            job.OutputPackage
                        });



                        Response.Output.WriteLine(s);
                        Response.Flush();

                        db.SaveChanges();

                        scope.Complete();
                    }
                }
            } while (true);
        }