private bool LookupFileInfo( PathString subPath, string contentType, out StaticFileInfo staticFileInfo) { var fileInfo = _fileProvider.GetFileInfo(subPath.Value); if (fileInfo.Exists) { var length = fileInfo.Length; DateTimeOffset last = fileInfo.LastModified; // Truncate to the second. var lastModified = new DateTimeOffset( last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset) .ToUniversalTime(); long etagHash = lastModified.ToFileTime() ^ length; var etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"'); staticFileInfo = new StaticFileInfo(fileInfo, etag, contentType); return(true); } staticFileInfo = default; return(false); }
public static FILETIME ToFileTime(DateTimeOffset fileTime) { var lft = fileTime.ToFileTime(); FILETIME ft; ft.dwLowDateTime = (int) (lft & 0xFFFFFFFF); ft.dwHighDateTime = (int) (lft >> 32); return ft; }
public static void ToFromFileTime() { var today = new DateTimeOffset(DateTime.Today); long dateTimeRaw = today.ToFileTime(); Assert.Equal(today, DateTimeOffset.FromFileTime(dateTimeRaw)); }
public static void TestConversion() { DateTimeOffset today = new DateTimeOffset(DateTime.Today); long dateTimeRaw = today.ToFileTime(); Assert.Equal(today, DateTimeOffset.FromFileTime(dateTimeRaw)); }
/// <summary> /// Writes a FILETIME timestamp. /// </summary> /// <param name="builder">The <see cref="IPacketBuilder">packet builder</see> to use.</param> /// <param name="instant">An <see cref="DateTimeOffset"/> value.</param> /// <inheritdoc cref="PacketBuilder.WriteInt64(long)" select="exception[@cref='ObjectDisposedException']" /> public static void WriteTimestamp(this IPacketBuilder builder, DateTimeOffset instant) { Guard.NotNull(() => builder, builder); var timestamp = instant.ToFileTime(); builder.WriteInt64(timestamp); }
public IActionResult OnGet(string fileName) { if (string.IsNullOrEmpty(fileName)) { return(NotFound()); } var path = Path.Combine(_imageDirectory, fileName); if (System.IO.File.Exists(path)) { if (Path.GetDirectoryName(path) == _imageDirectory) { var fi = new FileInfo(path); var length = fi.Length; DateTimeOffset last = fi.LastWriteTime; // Truncate to the second. var lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime(); long etagHash = lastModified.ToFileTime() ^ length; var etag_str = '\"' + Convert.ToString(etagHash, 16) + '\"'; string incomingEtag = (Request.Headers as FrameRequestHeaders).HeaderIfNoneMatch; if (String.Compare(incomingEtag, etag_str) == 0) { Response.Clear(); Response.StatusCode = (int)System.Net.HttpStatusCode.NotModified; return(new StatusCodeResult((int)System.Net.HttpStatusCode.NotModified)); } var etag = new EntityTagHeaderValue(etag_str); //var fs = new FileStream(path, FileMode.Open, FileAccess.Read); PhysicalFileResult pfr = base.PhysicalFile(path, "image/jpg"); pfr.EntityTag = etag; return(pfr); //var image = new FileInfo(path); //if (!String.IsNullOrEmpty(Request.Headers["If-Modified-Since"])) //{ // CultureInfo provider = CultureInfo.InvariantCulture; // var lastMod = DateTime.ParseExact(Request.Headers["If-Modified-Since"], "r", provider).ToLocalTime(); // if (lastMod == image.LastWriteTime.AddMilliseconds(-image.LastWriteTime.Millisecond)) // { // Response.StatusCode = 304; // //Response.StatusDescription = "Not Modified"; // return Content(String.Empty); // } //} //var stream = new MemoryStream(image.GetImage()); //Response.Cache.SetCacheability(HttpCacheability.Public); //Response.Cache.SetLastModified(image.TimeStamp); //return File(stream, image.MimeType); } } return(NotFound()); }
public static FILETIME ToFileTime(DateTimeOffset fileTime) { var lft = fileTime.ToFileTime(); FILETIME ft; ft.dwLowDateTime = (int)(lft & 0xFFFFFFFF); ft.dwHighDateTime = (int)(lft >> 32); return(ft); }
public static void SetLastWriteTime(string fullPath, DateTimeOffset time, bool asDirectory) { using (SafeFileHandle handle = OpenHandle(fullPath, asDirectory)) { if (!Interop.Kernel32.SetFileTime(handle, lastWriteTime: time.ToFileTime())) { throw Win32Marshal.GetExceptionForLastWin32Error(fullPath); } } }
public static void SetLastAccessTime(string fullPath, DateTimeOffset time, bool asDirectory, bool backupMode = false) { using (SafeFileHandle handle = OpenHandle(fullPath, asDirectory, true, backupMode)) { if (!Win32Api.Kernel32.SetFileTime(handle, lastAccessTime: time.ToFileTime())) { throw PalWin32FileStream.GetExceptionForLastWin32Error(fullPath); } } }
private static void SetLastWriteTimeInternal(string fullPath, DateTimeOffset time, bool asDirectory) { using (SafeFileHandle handle = OpenHandle(fullPath, asDirectory)) { bool r = Interop.mincore.SetFileTime(handle, lastWriteTime: time.ToFileTime()); if (!r) { throw Win32Marshal.GetExceptionForLastWin32Error(fullPath); } } }
public EntityTagHeaderValue EntityTagBuild(DateTime fileModifiedAtUtc, long fileSize) { var entityTag = new EntityTagHeaderValue("\"CalculatedEtagValue\""); var lastOffset = ToDateTimeOffset(DateTime.SpecifyKind(fileModifiedAtUtc, DateTimeKind.Utc)); var _lastModified = new DateTimeOffset(lastOffset.Year, lastOffset.Month, lastOffset.Day, lastOffset.Hour, lastOffset.Minute, lastOffset.Second, lastOffset.Offset); var etagHash = _lastModified.ToFileTime() ^ fileSize; entityTag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"'); return(entityTag); }
public void WriteValue(DateTimeOffset value) { if (value == default) { WriteByte(DataBytesDefinition.DateTimeOffsetDefault); } else { WriteDefLong(DataBytesDefinition.DateTimeOffset, value.ToFileTime()); } }
/// <summary> /// Called on GET. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="serverTiming">The server timing.</param> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public IActionResult OnGet([FromServices] IConfiguration configuration, [FromServices] IServerTiming serverTiming, string fileName) { var watch = new Stopwatch(); watch.Start(); string imageDirectory = configuration["ImageDirectory"]; if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(imageDirectory)) { serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("GET", watch.ElapsedMilliseconds, "error")); return(NotFound("No image directory present")); } string path = Path.Combine(imageDirectory, fileName); if (System.IO.File.Exists(path)) { if (Path.GetDirectoryName(path) == imageDirectory) { var fi = new FileInfo(path); var length = fi.Length; DateTimeOffset last = fi.LastWriteTime; // Truncate to the second. var lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime(); long etagHash = lastModified.ToFileTime() ^ length; var etag_str = $"\"{Convert.ToString(etagHash, 16)}\""; if (Request.Headers.TryGetValue(HeaderNames.IfNoneMatch, out StringValues incomingEtag) && string.Compare(incomingEtag[0], etag_str) == 0) { Response.Clear(); Response.StatusCode = (int)HttpStatusCode.NotModified; serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("GET", watch.ElapsedMilliseconds, "NotModified GET")); return(new StatusCodeResult((int)HttpStatusCode.NotModified)); } var etag = new EntityTagHeaderValue(etag_str); //var fs = new FileStream(path, FileMode.Open, FileAccess.Read); PhysicalFileResult pfr = base.PhysicalFile(path, MediaTypeNames.Image.Jpeg); pfr.EntityTag = etag; //pfr.LastModified = lastModified; serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("GET", watch.ElapsedMilliseconds, "full file GET")); return(pfr); } } serverTiming.Metrics.Add(new Lib.AspNetCore.ServerTiming.Http.Headers.ServerTimingMetric("GET", watch.ElapsedMilliseconds, "not found GET")); return(NotFound()); }
public bool LookupFileInfo() { if (_fileInfo.Exists) { _length = _fileInfo.Length; DateTimeOffset last = _fileInfo.LastModified; // Truncate to the second. _lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset); long etagHash = _lastModified.ToFileTime() ^ _length; _etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"'); } return(_fileInfo.Exists); }
public void WriteValue(DateTimeOffset value) { if (value == default) { WriteByte(DataBytesDefinition.DateTimeOffsetDefault); } else if (_dateTimeOffsetCache.TryGetValue(value, out var objIdx)) { WriteDefInt(DataBytesDefinition.RefDateTimeOffset, objIdx); } else { WriteDefLong(DataBytesDefinition.DateTimeOffset, value.ToFileTime()); _dateTimeOffsetCache.Set(value); } }
public bool LookupFileInfo() { _fileInfo = _fileProvider.GetFileInfo(_subPath.Value); if (_fileInfo.Exists) { _length = _fileInfo.Length; var last = _fileInfo.LastModified; // Truncate to the second. _lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime(); var etagHash = _lastModified.ToFileTime() ^ _length; _etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"'); } return(_fileInfo.Exists); }
public void WriteValue(DateTimeOffset value) { if (value == default) { WriteByte(DataBytesDefinition.DateTimeOffsetDefault); return; } if (_dateTimeOffsetCache.TryGetValue(value, out var objIdx)) { WriteDefInt(DataBytesDefinition.RefDateTimeOffset, objIdx); return; } var longBinary = value.ToFileTime(); WriteDefLong(DataBytesDefinition.DateTimeOffset, longBinary); _dateTimeOffsetCache.Set(value); }
public static ETag Create(IFileInfo info) { if (!info.Exists) { throw new FileNotFoundException(info.Name); } DateTimeOffset last = info.LastModified.ToUniversalTime(); var lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset).ToUniversalTime(); long etagHash = lastModified.ToFileTime() ^ info.Size; return(new ETag() { Value = Convert.ToString(etagHash, 16) }); }
public static Stream CreateFileGroupDescriptorW(string fileName, DateTimeOffset lastWriteTime, long?fileSize) { var fileGroupDescriptor = new FILEGROUPDESCRIPTORW() { cItems = 1 }; var fileDescriptor = new FILEDESCRIPTORW() { cFileName = fileName }; fileDescriptor.dwFlags |= FD_SHOWPROGRESSUI; if (lastWriteTime != default) { fileDescriptor.dwFlags |= FD_CREATETIME | FD_WRITESTIME; var changeTime = lastWriteTime.ToFileTime(); var changeTimeFileTime = new System.Runtime.InteropServices.ComTypes.FILETIME { dwLowDateTime = (int)(changeTime & 0xffffffff), dwHighDateTime = (int)(changeTime >> 32), }; fileDescriptor.ftLastWriteTime = changeTimeFileTime; fileDescriptor.ftCreationTime = changeTimeFileTime; } if (fileSize.HasValue) { fileDescriptor.dwFlags |= FD_FILESIZE; // TODO: remove ! once https://github.com/dotnet/roslyn/issues/33330 is fixed fileDescriptor.nFileSizeLow = (uint)(fileSize & 0xffffffff) !; fileDescriptor.nFileSizeHigh = (uint)(fileSize >> 32) !; } var fileGroupDescriptorBytes = StructureBytes(fileGroupDescriptor); var fileDescriptorBytes = StructureBytes(fileDescriptor); var memoryStream = new MemoryStream(); memoryStream.Write(fileGroupDescriptorBytes, 0, fileGroupDescriptorBytes.Length); memoryStream.Write(fileDescriptorBytes, 0, fileDescriptorBytes.Length); return(memoryStream); }
static string FromDateTimeOffset(DateTimeOffset value, string format, string timeZone) { if (format == Unix) { return((value - epoch).TotalSeconds.ToString()); } if (format == FileTime) { return(value.ToFileTime().ToString()); } if (format == Excel) { value = new DateTimeOffset(ConvertTimeZone(value, timeZone).DateTime, TimeSpan.Zero); var days = (value - excelBase).TotalDays + 2; if (days < 61) { --days; } return(days.ToString()); } if (format == Ticks) { return(ConvertTimeZone(value, timeZone).Ticks.ToString()); } var tz = GetTimeZone(timeZone); if (tz is TimeZoneInfo) { value = TimeZoneInfo.ConvertTime(value, tz as TimeZoneInfo); } else if (tz is TimeSpan) { value = value.ToOffset((TimeSpan)tz); } return(value.ToString(format)); }
private static byte[] FromDateTimeOffset(DateTimeOffset data) => BitConverter.GetBytes(data.ToFileTime());
public void SetTimes(string path, string accountName, DateTimeOffset modificationTime, DateTimeOffset accessTime) { _client.FileSystem.SetTimes(path, accountName, modificationTime.ToFileTime(), accessTime.ToFileTime()); }
/// <summary> /// Invoked when 'Get History' button is clicked. /// Depending on the user selection, this handler uses one of the overloaded /// 'GetSystemHistoryAsync' APIs to retrieve the pedometer history of the user /// </summary> /// <param name="sender">unused</param> /// <param name="e">unused</param> async private void GetHistory_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { GetHistory.IsEnabled = false; // Determine if we can access pedometers var deviceAccessInfo = DeviceAccessInformation.CreateFromDeviceClassId(PedometerClassId); if (deviceAccessInfo.CurrentStatus == DeviceAccessStatus.Allowed) { // Determine if a pedometer is present // This can also be done using Windows::Devices::Enumeration::DeviceInformation::FindAllAsync var sensor = await Pedometer.GetDefaultAsync(); if (sensor != null) { IReadOnlyList <PedometerReading> historyReadings = null; var timestampFormatter = new DateTimeFormatter("shortdate longtime"); // Disable subsequent history retrieval while the async operation is in progress GetHistory.IsEnabled = false; // clear previous content being displayed historyRecords.Clear(); try { if (getAllHistory) { var dt = DateTime.FromFileTimeUtc(0); var fromBeginning = new DateTimeOffset(dt); rootPage.NotifyUser("Retrieving all available History", NotifyType.StatusMessage); historyReadings = await Pedometer.GetSystemHistoryAsync(fromBeginning); } else { String notificationString = "Retrieving history from: "; var calendar = new Calendar(); calendar.ChangeClock("24HourClock"); // DateTime picker will also include hour, minute and seconds from the the system time. // Decrement the same to be able to correctly add TimePicker values. calendar.SetDateTime(FromDate.Date); calendar.AddNanoseconds(-calendar.Nanosecond); calendar.AddSeconds(-calendar.Second); calendar.AddMinutes(-calendar.Minute); calendar.AddHours(-calendar.Hour); calendar.AddSeconds(Convert.ToInt32(FromTime.Time.TotalSeconds)); DateTimeOffset fromTime = calendar.GetDateTime(); calendar.SetDateTime(ToDate.Date); calendar.AddNanoseconds(-calendar.Nanosecond); calendar.AddSeconds(-calendar.Second); calendar.AddMinutes(-calendar.Minute); calendar.AddHours(-calendar.Hour); calendar.AddSeconds(Convert.ToInt32(ToTime.Time.TotalSeconds)); DateTimeOffset toTime = calendar.GetDateTime(); notificationString += timestampFormatter.Format(fromTime); notificationString += " To "; notificationString += timestampFormatter.Format(toTime); if (toTime.ToFileTime() < fromTime.ToFileTime()) { rootPage.NotifyUser("Invalid time span. 'To Time' must be equal or more than 'From Time'", NotifyType.ErrorMessage); // Enable subsequent history retrieval while the async operation is in progress GetHistory.IsEnabled = true; } else { TimeSpan span = TimeSpan.FromTicks(toTime.Ticks - fromTime.Ticks); rootPage.NotifyUser(notificationString, NotifyType.StatusMessage); historyReadings = await Pedometer.GetSystemHistoryAsync(fromTime, span); } } if (historyReadings != null) { foreach (PedometerReading reading in historyReadings) { HistoryRecord record = new HistoryRecord(reading); historyRecords.Add(record); // Get at most 100 records (number is arbitrary chosen for demonstration purposes) if (historyRecords.Count == 100) { break; } } rootPage.NotifyUser("History retrieval completed", NotifyType.StatusMessage); } } catch (UnauthorizedAccessException) { rootPage.NotifyUser("User has denied access to activity history", NotifyType.ErrorMessage); } // Finally, re-enable history retrieval GetHistory.IsEnabled = true; } else { rootPage.NotifyUser("No pedometers found", NotifyType.ErrorMessage); } } else { rootPage.NotifyUser("Access to pedometers is denied", NotifyType.ErrorMessage); } }
public virtual Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd) { return(Database.HashSetAsync(UserLockDateHashKey, new[] { new HashEntry(((IUser)user).Id, lockoutEnd.ToFileTime()) })); }
public static void SetLastWriteTime(string fullPath, DateTimeOffset time, bool asDirectory) => SetFileTime(fullPath, asDirectory, lastWriteTime: time.ToFileTime());
public void SetHeader(string header, DateTimeOffset dt) { Headers[header] = dt.ToFileTime().ToString(CultureInfo.InvariantCulture); }
public long ToFileTime() { return(value.ToFileTime()); }
/// <summary> /// Invoked when 'Get History' button is clicked. /// Depending on the user selection, this handler uses one of the overloaded /// 'GetSystemHistoryAsync' APIs to retrieve the pedometer history of the user /// </summary> /// <param name="sender">unused</param> /// <param name="e">unused</param> async private void GetHistory_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { IReadOnlyList <PedometerReading> historyReadings = null; DateTimeFormatter timestampFormatter = new DateTimeFormatter("shortdate longtime"); // Disable subsequent history retrieval while the async operation is in progress GetHistory.IsEnabled = false; // clear previous content being displayed historyRecords.Clear(); try { if (getAllHistory) { DateTime dt = DateTime.FromFileTimeUtc(0); DateTimeOffset fromBeginning = new DateTimeOffset(dt); rootPage.NotifyUser("Retrieving all available History", NotifyType.StatusMessage); historyReadings = await Pedometer.GetSystemHistoryAsync(fromBeginning); } else { String notificationString = "Retrieving history from: "; Calendar calendar = new Calendar(); calendar.ChangeClock("24HourClock"); // DateTime picker will also include hour, minute and seconds from the the system time. // Decrement the same to be able to correctly add TimePicker values. calendar.SetDateTime(FromDate.Date); calendar.AddNanoseconds(-calendar.Nanosecond); calendar.AddSeconds(-calendar.Second); calendar.AddMinutes(-calendar.Minute); calendar.AddHours(-calendar.Hour); calendar.AddSeconds(Convert.ToInt32(FromTime.Time.TotalSeconds)); DateTimeOffset fromTime = calendar.GetDateTime(); calendar.SetDateTime(ToDate.Date); calendar.AddNanoseconds(-calendar.Nanosecond); calendar.AddSeconds(-calendar.Second); calendar.AddMinutes(-calendar.Minute); calendar.AddHours(-calendar.Hour); calendar.AddSeconds(Convert.ToInt32(ToTime.Time.TotalSeconds)); DateTimeOffset toTime = calendar.GetDateTime(); notificationString += timestampFormatter.Format(fromTime); notificationString += " To "; notificationString += timestampFormatter.Format(toTime); if (toTime.ToFileTime() < fromTime.ToFileTime()) { rootPage.NotifyUser("Invalid time span. 'To Time' must be equal or more than 'From Time'", NotifyType.ErrorMessage); // Enable subsequent history retrieval while the async operation is in progress GetHistory.IsEnabled = true; } else { TimeSpan span; span = TimeSpan.FromTicks(toTime.Ticks - fromTime.Ticks); rootPage.NotifyUser(notificationString, NotifyType.StatusMessage); historyReadings = await Pedometer.GetSystemHistoryAsync(fromTime, span); } } if (historyReadings != null) { foreach (PedometerReading reading in historyReadings) { HistoryRecord record = new HistoryRecord(reading); historyRecords.Add(record); } rootPage.NotifyUser("History retrieval completed", NotifyType.StatusMessage); } } catch (UnauthorizedAccessException) { rootPage.NotifyUser("User has denied access to activity history", NotifyType.ErrorMessage); } // Finally, re-enable history retrieval GetHistory.IsEnabled = true; }
public void SetHeader(string header, DateTimeOffset dt) { Headers[header] = dt.ToFileTime().ToString(); }
public bool LookupFileInfo() { _fileInfo = _options.FileProvider.GetFileInfo(_subPath.Value); if (_fileInfo.Exists) { _length = _fileInfo.Length; DateTimeOffset last = _fileInfo.LastModified; // Truncate to the second. _lastModified = new DateTimeOffset(last.Year, last.Month, last.Day, last.Hour, last.Minute, last.Second, last.Offset); long etagHash = _lastModified.ToFileTime() ^ _length; _etag = new EntityTagHeaderValue('\"' + Convert.ToString(etagHash, 16) + '\"'); } return _fileInfo.Exists; }
public void StaticFileChunkHandler( HttpListenerRequest req, HttpListenerResponse res, string dir = "") { string absolutePath = req.Url.AbsolutePath; string str1 = absolutePath.Substring(absolutePath.Substring(1).IndexOf("/", StringComparison.OrdinalIgnoreCase) + 2); string str2 = string.IsNullOrEmpty(dir) ? Path.Combine(this.mRootDir, str1.Replace("/", "\\")) : Path.Combine(dir, str1.Replace("/", "\\")); int num1 = 0; while (!System.IO.File.Exists(str2)) { ++num1; Thread.Sleep(100); if (num1 == 20) { break; } } int num2 = 0; if (System.IO.File.Exists(str2)) { FileInfo fileInfo = new FileInfo(str2); long length = fileInfo.Length; DateTimeOffset lastWriteTimeUtc = (DateTimeOffset)fileInfo.LastWriteTimeUtc; DateTimeOffset universalTime = new DateTimeOffset(lastWriteTimeUtc.Year, lastWriteTimeUtc.Month, lastWriteTimeUtc.Day, lastWriteTimeUtc.Hour, lastWriteTimeUtc.Minute, lastWriteTimeUtc.Second, lastWriteTimeUtc.Offset).ToUniversalTime(); long num3 = universalTime.ToFileTime() ^ length; if (string.Equals("\"" + Convert.ToString(num3, 16) + "\"", req.Headers.Get("If-None-Match"), StringComparison.InvariantCultureIgnoreCase) && string.Equals(Convert.ToString((object)universalTime, (IFormatProvider)CultureInfo.InvariantCulture), req.Headers.Get("If-Modified-Since"), StringComparison.InvariantCultureIgnoreCase)) { res.StatusCode = 304; res.StatusDescription = "Not Modified."; } else { if (str2.EndsWith(".flv", StringComparison.OrdinalIgnoreCase)) { res.Headers.Add("Content-Type: video/x-flv"); } if (str2.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { res.Headers.Add("Content-Type: image/png"); } res.Headers.Add("Cache-Control: public,max-age=120"); res.Headers.Add("ETag: \"" + Convert.ToString(num3, 16) + "\""); res.Headers.Add("Last-Modified: " + Convert.ToString((object)universalTime, (IFormatProvider)CultureInfo.InvariantCulture)); int count1 = 1048576; bool flag = false; FileStream fileStream = new FileStream(str2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); while (true) { byte[] buffer = new byte[count1]; int count2 = fileStream.Read(buffer, 0, count1); if (count2 != 0) { res.OutputStream.Write(buffer, 0, count2); flag = true; } else if (!(num2++ == 50 | flag)) { Thread.Sleep(100); } else { break; } } fileStream.Close(); } } else { Logger.Error(string.Format((IFormatProvider)CultureInfo.InvariantCulture, "File {0} doesn't exist", (object)str2)); res.StatusCode = 404; res.StatusDescription = "Not Found."; } }
public static byte[] FromDateTimeOffset(DateTimeOffset data, DateTimeOffset?timestamp = null) => BitConverter.GetBytes(data.ToFileTime()).AppendTimestamp(timestamp);