本文整理汇总了C#中Response类的典型用法代码示例。如果您正苦于以下问题:C# Response类的具体用法?C# Response怎么用?C# Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于命名空间,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateMeta
public Response ActivateMeta(MetaSearchModel metaSearchModel)
{
var response = new Response { Success = true, Warning = false };
try
{
var deRowPost = new ET_DataExtensionRow
{
AuthStub = conexion.ETCliente,
DataExtensionName = "METASAPPBENEFICIOS",
};
deRowPost.ColumnValues.Add("ID", metaSearchModel.Id);
deRowPost.ColumnValues.Add("ACTIVED", "TRUE");
try
{
var postResponse = deRowPost.Patch();
response.Success = postResponse.Status;
response.Message = postResponse.Message;
response.Code = postResponse.Code;
}
catch (Exception exCreate)
{
response.Success = false;
response.Message = exCreate.Message;
}
}
catch (Exception ex)
{
response.Success = false;
response.Message = ex.Message;
}
return response;
}
示例2: ResponseMayHaveContentLength
public void ResponseMayHaveContentLength()
{
AppDelegate app = call =>
{
var response = new Response();
response.Headers.SetHeader("Content-Length", "12");
response.Write("Hello world.");
return response.EndAsync();
};
using (ServerFactory.Create(app, 8090, null))
{
var request = (HttpWebRequest)WebRequest.Create("http://localhost:8090/");
string text;
using (var response = request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
text = reader.ReadToEnd();
}
}
}
Assert.That(text, Is.EqualTo("Hello world."));
}
}
示例3: ViewAllPtoRequests
public Response<List<PaidTimeOff>> ViewAllPtoRequests()
{
Response<List<PaidTimeOff>> response = new Response<List<PaidTimeOff>>();
List<PaidTimeOff> ptoList = _ptoRepo.ViewAllPtoRequests();
try
{
if (ptoList.Count > 0)
{
response.Data = ptoList;
response.Success = true;
}
else
{
response.Success = false;
response.Message = "There are no requests to display";
}
}
catch (Exception ex)
{
response.Success = false;
response.Message = ex.Message;
}
return response;
}
示例4: CreateOrder
public Response<Order> CreateOrder(OrderRequest orderToAddRequest)
{
var response = new Response<Order>();
try
{
var orders = _orderRepo.ListAll(orderToAddRequest.OrderDate);
if (orderToAddRequest.Order.OrderNumber == 0)
{
orderToAddRequest.Order.OrderNumber = GenerateOrderNumber(orders);
}
orderToAddRequest = GetTaxRate(orderToAddRequest);
orderToAddRequest = UpdateCosts(orderToAddRequest);
_orderRepo.Add(orderToAddRequest);
response.Success = true;
response.Data = orderToAddRequest.Order;
}
catch (Exception ex)
{
response.Success = false;
response.Message = ex.Message;
}
return response;
}
示例5: PutResponse
public IHttpActionResult PutResponse(int id, Response response)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
if (id != response.Id)
{
return BadRequest();
}
CITDataContext.Entry(response).State = EntityState.Modified;
try
{
CITDataContext.SaveChanges();
}
catch (DbUpdateConcurrencyException)
{
if (!ResponseExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return StatusCode(HttpStatusCode.NoContent);
}
示例6: if
public Response<TradePlayer>TradePlayer(TradePlayer trader)
{
Response<TradePlayer> response = new Response<TradePlayer>();
try
{
if (trader.Player1ID == trader.Player2ID)
{
response.Success = false;
response.Message = "You cannot trade the same player!";
}
else if (trader.Team1ID == trader.Team2ID)
{
response.Success = false;
response.Message = "you cannot trade to the same team!";
}
else
{
_repo.TradePlayer(trader);
response.Success = true;
response.Message = "Successfully traded players.";
}
}
catch(Exception ex)
{
response.Success = false;
response.Message = ex.Message;
}
return response;
}
示例7: Get
public IHttpActionResult Get(int CurrentPage)
{
//申明参数
int _pageSize = 10;
try
{
PageInfo pageInfo = new PageInfo()
{
PageIndex = CurrentPage,
PageSize = _pageSize,
OrderField = "POSTID",
Order = OrderEnum.asc
};
var list = bll.GetList(pageInfo);
Response<IEnumerable<V_tm_pm_post>> response = new Response<IEnumerable<V_tm_pm_post>>
{
Data = list,
PagesCount = pageInfo.Total / _pageSize
};
return Ok(response);
}
catch (Exception ex)
{
LogHelper.WriteInfo(ex.ToString());
return BadRequest("异常");
}
}
示例8: Handle
/// <summary>
/// Tries to handle request.
/// </summary>
/// <param name="request">
/// The request.
/// </param>
/// <returns>
/// The WebServer.BusinessLogic.Response.
/// </returns>
public override Response Handle(Request request)
{
if (request.HttpPath.EndsWith("/"))
{
string path = Configurator.Instance.RelativeWwwPath + request.HttpPath.Replace("/", "\\");
if(!Directory.Exists(path))
{
return NextHandler.Handle(request);
}
DirectoryInfo directory = new DirectoryInfo(path);
List<FileSystemInfo> descendants = new List<FileSystemInfo>();
descendants.AddRange(directory.GetFileSystemInfos());
if (descendants.Select(desc => desc.Name).Contains("index.html"))
{
request.HttpPath += "index.html";
return NextHandler.Handle(request);
}
string webPage = this.CreateWebPage(descendants, request);
Response toReturn = new Response("text/html", request.HttpVersion, Encoding.UTF8.GetBytes(webPage));
if (Configurator.Instance.UseResponseCompression && request.AcceptEncoding == EnumAcceptEncoding.Gzip)
{
toReturn.Data = GzipCompress(toReturn.Data);
toReturn.ContentEncoding = "gzip";
}
return toReturn;
}
return NextHandler.Handle(request);
}
示例9: DisplayFiles
public Response<List<Resumes>> DisplayFiles(string filePath)
{
var repo = new FileRepository();
var response = new Response<List<Resumes>>();
try
{
response.Data = repo.GetFiles(filePath);
if (response.Data != null)
{
response.Success = true;
}
else
{
response.Success = false;
response.Message = "There are no files to display.";
}
}
catch (Exception ex)
{
response.Message = ex.Message;
response.Success = false;
}
return response;
}
示例10: HasDefaultMessage
public void HasDefaultMessage()
{
var response = new Response((HttpStatusCode)451, null, new Dictionary<string, string>(), "application/json");
var legalRestrictionException = new LegalRestrictionException(response);
Assert.Equal("Resource taken down due to a DMCA notice.", legalRestrictionException.Message);
}
示例11: IsNew
public Boolean IsNew(Response response)
{
Int32? obs = response.Observe;
if (!obs.HasValue)
{
// this is a final response, e.g., error or proactive cancellation
return true;
}
// Multiple responses with different notification numbers might
// arrive and be processed by different threads. We have to
// ensure that only the most fresh one is being delivered.
// We use the notation from the observe draft-08.
DateTime T1 = Timestamp;
DateTime T2 = DateTime.Now;
Int32 V1 = Current;
Int32 V2 = obs.Value;
Int64 notifMaxAge = (_config ?? CoapConfig.Default).NotificationMaxAge;
if (V1 < V2 && V2 - V1 < 1 << 23
|| V1 > V2 && V1 - V2 > 1 << 23
|| T2 > T1.AddMilliseconds(notifMaxAge))
{
Timestamp = T2;
_number = V2;
return true;
}
else
{
return false;
}
}
示例12: AddPost
public Response<Post> AddPost(Post newPost)
{
Regex pattern = new Regex(@"#\w+", RegexOptions.IgnoreCase);
var cats = new List<string>();
List<Category> catList = new List<Category>();
foreach (Match match in pattern.Matches(newPost.Content))
{
string cat = match.Value;
cats.Add(cat.Substring(1, cat.Length - 1) + " ");
foreach (var c in cats)
{
catList.Add(new Category() { category = c });
}
}
newPost.Categories = catList;
var response = new Response<Post>();
try
{
_repo.AddPost(newPost);
response.Success = true;
response.Message = "Successfully added post.";
}
catch(Exception ex)
{
response.Success = false;
response.Message = ex.Message;
}
return response;
}
示例13: JsonFormatterExtensionsFixtures
public JsonFormatterExtensionsFixtures()
{
this.formatter = A.Fake<IResponseFormatter>();
this.model = new Person { FirstName = "Andy", LastName = "Pike" };
DefaultSerializersStartup.JsonSerializer = new DefaultJsonSerializer();
this.response = this.formatter.AsJson(model);
}
示例14: Should_not_parse_wrong_xml
public void Should_not_parse_wrong_xml()
{
var response = new Response(HttpStatusCode.OK, XmlContentType(), XmlWrongDtoResponseText);
var deserializer = new ResponseDeserializer();
Assert.Throws<UnexpectedXmlContentException>(() => deserializer.DeserializeResponse<Status>(response, false));
}
示例15: Should_set_properties_when_creating_oauth_exception
public void Should_set_properties_when_creating_oauth_exception()
{
var dummyResponse = new Response(HttpStatusCode.BadRequest,"Test Body");
var result = new OAuthException(dummyResponse);
Assert.That(result.ResponseBody, Is.EqualTo(dummyResponse.Body));
Assert.That(result.StatusCode, Is.EqualTo(dummyResponse.StatusCode));
}