public void Attach(byte[] streamId, byte[] streamIdToAttach, DateTime expiresAt) { if (ByteArrayHelper.Compare(streamId, streamIdToAttach)) throw new ArgumentException("Attaching a stream to itself is now allowed."); var stream = repository.Load(streamId); var result = stream.Attach(streamIdToAttach, expiresAt.ToFileTimeUtc()); if (result.IsSuccessful) repository.AttachStream(streamId, streamIdToAttach, expiresAt.ToFileTimeUtc()); }
void FixedUpdate() { for (int i = 0; i < buildTimes.Length; i++) { if (buildTimes[i].state == TroopState.Training) { System.DateTime dt1 = System.Convert.ToDateTime("1970-1-1 00:00:00"); long now = System.DateTime.Now.ToFileTimeUtc() - dt1.ToFileTimeUtc(); float a = now / 10000000; int aa = Mathf.FloorToInt(a); if (aa > buildTimes[i].endTime) { int end = aa - buildTimes [i].endTime; int start = aa - buildTimes [i].startTime; Transform trans = buildSlot [i].transform; Transform timeTrans = trans.FindChild("Time_Pro"); Transform labTime = timeTrans.FindChild("Lab_Time"); Transform progressbar = timeTrans.FindChild("ProgressBar"); UILabel label = labTime.GetComponent <UILabel> (); label.text = end.ToString(); UIProgressBar progress = progressbar.GetComponent <UIProgressBar> (); progress.value = 1f - end / start; } } } }
public sealed override byte[] EncodeUtcTime(DateTime utcTime) { long ft = utcTime.ToFileTimeUtc(); unsafe { return Interop.Crypt32.CryptEncodeObjectToByteArray(CryptDecodeObjectStructType.PKCS_UTC_TIME, &ft); } }
/// <summary> /// Converts DateTime to Win32 FileTime format /// </summary> public static Win32FileTime DateTimeToFiletime( DateTime time ) { Win32FileTime ft; var fileTime = time.ToFileTimeUtc( ); ft.DateTimeLow = ( uint ) ( fileTime & 0xFFFFFFFF ); ft.DateTimeHigh = ( uint ) ( fileTime >> 32 ); return ft; }
public static void Set(PublishedFileId_t item, System.DateTime lastModified) { InstalledLanguageData installedLanguageData = new InstalledLanguageData(); installedLanguageData.PublishedFileId = item.m_PublishedFileId; installedLanguageData.LastModified = lastModified.ToFileTimeUtc(); YamlIO.Save(installedLanguageData, FilePath(), null); }
public static string GetFileMd5(string fileName, DateTime modified) { fileName += modified.ToFileTimeUtc(); char[] fileNameChars = fileName.ToCharArray(); byte[] buffer = new byte[_stringEncoder.GetByteCount(fileNameChars, 0, fileName.Length, true)]; _stringEncoder.GetBytes(fileNameChars, 0, fileName.Length, buffer, 0, true); return BitConverter.ToString(_md5CryptoProvider.ComputeHash(buffer)).Replace("-", string.Empty); }
static FILETIME DateTimeToFILETIME(DateTime time) { FILETIME ft; var value = time.ToFileTimeUtc(); ft.dwLowDateTime = (int)(value & 0xFFFFFFFF); ft.dwHighDateTime = (int)(value >> 32); return ft; }
public static FILETIME DateTimeToFiletime(DateTime time) { FILETIME ft; long hFT1 = time.ToFileTimeUtc(); ft.dwLowDateTime = (uint)(hFT1 & 0xFFFFFFFF); ft.dwHighDateTime = (uint)(hFT1 >> 32); return ft; }
public static FILETIME ToFileTimeStructureUtc(DateTime dateTime) { var value = dateTime.ToFileTimeUtc(); return new FILETIME { dwHighDateTime = unchecked((int)((value >> 32) & 0xFFFFFFFF)), dwLowDateTime = unchecked((int)(value & 0xFFFFFFFF)) }; }
public void Detach(byte[] streamId, byte[] streamIdToDetach, DateTime detachedSince) { if (ByteArrayHelper.Compare(streamId, streamIdToDetach)) throw new ArgumentException("Detaching a stream from itself is now allowed."); var stream = repository.Load(streamId); var result = stream.Detach(streamIdToDetach, detachedSince); if (result.IsSuccessful) repository.DetachStream(streamId, streamIdToDetach, detachedSince.ToFileTimeUtc()); }
// 日志初始化 private static void Init() { mIsInit = true; System.DateTime dt = System.DateTime.Now; mLogFileName = Application.persistentDataPath + "/" + dt.ToFileTimeUtc() + ".log"; mFlushTimer.Enabled = true; mFlushTimer.Elapsed += new ElapsedEventHandler(WriteLog); UnityEngine.Debug.Log("Output log file in: " + mLogFileName); }
/// <summary> /// Create a path to queue for the given <paramref name="peer"/> and <paramref name="messageQueuedTime"/>. /// </summary> /// <param name="peer">The peer to build the path for.</param> /// <param name="messageQueuedTime">The message file time to build a path for.</param> /// <returns>A path to queue for the given <paramref name="peer"/> and <paramref name="messageQueuedTime"/>.</returns> public static string MessageLocation(IPeer peer, DateTime messageQueuedTime) { var messageLocation = string.Format( CultureInfo.InvariantCulture, "/{0}/queue/{1}", peer.EscapePeerAddress(), messageQueuedTime.ToFileTimeUtc()); return messageLocation; }
public static void WaitThenDoStuff(DateTime time, Action stuff) { Task.Run(() => { IntPtr timer = NativeMethods.CreateWaitableTimer(IntPtr.Zero, 1, null); long abs_utc_time = time.ToFileTimeUtc(); NativeMethods.SetWaitableTimer(timer, ref abs_utc_time, 0, IntPtr.Zero, IntPtr.Zero, 1); NativeMethods.WaitForSingleObject(timer, NativeMethods.INFINITE); stuff(); }); }
//获取当前队伍某位置的单位的训练状态 public TroopState GetTroopState(int index) { MarchVo march = playerProxy.marchList [marchIndex]; //临时处理 TroopVo troop = null; if (march.troopList.Count <= index) { if (addTrainList.Count > index - march.troopList.Count) { troop = addTrainList [index - march.troopList.Count]; } } else { troop = march.troopList [index]; } List <Tab_RoleBaseAttr> attrList = TableManager.GetRoleBaseAttrByID(troop.type); Tab_RoleBaseAttr roleAttr = attrList [troop.level - 1]; int totalHP = roleAttr.MaxHP * 18; if (troop.health < totalHP) { for (int i = 0; i < playerProxy.city.trainList.Count; i++) { if (playerProxy.city.trainList[i].queueIndex == troop.queueIndex) { if (playerProxy.city.trainList[i].troopType <= 0) { break; } //类型为0说明没有训练了 时间到了等于训练结束了 System.DateTime dt1 = System.Convert.ToDateTime("1970-1-1 00:00:00"); long now = System.DateTime.Now.ToFileTimeUtc() - dt1.ToFileTimeUtc(); float a = now / 10000000; int aa = Mathf.FloorToInt(a); //等于0也算是空闲 if (playerProxy.city.trainList[i].troopType >= 0) { if (playerProxy.city.trainList[i].endTime <= aa) { return(TroopState.Training); //训练中 } } } } return(TroopState.NeedTrain); } return(TroopState.TrainFull); }
public static bool IsValidValue(DateTime value) { var flag = true; try { value.ToFileTimeUtc(); } catch { flag = false; } return flag; }
private static byte[] Encode(DateTime signingTime) { long val = signingTime.ToFileTimeUtc(); System.Security.Cryptography.SafeLocalAllocHandle handle = System.Security.Cryptography.CAPI.LocalAlloc(0x40, new IntPtr(Marshal.SizeOf(typeof(long)))); Marshal.WriteInt64(handle.DangerousGetHandle(), val); byte[] encodedData = new byte[0]; if (!System.Security.Cryptography.CAPI.EncodeObject("1.2.840.113549.1.9.5", handle.DangerousGetHandle(), out encodedData)) { throw new CryptographicException(Marshal.GetLastWin32Error()); } handle.Dispose(); return encodedData; }
public static bool IsValidValue(DateTime value) { bool result = true; try { value.ToFileTimeUtc(); } catch { result = false; } return result; }
/// <summary> /// Creates a new instance of the FILETIME struct. /// </summary> /// <param name="dateTime">A <see cref="DateTime"/> object to copy data from.</param> public FILETIME(DateTime dateTime) { // Get the file time as a long in Utc // long fileTime = dateTime.ToFileTimeUtc(); // Copy the low bits // dwLowDateTime = (DWORD)(fileTime & 0xFFFFFFFF); // Copy the high bits // dwHighDateTime = (DWORD)(fileTime >> 32); }
public void DataTimeTransfer(ref long dataTimeValue) { DateTime dtServerTime = new DateTime(2016, 2, 8); DateTime dtFromClient = DateTime.FromFileTimeUtc(dataTimeValue); if (dtServerTime == dtFromClient) { dataTimeValue = dtServerTime.ToFileTimeUtc(); } else { dataTimeValue = -1; } }
public static InvitationInfo Invitations(DateTime since) { string parameters = "id=" + Properties.Settings.Default.ID + "&secret=" + Properties.Settings.Default.Secret + "&since=" + since.ToFileTimeUtc().ToString(); HttpWebRequest req = WebRequest.Create(MakeUrl("Invitations", parameters)) as HttpWebRequest; req.KeepAlive = true; req.Method = "GET"; using (var response = req.GetResponse()) using (var reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)) { var serializer = new JavaScriptSerializer(); return serializer.Deserialize<InvitationInfo>(reader.ReadToEnd()); } }
private bool SetSymLinkLastWriteTime(string fileName, DateTime lastWriteTime) { SafeFileHandle handle = WindowsNativeLibrary.CreateFile(fileName, WindowsNativeLibrary.FileAccess.FILE_WRITE_ATTRIBUTES, FileShare.None, IntPtr.Zero, (FileMode)3, FileAttributes.ReparsePoint, IntPtr.Zero); if (handle.IsInvalid) { return false; } //long lpCreationTime = File.GetCreationTimeUtc(fileName).ToFileTimeUtc(); //long lpLastAccessTime = File.GetLastAccessTimeUtc(fileName).ToFileTimeUtc(); long lpLastWriteTime = lastWriteTime.ToFileTimeUtc(); if (!WindowsNativeLibrary.SetFileTime(handle, ref lpLastWriteTime, ref lpLastWriteTime, ref lpLastWriteTime)) { Console.WriteLine(Marshal.GetLastWin32Error()); return false; } return true; }
public XmlDocument GetNewFeed(int nodesToChange, DateTime newUpdateDate, IDataMunger dataMunger) { //make int array size of nodesToChange int[] nodeIndices = new int[nodesToChange]; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(this.xmlFilePath); XmlNamespaceManager nsmanager = new XmlNamespaceManager(xmlDoc.NameTable); nsmanager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); //xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns="http://www.w3.org/2005/Atom" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://schemas.sage.com/sdata/http/2008/1" xmlns:sme="http://schemas.sage.com/sdata/sme/2007" xmlns:sdata="http://schemas.sage.com/sdata/2008/1" var nodeList = xmlDoc.SelectNodes("//atom:entry", nsmanager); //fill int array with randomn numbers between zero and {number of AtomEntries in feed}, all different int maxCount = nodeList.Count - 1; Random rand = new Random(DateTime.Now.Millisecond); for(int loop = 0; loop < nodesToChange; loop++) { int index = rand.Next(maxCount); nodeIndices[loop] = index; } //get corresponding node for each foreach (int index in nodeIndices) { XmlNode node = nodeList[index]; //set update date node.SelectSingleNode("//atom:updated", nsmanager).InnerText = newUpdateDate.ToFileTimeUtc().ToString(); //call datamunger on node dataMunger.MungeNodeData(ref node); } //return altered document return xmlDoc; }
public void ToFileTimeUtc () { // Randomly generated time outside DST. var utc = new DateTime (1993, 01, 28, 08, 49, 48, DateTimeKind.Utc); var local = utc.ToLocalTime (); var unspecified = new DateTime (1993, 01, 28, 08, 49, 48); Assert.AreEqual (DateTimeKind.Utc, utc.Kind); Assert.AreEqual (DateTimeKind.Local, local.Kind); Assert.AreEqual (DateTimeKind.Unspecified, unspecified.Kind); Assert.AreEqual (628638077880000000, utc.Ticks); Console.WriteLine (local.Ticks - utc.Ticks); var offset = TimeZone.CurrentTimeZone.GetUtcOffset (local); var utcFt = utc.ToFileTime (); var localFt = local.ToFileTime (); var unspecifiedFt = unspecified.ToFileTime (); var utcUft = utc.ToFileTimeUtc (); var localUft = local.ToFileTimeUtc (); var unspecifiedUft = unspecified.ToFileTimeUtc (); Assert.AreEqual (123726845880000000, utcFt); Assert.AreEqual (utcFt, localFt); Assert.AreEqual (offset.Ticks, utcFt - unspecifiedFt); Assert.AreEqual (utcFt, utcUft); Assert.AreEqual (utcFt, localUft); Assert.AreEqual (utcFt, unspecifiedUft); }
[System.Security.SecuritySafeCritical] // auto-generated public unsafe static void SetLastAccessTimeUtc(String path,DateTime lastAccessTimeUtc) { using (SafeFileHandle handle = Directory.OpenHandle(path)) { Win32Native.FILE_TIME fileTime = new Win32Native.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc()); bool r = Win32Native.SetFileTime(handle, null, &fileTime, null); if (!r) { int errorCode = Marshal.GetLastWin32Error(); __Error.WinIOError(errorCode, path); } } }
private void WriteInternal( DateTime occurenceTime, DateTime receiveTime, string inputProtocol, string source, string manifestId, byte[] eventPayload) { // Maximum record size is 64K for both system and user data, so counting 88 bytes for system data here as well var maxPayloadSize = MaxPayloadSize - (manifestId.Length + source.Length + inputProtocol.Length) * 2; if (maxPayloadSize <= 0) { throw new ArgumentOutOfRangeException(); } var occurenceFileTimeUtc = occurenceTime.ToFileTimeUtc(); var receiveFileTimeUtc = receiveTime.ToFileTimeUtc(); if (eventPayload.Length <= maxPayloadSize) { this.WriteBinaryPayload( occurenceFileTimeUtc, receiveFileTimeUtc, inputProtocol, source, manifestId, unchecked((uint)(eventPayload.Length)), eventPayload); } else { // User data for chunked event is 12 bytes greather than non-chunked event maxPayloadSize -= 12; var chunks = eventPayload.Split(maxPayloadSize); lock (this.writeChuckedBinaryPayloadGuard) { var packageId = unchecked(this.currentPackageId++); for (uint i = 0; i < chunks.Length; i++) { this.WriteChunkedBinaryPayload( packageId, occurenceFileTimeUtc, receiveFileTimeUtc, inputProtocol, source, manifestId, unchecked((uint)(chunks.Length)), i, unchecked((uint)(chunks[i].Length)), chunks[i]); } } } }
private void WriteManifestInternal( DateTime occurenceTime, DateTime receiveTime, string inputProtocol, string source, string manifestId, string manifestData) { // Maximum record size is 64K for both system and user data, so counting 88 bytes for system data here as well var maxPayloadSize = (MaxPayloadSize / 2) - (manifestId.Length + source.Length + inputProtocol.Length) * 2; if (maxPayloadSize <= 0) { throw new ArgumentOutOfRangeException(); } var occurenceFileTimeUtc = occurenceTime.ToFileTimeUtc(); var receiveFileTimeUtc = receiveTime.ToFileTimeUtc(); if (manifestData.Length <= maxPayloadSize) { this.WriteManifestPayload( occurenceFileTimeUtc, receiveFileTimeUtc, inputProtocol, source, manifestId, manifestData); } else { // User data for chunked event is 12 bytes greather than non-chunked event maxPayloadSize -= 12; List<string> chunks = new List<string>(manifestData.WholeChunks(maxPayloadSize)); lock (this.writeChuckedManifestPayloadGuard) { var packageId = unchecked(this.currentManifestPackageId++); int i = 0; foreach (string chunk in chunks) { this.WriteChunkedManifestPayload( packageId, occurenceFileTimeUtc, receiveFileTimeUtc, inputProtocol, source, manifestId, chunks.Count, i++, chunk); } } } }
public static unsafe void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc) { var normalizedPath = Path.NormalizeLongPath(Path.GetFullPath(path)); using (SafeFileHandle handle = GetDirectoryHandle(normalizedPath)) { var fileTime = new NativeMethods.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc()); bool r = NativeMethods.SetFileTime(handle, null, null, &fileTime); if (!r) { int errorCode = Marshal.GetLastWin32Error(); Common.ThrowIOError(errorCode, path); } } }
public unsafe static void SetLastWriteTimeUtc(String path, DateTime lastWriteTimeUtc) { SafeFileHandle handle; using(OpenFile(path, FileAccess.Write, out handle)) { Win32Native.FILE_TIME fileTime = new Win32Native.FILE_TIME(lastWriteTimeUtc.ToFileTimeUtc()); bool r = Win32Native.SetFileTime(handle, null, null, &fileTime); if (!r) { int errorCode = Marshal.GetLastWin32Error(); __Error.WinIOError(errorCode, path); } } }
/// <summary> /// Compresion utility function for converting a DateTime structure /// to old-style date and time values. /// </summary> public static void DateTimeToDosDateAndTime( DateTime dateTime, out short dosDate, out short dosTime) { dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Utc); long filetime = dateTime.ToFileTimeUtc(); SafeNativeMethods.FileTimeToDosDateTime(ref filetime, out dosDate, out dosTime); }
/// <summary> /// Update the file times on the given file handle. /// </summary> public static unsafe void SetFileCreationTime(SafeFileHandle hFile, DateTime creationTime) { FILETIME fileCreationTime = new FILETIME(creationTime.ToFileTimeUtc()); if (!SetFileTime(hFile, &fileCreationTime, null, null)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } }
/// <summary> /// Initialize a new instance of FILETIME structure from the specified DateTime object. /// </summary> /// <param name="dateTime"> /// The DateTime object used to initialize the value of the new instance. /// </param> /// <returns>A FILETIME.</returns> public static _FILETIME ToFileTime(DateTime dateTime) { _FILETIME retVal; if (dateTime == DateTime.MaxValue.ToUniversalTime()) { retVal.dwLowDateTime = 0xFFFFFFFFu; // According to TD section 2.5 KERB_VALIDATION_INFO, // "(If the session should not expire,) // (If the client should not be logged off,) // (If the password will not expire,) // this structure SHOULD have the // dwHighDateTime member set to 0x7FFFFFFF and the dwLowDateTime member // set to 0xFFFFFFFF." retVal.dwHighDateTime = 0x7FFFFFFFu; } else { long fileTime = dateTime.ToFileTimeUtc(); retVal.dwLowDateTime = (uint)(fileTime & 0xFFFFFFFF); retVal.dwHighDateTime = (uint)((fileTime >> 32) & 0xFFFFFFFF); } return retVal; }
public static long ToUnixTimeUtc(DateTime dt) { return ToUnixTimeUtc(dt.ToFileTimeUtc()); }
public unsafe static void SetLastAccessTimeUtc(String path,DateTime lastAccessTimeUtc) { #if !FEATURE_PAL if ((Environment.OSInfo & Environment.OSName.WinNT) == Environment.OSName.WinNT) #endif //!FEATURE_PAL { using (SafeFileHandle handle = Directory.OpenHandle(path)) { Win32Native.FILE_TIME fileTime = new Win32Native.FILE_TIME(lastAccessTimeUtc.ToFileTimeUtc()); bool r = Win32Native.SetFileTime(handle, null, &fileTime, null); if (!r) { int errorCode = Marshal.GetLastWin32Error(); __Error.WinIOError(errorCode, path); } } } }
public IEnumerable<Activity> Load(Feed feed, DateTime timestamp) { var result = store.Get(feed, new Paging(timestamp.ToFileTimeUtc(), 20)); return result; }