Example #1
0
    public static void Main()
    {
        bool reindex = false;

        Region[]    regions;
        SortVersion ver = null;

        // If the data has not been saved, create it.
        if (!File.Exists(FILENAME))
        {
            regions = GenerateData();
            ver     = CultureInfo.CurrentCulture.CompareInfo.Version;
            reindex = true;
        }
        // Retrieve the existing data.
        else
        {
            regions = RestoreData(out ver);
        }

        // Determine whether the current ordering is valid; if not, reorder.
        if (reindex || ver != CultureInfo.CurrentCulture.CompareInfo.Version)
        {
            Array.Sort(regions, new Example());
            // Save newly reordered data.
            SaveData(regions);
        }

        // Continue with application...
    }
Example #2
0
 public static bool IsEqual(this SortVersion @this, SortVersion other)
 {
     return(@this != null &&
            other != null &&
            @this.FullVersion == other.FullVersion &&
            @this.SortId == other.SortId);
 }
Example #3
0
        public void EquaityTest()
        {
            SortVersion version1 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
            SortVersion version2 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));

            Assert.Equal(version2, version1);
        }
        public void EquaityTest()
        {
            SortVersion version1 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));
            SortVersion version2 = new SortVersion(393742, new Guid("00000001-57ee-1e5c-00b4-d0000bb1e11e"));

            Assert.Equal(version2, version1);
        }
 public void ConstructionsTest()
 {
     string guidString =  "00000001-57ee-1e5c-00b4-d0000bb1e11e";
     SortVersion version = new SortVersion(393742, new Guid(guidString));
     Assert.Equal(393742, version.FullVersion);
     Assert.Equal(new Guid(guidString), version.SortId);
 }
Example #6
0
        public void VersionTest()
        {
            SortVersion sv1 = CultureInfo.GetCultureInfo("en-US").CompareInfo.Version;
            SortVersion sv2 = CultureInfo.GetCultureInfo("ja-JP").CompareInfo.Version;

            Assert.Equal(sv1.FullVersion, sv2.FullVersion);
            Assert.NotEqual(sv1.SortId, sv2.SortId);
        }
Example #7
0
        public void ConstructionsTest()
        {
            string      guidString = "00000001-57ee-1e5c-00b4-d0000bb1e11e";
            SortVersion version    = new SortVersion(393742, new Guid(guidString));

            Assert.Equal(393742, version.FullVersion);
            Assert.Equal(new Guid(guidString), version.SortId);
        }
Example #8
0
        public static void IsEqual(this SortVersion @this, SortVersion other, bool isSamePlatform)
        {
            if (@this == null && other == null)
            {
                return;
            }

            Assert.NotNull(@this);
            Assert.NotNull(other);
            Assert.Equal(@this.FullVersion, other.FullVersion);
            Assert.Equal(@this.SortId, other.SortId);
        }
Example #9
0
    private static void SaveData(Region[] regions)
    {
        SortVersion ver = CultureInfo.CurrentCulture.CompareInfo.Version;

        BinaryWriter wrtr = new BinaryWriter(File.Open(FILENAME, FileMode.Create));

        wrtr.Write(ver.FullVersion);
        wrtr.Write(ver.SortId.ToString());

        foreach (var region in regions)
        {
            wrtr.Write(region.Id);
            wrtr.Write(region.NativeName);
        }
        wrtr.Close();
    }
Example #10
0
    private static Region[] RestoreData(out SortVersion ver)
    {
        List <Region> regions = new List <Region>();

        BinaryReader rdr = new BinaryReader(File.Open(FILENAME, FileMode.Open));

        int  sortVer = rdr.ReadInt32();
        Guid sortId  = Guid.Parse(rdr.ReadString());

        ver = new SortVersion(sortVer, sortId);

        string id, name;

        while (rdr.PeekChar() != -1)
        {
            id   = rdr.ReadString();
            name = rdr.ReadString();
            regions.Add(new Region(id, name));
        }
        return(regions.ToArray());
    }