public InstantMessagingBridgeJob(string jobid, string instanceid, AzureBasedApplicationBase azureApplication, InstantMessagingBridgeJobInput input)
     : base(jobid, instanceid, azureApplication, input, JobType.InstantMessagingBridge)
 {
     m_handleIncomingMessageInput = base.JobInput as InstantMessagingBridgeJobInput;
     if (m_handleIncomingMessageInput == null)
     {
         throw new ArgumentNullException("Failed to get job input as InstantMessagingBridgeJobInput!");
     }
 }
        public HttpResponseMessage Post(InstantMessagingBridgeJobInput input)
        {
            if (input == null || string.IsNullOrEmpty(input.InviteTargetUri))
            {
                return(CreateHttpResponse(HttpStatusCode.BadRequest, "{\"Error\":\"Invalid OutgoingMessagingNotifyInput\"}"));
            }

            if (!input.InviteTargetUri.StartsWith("sip", StringComparison.InvariantCultureIgnoreCase))
            {
                return(CreateHttpResponse(HttpStatusCode.BadRequest, "{\"Error\":\"Invalid To\"}"));
            }

            var jobConfig = new PlatformServiceSampleJobConfiguration
            {
                JobType = JobType.InstantMessagingBridge,
                InstantMessagingBridgeJobInput = input
            };
            string jobId = Guid.NewGuid().ToString("N");

            try
            {
                PlatformServiceJobBase job = PlatformServiceClientJobHelper.GetJob(jobId, WebApiApplication.InstanceId, WebApiApplication.AzureApplication, jobConfig);

                if (job == null)
                {
                    return(CreateHttpResponse(HttpStatusCode.BadRequest, "{\"Error\":\"Invalid job input or job type\"}"));
                }

                job.ExecuteAsync().Observe <Exception>();
                return(Request.CreateResponse(job));
            }
            catch (Exception e)
            {
                Logger.Instance.Error(e, "Exception happened in schedule job");
                return(CreateHttpResponse(HttpStatusCode.InternalServerError, "{\"Error\":\"Unable to start a job run\"}"));
            }
        }