Esempio n. 1
0
        void InvokeResfulMethod()
        {
            string            httpMethod = HttpCurrentContext.Current.Request.HttpMethod;
            string            urlSuffix  = HttpCurrentContext.Current.Request.Url.PathAndQuery;
            List <MethodBase> methods    = GetRestfulMethods();

            foreach (MethodBase method in methods)
            {
                RestfulAttribute restfulAttr = method.GetCustomAttribute <RestfulAttribute>();
                if (string.Compare(restfulAttr.Method, httpMethod, true) == 0)
                {
                    UriTemplate      template    = new UriTemplate(restfulAttr.UriTemplate);
                    Uri              baseAddress = new Uri("http://temp.org");
                    UriTemplateMatch match       = template.Match(baseAddress, new Uri(baseAddress, urlSuffix));
                    if (match != null)
                    {
                        Object[] parameters = GetParameters(method, restfulAttr.ParameterStyle, match);
                        try
                        {
                            method.Invoke(m_messageProxy, parameters);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.GetExceptionText());
                        }
                        return;
                    }
                }
            }
            HttpCurrentContext.CloseAsNotImplemented();
        }
Esempio n. 2
0
        public void GetJobWait(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.ExecuteLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    DateTime start = DateTime.Now;
                    if (Wait(job, JobStatus.Scheduled, LongLoopTimeout))
                    {
                        //Log.Default.Trace(" Client:{0} job:{1}", client, job.Message);
                        try
                        {
                            HttpCurrentContext.Close(HttpStatusCode.OK, job.Message);
                            job.Status = JobStatus.Running;
                            Log.Default.Trace("Client:{0} Running", client);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        HttpCurrentContext.CloseAsTimeout();
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }
Esempio n. 3
0
        public void SendResult(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.ExecuteLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    if (job.Status == JobStatus.Running)
                    {
                        try
                        {
                            job.Message = HttpCurrentContext.Body;
                            HttpCurrentContext.Close();
                            job.Status = JobStatus.Finished;
                            Log.Default.Trace("Client:{0} Finished", client);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        HttpCurrentContext.Close(HttpStatusCode.Forbidden, string.Format("Current job status is: {0}", job.Status.ToString()));
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }
Esempio n. 4
0
        public void ExecuteJob(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.InvokeLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    if (job.Status == JobStatus.Idle)
                    {
                        try
                        {
                            job.Message = HttpCurrentContext.Body;
                            job.Status  = JobStatus.Scheduled;
                            //Log.Default.Trace(" Client:{0} Job:{1}", client, job.Message);
                            if (Wait(job, JobStatus.Finished, ExecuteTimeout))
                            {
                                string msg = job.Message;
                                msg = msg.Length > 1000 ? msg.Substring(0, 1000) : msg;
                                //Log.Default.Trace(" Client:{0} Result:{1}", client, msg);
                                HttpCurrentContext.Close(HttpStatusCode.OK, job.Message);
                            }
                            else
                            {
                                HttpCurrentContext.CloseAsTimeout();
                            }
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            job.Status = JobStatus.Idle;
                            Log.Default.Trace("Client:{0} Idle", client);
                        }
                    }
                    else
                    {
                        HttpCurrentContext.Close(HttpStatusCode.Forbidden, "Job status not Idle!");
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }