コード例 #1
0
ファイル: Registry.cs プロジェクト: praveeds/jOVAL
            public static DateTime GetLastWriteTime(int hive, String subkey)
            {
                UIntPtr hKey = UIntPtr.Zero;
                int result = RegOpenKeyEx(hive, subkey, 0, KEYREAD, ref hKey);
                if (result != 0) {
                throw new System.ComponentModel.Win32Exception(result);
                }

                StringBuilder lpClass = new StringBuilder(1024);
                IntPtr lpcbClass = IntPtr.Zero;
                IntPtr lpReserved = IntPtr.Zero;
                uint lpcSubKeys;
                uint lpcbMaxSubKeyLen;
                uint lpcbMaxClassLen;
                uint lpcValues;
                uint lpcbMaxValueNameLen;
                uint lpcbMaxValueLen;
                uint lpcbSecurityDescriptor;
                FILETIME lastWriteTime = new FILETIME();
                result = RegQueryInfoKey(hKey, out lpClass, ref lpcbClass, lpReserved, out lpcSubKeys, out lpcbMaxSubKeyLen,
                     out lpcbMaxClassLen, out lpcValues, out lpcbMaxValueNameLen, out lpcbMaxValueLen,
                     out lpcbSecurityDescriptor, ref lastWriteTime);
                RegCloseKey(hKey);
                if (result != 0) {
                throw new System.ComponentModel.Win32Exception(result);
                }

                byte[] high = BitConverter.GetBytes(lastWriteTime.HighDateTime);
                byte[] low = BitConverter.GetBytes(lastWriteTime.LowDateTime);
                byte[] buff = new byte[high.Length + low.Length];
                Buffer.BlockCopy(low, 0, buff, 0, low.Length );
                Buffer.BlockCopy(high, 0, buff, low.Length, high.Length );
                long time = BitConverter.ToInt64(buff, 0);
                return DateTime.FromFileTimeUtc(time);
            }
コード例 #2
0
ファイル: WinApis.cs プロジェクト: CharlesZHENG/csexwb2
        public static DateTime FiletimeToDateTime(FILETIME fileTime)
        {
            if ((fileTime.dwHighDateTime == Int32.MaxValue) ||
                (fileTime.dwHighDateTime == 0 && fileTime.dwLowDateTime == 0))
            {
                // Not going to fit in the DateTime.  In the WinInet APIs, this is
                // what happens when there is no FILETIME attached to the cache entry.
                // We're going to use DateTime.MinValue as a marker for this case.
                return DateTime.MaxValue;
            }
            //long hFT2 = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
            //return DateTime.FromFileTimeUtc(hFT2);

            SYSTEMTIME syst = new SYSTEMTIME();
            SYSTEMTIME systLocal = new SYSTEMTIME();
            if (0 == FileTimeToSystemTime(ref fileTime, ref syst))
            {
                throw new ApplicationException("Error calling FileTimeToSystemTime: " + Marshal.GetLastWin32Error().ToString());
            }
            if (0 == SystemTimeToTzSpecificLocalTime(IntPtr.Zero, ref syst, out systLocal))
            {
                throw new ApplicationException("Error calling SystemTimeToTzSpecificLocalTime: " + Marshal.GetLastWin32Error().ToString());
            }
            return new DateTime(systLocal.Year, systLocal.Month, systLocal.Day, systLocal.Hour, systLocal.Minute, systLocal.Second);
        }
コード例 #3
0
 public static extern WindowsError RegQueryInfoKeyW(
     RegistryKeyHandle hKey,
     SafeHandle lpClass,
     ref uint lpcClass,
     IntPtr lpReserved,
     out uint lpcSubKeys,
     out uint lpcMaxSubKeyLen,
     out uint lpcMaxClassLen,
     out uint lpcValues,
     out uint lpcMaxValueNameLen,
     out uint lpcMaxValueLen,
     out uint lpcbSecurityDescriptor,
     out FILETIME lpftLastWriteTime);
コード例 #4
0
        static public DateTime FileTimeToDateTime(FILETIME FileTime)
        {
            long FileTimeLong = (((long)FileTime.dwHighDateTime) << 32) | ((long)FileTime.dwLowDateTime);

            if (FileTimeLong == 0)
            {
                return(DateTime.MinValue);
            }
            else
            {
                return(DateTime.FromFileTime(FileTimeLong));
            }
        }
コード例 #5
0
        private unsafe void FindByTime(DateTime dateTime, int compareResult)
        {
            FILETIME fileTime = FILETIME.FromDateTime(dateTime);

            FindCore(
                delegate(SafeCertContextHandle pCertContext)
            {
                int comparison = Interop.crypt32.CertVerifyTimeValidity(ref fileTime,
                                                                        pCertContext.CertContext->pCertInfo);
                GC.KeepAlive(pCertContext);
                return(comparison == compareResult);
            });
        }
コード例 #6
0
    public void method_17(DateTime A_0)
    {
        if (this.method_6() != PIDSI.EditTime)
        {
            A_0 = A_0.ToUniversalTime();
        }
        ulong    num      = (ulong)(A_0.Ticks - 0x701ce1722770000L);
        FILETIME filetime = new FILETIME {
            dwHighDateTime = (int)((num & -4294967296L) >> 0x20),
            dwLowDateTime  = (int)(num & ((ulong)0xffffffffL))
        };

        this.method_11(filetime);
    }
コード例 #7
0
ファイル: Utils.cs プロジェクト: ARLM-Attic/sharpbits
        internal static FILETIME DateTime2FileTime(DateTime dateTime)
        {
            long fileTime = 0;

            if (dateTime != DateTime.MinValue)      //Checking for MinValue
            {
                fileTime = dateTime.ToFileTime();
            }
            FILETIME resultingFileTime = new FILETIME();

            resultingFileTime.dwLowDateTime  = (uint)(fileTime & 0xFFFFFFFF);
            resultingFileTime.dwHighDateTime = (uint)(fileTime >> 32);
            return(resultingFileTime);
        }
コード例 #8
0
ファイル: CpuMonitor.cs プロジェクト: Pircs/Yi
        public float GetUsage()
        {
            var cpuCopy = _cpuUsage;

            if (Interlocked.Increment(ref _runCount) == 1)
            {
                if (!EnoughTimePassed)
                {
                    Interlocked.Decrement(ref _runCount);
                    return(cpuCopy);
                }

                FILETIME sysIdle, sysKernel, sysUser;

                var process  = Process.GetCurrentProcess();
                var procTime = process.TotalProcessorTime;

                if (!NativeMethods.GetSystemTimes(out sysIdle, out sysKernel, out sysUser))
                {
                    Interlocked.Decrement(ref _runCount);
                    return(cpuCopy);
                }

                if (!IsFirstRun)
                {
                    var sysKernelDiff = SubtractTimes(sysKernel, _prevSysKernel);
                    var sysUserDiff   = SubtractTimes(sysUser, _prevSysUser);

                    var sysTotal = sysKernelDiff + sysUserDiff;

                    var procTotal = procTime.Ticks - _prevProcTotal.Ticks;

                    if (sysTotal > 0)
                    {
                        _cpuUsage = 100.0f * procTotal / sysTotal * Environment.ProcessorCount;
                    }
                }

                _prevProcTotal = procTime;
                _prevSysKernel = sysKernel;
                _prevSysUser   = sysUser;

                _lastRun = DateTime.UtcNow;

                cpuCopy = _cpuUsage;
            }
            Interlocked.Decrement(ref _runCount);

            return((float)Math.Round(cpuCopy, 2));
        }
コード例 #9
0
    public DateTime method_16()
    {
        FILETIME filetime = this.method_10();
        long     ticks    = (filetime.dwHighDateTime << 0x20) + ((long)((ulong)filetime.dwLowDateTime));

        ticks += 0x701ce1722770000L;
        DateTime time = new DateTime(ticks);

        if (this.method_6() != PIDSI.EditTime)
        {
            time = time.ToLocalTime();
        }
        return(time);
    }
コード例 #10
0
        private static DateTime ToDateTime(FILETIME time)
        {
            var high     = (ulong)time.dwHighDateTime;
            var low      = (uint)time.dwLowDateTime;
            var fileTime = (long)((high << 32) + low);

            try
            {
                return(DateTime.FromFileTimeUtc(fileTime));
            }
            catch
            {
                return(DateTime.FromFileTimeUtc(0xFFFFFFFF));
            }
        }
コード例 #11
0
        /// <summary>
        /// Query the underlying OS to retrieve the current system file time
        /// </summary>
        /// <returns>System time as file time</returns>
        public static ulong GetSystemTimeAsFileTimeUlong()
        {
            FILETIME fileTimeNow = new FILETIME();
            ulong    now;

            // Get the time as a FILETIME
            SafeNativeMethods.GetSystemTimePreciseAsFileTime(out fileTimeNow);

            // Unpack filetime
            now  = (uint)fileTimeNow.dwHighDateTime;
            now  = now << 32;
            now += (uint)fileTimeNow.dwLowDateTime;

            return(now);
        }
コード例 #12
0
ファイル: DateExtensions.cs プロジェクト: zhuxb711/Files
        public static DateTime ToDateTime(this FILETIME time)
        {
            uint  low      = (uint)time.dwLowDateTime;
            ulong high     = (ulong)time.dwHighDateTime;
            long  fileTime = (long)((high << 32) + low);

            try
            {
                return(DateTime.FromFileTimeUtc(fileTime));
            }
            catch
            {
                return(DateTime.FromFileTimeUtc(0xFFFFFFFF));
            }
        }
コード例 #13
0
ファイル: DiffProcessing.cs プロジェクト: blaubart69/CmpTrees
        private static string ConvertFiletimeToString(FILETIME filetime, string FullFilename, string KindOfFiletime)
        {
            string result;

            try
            {
                result = Misc.FiletimeToString(filetime);
            }
            catch (System.ComponentModel.Win32Exception wex)
            {
                result = "error";
                System.Console.Error.WriteLine($"error converting filetime: value 0x{Misc.FiletimeToLong(filetime):x}, message: {wex.Message}, TypeOf: {KindOfFiletime}, Filename: [{FullFilename}]");
            }
            return(result);
        }
コード例 #14
0
        static void Main(string[] args)
        {
            Int64 time  = 131611356934580000;
            var   data  = BitConverter.GetBytes(time);
            var   ftime = new FILETIME
            {
                dwLowDateTime  = BitConverter.ToInt32(data, 0),
                dwHighDateTime = BitConverter.ToInt32(data, 4)
            };

            Console.WriteLine($"FileTime - Low : {ftime.dwLowDateTime}, Hight : {ftime.dwHighDateTime}");
            var fileTime   = (((long)ftime.dwHighDateTime) << 32) + ftime.dwLowDateTime;
            var systemTime = DateTime.FromFileTime(fileTime);

            Console.ReadLine();
        }
コード例 #15
0
        private static DateTime ToDateTime(FILETIME fileTime)
        {
            // thanks to http://stackoverflow.com/questions/6083733/not-being-able-to-convert-from-filetime-windows-time-to-datetime-i-get-a-dif
            // adapted from answer down at bottom

            long longValue;

            byte[] highBytes = BitConverter.GetBytes(fileTime.dwHighDateTime);
            Array.Resize(ref highBytes, 8);

            longValue = BitConverter.ToInt64(highBytes, 0);
            longValue = longValue << 32;
            longValue = longValue | fileTime.dwLowDateTime;

            return(DateTime.FromFileTime(longValue));
        }
コード例 #16
0
        static float GetUsage(Process process, out float processorCpuUsage)
        {
            processorCpuUsage = 0.0f;

            float    _processCpuUsage = 0.0f;
            FILETIME sysIdle, sysKernel, sysUser;

            TimeSpan procTime = process.TotalProcessorTime;

            if (!GetSystemTimes(out sysIdle, out sysKernel, out sysUser))
            {
                return(0.0f);
            }

            if (_prevProcTotal != TimeSpan.MinValue)
            {
                ulong sysKernelDiff = SubtractTimes(sysKernel, _prevSysKernel);
                ulong sysUserDiff   = SubtractTimes(sysUser, _prevSysUser);
                ulong sysIdleDiff   = SubtractTimes(sysIdle, _prevSysIdle);

                ulong sysTotal    = sysKernelDiff + sysUserDiff;
                long  kernelTotal = (long)(sysKernelDiff - sysIdleDiff);

                if (kernelTotal < 0)
                {
                    kernelTotal = 0;
                }

                processorCpuUsage = (float)((((ulong)kernelTotal + sysUserDiff) * 100.0) / sysTotal);

                long procTotal = (procTime.Ticks - _prevProcTotal.Ticks);

                if (sysTotal > 0)
                {
                    _processCpuUsage = (short)((100.0 * procTotal) / sysTotal);
                }
            }

            _prevProcTotal = procTime;
            _prevSysKernel = sysKernel;
            _prevSysUser   = sysUser;
            _prevSysIdle   = sysIdle;

            return(_processCpuUsage);
        }
コード例 #17
0
 static public DateTime GetFileCreationTime(string filepath)
 {
     try
     {
         using (Win32FileHandleHelper hDir = new Win32FileHandleHelper(filepath))
         {
             FILETIME lpCreationTime   = new FILETIME();
             FILETIME lpLastAccessTime = new FILETIME();
             FILETIME lpLastWriteTime  = new FILETIME();
             Kernel32.GetFileTime(hDir.Handle, ref lpCreationTime, ref lpLastAccessTime, ref lpLastWriteTime);
             return(FileTimeToDateTime(lpCreationTime));
         }
     }
     catch
     {
         return(DateTime.MinValue);
     }
 }
コード例 #18
0
        public static bool setLastWrite(string sFile, DateTime dt)
        {
            bool   bRet  = false;
            IntPtr hFile = CreateFile(sFile, EFileAccess.FILE_GENERIC_READ, EFileShare.Write, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Normal, IntPtr.Zero);

            if (hFile != null)
            {
                FILETIME ftCreation   = new FILETIME();
                FILETIME ftLastAccess = new FILETIME();
                FILETIME ftLastWrite  = new FILETIME();
                if (GetFileTime(hFile, ref ftCreation, ref ftLastAccess, ref ftLastWrite))
                {
                    FILETIME ftNewLastWrite = new FILETIME();
                    ftNewLastWrite = getFileTime(dt);
                    SetFileTime(hFile, ref ftCreation, ref ftLastAccess, ref ftNewLastWrite);
                }
            }
            return(bRet);
        }
コード例 #19
0
        private static RestartMgr.RmUniqueProcess Convert(ILockingProcessInfo process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }
            var fileTimeUtc = process.StartTime.ToFileTimeUtc();
            var filetime    = new FILETIME()
            {
                dwHighDateTime = (int)(fileTimeUtc >> 32),
                dwLowDateTime  = (int)(fileTimeUtc & (long)uint.MaxValue)
            };

            return(new RestartMgr.RmUniqueProcess()
            {
                DwProcessId = process.Id,
                ProcessStartTime = filetime
            });
        }
コード例 #20
0
 public Win32FileTimeInfo(string filepath)
 {
     try
     {
         using (Win32FileHandleHelper hDir = new Win32FileHandleHelper(filepath))
         {
             FILETIME lpCreationTime   = new FILETIME();
             FILETIME lpLastAccessTime = new FILETIME();
             FILETIME lpLastWriteTime  = new FILETIME();
             Kernel32.GetFileTime(hDir.Handle, ref lpCreationTime, ref lpLastAccessTime, ref lpLastWriteTime);
             CreationTime   = FileTimeToDateTime(lpCreationTime);
             LastAccessTime = FileTimeToDateTime(lpLastAccessTime);
             LastWriteTime  = FileTimeToDateTime(lpLastWriteTime);
         }
     }
     catch
     {
     }
 }
コード例 #21
0
        public static bool FsSetTime(string remoteName, FILETIME creationTime, FILETIME lastAccessTime, FILETIME lastWriteTime)
        {
            var result = false;

            try
            {
                result = Plugin.SetFileTime(
                    remoteName,
                    DateTimeUtil.FromFileTime(creationTime),
                    DateTimeUtil.FromFileTime(lastAccessTime),
                    DateTimeUtil.FromFileTime(lastWriteTime)
                    );
            }
            catch (Exception ex)
            {
                UnhandledError(ex);
            }
            return(result);
        }
コード例 #22
0
        internal static SensorReport FromNativeReport(Sensor originator, ISensorDataReport iReport)
        {
            SystemTime systemTimeStamp = new SystemTime();

            iReport.GetTimestamp(out systemTimeStamp);
            FILETIME ftTimeStamp = new FILETIME();

            SensorNativeMethods.SystemTimeToFileTime(ref systemTimeStamp, out ftTimeStamp);
            long     lTimeStamp = (((long)ftTimeStamp.dwHighDateTime) << 32) + (long)ftTimeStamp.dwLowDateTime;
            DateTime timeStamp  = DateTime.FromFileTime(lTimeStamp);

            SensorReport sensorReport = new SensorReport();

            sensorReport.originator = originator;
            sensorReport.timeStamp  = timeStamp;
            sensorReport.sensorData = SensorData.FromNativeReport(originator.internalObject, iReport);

            return(sensorReport);
        }
コード例 #23
0
        public static IEnumerable <object[]> GetCompareVersionAndDateData()
        {
            var empty = new string[0];

            var v1 = new Version(1, 0);
            var v2 = new Version(2, 0);

            var ft1 = new FILETIME {
                dwHighDateTime = 1
            };
            var ft2 = new FILETIME {
                dwHighDateTime = 2
            };

            Instance Mock(Version v = null, FILETIME ft = default(FILETIME))
            {
                var mock = new Mock <ISetupInstance2>();

                mock.As <ISetupPropertyStore>().Setup(x => x.GetNames()).Returns(empty);

                mock.Setup(x => x.GetInstallationVersion()).Returns(v?.ToString());
                mock.Setup(x => x.GetInstallDate()).Returns(ft);

                return(new Instance(mock.Object));
            }

            return(new[]
            {
                new object[] { null, null, 0 },
                new object[] { null, Mock(), -1 },
                new object[] { Mock(), null, 1 },
                new object[] { Mock(), Mock(v1), -1 },
                new object[] { Mock(v1), Mock(), 1 },
                new object[] { Mock(v1), Mock(v1), 0 },
                new object[] { Mock(v1), Mock(v2), -1 },
                new object[] { Mock(v2), Mock(v1), 1 },
                new object[] { Mock(v1, ft2), Mock(v2, ft1), -1 },
                new object[] { Mock(v2, ft1), Mock(v1, ft2), 1 },
                new object[] { Mock(v2, ft1), Mock(v2, ft2), -1 },
                new object[] { Mock(v2, ft2), Mock(v2, ft1), 1 },
            });
        }
コード例 #24
0
        /// <summary>
        /// Sets the date and time, in local time, that the file was last updated or written to.</summary>
        /// <param name="path">The file for which to set the creation date and time information.</param>
        /// <param name="lastWriteTime">A DateTime containing the value to set for the last write date and time of path. This value is expressed in local time.</param>
        public static void SetLastWriteTime(string path, DateTime lastWriteTime)
        {
            FILETIME ft;
            IntPtr   hFile = IntPtr.Zero;

            if (path == null)
            {
                throw new ArgumentNullException();
            }

            if (path.Length > 260)
            {
                throw new PathTooLongException();
            }

            if (path.Trim().Length == 0)
            {
                throw new ArgumentException();
            }

            hFile = CreateFile(path, FileAccess.Write, FileShare.Write, FileCreateDisposition.OpenExisting, 0);

            if ((int)hFile == InvalidHandle)
            {
                int e = Marshal.GetLastWin32Error();
                if ((e == 2) || (e == 3))
                {
                    throw new FileNotFoundException();
                }
                else
                {
                    throw new Exception("Unmanaged Error: " + e);
                }
            }

            ft = new FILETIME(lastWriteTime.ToFileTime());

            SetFileTime(hFile, null, ft, null);

            CloseHandle(hFile);
        }
コード例 #25
0
            public static DateTime GetLastWriteTime(int hive, String subkey)
            {
                UIntPtr hKey   = UIntPtr.Zero;
                int     result = RegOpenKeyEx(hive, subkey, 0, KEYREAD, ref hKey);

                if (result != 0)
                {
                    throw new System.ComponentModel.Win32Exception(result);
                }

                StringBuilder lpClass    = new StringBuilder(1024);
                IntPtr        lpcbClass  = IntPtr.Zero;
                IntPtr        lpReserved = IntPtr.Zero;
                uint          lpcSubKeys;
                uint          lpcbMaxSubKeyLen;
                uint          lpcbMaxClassLen;
                uint          lpcValues;
                uint          lpcbMaxValueNameLen;
                uint          lpcbMaxValueLen;
                uint          lpcbSecurityDescriptor;
                FILETIME      lastWriteTime = new FILETIME();

                result = RegQueryInfoKey(hKey, out lpClass, ref lpcbClass, lpReserved, out lpcSubKeys, out lpcbMaxSubKeyLen,
                                         out lpcbMaxClassLen, out lpcValues, out lpcbMaxValueNameLen, out lpcbMaxValueLen,
                                         out lpcbSecurityDescriptor, ref lastWriteTime);
                RegCloseKey(hKey);
                if (result != 0)
                {
                    throw new System.ComponentModel.Win32Exception(result);
                }

                byte[] high = BitConverter.GetBytes(lastWriteTime.HighDateTime);
                byte[] low  = BitConverter.GetBytes(lastWriteTime.LowDateTime);
                byte[] buff = new byte[high.Length + low.Length];
                Buffer.BlockCopy(low, 0, buff, 0, low.Length);
                Buffer.BlockCopy(high, 0, buff, low.Length, high.Length);
                long time = BitConverter.ToInt64(buff, 0);

                return(DateTime.FromFileTimeUtc(time));
            }
コード例 #26
0
        CopyIntPtr_to_WIN32_FIND_DATA(IntPtr pIn,
                                      ref WIN32_FIND_DATA pffd)
        {
            // Handy values for incrementing IntPtr pointer.
            int      i     = 0;
            int      cbInt = Marshal.SizeOf(i);
            FILETIME ft    = new FILETIME();
            int      cbFT  = Marshal.SizeOf(ft);

            // int dwFileAttributes
            pffd.dwFileAttributes = Marshal.ReadInt32(pIn);
            pIn = (IntPtr)((int)pIn + cbInt);

            // FILETIME ftCreationTime;
            Marshal.PtrToStructure(pIn, pffd.ftCreationTime);
            pIn = (IntPtr)((int)pIn + cbFT);

            // FILETIME ftLastAccessTime;
            Marshal.PtrToStructure(pIn, pffd.ftLastAccessTime);
            pIn = (IntPtr)((int)pIn + cbFT);

            // FILETIME ftLastWriteTime;
            Marshal.PtrToStructure(pIn, pffd.ftLastWriteTime);
            pIn = (IntPtr)((int)pIn + cbFT);

            // int nFileSizeHigh;
            pffd.nFileSizeHigh = Marshal.ReadInt32(pIn);
            pIn = (IntPtr)((int)pIn + cbInt);

            // int nFileSizeLow;
            pffd.nFileSizeLow = Marshal.ReadInt32(pIn);
            pIn = (IntPtr)((int)pIn + cbInt);

            // int dwOID;
            pffd.dwOID = Marshal.ReadInt32(pIn);
            pIn        = (IntPtr)((int)pIn + cbInt);

            // String cFileName;
            pffd.cFileName = Marshal.PtrToStringUni(pIn);
        }
コード例 #27
0
        public OpcDaVQTE[] Read(IList <string> itemIds, IList <TimeSpan> maxAge)
        {
            if (maxAge == null)
            {
                maxAge = new TimeSpan[itemIds.Count];
            }
            if (itemIds.Count != maxAge.Count)
            {
                throw new ArgumentException("Invalid size of maxAge", "maxAge");
            }

            int[] intMaxAge = ArrayHelpers.CreateMaxAgeArray(maxAge, itemIds.Count);

            string[] pszItemIDs     = itemIds.ToArray();
            var      ppvValues      = new object[pszItemIDs.Length];
            var      ppwQualities   = new short[pszItemIDs.Length];
            var      ppftTimeStamps = new FILETIME[pszItemIDs.Length];
            var      ppErrors       = new HRESULT[pszItemIDs.Length];

            DoComCall(ComObject, "IOPCItemIO::Read", () =>
                      ComObject.Read(pszItemIDs.Length, pszItemIDs, intMaxAge, out ppvValues, out ppwQualities,
                                     out ppftTimeStamps, out ppErrors), pszItemIDs.Length, pszItemIDs,
                      maxAge);

            var result = new OpcDaVQTE[itemIds.Count];

            for (int i = 0; i < ppvValues.Length; i++)
            {
                var vqte = new OpcDaVQTE
                {
                    Value     = ppvValues[i],
                    Quality   = ppwQualities[i],
                    Timestamp = FileTimeConverter.FromFileTime(ppftTimeStamps[i]),
                    Error     = ppErrors[i]
                };
                result[i] = vqte;
            }
            return(result);
        }
コード例 #28
0
        public static DateTime getFileTime(string sFile)
        {
            DateTime dt = new DateTime();

            IntPtr hFile = CreateFile(sFile, EFileAccess.FILE_GENERIC_READ, EFileShare.Write, IntPtr.Zero, ECreationDisposition.OpenExisting, EFileAttributes.Normal, IntPtr.Zero);

            if (hFile != IntPtr.Zero)
            {
                FILETIME ftCreation   = new FILETIME();
                FILETIME ftLastAccess = new FILETIME();
                FILETIME ftLastWrite  = new FILETIME();
                if (GetFileTime(hFile, ref ftCreation, ref ftLastAccess, ref ftLastWrite))
                {
                    SYSTEMTIME st = new SYSTEMTIME();
                    if (FileTimeToSystemTime(ref ftLastAccess, out st))
                    {
                        dt = getDateTime(st);
                    }
                }
            }
            return(dt);
        }
コード例 #29
0
        public static string GenerateDicomUniqueIdentifier()
        {
            SystemTime systemTime = new SystemTime();
            FILETIME   fileTime   = new FILETIME();
            uint       Tick;
            uint       HighWord;
            Random     rand = new Random();

            GetSystemTime(systemTime);
            SystemTimeToFileTime(systemTime, ref fileTime);
            Tick     = GetTickCount();
            HighWord = (uint)fileTime.dwHighDateTime + 0x146BF4;

            return(string.Format("1.2.840.114257.1.1{0:D010}{1:D05}{2:D05}{3:D05}{4:D05}{5:D05}{6:D05}",
                                 fileTime.dwLowDateTime,
                                 LOWORD(HighWord),
                                 HIWORD(HighWord | 0x10000000),
                                 LOWORD((uint)rand.Next()),
                                 HIWORD(Tick),
                                 LOWORD(Tick),
                                 LOWORD((uint)rand.Next())));
        }
コード例 #30
0
        /// <summary>
        /// Creates an array of item value result objects from the callback data.
        /// </summary>
        private ItemValueResult[] UnmarshalValues(
            int dwCount,
            int[] phClientItems,
            object[] pvValues,
            short[] pwQualities,
            OpcRcw.Da.FILETIME[] pftTimeStamps,
            int[] pErrors)
        {
            // contruct the item value results.
            ItemValueResult[] values = new ItemValueResult[dwCount];

            for (int ii = 0; ii < values.Length; ii++)
            {
                // lookup the external client handle.
                ItemIdentifier itemID = (ItemIdentifier)m_group.Items[phClientItems[ii]];

                values[ii] = new ItemValueResult(itemID);
                //values[ii].ClientHandle       = phClientItems[ii];
                values[ii].Value            = pvValues[ii];
                values[ii].Quality          = new Quality(pwQualities[ii]);
                values[ii].QualitySpecified = true;
                FILETIME output = new FILETIME();
                output.dwLowDateTime          = pftTimeStamps[ii].dwLowDateTime;
                output.dwHighDateTime         = pftTimeStamps[ii].dwHighDateTime;
                values[ii].Timestamp          = HD.OPC.Client.Core.Com.Interop.GetFILETIME(output);
                values[ii].TimestampSpecified = values[ii].Timestamp != DateTime.MinValue;
                values[ii].ResultID           = HD.OPC.Client.Core.Com.Interop.GetResultID(pErrors[ii]);
                values[ii].DiagnosticInfo     = null;

                // convert COM code to unified DA code.
                if (pErrors[ii] == ResultIDs.E_BADRIGHTS)
                {
                    values[ii].ResultID = new ResultID(ResultID.Da.E_WRITEONLY, ResultIDs.E_BADRIGHTS);
                }
            }

            // return results
            return(values);
        }
コード例 #31
0
    //===============================================================================
    // Name: Function GetSubKeys
    // Input:
    //   ByRef strKey As String - Key name
    //   ByRef SubKey As String - Sub key name
    //   ByRef SubKeyCnt As Long - Number of keys
    // Output:
    //   String - Sub key list of a given key (separated by commas)
    // Purpose: Gets subkeys from a given key separated by commas
    // Remarks: None
    //===============================================================================
    public static string GetSubKeys(ref string strKey, ref string SubKey, ref int SubKeyCnt)
    {
        string[] strValues = null;
        string   strTemp   = string.Empty;
        int      lngSub    = 0;
        short    intCnt    = 0;
        int      lngRet    = 0;
        short    intKeyCnt = 0;
        FILETIME FT        = default(FILETIME);

        GetSubKeys() = string.Empty;
        lngRet       = RegOpenKeyEx((int)strKey, SubKey, 0, KEY_ENUMERATE_SUB_KEYS, ref lngSub);

        if (lngRet != ERROR_SUCCESS)
        {
            SubKeyCnt = 0;
            return;
        }
        lngRet = RegQueryInfoKey(lngSub, Constants.vbNullString, ref 0, 0, ref SubKeyCnt, ref 65, ref 0, ref 0, ref 0, ref 0,
                                 ref 0, ref FT);
        if ((lngRet != ERROR_SUCCESS) | (SubKeyCnt <= 0))
        {
            SubKeyCnt = 0;
        }
        strValues = new string[SubKeyCnt];
        for (intCnt = 0; intCnt <= SubKeyCnt - 1; intCnt++)
        {
            strValues[intCnt] = new string(Strings.Chr(0), 65);
            RegEnumKeyEx(lngSub, intCnt, strValues[intCnt], ref 65, 0, Constants.vbNullString, ref 0, ref FT);
            strValues[intCnt] = StripNulls(strValues[intCnt]);
        }
        RegCloseKey(lngSub);
        for (intKeyCnt = Information.LBound(strValues); intKeyCnt <= Information.UBound(strValues); intKeyCnt++)
        {
            strTemp = strTemp + strValues[intKeyCnt] + ",";
        }
        return(strTemp);
    }
コード例 #32
0
        private void SetAttributes()
        {
            var            prefixFullname = PREFIX + filename;
            SafeFileHandle fileHandle     = ExternalCalls.CreateFile(prefixFullname,
                                                                     ExternalCalls.ExtFileAccess.GenericRead, ExternalCalls.ExtFileShare.Read, IntPtr.Zero,
                                                                     ExternalCalls.ECreationDisposition.OpenExisting, 0, IntPtr.Zero);

            if (fileHandle != null && !fileHandle.IsInvalid)
            {
                using (var fileStream = new FileStream(fileHandle, FileAccess.Read))
                {
                    if (fileStream.Length > 0)
                    {
                        exists = true;
                    }
                    length = fileStream.Length;
                }
                name      = filename.Split('\\').Last();
                extention = filename.Split('.').Last();
                IntPtr ptr              = fileHandle.DangerousGetHandle();
                var    ftCreationTime   = new FILETIME();
                var    ftLastAccessTime = new FILETIME();
                var    ftLastWriteTime  = new FILETIME();
                ExternalCalls.GetFileTime(ptr, ref ftCreationTime, ref ftLastAccessTime, ref ftLastWriteTime);
                var creationTime   = DateTime.FromFileTimeUtc((((long)ftCreationTime.dwHighDateTime) << 32) | ((uint)ftCreationTime.dwLowDateTime));
                var lastAccessTime = DateTime.FromFileTimeUtc((((long)ftLastAccessTime.dwHighDateTime) << 32) | ((uint)ftLastAccessTime.dwLowDateTime));
                var lastWriteTime  = DateTime.FromFileTimeUtc((((long)ftLastWriteTime.dwHighDateTime) << 32) | ((uint)ftLastWriteTime.dwLowDateTime));
                this.creationTime = creationTime;
                if (!fileHandle.IsClosed)
                {
                    fileHandle.Close();
                }
                if ((ExternalCalls.GetFileAttributes(prefixFullname) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    this.readOnly = true;
                }
            }
        }
コード例 #33
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int RegEnumKeyEx(IntPtr hKey, int dwIndex, string lpName, ref int lpcbName,
                                       ref int lpReserved, string lpClass, ref int lpcbClass,
                                       ref FILETIME lpftLastWriteTime);
コード例 #34
0
ファイル: Kernel.cs プロジェクト: santosh-mnrec/rsync.net
		[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int FileTimeToLocalFileTime(ref FILETIME lpFileTime, ref FILETIME lpLocalFileTime);
コード例 #35
0
 void IMoniker.GetTimeOfLastChange(IBindCtx pbc, IMoniker pmkToLeft, out FILETIME pFileTime)
 {
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException());
 }
コード例 #36
0
 public static DateTime FileTimeToDateTime(FILETIME fileTime)
 {
     long ticks = (((long)fileTime.HighDateTime) << 32) + fileTime.LowDateTime;
     return DateTime.FromFileTimeUtc(ticks);
 }
コード例 #37
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int GetProcessTimes(IntPtr hProcess, ref FILETIME lpCreationTime, ref FILETIME lpExitTime,
                                          ref FILETIME lpKernelTime, ref FILETIME lpUserTime);
コード例 #38
0
ファイル: Interop.crypt32.cs プロジェクト: johnhhm/corefx
 private static extern unsafe bool CertGetCertificateChain(IntPtr hChainEngine, SafeCertContextHandle pCertContext, FILETIME* pTime, SafeCertStoreHandle hStore, [In] ref CERT_CHAIN_PARA pChainPara, CertChainFlags dwFlags, IntPtr pvReserved, out SafeX509ChainHandle ppChainContext);
コード例 #39
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int DosDateTimeToFileTime(int wFatDate, int wFatTime, ref FILETIME lpFileTime);
コード例 #40
0
ファイル: Utils.cs プロジェクト: schraubchen/BITSDL
 internal static FILETIME DateTime2FileTime(DateTime dateTime)
 {
     long fileTime = 0;
     if (dateTime != DateTime.MinValue)      //Checking for MinValue
         fileTime = dateTime.ToFileTime();
     FILETIME resultingFileTime = new FILETIME();
     resultingFileTime.dwLowDateTime = (uint)(fileTime & 0xFFFFFFFF);
     resultingFileTime.dwHighDateTime = (uint)(fileTime >> 32);
     return resultingFileTime;
 }
コード例 #41
0
ファイル: Interop.crypt32.cs プロジェクト: johnhhm/corefx
 public static unsafe bool CertGetCertificateChain(ChainEngine hChainEngine, SafeCertContextHandle pCertContext, FILETIME* pTime, SafeCertStoreHandle hStore, [In] ref CERT_CHAIN_PARA pChainPara, CertChainFlags dwFlags, IntPtr pvReserved, out SafeX509ChainHandle ppChainContext)
 {
     return CertGetCertificateChain((IntPtr)hChainEngine, pCertContext, pTime, hStore, ref pChainPara, dwFlags, pvReserved, out ppChainContext);
 }
コード例 #42
0
ファイル: Registry.cs プロジェクト: praveeds/jOVAL
 public static extern int RegQueryInfoKey(UIntPtr hkey, out StringBuilder lpClass, ref IntPtr lpcbClass,
     IntPtr lpReserved, out uint lpcSubKeys, out uint lpcbMaxSubKeyLen, out uint lpcbMaxClassLen,
     out uint lpcValues, out uint lpcbMaxValueNameLen, out uint lpcbMaxValueLen, out uint lpcbSecurityDescriptor,
     ref FILETIME lastWriteTime);
コード例 #43
0
        public static string ToStringFromFileTime(FILETIME ft)
        {
            DateTime dt = FiletimeToDateTime(ft);
            if (dt == DateTime.MinValue)
            {
                return string.Empty;
            }

            return dt.ToString();
        }
コード例 #44
0
 public static extern long FileTimeToSystemTime(ref FILETIME FileTime, 
     ref SYSTEMTIME SystemTime);
コード例 #45
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int RegQueryInfoKey(IntPtr hKey, string lpClass, ref int lpcbClass, ref int lpReserved,
                                          ref int lpcSubKeys, ref int lpcbMaxSubKeyLen, ref int lpcbMaxClassLen,
                                          ref int lpcValues, ref int lpcbMaxValueNameLen, ref int lpcbMaxValueLen,
                                          ref int lpcbSecurityDescriptor, ref FILETIME lpftLastWriteTime);
コード例 #46
0
ファイル: Utils.cs プロジェクト: schraubchen/BITSDL
        internal static DateTime FileTime2DateTime(FILETIME fileTime)
        {
            if (fileTime.dwHighDateTime == 0 && fileTime.dwLowDateTime == 0)    //Checking for MinValue
                return DateTime.MinValue;

            long dateTime = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
            return DateTime.FromFileTime(dateTime);
        }
コード例 #47
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int CompareFileTime(ref FILETIME lpFileTime1, ref FILETIME lpFileTime2);
コード例 #48
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int LocalFileTimeToFileTime(ref FILETIME lpLocalFileTime, ref FILETIME lpFileTime);
コード例 #49
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int FileTimeToDosDateTime(ref FILETIME lpFileTime, ref int lpFatDate, ref int lpFatTime);
コード例 #50
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
コード例 #51
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int GetThreadTimes(IntPtr hThread, ref FILETIME lpCreationTime, ref FILETIME lpExitTime,
                                         ref FILETIME lpKernelTime, ref FILETIME lpUserTime);
コード例 #52
0
ファイル: Kernel.cs プロジェクト: santosh-mnrec/rsync.net
		[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int FileTimeToDosDateTime(ref FILETIME lpFileTime, ref int lpFatDate, ref int lpFatTime);
コード例 #53
0
ファイル: Kernel.cs プロジェクト: luowei98/RobertLw
 public static extern int SetFileTime(IntPtr hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime,
                                      ref FILETIME lpLastWriteTime);
コード例 #54
0
ファイル: Kernel.cs プロジェクト: usbhell/flurrysharp
 public static extern int GetFileTime(HANDLE hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime);
コード例 #55
0
ファイル: winapi.func.cs プロジェクト: AndrewEastwood/desktop
 public static extern Boolean GetFileTime(IntPtr hFile, FILETIME lpCreationTime,
     out FILETIME lpLastAccessTime, out FILETIME lpLastWriteTime);
コード例 #56
0
ファイル: winapi.func.cs プロジェクト: AndrewEastwood/desktop
 public static extern Boolean FileTimeToSystemTime(ref FILETIME lpFileTime, 
     out SYSTEMTIME lpSystemTime);
コード例 #57
0
ファイル: Kernel.cs プロジェクト: dusdong/BaseComponent
		[DllImport("kernel32")] public static extern int GetProcessTimes(HANDLE hProcess, ref FILETIME lpCreationTime, ref FILETIME lpExitTime, ref FILETIME lpKernelTime, ref FILETIME lpUserTime);
コード例 #58
0
ファイル: winapi.func.cs プロジェクト: AndrewEastwood/desktop
 public static extern Boolean FileTimeToLocalFileTime(ref FILETIME lpFileTime, 
     out FILETIME lpLocalFileTime);
コード例 #59
0
ファイル: Kernel.cs プロジェクト: santosh-mnrec/rsync.net
		[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int SystemTimeToFileTime(ref SYSTEMTIME lpSystemTime, ref FILETIME lpFileTime);
コード例 #60
0
ファイル: Kernel.cs プロジェクト: santosh-mnrec/rsync.net
		[DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern int SetFileTime(HANDLE hFile, ref FILETIME lpCreationTime, ref FILETIME lpLastAccessTime, ref FILETIME lpLastWriteTime);