private static Recurrence CreateTimeZoneRRule(NativeMethods.SystemTime systemTime) { int num = (int)systemTime.Day; if (num == 5) { num = -1; } DayOfWeek dayOfWeek = (DayOfWeek)systemTime.DayOfWeek; Recurrence.ByDay byDay = new Recurrence.ByDay(dayOfWeek, num); return(new Recurrence { Frequency = Frequency.Yearly, Interval = 1, ByMonth = new int[] { (int)systemTime.Month }, ByDayList = new Recurrence.ByDay[] { byDay } }); }
private static NativeMethods.SystemTime Win32SystemTimeFromRecurringTime(ExYearlyRecurringTime recurring) { NativeMethods.SystemTime result = default(NativeMethods.SystemTime); ExYearlyRecurringDate exYearlyRecurringDate = recurring as ExYearlyRecurringDate; ExYearlyRecurringDay exYearlyRecurringDay = recurring as ExYearlyRecurringDay; if (exYearlyRecurringDate != null) { result.Year = (ushort)ExDateTime.Now.Year; result.Month = (ushort)exYearlyRecurringDate.Month; result.Day = (ushort)exYearlyRecurringDate.Day; result.Hour = (ushort)exYearlyRecurringDate.Hour; result.Minute = (ushort)exYearlyRecurringDate.Minute; result.Second = (ushort)exYearlyRecurringDate.Second; result.Milliseconds = (ushort)exYearlyRecurringDate.Milliseconds; } else { if (exYearlyRecurringDay == null) { throw new InvalidOperationException(); } result.Year = 0; result.Month = (ushort)exYearlyRecurringDay.Month; result.Day = (ushort)((exYearlyRecurringDay.Occurrence == -1) ? 5 : exYearlyRecurringDay.Occurrence); result.DayOfWeek = (ushort)exYearlyRecurringDay.DayOfWeek; result.Hour = (ushort)exYearlyRecurringDay.Hour; result.Minute = (ushort)exYearlyRecurringDay.Minute; result.Second = (ushort)exYearlyRecurringDay.Second; result.Milliseconds = (ushort)exYearlyRecurringDay.Milliseconds; } return(result); }
protected override void ProcessRecord() { DateTime dateToUse; switch (ParameterSetName) { case "Date": dateToUse = Date; break; case "Adjust": dateToUse = DateTime.Now.Add(Adjust); break; default: Dbg.Diagnostics.Assert(false, "Only one of the specified parameter sets should be called."); goto case "Date"; } if (ShouldProcess(dateToUse.ToString())) { #if UNIX if (!Platform.NonWindowsSetDate(dateToUse)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } #else // build up the SystemTime struct to pass to SetSystemTime NativeMethods.SystemTime systemTime = new NativeMethods.SystemTime(); systemTime.Year = (UInt16)dateToUse.Year; systemTime.Month = (UInt16)dateToUse.Month; systemTime.Day = (UInt16)dateToUse.Day; systemTime.Hour = (UInt16)dateToUse.Hour; systemTime.Minute = (UInt16)dateToUse.Minute; systemTime.Second = (UInt16)dateToUse.Second; systemTime.Milliseconds = (UInt16)dateToUse.Millisecond; #pragma warning disable 56523 if (!NativeMethods.SetLocalTime(ref systemTime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // MSDN says to call this twice to account for changes // between DST if (!NativeMethods.SetLocalTime(ref systemTime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } #pragma warning restore 56523 #endif } // output DateTime object wrapped in an PSObject with DisplayHint attached PSObject outputObj = new PSObject(dateToUse); PSNoteProperty note = new PSNoteProperty("DisplayHint", DisplayHint); outputObj.Properties.Add(note); WriteObject(outputObj); }
internal SerializableTimeZoneTime(int bias, NativeMethods.SystemTime systemTime) { this.bias = bias; this.month = (short)systemTime.Month; this.dayOrder = (short)systemTime.Day; this.dayOfWeek = (DayOfWeek)systemTime.DayOfWeek; this.year = (short)systemTime.Year; this.time = new TimeSpan((int)systemTime.Hour, (int)systemTime.Minute, (int)systemTime.Second); }
private static NativeMethods.SystemTime ToSystemTime(DateTime dateTime) { long fileTime = dateTime.ToFileTime(); var systemTime = new NativeMethods.SystemTime(); if (!NativeMethods.FileTimeToSystemTime(ref fileTime, systemTime)) { ThrowExceptionIfGetLastErrorIsNotZero(); } return(systemTime); }
public BLUETOOTH_DEVICE_INFO(long address) { this.dwSize = 560; this.Address = address; this.ulClassofDevice = 0; this.fConnected = false; this.fRemembered = false; this.fAuthenticated = false; this.stLastSeen = new NativeMethods.SystemTime(); this.stLastUsed = new NativeMethods.SystemTime(); this.szName = ""; }
private static void GetStartAndRuleFromTimeZoneTransition(NativeMethods.SystemTime systemTime, out ExDateTime start, out Recurrence rule) { rule = null; int num; int num2; int num3; if (systemTime.Year == 0) { if (systemTime.Month != 0) { rule = VTimeZone.CreateTimeZoneRRule(systemTime); } DateTime minSupportedDateTime = CultureInfo.CurrentCulture.Calendar.MinSupportedDateTime; DateTime maxSupportedDateTime = CultureInfo.CurrentCulture.Calendar.MaxSupportedDateTime; if (minSupportedDateTime.Year < 1601 && maxSupportedDateTime.Year >= 1601) { num = 1601; num2 = 1; num3 = 1; } else { num = minSupportedDateTime.Year; num2 = minSupportedDateTime.Month; num3 = minSupportedDateTime.Day; } } else { num = (int)systemTime.Year; num2 = (int)systemTime.Month; num3 = (int)systemTime.Day; } try { start = new ExDateTime(ExTimeZone.UnspecifiedTimeZone, num, num2, num3, (int)systemTime.Hour, (int)systemTime.Minute, (int)systemTime.Second, (int)systemTime.Milliseconds); } catch (ArgumentOutOfRangeException innerException) { ExTraceGlobals.ICalTracer.TraceError(0L, "VTimezone::GetStartAndRuleFromTimeZoneTransition. The timezone is invalid.\r\nYear: {0}, Month: {1}, Day: {2}, Hour: {3}, Minute: {4}, Second: {5}, Milliseconds: {6}.", new object[] { num, num2, num3, systemTime.Hour, systemTime.Minute, systemTime.Second, systemTime.Milliseconds }); throw new CorruptDataException(ServerStrings.ExCorruptedTimeZone, innerException); } }
public BLUETOOTH_DEVICE_INFO(NativeMethods.BluetoothAddress address) { if (address == null) { throw new ArgumentNullException("address"); } this.dwSize = 560; this.Address = address.ToInt64(); this.ulClassofDevice = 0; this.fConnected = false; this.fRemembered = false; this.fAuthenticated = false; this.stLastSeen = new NativeMethods.SystemTime(); this.stLastUsed = new NativeMethods.SystemTime(); this.szName = ""; }
protected override void ProcessRecord() { DateTime date; string str; if ((((str = base.ParameterSetName) == null) || (str == "Date")) || (str != "Adjust")) { date = this.Date; } else { date = DateTime.Now.Add(this.Adjust); } NativeMethods.SystemTime systime = new NativeMethods.SystemTime { Year = (ushort)date.Year, Month = (ushort)date.Month, Day = (ushort)date.Day, Hour = (ushort)date.Hour, Minute = (ushort)date.Minute, Second = (ushort)date.Second, Milliseconds = (ushort)date.Millisecond }; if (base.ShouldProcess(date.ToString())) { if (!NativeMethods.SetLocalTime(ref systime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } if (!NativeMethods.SetLocalTime(ref systime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } PSObject sendToPipeline = new PSObject(date); PSNoteProperty member = new PSNoteProperty("DisplayHint", this.DisplayHint); sendToPipeline.Properties.Add(member); base.WriteObject(sendToPipeline); }
protected override void ProcessRecord() { DateTime date; string str; if ((((str = base.ParameterSetName) == null) || (str == "Date")) || (str != "Adjust")) { date = this.Date; } else { date = DateTime.Now.Add(this.Adjust); } NativeMethods.SystemTime systime = new NativeMethods.SystemTime { Year = (ushort) date.Year, Month = (ushort) date.Month, Day = (ushort) date.Day, Hour = (ushort) date.Hour, Minute = (ushort) date.Minute, Second = (ushort) date.Second, Milliseconds = (ushort) date.Millisecond }; if (base.ShouldProcess(date.ToString())) { if (!NativeMethods.SetLocalTime(ref systime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } if (!NativeMethods.SetLocalTime(ref systime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } PSObject sendToPipeline = new PSObject(date); PSNoteProperty member = new PSNoteProperty("DisplayHint", this.DisplayHint); sendToPipeline.Properties.Add(member); base.WriteObject(sendToPipeline); }
protected override void ProcessRecord() { DateTime dateToUse; switch (ParameterSetName) { case "Date": dateToUse = Date; break; case "Adjust": dateToUse = DateTime.Now.Add(Adjust); break; default: Dbg.Diagnostics.Assert(false, "Only one of the specified parameter sets should be called."); goto case "Date"; } // // build up the SystemTime struct to pass to SetSystemTime NativeMethods.SystemTime systemTime = new NativeMethods.SystemTime(); systemTime.Year = (UInt16)dateToUse.Year; systemTime.Month = (UInt16)dateToUse.Month; systemTime.Day = (UInt16)dateToUse.Day; systemTime.Hour = (UInt16)dateToUse.Hour; systemTime.Minute = (UInt16)dateToUse.Minute; systemTime.Second = (UInt16)dateToUse.Second; systemTime.Milliseconds = (UInt16)dateToUse.Millisecond; if (ShouldProcess(dateToUse.ToString())) { if (Platform.IsWindows) { #pragma warning disable 56523 if (!NativeMethods.SetLocalTime(ref systemTime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // MSDN says to call this twice to account for changes // between DST if (!NativeMethods.SetLocalTime(ref systemTime)) { throw new Win32Exception(Marshal.GetLastWin32Error()); } #pragma warning restore 56523 } else { Platform.NonWindowsSetDate(dateToUse); } } //output DateTime object wrapped in an PSObject with DisplayHint attached PSObject outputObj = new PSObject(dateToUse); PSNoteProperty note = new PSNoteProperty("DisplayHint", DisplayHint); outputObj.Properties.Add(note); WriteObject(outputObj); } // EndProcessing
internal ChangeDate(NativeMethods.SystemTime systemTime) { this.systemTime = systemTime; }
internal ZoneTransition(int bias, NativeMethods.SystemTime systemTime) { this.bias = bias; this.changeDate = new ChangeDate(systemTime); }