本文整理汇总了C#中HttpRequest.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequest.ExecuteAsync方法的具体用法?C# HttpRequest.ExecuteAsync怎么用?C# HttpRequest.ExecuteAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.ExecuteAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNoteDB
public void GetNoteDB( HttpRequest.RequestResult resultCallback )
{
RequestingNoteDB = true;
Rock.Mobile.Network.HttpRequest request = new HttpRequest();
RestRequest restRequest = new RestRequest( Method.GET );
restRequest.RequestFormat = DataFormat.Xml;
request.ExecuteAsync<NoteDB>( GeneralConfig.NoteBaseURL + "note_db.xml", restRequest,
delegate(System.Net.HttpStatusCode statusCode, string statusDescription, NoteDB noteModel )
{
if ( Rock.Mobile.Network.Util.StatusInSuccessRange( statusCode ) == true && noteModel != null && noteModel.SeriesList.Count > 0 )
{
Rock.Mobile.Util.Debug.WriteLine( "Got NoteDB info." );
Data.NoteDB = noteModel;
Data.NoteDB.ProcessPrivateNotes( App.Shared.Network.RockGeneralData.Instance.Data.DeveloperModeEnabled );
Data.NoteDB.MakeURLsAbsolute( );
Data.NoteDBTimeStamp = DateTime.Now;
// download the first note so the user can immediately access it without having to wait
// for other crap.
if( Data.NoteDB.SeriesList[ 0 ].Messages.Count > 0 &&
string.IsNullOrEmpty( Data.NoteDB.SeriesList[ 0 ].Messages[ 0 ].NoteUrl ) == false )
{
App.Shared.Notes.Note.TryDownloadNote( Data.NoteDB.SeriesList[ 0 ].Messages[ 0 ].NoteUrl, Data.NoteDB.HostDomain, true, delegate
{
RequestingNoteDB = false;
if ( resultCallback != null )
{
resultCallback( statusCode, statusDescription );
}
});
}
else
{
Rock.Mobile.Util.Debug.WriteLine( "No note for latest message." );
RequestingNoteDB = false;
if ( resultCallback != null )
{
resultCallback( statusCode, statusDescription );
}
}
}
else if ( noteModel == null || noteModel.SeriesList.Count == 0 )
{
statusDescription = "NoteDB downloaded but failed parsing.";
statusCode = System.Net.HttpStatusCode.BadRequest;
Rock.Mobile.Util.Debug.WriteLine( statusDescription );
RequestingNoteDB = false;
if ( resultCallback != null )
{
resultCallback( statusCode, statusDescription );
}
// jhm hack: store the error so I can debug and figure this out.
if( noteModel == null )
{
HackNotesErrorCheck = "Code 1";
}
else if ( noteModel.SeriesList.Count == 0 )
{
HackNotesErrorCheck = "Code 2";
}
}
else
{
// jhm hack: store the error so I can debug and figure this out.
HackNotesErrorCheck = "Code 3: " + statusCode;
Rock.Mobile.Util.Debug.WriteLine( "NoteDB request failed." );
RequestingNoteDB = false;
if ( resultCallback != null )
{
resultCallback( statusCode, statusDescription );
}
}
} );
}
示例2: TryDownloadProfilePicture
public void TryDownloadProfilePicture( uint dimensionSize, HttpRequest.RequestResult profilePictureResult )
{
switch ( AccountType )
{
case BoundAccountType.Facebook:
{
// grab the actual image
string facebookID = UserID.Substring( UserID.IndexOf( "_" ) + 1 ); //chop off the "facebook_" prefix we add.
string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", facebookID, "large", AccessToken);
RestRequest request = new RestRequest( Method.GET );
// get the raw response
HttpRequest webRequest = new HttpRequest();
webRequest.ExecuteAsync( profilePictureUrl, request, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, byte[] model )
{
// it worked out ok!
if ( Util.StatusInSuccessRange( statusCode ) == true )
{
MemoryStream imageStream = new MemoryStream( model );
SaveProfilePicture( imageStream );
imageStream.Dispose( );
}
// notify the caller
if ( profilePictureResult != null )
{
profilePictureResult( statusCode, statusDescription );
}
} );
break;
}
case BoundAccountType.Rock:
{
if ( Person.PhotoId != null )
{
RockApi.Instance.GetProfilePicture( Person.PhotoId.ToString( ), dimensionSize, delegate(System.Net.HttpStatusCode statusCode, string statusDescription, MemoryStream imageStream )
{
if ( Util.StatusInSuccessRange( statusCode ) == true )
{
// if successful, update the file on disk.
SaveProfilePicture( imageStream );
}
// notify the caller
if ( profilePictureResult != null )
{
profilePictureResult( statusCode, statusDescription );
}
} );
}
break;
}
}
}