public void Serialize(SyslogMessage message, System.IO.Stream stream) { int priorityValue = CalculatePriorityValue(message.Facility, message.Severity); string timestamp = null; if (message.DateTimeOffset.HasValue) { System.DateTimeOffset dt = message.DateTimeOffset.Value; string day = dt.Day < 10 ? " " + dt.Day.ToString(System.Globalization.CultureInfo.InvariantCulture) : dt.Day.ToString(System.Globalization.CultureInfo.InvariantCulture); // Yes, this is stupid but it's in the spec timestamp = string.Concat(dt.ToString("MMM' '", System.Globalization.CultureInfo.InvariantCulture), day, dt.ToString("' 'HH':'mm':'ss", System.Globalization.CultureInfo.InvariantCulture)); } System.Text.StringBuilder headerBuilder = new System.Text.StringBuilder(); headerBuilder.Append("<").Append(priorityValue).Append(">"); headerBuilder.Append(timestamp).Append(" "); headerBuilder.Append(message.HostName).Append(" "); headerBuilder.Append(message.AppName.IfNotNullOrWhitespace(x => x.EnsureMaxLength(32) + ":")); if (!this.m_useUtf8) { headerBuilder.Append(message.Message ?? ""); } byte[] asciiBytes = System.Text.Encoding.ASCII.GetBytes(headerBuilder.ToString()); stream.Write(asciiBytes, 0, asciiBytes.Length); if (this.m_useUtf8) { stream.Write(System.Text.Encoding.UTF8.GetPreamble(), 0, System.Text.Encoding.UTF8.GetPreamble().Length); asciiBytes = System.Text.Encoding.UTF8.GetBytes(message.Message ?? ""); stream.Write(asciiBytes, 0, asciiBytes.Length); } }
private string ExtractTimeAndTimeZone(System.DateTimeOffset localDateTime) { var value = localDateTime.ToString(); return(value.Substring(value.Length - 17)); }
public async System.Threading.Tasks.Task <Application.Common.Interfaces.Success2> GetFlightOffersAsync(string originLocationCode, string destinationLocationCode, System.DateTimeOffset departureDate, System.DateTimeOffset?returnDate, int adults, int?children, int?infants, TravelClass2?travelClass, string?includedAirlineCodes, string?excludedAirlineCodes, bool?nonStop, string?currencyCode, int?maxPrice, int?max, System.Threading.CancellationToken cancellationToken) { if (originLocationCode == null) { throw new System.ArgumentNullException("originLocationCode"); } if (destinationLocationCode == null) { throw new System.ArgumentNullException("destinationLocationCode"); } if (departureDate == null) { throw new System.ArgumentNullException("departureDate"); } if (adults == null) { throw new System.ArgumentNullException("adults"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/shopping/flight-offers?"); urlBuilder_.Append(System.Uri.EscapeDataString("originLocationCode") + "=").Append(System.Uri.EscapeDataString(ConvertToString(originLocationCode, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Append(System.Uri.EscapeDataString("destinationLocationCode") + "=").Append(System.Uri.EscapeDataString(ConvertToString(destinationLocationCode, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); urlBuilder_.Append(System.Uri.EscapeDataString("departureDate") + "=").Append(System.Uri.EscapeDataString(departureDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&"); if (returnDate != null) { urlBuilder_.Append(System.Uri.EscapeDataString("returnDate") + "=").Append(System.Uri.EscapeDataString(returnDate.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Append(System.Uri.EscapeDataString("adults") + "=").Append(System.Uri.EscapeDataString(ConvertToString(adults, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); if (children != null) { urlBuilder_.Append(System.Uri.EscapeDataString("children") + "=").Append(System.Uri.EscapeDataString(ConvertToString(children, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (infants != null) { urlBuilder_.Append(System.Uri.EscapeDataString("infants") + "=").Append(System.Uri.EscapeDataString(ConvertToString(infants, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (travelClass != null) { urlBuilder_.Append(System.Uri.EscapeDataString("travelClass") + "=").Append(System.Uri.EscapeDataString(ConvertToString(travelClass, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (includedAirlineCodes != null) { urlBuilder_.Append(System.Uri.EscapeDataString("includedAirlineCodes") + "=").Append(System.Uri.EscapeDataString(ConvertToString(includedAirlineCodes, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (excludedAirlineCodes != null) { urlBuilder_.Append(System.Uri.EscapeDataString("excludedAirlineCodes") + "=").Append(System.Uri.EscapeDataString(ConvertToString(excludedAirlineCodes, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (nonStop != null) { urlBuilder_.Append(System.Uri.EscapeDataString("nonStop") + "=").Append(System.Uri.EscapeDataString(ConvertToString(nonStop, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (currencyCode != null) { urlBuilder_.Append(System.Uri.EscapeDataString("currencyCode") + "=").Append(System.Uri.EscapeDataString(ConvertToString(currencyCode, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (maxPrice != null) { urlBuilder_.Append(System.Uri.EscapeDataString("maxPrice") + "=").Append(System.Uri.EscapeDataString(ConvertToString(maxPrice, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } if (max != null) { urlBuilder_.Append(System.Uri.EscapeDataString("max") + "=").Append(System.Uri.EscapeDataString(ConvertToString(max, System.Globalization.CultureInfo.InvariantCulture))).Append("&"); } urlBuilder_.Length--; var client_ = _httpClient; var disposeClient_ = false; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { request_.Method = new System.Net.Http.HttpMethod("GET"); request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/vnd.amadeus+json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); var disposeResponse_ = true; try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; if (status_ == 200) { var objectResponse_ = await ReadObjectResponseAsync <Application.Common.Interfaces.Success2>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } return(objectResponse_.Object); } else if (status_ == 400) { var objectResponse_ = await ReadObjectResponseAsync <Error_400>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } throw new ApiException <Error_400>("code | title \n------- | ------------------------------------- \n425 | INVALID DATE\n477 | INVALID FORMAT\n2668 | PARAMETER COMBINATION INVALID/RESTRICTED\n4926 | INVALID DATA RECEIVED\n10661 | MAXIMUM NUMBER OF OCCURRENCES EXCEEDED \n32171 | MANDATORY DATA MISSING\n", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } else { var objectResponse_ = await ReadObjectResponseAsync <Error_500>(response_, headers_, cancellationToken).ConfigureAwait(false); if (objectResponse_.Object == null) { throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); } throw new ApiException <Error_500>("Unexpected error", status_, objectResponse_.Text, headers_, objectResponse_.Object, null); } } finally { if (disposeResponse_) { response_.Dispose(); } } } } finally { if (disposeClient_) { client_.Dispose(); } } }
public string Get2([FromUri] System.DateTimeOffset dateTime) { return(dateTime.ToString("dd/MM/yyyy - hh:mm:ss")); }