コード例 #1
0
        private static EraInfo[] GetJapaneseEras()
        {
            int erasCount = WinRTInterop.Callbacks.GetJapaneseEraCount();
            if (erasCount < 4)
            {
                return null;
            }

            EraInfo[] eras = new EraInfo[erasCount];
            int lastMaxYear = GregorianCalendar.MaxYear;

            for (int i = erasCount; i > 0; i--)
            {
                DateTimeOffset dateOffset;

                string eraName;
                string abbreviatedEraName;

                if (!GetJapaneseEraInfo(i, out dateOffset, out eraName, out abbreviatedEraName))
                {
                    return null;
                }

                DateTime dt = new DateTime(dateOffset.Ticks);

                eras[erasCount - i] = new EraInfo(i, dt.Year, dt.Month, dt.Day, dt.Year - 1, 1, lastMaxYear - dt.Year + 1,
                                                   eraName, abbreviatedEraName, GetJapaneseEnglishEraName(i));    // era #4 start year/month/day, yearOffset, minEraYear

                lastMaxYear = dt.Year;
            }

            return eras;
        }
コード例 #2
0
        //
        // Read our era info
        //
        // m_EraInfo must be listed in reverse chronological order.  The most recent era
        // should be the first element.
        // That is, m_EraInfo[0] contains the most recent era.
        //
        // We know about 4 built-in eras, however users may add additional era(s) from the
        // registry, by adding values to HKLM\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras
        // we don't read the registry and instead we call WinRT to get the needed informatio
        //
        // Registry values look like:
        //      yyyy.mm.dd=era_abbrev_english_englishabbrev
        //
        // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
        // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
        // era is the Japanese Era name
        // abbrev is the Abbreviated Japanese Era Name
        // english is the English name for the Era (unused)
        // englishabbrev is the Abbreviated English name for the era.
        // . is a delimiter, but the value of . doesn't matter.
        // '_' marks the space between the japanese era name, japanese abbreviated era name
        //     english name, and abbreviated english names.
        //
        internal static EraInfo[] GetEraInfo()
        {
            // See if we need to build it
            if (japaneseEraInfo == null)
            {
                japaneseEraInfo = GetJapaneseEras();
                // See if we have to use the built-in eras
                if (japaneseEraInfo == null)
                {
                    // We know about some built-in ranges
                    EraInfo[] defaultEraRanges = new EraInfo[4];
                    defaultEraRanges[0] = new EraInfo(4, 1989, 1, 8, 1988, 1, GregorianCalendar.MaxYear - 1988,
                                                      "\x5e73\x6210", "\x5e73", "H");     // era #4 start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[1] = new EraInfo(3, 1926, 12, 25, 1925, 1, 1989 - 1925,
                                                      "\x662d\x548c", "\x662d", "S");     // era #3,start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[2] = new EraInfo(2, 1912, 7, 30, 1911, 1, 1926 - 1911,
                                                      "\x5927\x6b63", "\x5927", "T");     // era #2,start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[3] = new EraInfo(1, 1868, 1, 1, 1867, 1, 1912 - 1867,
                                                      "\x660e\x6cbb", "\x660e", "M");     // era #1,start year/month/day, yearOffset, minEraYear

                    // Remember the ranges we built
                    japaneseEraInfo = defaultEraRanges;
                }
            }

            // return the era we found/made
            return(japaneseEraInfo);
        }
コード例 #3
0
        /*=================================InitEraInfo==========================
         **Action: Get the era range information from calendar.nlp.
         **Returns: An array of EraInfo, which contains the information about an era.
         **Arguments:
         **      calID     the Calendar ID defined in Calendar.cs
         **============================================================================*/
        internal static EraInfo[] InitEraInfo(int calID)
        {
            //
            // Initialize era information.
            //

            /*
             * Japaense era info example:
             * eraInfo[0] = new EraInfo(4, new DateTime(1989, 1, 8).Ticks, 1988, 1, GregorianCalendar.MaxYear - 1988);    // Heisei. Most recent
             * eraInfo[1] = new EraInfo(3, new DateTime(1926, 12, 25).Ticks, 1925, 1, 1989 - 1925);  // Showa
             * eraInfo[2] = new EraInfo(2, new DateTime(1912, 7, 30).Ticks, 1911, 1, 1926 - 1911);   // Taisho
             * eraInfo[3] = new EraInfo(1, new DateTime(1868, 9, 8).Ticks, 1867, 1, 1912 - 1867);    // Meiji
             */
            BCLDebug.Assert(calID > 0, "[GregorianCalendarHelper.InitEraInfo] Expected calID > 0");
            int[][]    eraRanges  = CalendarTable.Default.SERARANGES(calID);
            EraInfo [] eraInfo    = new EraInfo[eraRanges.Length];
            int        maxEraYear = GregorianCalendar.MaxYear;

            for (int i = 0; i < eraRanges.Length; i++)
            {
                //
                // The eraRange arrays are each the form of "4 1989 1 8 1988 1".
                // eraRanges[i][0] is the era value.
                // eraRanges[i][1] is the year when the era starts.
                // eraRanges[i][2] is the month when the era starts.
                // eraRanges[i][3] is the day when the era starts.
                // eraRanges[i][4] is the offset to Gregorian year (1988).
                // eraRanges[i][5] is the minimum era year for this era.
                //
                BCLDebug.Assert(eraRanges[i].Length == 6, "[GregorianCalendarHelper.InitEraInfo] Expected 6 SERARANGE elements (0-5), not " + eraRanges[i].Length);
                eraInfo[i] = new EraInfo(eraRanges[i][0], new DateTime(eraRanges[i][1], eraRanges[i][2], eraRanges[i][3]).Ticks, eraRanges[i][4], eraRanges[i][5], maxEraYear - eraRanges[i][4]);
                maxEraYear = eraRanges[i][1];
            }
            return(eraInfo);
        }
コード例 #4
0
        private static EraInfo[] GetJapaneseEras()
        {
            int erasCount = GetJapaneseEraCount();

            if (erasCount < 4)
            {
                return(null);
            }

            EraInfo[] eras        = new EraInfo[erasCount];
            int       lastMaxYear = GregorianCalendar.MaxYear;

            for (int i = erasCount; i > 0; i--)
            {
                DateTimeOffset dateOffset;

                string eraName;
                string abbreviatedEraName;

                if (!GetJapaneseEraInfo(i, out dateOffset, out eraName, out abbreviatedEraName))
                {
                    return(null);
                }

                DateTime dt = new DateTime(dateOffset.Ticks);

                eras[erasCount - i] = new EraInfo(i, dt.Year, dt.Month, dt.Day, dt.Year - 1, 1, lastMaxYear - dt.Year + 1,
                                                  eraName, abbreviatedEraName, GetJapaneseEnglishEraName(i));     // era #4 start year/month/day, yearOffset, minEraYear

                lastMaxYear = dt.Year;
            }

            return(eras);
        }
コード例 #5
0
 internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo)
 {
     this.m_Cal = cal;
     this.m_EraInfo = eraInfo;
     this.m_minDate = this.m_Cal.MinSupportedDateTime;
     this.m_maxYear = this.m_EraInfo[0].maxEraYear;
     this.m_minYear = this.m_EraInfo[0].minEraYear;
 }
コード例 #6
0
        internal static EraInfo[] InitEraInfo(int calID)
        {
            int[][]   numArray  = CalendarTable.Default.SERARANGES(calID);
            EraInfo[] infoArray = new EraInfo[numArray.Length];
            int       num       = 0x270f;

            for (int i = 0; i < numArray.Length; i++)
            {
                DateTime time = new DateTime(numArray[i][1], numArray[i][2], numArray[i][3]);
                infoArray[i] = new EraInfo(numArray[i][0], time.Ticks, numArray[i][4], numArray[i][5], num - numArray[i][4]);
                num          = numArray[i][1];
            }
            return(infoArray);
        }
コード例 #7
0
        /*=================================InitEraInfo==========================
         **Action: Get the era range information from calendar.nlp.
         **Returns: An array of EraInfo, which contains the information about an era.
         **Arguments:
         **      calID     the Calendar ID defined in Calendar.cs
         **============================================================================*/
        internal static EraInfo[] InitEraInfo(int calID)
        {
            //
            // Initialize era information.
            //

            /*
             * Japaense era info example:
             * eraInfo[0] = new EraInfo(4, new DateTime(1989, 1, 8).Ticks, 1988, 1, GregorianCalendar.MaxYear - 1988);    // Heisei. Most recent
             * eraInfo[1] = new EraInfo(3, new DateTime(1926, 12, 25).Ticks, 1925, 1, 1989 - 1925);  // Showa
             * eraInfo[2] = new EraInfo(2, new DateTime(1912, 7, 30).Ticks, 1911, 1, 1926 - 1911);   // Taisho
             * eraInfo[3] = new EraInfo(1, new DateTime(1868, 9, 8).Ticks, 1867, 1, 1912 - 1867);    // Meiji
             */
            String[]   eraRanges  = CalendarTable.GetMultipleStringValues(calID, CalendarTable.SERARANGES, false);
            EraInfo [] eraInfo    = new EraInfo[eraRanges.Length];
            int        maxEraYear = GregorianCalendar.MaxYear;

            for (int i = 0; i < eraRanges.Length; i++)
            {
                //
                // The eraRange string is in the form of "4;1989;1;8;1988;1".
                // num[0] is the era value.
                // num[1] is the year when the era starts.
                // num[2] is the month when the era starts.
                // num[3] is the day when the era starts.
                // num[4] is the offset to Gregorian year (1988).
                // num[5] is the minimum era year for this era.
                //
                String[] numStrs = eraRanges[i].Split(new char[] { ';' });
                int[]    nums    = new int[6];
                for (int j = 0; j < 6; j++)
                {
                    nums[j] = Int32.Parse(numStrs[j], CultureInfo.InvariantCulture);
                }
                eraInfo[i] = new EraInfo(nums[0], new DateTime(nums[1], nums[2], nums[3]).Ticks, nums[4], nums[5], maxEraYear - nums[4]);
                maxEraYear = nums[1];
            }
            return(eraInfo);
        }
 private static EraInfo[] TrimEras(EraInfo[] baseEras)
 {
     EraInfo[] array = new EraInfo[baseEras.Length];
     int index = 0;
     for (int i = 0; i < baseEras.Length; i++)
     {
         if ((baseEras[i].yearOffset + baseEras[i].minEraYear) < 0x801)
         {
             if ((baseEras[i].yearOffset + baseEras[i].maxEraYear) < 0x7a8)
             {
                 break;
             }
             array[index] = baseEras[i];
             index++;
         }
     }
     if (index == 0)
     {
         return baseEras;
     }
     Array.Resize<EraInfo>(ref array, index);
     return array;
 }
コード例 #9
0
        // Token: 0x06002F37 RID: 12087 RVA: 0x000B50AC File Offset: 0x000B32AC
        private static EraInfo[] TrimEras(EraInfo[] baseEras)
        {
            EraInfo[] array = new EraInfo[baseEras.Length];
            int       num   = 0;

            for (int i = 0; i < baseEras.Length; i++)
            {
                if (baseEras[i].yearOffset + baseEras[i].minEraYear < 2049)
                {
                    if (baseEras[i].yearOffset + baseEras[i].maxEraYear < 1960)
                    {
                        break;
                    }
                    array[num] = baseEras[i];
                    num++;
                }
            }
            if (num == 0)
            {
                return(baseEras);
            }
            Array.Resize <EraInfo>(ref array, num);
            return(array);
        }
コード例 #10
0
        private static EraInfo[] TrimEras(EraInfo[] baseEras)
        {
            EraInfo[] array = new EraInfo[baseEras.Length];
            int       index = 0;

            for (int i = 0; i < baseEras.Length; i++)
            {
                if ((baseEras[i].yearOffset + baseEras[i].minEraYear) < 0x801)
                {
                    if ((baseEras[i].yearOffset + baseEras[i].maxEraYear) < 0x7a8)
                    {
                        break;
                    }
                    array[index] = baseEras[i];
                    index++;
                }
            }
            if (index == 0)
            {
                return(baseEras);
            }
            Array.Resize <EraInfo>(ref array, index);
            return(array);
        }
コード例 #11
0
ファイル: KoreanCalendar.cs プロジェクト: sjyanxin/WPFSource
 static EraInfo[] InitEraInfo()
 {
     EraInfo[] eraRanges = new EraInfo[1];
     eraRanges[0] = new EraInfo( 1, 1, 1, 1, -2333, 2334, GregorianCalendar.MaxYear + 2333);   // era #, start year/month/day, yearOffset, minEraYear 
     return eraRanges;
 } 
コード例 #12
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;
            EraInfo[] registryEraRanges = null;
#if !MONO            
            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);

                // Abort if we didn't find anything
                if (key == null) return null;

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null) continue;

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;                        
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return null;
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return null;
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return null;
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4) return null;

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i-1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }
#endif
            // Return our ranges
            return registryEraRanges;
        }
コード例 #13
0
 //
 // Compare two era ranges, eg just the ticks
 // Remember the era array is supposed to be in reverse chronological order
 //
 private static int CompareEraRanges(EraInfo a, EraInfo b)
 {
     return b.ticks.CompareTo(a.ticks);
 }
コード例 #14
0
 // Construct an instance of gregorian calendar.
 internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo) {
     m_Cal = cal;
     m_EraInfo = eraInfo;            
     m_minDate = new DateTime(m_EraInfo[m_EraInfo.Length - 1].ticks);
     m_maxYear = m_EraInfo[0].maxEraYear;
     m_minYear = m_EraInfo[0].minEraYear;;
 }
コード例 #15
0
        //
        // Read our era info
        //
        // m_EraInfo must be listed in reverse chronological order.  The most recent era
        // should be the first element.
        // That is, m_EraInfo[0] contains the most recent era.
        //
        // We know about 4 built-in eras, however users may add additional era(s) from the
        // registry, by adding values to HKLM\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras
        //
        // Registry values look like:
        //      yyyy.mm.dd=era_abbrev_english_englishabbrev
        //
        // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
        // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
        // era is the Japanese Era name
        // abbrev is the Abbreviated Japanese Era Name
        // english is the English name for the Era (unused)
        // englishabbrev is the Abbreviated English name for the era.
        // . is a delimiter, but the value of . doesn't matter.
        // '_' marks the space between the japanese era name, japanese abbreviated era name
        //     english name, and abbreviated english names.
        //
        internal static EraInfo[] GetEraInfo()
        {
            // See if we need to build it
            if (japaneseEraInfo == null)
            {
#if !__APPLE__

                // See if we have any eras from the registry
                japaneseEraInfo = GetErasFromRegistry();
#endif
                // See if we have to use the built-in eras
                if (japaneseEraInfo == null)
                {
                    // We know about some built-in ranges
                    EraInfo[] defaultEraRanges = new EraInfo[4];
                    defaultEraRanges[0] = new EraInfo( 4, 1989,  1,  8, 1988, 1, GregorianCalendar.MaxYear - 1988,
                                                       "\x5e73\x6210", "\x5e73", "H");    // era #4 start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[1] = new EraInfo( 3, 1926, 12, 25, 1925, 1, 1989-1925,
                                                       "\x662d\x548c", "\x662d", "S");    // era #3,start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[2] = new EraInfo( 2, 1912,  7, 30, 1911, 1, 1926-1911,
                                                       "\x5927\x6b63", "\x5927", "T");    // era #2,start year/month/day, yearOffset, minEraYear
                    defaultEraRanges[3] = new EraInfo( 1, 1868,  1,  1, 1867, 1, 1912-1867,
                                                       "\x660e\x6cbb", "\x660e", "M");    // era #1,start year/month/day, yearOffset, minEraYear

                    // Remember the ranges we built
                    japaneseEraInfo = defaultEraRanges;
                }
            }

            // return the era we found/made
            return japaneseEraInfo;
        }
コード例 #16
0
        // We know about 5 built-in eras, however users may add additional era(s) from the
        // registry, by adding values to HKLM\SYSTEM\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras
        //
        // Registry values look like:
        //      yyyy.mm.dd=era_abbrev_english_englishabbrev
        //
        // Where yyyy.mm.dd is the registry value name, and also the date of the era start.
        // yyyy, mm, and dd are the year, month & day the era begins (4, 2 & 2 digits long)
        // era is the Japanese Era name
        // abbrev is the Abbreviated Japanese Era Name
        // english is the English name for the Era (unused)
        // englishabbrev is the Abbreviated English name for the era.
        // . is a delimiter, but the value of . doesn't matter.
        // '_' marks the space between the japanese era name, japanese abbreviated era name
        //     english name, and abbreviated english names.
        private static EraInfo[]? GetJapaneseEras()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;

            EraInfo[]? registryEraRanges = null;

            try
            {
                // Need to access registry
                using (RegistryKey? key = Registry.LocalMachine.OpenSubKey(JapaneseErasHive))
                {
                    // Abort if we didn't find anything
                    if (key == null)
                    {
                        return(null);
                    }

                    // Look up the values in our reg key
                    string[] valueNames = key.GetValueNames();
                    if (valueNames != null && valueNames.Length > 0)
                    {
                        registryEraRanges = new EraInfo[valueNames.Length];

                        // Loop through the registry and read in all the values
                        for (int i = 0; i < valueNames.Length; i++)
                        {
                            // See if the era is a valid date
                            EraInfo?era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i])?.ToString());

                            // continue if not valid
                            if (era == null)
                            {
                                continue;
                            }

                            // Remember we found one.
                            registryEraRanges[iFoundEras] = era;
                            iFoundEras++;
                        }
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return(null);
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return(null);
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return(null);
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 5 eras
            //
            if (iFoundEras < 5)
            {
                return(null);
            }

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges !, CompareEraRanges); // TODO-NULLABLE: Remove ! when nullable attributes are respected

            // Clean up era information
            for (int i = 0; i < registryEraRanges !.Length; i++) // TODO-NULLABLE: Remove ! when nullable attributes are respected
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i - 1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }

            // Return our ranges
            return(registryEraRanges);
        }
コード例 #17
0
 // Construct an instance of gregorian calendar.
 internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo)
 {
     m_Cal = cal;
     m_EraInfo = eraInfo;
     m_maxYear = m_EraInfo[0].maxEraYear;
     m_minYear = m_EraInfo[0].minEraYear; ;
 }
コード例 #18
0
        // Trim off the eras that are before our date range
        private static EraInfo[] TrimEras(EraInfo[] baseEras)
        {
            EraInfo[] newEras = new EraInfo[baseEras.Length];
            int newIndex = 0;

            // Eras have most recent first, so start with that
            for (int i = 0; i < baseEras.Length; i++)
            {
                // If this one's minimum year is bigger than our maximum year
                // then we can't use it.
                if (baseEras[i].yearOffset + baseEras[i].minEraYear >= MAX_LUNISOLAR_YEAR)
                {
                    // skip this one.
                    continue;
                }

                // If this one's maximum era is less than our minimum era
                // then we've gotten too low in the era #s, so we're done
                if (baseEras[i].yearOffset + baseEras[i].maxEraYear < MIN_LUNISOLAR_YEAR)
                {
                    break;
                }

                // Wasn't too large or too small, can use this one
                newEras[newIndex] = baseEras[i];
                newIndex++;
            }

            // If we didn't copy any then something was wrong, just return base
            if (newIndex == 0) return baseEras;

            // Resize the output array
            Array.Resize(ref newEras, newIndex);
            return newEras;
        }
コード例 #19
0
 //
 // Compare two era ranges, eg just the ticks
 // Remember the era array is supposed to be in reverse chronological order
 //
 private static int CompareEraRanges(EraInfo a, EraInfo b)
 {
     return(b.ticks.CompareTo(a.ticks));
 }
コード例 #20
0
 // Construct an instance of gregorian calendar.
 internal GregorianCalendarHelper(Calendar cal, EraInfo[] eraInfo) {
     m_Cal = cal;
     m_EraInfo = eraInfo;            
     // m_minDate is existing here just to keep the serialization compatibility. 
     // it has nothing to do with the code anymore. 
     m_minDate = m_Cal.MinSupportedDateTime;
     m_maxYear = m_EraInfo[0].maxEraYear;
     m_minYear = m_EraInfo[0].minEraYear;;
 }
コード例 #21
0
        private static EraInfo[] GetErasFromRegistry()
        {
            int newSize = 0;

            EraInfo[] array = (EraInfo[])null;
            try
            {
                PermissionSet      permissionSet      = new PermissionSet(PermissionState.None);
                RegistryPermission registryPermission = new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras");
                permissionSet.AddPermission((IPermission)registryPermission);
                permissionSet.Assert();
                RegistryKey registryKey = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey("System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras", false);
                if (registryKey == null)
                {
                    return((EraInfo[])null);
                }
                string[] valueNames = registryKey.GetValueNames();
                if (valueNames != null)
                {
                    if (valueNames.Length != 0)
                    {
                        array = new EraInfo[valueNames.Length];
                        for (int index = 0; index < valueNames.Length; ++index)
                        {
                            EraInfo eraFromValue = JapaneseCalendar.GetEraFromValue(valueNames[index], registryKey.GetValue(valueNames[index]).ToString());
                            if (eraFromValue != null)
                            {
                                array[newSize] = eraFromValue;
                                ++newSize;
                            }
                        }
                    }
                }
            }
            catch (SecurityException ex)
            {
                return((EraInfo[])null);
            }
            catch (IOException ex)
            {
                return((EraInfo[])null);
            }
            catch (UnauthorizedAccessException ex)
            {
                return((EraInfo[])null);
            }
            if (newSize < 4)
            {
                return((EraInfo[])null);
            }
            Array.Resize <EraInfo>(ref array, newSize);
            Array.Sort <EraInfo>(array, new Comparison <EraInfo>(JapaneseCalendar.CompareEraRanges));
            for (int index = 0; index < array.Length; ++index)
            {
                array[index].era = array.Length - index;
                if (index == 0)
                {
                    array[0].maxEraYear = 9999 - array[0].yearOffset;
                }
                else
                {
                    array[index].maxEraYear = array[index - 1].yearOffset + 1 - array[index].yearOffset;
                }
            }
            return(array);
        }
コード例 #22
0
        /*=================================InitEraInfo==========================
        **Action: Get the era range information from calendar.nlp.
        **Returns: An array of EraInfo, which contains the information about an era.
        **Arguments:
        **      calID     the Calendar ID defined in Calendar.cs
        ============================================================================*/
        internal static EraInfo[] InitEraInfo(int calID) {
            //
            // Initialize era information.
            //

            /*
            Japaense era info example:
            eraInfo[0] = new EraInfo(4, new DateTime(1989, 1, 8).Ticks, 1988, 1, GregorianCalendar.MaxYear - 1988);    // Heisei. Most recent
            eraInfo[1] = new EraInfo(3, new DateTime(1926, 12, 25).Ticks, 1925, 1, 1989 - 1925);  // Showa
            eraInfo[2] = new EraInfo(2, new DateTime(1912, 7, 30).Ticks, 1911, 1, 1926 - 1911);   // Taisho
            eraInfo[3] = new EraInfo(1, new DateTime(1868, 9, 8).Ticks, 1867, 1, 1912 - 1867);    // Meiji            
            */
            String[] eraRanges = CalendarTable.GetMultipleStringValues(calID, CalendarTable.SERARANGES, false);
            EraInfo [] eraInfo = new EraInfo[eraRanges.Length];
            int maxEraYear = GregorianCalendar.MaxYear;
            for (int i = 0; i < eraRanges.Length; i++) {
                //
                // The eraRange string is in the form of "4;1989;1;8;1988;1".
                // num[0] is the era value.
                // num[1] is the year when the era starts.
                // num[2] is the month when the era starts.
                // num[3] is the day when the era starts.
                // num[4] is the offset to Gregorian year (1988).
                // num[5] is the minimum era year for this era.
                //
                String[] numStrs = eraRanges[i].Split(new char[] {';'});
                int[] nums = new int[6];
                for (int j = 0; j < 6; j++) {
                    nums[j] = Int32.Parse(numStrs[j], CultureInfo.InvariantCulture);
                }
                eraInfo[i] = new EraInfo(nums[0], new DateTime(nums[1], nums[2], nums[3]).Ticks, nums[4], nums[5], maxEraYear - nums[4]);
                maxEraYear= nums[1];
            }
            return (eraInfo);
        }
コード例 #23
0
        /*=================================InitEraInfo==========================
        **Action: Get the era range information from calendar.nlp.
        **Returns: An array of EraInfo, which contains the information about an era.
        **Arguments:
        **      calID     the Calendar ID defined in Calendar.cs
        ============================================================================*/
        internal static EraInfo[] InitEraInfo(int calID) {
            //
            // Initialize era information.
            //

            /*
            Japaense era info example:
            eraInfo[0] = new EraInfo(4, new DateTime(1989, 1, 8).Ticks, 1988, 1, GregorianCalendar.MaxYear - 1988);    // Heisei. Most recent
            eraInfo[1] = new EraInfo(3, new DateTime(1926, 12, 25).Ticks, 1925, 1, 1989 - 1925);  // Showa
            eraInfo[2] = new EraInfo(2, new DateTime(1912, 7, 30).Ticks, 1911, 1, 1926 - 1911);   // Taisho
            eraInfo[3] = new EraInfo(1, new DateTime(1868, 9, 8).Ticks, 1867, 1, 1912 - 1867);    // Meiji            
            */
            BCLDebug.Assert(calID > 0, "[GregorianCalendarHelper.InitEraInfo] Expected calID > 0");
            int[][] eraRanges = CalendarTable.Default.SERARANGES(calID);
            EraInfo [] eraInfo = new EraInfo[eraRanges.Length];
            int maxEraYear = GregorianCalendar.MaxYear;
            for (int i = 0; i < eraRanges.Length; i++)
            {
                //
                // The eraRange arrays are each the form of "4 1989 1 8 1988 1".
                // eraRanges[i][0] is the era value.
                // eraRanges[i][1] is the year when the era starts.
                // eraRanges[i][2] is the month when the era starts.
                // eraRanges[i][3] is the day when the era starts.
                // eraRanges[i][4] is the offset to Gregorian year (1988).
                // eraRanges[i][5] is the minimum era year for this era.
                //
                BCLDebug.Assert(eraRanges[i].Length == 6, "[GregorianCalendarHelper.InitEraInfo] Expected 6 SERARANGE elements (0-5), not " + eraRanges[i].Length);
                eraInfo[i] = new EraInfo(eraRanges[i][0], new DateTime(eraRanges[i][1], eraRanges[i][2], eraRanges[i][3]).Ticks, eraRanges[i][4], eraRanges[i][5], maxEraYear - eraRanges[i][4]);
                maxEraYear= eraRanges[i][1];
            }
            return (eraInfo);
        }
コード例 #24
0
        private static EraInfo[] GetErasFromRegistry()
        {
            int index = 0;

            EraInfo[] array = null;
            try
            {
                PermissionSet set = new PermissionSet(PermissionState.None);
                set.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, @"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras"));
                set.Assert();
                RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(@"System\CurrentControlSet\Control\Nls\Calendars\Japanese\Eras", false);
                if (key == null)
                {
                    return(null);
                }
                string[] valueNames = key.GetValueNames();
                if ((valueNames != null) && (valueNames.Length > 0))
                {
                    array = new EraInfo[valueNames.Length];
                    for (int j = 0; j < valueNames.Length; j++)
                    {
                        EraInfo eraFromValue = GetEraFromValue(valueNames[j], key.GetValue(valueNames[j]).ToString());
                        if (eraFromValue != null)
                        {
                            array[index] = eraFromValue;
                            index++;
                        }
                    }
                }
            }
            catch (SecurityException)
            {
                return(null);
            }
            catch (IOException)
            {
                return(null);
            }
            catch (UnauthorizedAccessException)
            {
                return(null);
            }
            if (index < 4)
            {
                return(null);
            }
            Array.Resize <EraInfo>(ref array, index);
            Array.Sort <EraInfo>(array, new Comparison <EraInfo>(JapaneseCalendar.CompareEraRanges));
            for (int i = 0; i < array.Length; i++)
            {
                array[i].era = array.Length - i;
                if (i == 0)
                {
                    array[0].maxEraYear = 0x270f - array[0].yearOffset;
                }
                else
                {
                    array[i].maxEraYear = (array[i - 1].yearOffset + 1) - array[i].yearOffset;
                }
            }
            return(array);
        }
コード例 #25
0
 internal static EraInfo[] InitEraInfo(int calID)
 {
     int[][] numArray = CalendarTable.Default.SERARANGES(calID);
     EraInfo[] infoArray = new EraInfo[numArray.Length];
     int num = 0x270f;
     for (int i = 0; i < numArray.Length; i++)
     {
         DateTime time = new DateTime(numArray[i][1], numArray[i][2], numArray[i][3]);
         infoArray[i] = new EraInfo(numArray[i][0], time.Ticks, numArray[i][4], numArray[i][5], num - numArray[i][4]);
         num = numArray[i][1];
     }
     return infoArray;
 }
コード例 #26
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;

            EraInfo[] registryEraRanges = null;

            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);

                // Abort if we didn't find anything
                if (key == null)
                {
                    return(null);
                }

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null)
                        {
                            continue;
                        }

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return(null);
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return(null);
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return(null);
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4)
            {
                return(null);
            }

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i - 1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }

            // Return our ranges
            return(registryEraRanges);
        }