2023-05-23 23:54:28 +08:00
|
|
|
|
#region copyright
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
|
|
|
|
|
|
// 此代码版权(除特别声明外的代码)归作者本人Diego所有
|
|
|
|
|
|
// 源代码使用协议遵循本仓库的开源协议及附加协议
|
2023-07-16 17:48:22 +08:00
|
|
|
|
// Gitee源代码仓库:https://gitee.com/diego2098/ThingsGateway
|
2023-05-23 23:54:28 +08:00
|
|
|
|
// Github源代码仓库:https://github.com/kimdiego2098/ThingsGateway
|
2023-07-16 17:48:22 +08:00
|
|
|
|
// 使用文档:https://diego2098.gitee.io/thingsgateway-docs/
|
2023-05-23 23:54:28 +08:00
|
|
|
|
// QQ群:605534569
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2023-06-07 18:03:57 +08:00
|
|
|
|
namespace ThingsGateway.Foundation.Adapter.OPCDA.Comn;
|
|
|
|
|
|
|
|
|
|
|
|
internal static class Convert
|
2023-03-09 11:19:48 +08:00
|
|
|
|
{
|
2023-06-07 18:03:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// windows的filetime是从1601-1-1 00:00:00开始的,datetime是从1-1-1 00:00:00开始的
|
|
|
|
|
|
/// datetime和filetime的滴答单位都是100ns(100纳秒,千万分之一秒),所以转换时只需要考虑开始时间即可
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static readonly DateTime FILETIME_BaseTime = new DateTime(1601, 1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
private static bool m_preserveUTC = false;
|
|
|
|
|
|
|
|
|
|
|
|
internal static object Clone(object source)
|
2023-03-09 11:19:48 +08:00
|
|
|
|
{
|
2023-06-07 18:03:57 +08:00
|
|
|
|
if (source == null)
|
2023-03-11 16:57:31 +08:00
|
|
|
|
{
|
2023-06-07 18:03:57 +08:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
2023-03-11 16:57:31 +08:00
|
|
|
|
|
2023-06-07 18:03:57 +08:00
|
|
|
|
if (source.GetType().IsValueType)
|
|
|
|
|
|
{
|
|
|
|
|
|
return source;
|
|
|
|
|
|
}
|
2023-03-11 16:57:31 +08:00
|
|
|
|
|
2023-06-07 18:03:57 +08:00
|
|
|
|
if (source.GetType().IsArray || source.GetType() == typeof(Array))
|
|
|
|
|
|
{
|
|
|
|
|
|
Array array = (Array)((Array)source).Clone();
|
|
|
|
|
|
for (int i = 0; i < array.Length; i++)
|
2023-03-11 16:57:31 +08:00
|
|
|
|
{
|
2023-06-07 18:03:57 +08:00
|
|
|
|
array.SetValue(Clone(array.GetValue(i)), i);
|
2023-03-11 16:57:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 18:03:57 +08:00
|
|
|
|
return array;
|
2023-03-11 16:57:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-07 18:03:57 +08:00
|
|
|
|
try
|
2023-03-09 11:19:48 +08:00
|
|
|
|
{
|
2023-06-07 18:03:57 +08:00
|
|
|
|
return ((ICloneable)source).Clone();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotSupportedException("Object cannot be cloned.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
internal static DateTime FileTimeToDateTime(System.Runtime.InteropServices.ComTypes.FILETIME filetime)
|
|
|
|
|
|
{
|
|
|
|
|
|
long num = filetime.dwHighDateTime;
|
|
|
|
|
|
if (num < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
num += 4294967296L;
|
|
|
|
|
|
}
|
|
|
|
|
|
long num2 = num << 32;
|
|
|
|
|
|
num = filetime.dwLowDateTime;
|
|
|
|
|
|
if (num < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
num += 4294967296L;
|
|
|
|
|
|
}
|
|
|
|
|
|
num2 += num;
|
|
|
|
|
|
if (num2 == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return DateTime.MinValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (m_preserveUTC)
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime fILETIME_BaseTime = FILETIME_BaseTime;
|
|
|
|
|
|
return fILETIME_BaseTime.Add(new TimeSpan(num2));
|
2023-03-09 11:19:48 +08:00
|
|
|
|
}
|
2023-06-07 18:03:57 +08:00
|
|
|
|
DateTime fILETIME_BaseTime2 = FILETIME_BaseTime;
|
|
|
|
|
|
return fILETIME_BaseTime2.Add(new TimeSpan(num2)).ToLocalTime();
|
2023-03-09 11:19:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|