/// <summary> /// This method receives requests from the HTTP agent and passes the request to the Site Controller. /// </summary> /// <param name="httpContext">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request data.</param> /// <returns>Returns true if the connection should be reset.</returns> public override bool Receive(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { context.ChangeState("ProcessData"); return context.Receive(job, Data); }
/// <summary> /// This method sets the transport context server connection parameters. /// </summary> /// <param name="context">The transport context.</param> /// <param name="job">The current job.</param> /// <param name="Data">The data.</param> /// <returns>Returns false as this context should be accepted.</returns> public override bool ListenRequest(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.Location = Data.ContractRequest.TransportUri; context.ServerContextID = Data.ContractRequest.ServerContextID; Data.ContractResponse.ConnectionType = TransportConnectionType.Connectionful; Data.Response.Status = CH.HTTPCodes.OK_200; return false; }
/// <summary> /// This private method reset the Completion job. /// </summary> public override void Reset() { base.Reset(); if (mJobCollection!=null) mJobCollection.Clear(); mParentJob = null; jobRequests = 0; }
/// <summary> /// This close method is initiated by the remote server. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public override bool Close(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { TransportContextTCPIP tcpContext = context as TransportContextTCPIP; tcpContext.ClosePending = true; tcpContext.SocketClose(); return true; }
/// <summary> /// This state manages connection requests from HTTP browsers. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The current job.</param> /// <param name="Data">The data in the request.</param> /// <returns>Returns false if the connection is successful, true if the connection should be reset.</returns> public override bool ConnectionRequest(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { RQCallbackServer Request = Data.ContractRequest; RSCallbackServer Response = Data.ContractResponse; Response.ServerContextID = context.SignatureID; Response.Status = CH.HTTPCodes.OK_200; Response.MessageResponse = null; Response.MessageRequestType = typeof(HTTPRequestMessage); context.URILocal = Request.LocalUri; context.URIRemote = Request.RemoteUri; context.ProtocolCommandID = Data.Sender; context.ProtocolContextID = Request.ProtocolContextID; context.ExpiryTimeSet(); context.ChangeState("AwaitRequest"); return false; }
public override bool Transmit(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { return base.Transmit(context, job, Data); }
/// <summary> /// This method swaps to the open state and calls the corresponding method. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public override bool OpenRequest(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.ChangeState("Open"); return context.OpenRequest(job, Data); }
public void JobComplete(SecurityManagerJob job, bool signal) { dJobComplete(job, signal); }
/// <summary> /// This private method initializes the completion job. /// </summary> /// <param name="job">The parent job.</param> /// <param name="callback">The completion callback.</param> /// <param name="state">The object state.</param> /// <param name="AutoExecute">This method identifies whether the jobs will execute automatically and only signal after the complete method has been set.</param> /// <param name="throttleThreshold">The throttle threshold is the amount of queued jobs that /// will trigger the throttle flag to be set.</param> /// <param name="trace">The trace flag determines whether the completion job should submit trace /// data during the job processing.</param> protected void Initialize(SecurityManagerJob job, CompletionJobCallBack callback, object state, bool AutoExecute, int throttleThreshold, bool trace) { mParentJob = job; CompletionJobComplete = callback; mState = state; autoExecute=AutoExecute; if (autoExecute) mStatus = CompletionJobStatus.Submitting; mJobShouldTrace = trace; if (mDependencyList != null) mDependencyList.Clear(); errorList.Clear(); errorCount = 0; this.throttleThreshold = throttleThreshold; if (throttleThreshold > 0) { if (mThrottlingQueue == null) mThrottlingQueue = new Queue<JobHolder>(); else mThrottlingQueue.Clear(); } ThrottleSet(); executingJobs = 0; }
/// <summary> /// This method is used to signal that a child job is complete. /// </summary> /// <param name="childJob"></param> public void ChildJobComplete(SecurityManagerJob childJob) { if(!RemoveJob(childJob.ID.Value,null, new CommandRSEventArgs(childJob))) return; //SecurityManagerJob.SecurityManagerJobReturn(childJob); }
/// <summary> /// This private method initializes the completion job. /// </summary> /// <param name="job">The parent job.</param> /// <param name="callback">The completion callback.</param> /// <param name="state">The object state.</param> /// <param name="AutoExecute">This method identifies whether the jobs will execute automatically and only signal after the complete method has been set.</param> /// <param name="throttleThreshold">The throttle threshold is the amount of queued jobs that /// will trigger the throttle flag to be set.</param> protected void Initialize(SecurityManagerJob job, CompletionJobCallBack callback, object state, bool AutoExecute, int throttleThreshold) { Initialize(job, callback, state, AutoExecute, throttleThreshold, false); }
/// <summary> /// This method identifies whether the job is contained in the queue. /// </summary> /// <param name="value">The job.</param> /// <returns>Returns true if the job exists in the queue.</returns> public bool Contains(SecurityManagerJob value) { if (value == null) return false; lock (syncObject) { return JobList.ContainsValue(value); } }
/// <summary> /// This method pushes a job on to the priority queue with the /// normal priority. /// </summary> /// <param name="job">The new job</param> /// <returns>The current position on the queue.</returns> public void Push(SecurityManagerJob job) { Push(job, JobPriority.Normal); }
/// <summary> /// This method receives requests from the HTTP agent and passes the request to the Site Controller. /// </summary> /// <param name="httpContext">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request data.</param> /// <returns>Returns true if the connection should be reset.</returns> public override bool Receive(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { RQCallbackServer Request = Data.ContractRequest; RSCallbackServer Response = Data.ContractResponse; HTTPRequestMessage httpRQ = null; RQRSContract<SiteControllerRequest, SiteControllerResponse> Env = null; try { httpRQ = Request.Message as HTTPRequestMessage; Env = context.EnvelopeHelper.Get(mSiteManager) as RQRSContract<SiteControllerRequest, SiteControllerResponse>; context.SenderIdentitySet((IXimuraRQRSEnvelope)Env); Env.DestinationAddress = new EnvelopeAddress(mSiteManager, "Receive"); //HTTPServerContext httpContext = context as HTTPServerContext; Env.ContractRequest.MessageMethod = httpRQ.Instruction.Verb; Env.ContractRequest.Message = httpRQ; Env.ContractRequest.MessageUri = ExtractUri(httpRQ, context.URILocal); Env.ContractRequest.MessageUserAgent = ExtractUserAgent(httpRQ); Env.ContractRequest.ServerType = "http"; Env.ContractRequest.URILocal = context.URILocal; Env.ContractRequest.URIRemote = context.URIRemote; context.ExpiryTime = null; Guid signatureID = context.SignatureID.Value; //Send the request synchronously to the server using the current job, //so that it is processed on the current thread. job.ProcessRequest((IXimuraRQRSEnvelope)Env); //Check whether the context has been reset during the call to the Site Controller. if (context == null || !context.SignatureID.HasValue || context.SignatureID.Value != signatureID) { Response.Status = CH.HTTPCodes.InternalServerError_500; Response.CloseNotify = true; return false; } context.ExpiryTimeSet(); Response.MessageResponse = Env.ContractResponse.Message; Response.MessageRequestType = typeof(HTTPRequestMessage); Response.MaxLength = 2000000; Response.Status = CH.HTTPCodes.OK_200; } catch (Exception ex) { Response.Status = CH.HTTPCodes.InternalServerError_500; Response.Substatus = ex.Message; } finally { Response.ProtocolContextID = Request.ProtocolContextID; Response.ServerContextID = context.SignatureID; if (httpRQ != null || httpRQ.ObjectPoolCanReturn) { httpRQ.ObjectPoolReturn(); } if (Env != null || Env.ObjectPoolCanReturn) { Env.ObjectPoolReturn(); } context.ChangeState("AwaitRequest"); } return false; }
public override bool Close(SiteServerContext<HTTPSiteServerRQ, HTTPSiteServerRS> context, SecurityManagerJob job, RQRSContract<RQCallbackServer, RSCallbackServer> Data) { return base.Close(context, job, Data); }
public virtual bool Transmit(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { throw new NotImplementedException("Transmit is not implemented."); }
/// <summary> /// This base method switches any close request to the Close State. /// </summary> /// <param name="context">The current context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns></returns> public virtual bool Close(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { context.ChangeState("Close"); return context.Close(job, Data); }
/// <summary> /// This method pushes a job on to the priority queue. /// </summary> /// <param name="job">The job.</param> /// <param name="priority">The job priority.</param> /// <returns>The current position on the queue.</returns> public void Push(SecurityManagerJob job, JobPriority priority) { lock (syncObject) { if (job == null) throw new ArgumentNullException("job", "job cannot be null."); if (!job.ID.HasValue) throw new ArgumentNullException("job.ID", "job.ID cannot be null."); if (JobList.ContainsKey(job.ID.Value)) throw new ArgumentException("The job is already queued.","job"); //Add the job to the job pending queue. This is a seperate object //in order to increase the productivity of the Queue. JobList.Add(job.ID.Value,job); //Push the job to the list. We do this first in case the queue //is full and it throws an error. QueueList.Push(job.ID.Value,priority,JobTTL); } }
/// <summary> /// This method is called after the transport-server handshake is confirmed. This method starts the listening process. /// </summary> /// <param name="context">The transport context.</param> /// <param name="job">The job.</param> /// <param name="Data">The request/response data.</param> /// <returns>Returns false is the listening process has started successfully.</returns> public override bool ListenConfirm(TransportContext context, SecurityManagerJob job, RQRSContract<TransportCommandRequest, TransportCommandResponse> Data) { TransportContextTCPIP tcpContext = context as TransportContextTCPIP; if (tcpContext == null) { Data.Response.Status = CH.HTTPCodes.ServiceUnavailable_503; return true; } Uri location = tcpContext.Location; //Ok, validate the IP address IPAddress address; if (!IPAddress.TryParse(location.Host, out address)) { if (location.Host.ToLowerInvariant() != "localhost") { Data.Response.Status = CH.HTTPCodes.BadRequest_400; Data.Response.Substatus = string.Format("Location '{0}' is not a valid listening address.", location.Host); return true; } address = IPAddress.Loopback; } IPEndPoint EndPoint = new IPEndPoint(address, location.Port); try { Socket listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //We need to start listening on the appropriate ports and IP addresses listeningSocket.Bind(EndPoint); //Start the socket listening, the cnLISTENQUEUE is the number of items we allow //in the connection queue listeningSocket.Listen(tcpContext.ListenerQueueLength); //tcpContext.LocalEndPoint = EndPoint; tcpContext.ActiveSocket = listeningSocket; //Ok, we need to shunt off the listening duties to another thread so that we can returns to //the server on this thread. AsyncCallback startListening = new AsyncCallback(tcpContext.ListenerStart); startListening.BeginInvoke(null, null, null); Data.Response.Status = CH.HTTPCodes.OK_200; return false; } catch (SocketException socex) { Data.Response.Status = CH.HTTPCodes.BadRequest_400; Data.Response.Substatus = string.Format("The socket threw an exception {0}:{1} ({2})", socex.ErrorCode, socex.SocketErrorCode, socex.Message); return true; } catch (ObjectDisposedException obex) { Data.Response.Status = CH.HTTPCodes.InternalServerError_500; Data.Response.Substatus = string.Format("The socket threw an object disposed exception {0}", obex.Message); return true; } catch (Exception ex) { Data.Response.Status = CH.HTTPCodes.InternalServerError_500; Data.Response.Substatus = string.Format("An unhandeled exception was caught {0}/{1}", ex.GetType().ToString(), ex.Message); return true; } }
/// <summary> /// This method initializes the session. /// </summary> /// <param name="secMan">The security manager.</param> /// <param name="jobRQ">The job request.</param> /// <param name="token">The session token.</param> /// <param name="parentJob">The parent job. This should be left null if this is not a child job.</param> public void Initialize(JobBase jobRQ, SessionToken token, SecurityManagerJob parentJob, CommandRSCallback RSCallback, CommandProgressCallback ProgressCallback) { try { //mSecMan = secMan; mParentJob=parentJob; if (parentJob!=null) mChildJobDepth = parentJob.ChildJobDepth+1; mRSCallback=RSCallback; mProgressCallback=ProgressCallback; mBaseJob = jobRQ; this.token=token; } catch(Exception ex) { Reset(); throw ex; } }
/// <summary> /// This private method initializes the completion job. /// </summary> /// <param name="job">The parent job.</param> /// <param name="callback">The completion callback.</param> /// <param name="state">The object state.</param> protected void Initialize(SecurityManagerJob job, CompletionJobCallBack callback, object state) { Initialize(job, callback, state, false, 0, false); }