Exemple #1
0
        public void CallStart(IJobExecutionContext jobContext)
        {
            try
            {
                var httpService = CastleWindsorService.Resolve <HttpComunicationService>();

                var call = new Call
                {
                    FireInstenceID = jobContext.FireInstanceId,
                    StartedAt      = jobContext.FireTimeUtc.DateTime.ToLocalTime(),
                    NextStart      = jobContext.NextFireTimeUtc.HasValue ? jobContext.NextFireTimeUtc.Value.DateTime.ToLocalTime() : DateTime.Parse("01/01/1753"),
                    EndedAt        = DateTime.Parse("01/01/1753")
                };

                var req = new ApiHttpRequest <Call>
                {
                    AppID    = AppId,
                    AppToken = AppToken,
                    data     = call
                };
                LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Calling API: " + Endpoint + "/Calls/End with body: " + req.Stringify());
                var resp = httpService.Post <ApiHttpResponse <HttpDataSingle <bool> > >(Endpoint + "/Calls/Start?jobKey=" + GetJobKey(jobContext.JobDetail), AppId, AppToken, false, req);
                LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "response " + resp.Stringify());
                if (resp.Code != System.Net.HttpStatusCode.OK)
                {
                    throw new HttpCommunicationException(resp.operationResult.Code + " : " + resp.operationResult.Message + "  -> " + resp.operationResult.Stack);
                }
                else
                {
                    LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(),
                                                        "Http Comunication 'Call Started' for job" + jobContext.JobDetail.Key.Name + " to Endpoint : " + Endpoint + " exit with code " + resp.Code.ToString() + " returns message " + resp.operationResult.Message);
                }
            }
            catch (Exception ex)
            {
                LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), ex.Message, ex);
            }
        }
Exemple #2
0
 public void AddJob(IJobDetail jobDetail)
 {
     try
     {
         var httpService = CastleWindsorService.Resolve <HttpComunicationService>();
         var job         = new Job
         {
             Key         = GetJobKey(jobDetail),
             Executing   = false,
             StartedAt   = DateTime.Parse("01/01/1753"),
             Description = jobDetail.Description
         };
         var req = new ApiHttpRequest <Job>
         {
             AppID    = AppId,
             AppToken = AppToken,
             data     = job
         };
         LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "Calling API: " + Endpoint + "/Jobs/Add with body: " + req.Stringify());
         var resp = httpService.Post <ApiHttpResponse <HttpDataSingle <long> > >(Endpoint + "/Jobs/Add", AppId, AppToken, false, req);
         LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(), "response " + resp.Stringify());
         if (resp.Code != System.Net.HttpStatusCode.OK)
         {
             throw new HttpCommunicationException(resp.operationResult.Code + " : " + resp.operationResult.Message + "  -> " + resp.operationResult.Stack);
         }
         else
         {
             LogsAppendersManager.Instance.Debug(this.GetType(), MethodBase.GetCurrentMethod(),
                                                 "Http Comunication 'Job Add' for job" + jobDetail.Key.Name + " to Endpoint : " + Endpoint + " exit with code " + resp.Code.ToString() + " returns message " + resp.operationResult.Message);
         }
     }
     catch (Exception ex)
     {
         LogsAppendersManager.Instance.Error(this.GetType(), MethodBase.GetCurrentMethod(), ex.Message, ex);
     }
 }