本文整理汇总了C#中RequestState类的典型用法代码示例。如果您正苦于以下问题:C# RequestState类的具体用法?C# RequestState怎么用?C# RequestState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestState类属于命名空间,在下文中一共展示了RequestState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObsRequestNode
public ObsRequestNode(XPathNavigator nav)
{
ID = nav.SelectSingleNode ("@id").Value;
Description = nav.SelectSingleNode ("description").Value;
State = new RequestState (nav.SelectSingleNode ("state"));
Action = new RequestAction (nav.SelectSingleNode ("action"));
}
示例2: GetStream
public virtual Task<Stream> GetStream()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ServiceUrl);
request.UserAgent = ApiConstants.UserAgentHeaderValue;
TaskCompletionSource<Stream> tcs = new TaskCompletionSource<Stream>();
RequestState state = new RequestState { Manager = this, TaskCompletionSource = tcs, Request = request };
if (Credentials != null)
{
NetworkCredential networkCred = Credentials.GetCredential(
Client.BaseAddress,
ApiConstants.BasicAuthorization);
string credParameter = Convert.ToBase64String(Encoding.ASCII.GetBytes(networkCred.UserName + ":" + networkCred.Password));
request.Headers[ApiConstants.AuthorizationHeaderName] = string.Format(
"{0} {1}",
ApiConstants.BasicAuthorization, credParameter);
}
LogRequest(request);
IAsyncResult result = request.BeginGetResponse(RemoteLogStreamManager.OnGetResponse, state);
if (result.CompletedSynchronously)
{
state.Response = (HttpWebResponse)request.EndGetResponse(result);
OnGetResponse(state);
}
return tcs.Task;
}
示例3: TestUrl_Async
public static HttpWebRequest TestUrl_Async(string url, int index, UrlTestUser caller)
{
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
url = url.Insert(0, "http://");
RequestState requestState = new RequestState();
requestState.index = index;
requestState.caller = caller;
HttpWebRequest request = null;
try
{
request = (HttpWebRequest)WebRequest.Create(url);
System.Net.Cache.HttpRequestCachePolicy policy =
new System.Net.Cache.HttpRequestCachePolicy(System.Net.Cache.HttpRequestCacheLevel.BypassCache);
request.CachePolicy = policy;
request.UserAgent = user_agent;
request.AllowAutoRedirect = false;
requestState.request = request;
IAsyncResult result = (IAsyncResult)request.BeginGetResponse(new AsyncCallback(TestUrl_AsyncCallback), requestState);
}
catch (WebException we)
{
requestState.connectionFailure = true;
if (we.Status != WebExceptionStatus.RequestCanceled) // old requests that are invalid now shouldn't write into the ListView
ResolveUrlTestResult(requestState);
}
catch (Exception e)
{
requestState.connectionFailure = true;
ResolveUrlTestResult(requestState);
}
return request;
}
示例4: ConnectAsync
public async Task<WebSocket> ConnectAsync(Uri uri, CancellationToken cancellationToken)
{
var state = new RequestState(uri, _pathBase, cancellationToken, _application);
if (ConfigureRequest != null)
{
ConfigureRequest(state.Context.HttpContext.Request);
}
// Async offload, don't let the test code block the caller.
var offload = Task.Factory.StartNew(async () =>
{
try
{
await _application.ProcessRequestAsync(state.Context);
state.PipelineComplete();
state.ServerCleanup(exception: null);
}
catch (Exception ex)
{
state.PipelineFailed(ex);
state.ServerCleanup(ex);
}
finally
{
state.Dispose();
}
});
return await state.WebSocketTask;
}
示例5: ActionStatusEventArgs
public ActionStatusEventArgs(RequestState state, string msg)
{
State = state;
Message = msg;
Time = DateTime.Now;
IsDetail = false;
}
示例6: Run
//public Run()
public void Run()
{/*{{{*/
allDone = new ManualResetEvent(false);
// Create an instance of the RequestState class.
RequestState myRequestState = new RequestState();
// Begin an asynchronous request for information like host name, IP addresses, or
// aliases for specified the specified URI.
IAsyncResult asyncResult = Dns.BeginGetHostEntry("www.contiioso.com", new AsyncCallback(RespCallback), myRequestState );
// Wait until asynchronous call completes.
allDone.WaitOne();
//asyncResult.AsyncWaitHandle.WaitOne();
if(myRequestState.host == null) return;
if(asyncResult.IsCompleted) Console.WriteLine("Get IPs!!");
Console.WriteLine("Host name : " + myRequestState.host.HostName);
Console.WriteLine("\nIP address list : ");
for(int index=0; index < myRequestState.host.AddressList.Length; index++)
{
Console.WriteLine(myRequestState.host.AddressList[index]);
}
Console.WriteLine("\nAliases : ");
for(int index=0; index < myRequestState.host.Aliases.Length; index++)
{
Console.WriteLine(myRequestState.host.Aliases[index]);
}
}/*}}}*/
示例7: Update
// This method is called by the timer delegate.
public void Update(Object stateInfo)
{
try
{
logger.Info(string.Format("start update categories..."));
string url = ConfigurationManager.AppSettings["cat_update_url"];
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(string.Format(@"{0}", url));
RequestState requestState = new RequestState();
requestState.request = httpWebRequest;
IAsyncResult result = (IAsyncResult)httpWebRequest.BeginGetResponse(new AsyncCallback(RespCallback), requestState);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), httpWebRequest, DefaultTimeout, true);
// The response came in the allowed time. The work processing will happen in the callback function.
allDone.WaitOne();
// Release the HttpWebResponse resource.
if (requestState != null && requestState.response != null)
requestState.response.Close();
AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;
}
catch (Exception ex)
{
logger.Error("update rates error", ex);
}
}
示例8: Download
public void Download()
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.uri);
request.Timeout = 500; // Wait for .5 sec only
RequestState state = new RequestState();
state.Request = request;
state.Completed = this.completed;
state.OriginalUri = this.uri;
state.Properties = this.properties;
IAsyncResult result = (IAsyncResult)request.BeginGetResponse(
new AsyncCallback(ResponseCallback), state);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle,
new WaitOrTimerCallback(TimeoutCallback), state,
DEFAULT_TIMEOUT, true);
}
catch (Exception ex)
{
completed(new WebDownloaderEventArgs
{
Exception = ex,
Stream = null,
ResponseUri = this.uri,
IsTimeout = false,
Properties = this.properties,
Status = HttpStatusCode.Unused
});
}
}
示例9: SendRequest
internal void SendRequest(RestRequestArgs args, Action<XElement> success, Failed failed)
{
if (args == null)
throw new ArgumentNullException("args");
if (success == null)
throw new ArgumentNullException("success");
if (failed == null)
throw new ArgumentNullException("failed");
// create a request state...
RequestState state = new RequestState()
{
Owner = this,
Args = args,
Success = success,
Failed = failed
};
// are we authenticated? if we're not, we need to call that first...
if (!(IsAuthenticated))
{
// call the authenticate routine, and ask it to call the state we just setup
// if authentication works...
ApiService.Authenticate(new Action(state.DoRequest), failed);
}
else
{
// call the method directly...
state.DoRequest();
}
}
示例10: ControlAddSliceToNodesSlice
/// <summary>
/// Creates a new control instance.
/// </summary>
public ControlAddSliceToNodesSlice()
{
// Initialize the component.
this.InitializeComponent();
// Create the request states.
this.requestStateSlices = new RequestState(null, this.OnSitesRequestResult, null, null, null);
this.requestStateNodes = new RequestState(null, this.OnNodesRequestResult, null, null, null);
}
示例11: Store
/// <summary>
/// Stores the specified request <paramref name="state"/>, overriding
/// any previous state with the same key
/// </summary>
/// <param name="state">Request state</param>
public void Store(RequestState state)
{
if (state == null)
throw new ArgumentNullException("state");
lock (this.SyncRoot)
{
HttpContext.Current.Session[GetStringKey(state.Key)] = state;
}
}
示例12: Store
/// <summary>
/// Stores the specified request <paramref name="state"/>, overriding
/// any previous state with the same key
/// </summary>
/// <param name="state">Request state</param>
public void Store(RequestState state)
{
if (state == null)
throw new ArgumentNullException("state");
lock (this.SyncRoot)
{
this.states[state.Key] = state;
}
}
示例13: login
public void login(string username, string password)
{
HttpWebRequest request = createLoginRequest();
RequestState state = new RequestState(request, new creds(username, password), this, url.LoginUrl);
request.BeginGetRequestStream(
new AsyncCallback(GetRequestStreamCallback),
state);
}
示例14: DownloadDataAsync
public void DownloadDataAsync(HttpWebRequest request, byte[] d, int millisecondsTimeout,
RequestCompletedEventHandler completedCallback)
{
RequestState state = new RequestState(request, d, millisecondsTimeout, completedCallback, null);
IAsyncResult result = request.BeginGetResponse(GetResponse, state);
#if !NETFX_CORE
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, state, millisecondsTimeout, true);
#endif
}
示例15: DownloadDataAsync
public static void DownloadDataAsync(HttpWebRequest request, int millisecondsTimeout,
DownloadProgressEventHandler downloadProgressCallback, RequestCompletedEventHandler completedCallback)
{
// Create an object to hold all of the state for this request
RequestState state = new RequestState(request, null, millisecondsTimeout, null, downloadProgressCallback,
completedCallback);
// Start the request for the remote server response
IAsyncResult result = request.BeginGetResponse(GetResponse, state);
// Register a timeout for the request
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, state, millisecondsTimeout, true);
}