Exemple #1
0
 private static bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, CallbackContext callbackContext)
 {
     GCHandle context = GCHandle.Alloc(callbackContext);
     try
     {
         return Interop.GlobalizationInterop.EnumCalendarInfo(EnumCalendarInfoCallback, localeName, calendarId, dataType, (IntPtr)context);
     }
     finally
     {
         context.Free();
     }
 }
Exemple #2
0
        internal static bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[] calendarData)
        {
            calendarData = null;

            CallbackContext callbackContext = new CallbackContext();
            bool result = EnumCalendarInfo(localeName, calendarId, dataType, callbackContext);
            if (result)
            {
                calendarData = callbackContext.Results.ToArray();
            }

            return result;
        }
Exemple #3
0
        private static bool EnumDatePatterns(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[] datePatterns)
        {
            datePatterns = null;

            CallbackContext callbackContext = new CallbackContext();
            callbackContext.DisallowDuplicates = true;
            bool result = EnumCalendarInfo(localeName, calendarId, dataType, callbackContext);
            if (result)
            {
                List<string> datePatternsList = callbackContext.Results;

                datePatterns = new string[datePatternsList.Count];
                for (int i = 0; i < datePatternsList.Count; i++)
                {
                    datePatterns[i] = NormalizeDatePattern(datePatternsList[i]);
                }
            }

            return result;
        }
Exemple #4
0
        private static bool EnumMonthNames(string localeName, CalendarId calendarId, CalendarDataType dataType, out string[] monthNames)
        {
            monthNames = null;

            CallbackContext callbackContext = new CallbackContext();
            bool result = EnumCalendarInfo(localeName, calendarId, dataType, callbackContext);
            if (result)
            {
                // the month-name arrays are expected to have 13 elements.  If ICU only returns 12, add an
                // extra empty string to fill the array.
                if (callbackContext.Results.Count == 12)
                {
                    callbackContext.Results.Add(string.Empty);
                }

                monthNames = callbackContext.Results.ToArray();
            }

            return result;
        }
        private int ChangeInternal(long dueTime, int period, WaitableTimerCallback callback, object state, bool resume)
        {
            if (period < 0)
            {
                throw new ArgumentException("period cannot be negative.");
            }

            // CallbackContext is used to avoid a race condition.
            CallbackContext context = null;
            Win32WaitableTimer.TimerAPCProc completionCallback = null;
            if (callback != null)
            {
                context = new CallbackContext(callback, state);
                completionCallback = context.TimerTick;
            }

            // Have to do this because SetWaitableTimer needs a reference
            long due = dueTime;
            bool rslt = Win32WaitableTimer.SetWaitableTimer(
                SafeWaitHandle,
                ref due,
                period,
                completionCallback,
                IntPtr.Zero,
                resume);
            if (!rslt)
            {
                throw GetWin32Exception();
            }
            TimerCompletionCallback = context;
            return Marshal.GetLastWin32Error();
        }