コード例 #1
0
        public void TestResourceManagerResourceSetClosedException()
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            ResourceManagerPoker rm = new ResourceManagerPoker();

            rm.InitResourceSets();

            ResourceSet rs = rm.GetResourceSet(CultureInfo.InvariantCulture,
                                               true, true);

            rs.Close();
            ResourceSet rs2 = rs;

            rs = rm.GetResourceSet(CultureInfo.InvariantCulture, true, true);
            Assert.IsTrue(Object.ReferenceEquals(rs2, rs), "#0");

            try {
                rm.GetString("HelloWorld");
                Assert.Fail("#1");
            } catch (ObjectDisposedException ex) {
                // ResourceSet is closed
                Assert.AreEqual(typeof(ObjectDisposedException), ex.GetType(), "#2");
                Assert.IsNull(ex.InnerException, "#3");
                Assert.IsNotNull(ex.Message, "#4");
            } finally {
                rm.ReleaseAllResources();
            }
        }
コード例 #2
0
ファイル: ZoneInfo.cs プロジェクト: jechague/DotNetClasses
        /// <summary>
        /// Returns all zoneinfo names for given zoneinfo directory.
        /// </summary>
        /// <param name="dir">Name of zoneinfo directory.</param>
        /// <returns>List of  all zoneinfo names from given zoneinfo directory.</returns>
        public static string[] GetAllNames(string dir)
        {
            if (dir == null)
            {
                throw new ArgumentNullException("dir", "Directory name can not be null.");
            }
#if !NETCORE
            ResourceManager rm = new ResourceManager(resRootName, Assembly.GetExecutingAssembly());
            ResourceSet     rs = rm.GetResourceSet(CultureInfo.InvariantCulture, true, true);

            ArrayList names   = new ArrayList();
            string    pattern = string.Format("{0}/", dir);
            foreach (DictionaryEntry entry in rs)
            {
                string key = (string)entry.Key;
                if (key.StartsWith(pattern))
                {
                    names.Add(key.Substring(pattern.Length));
                }
            }
            rs.Close();
            return((string[])names.ToArray(typeof(string)));
#else
            return(ZoneInfoConsts.AllNames);
#endif
        }
コード例 #3
0
        //currently does not work if called before Initialize, this will change when Board is implemented
        public bool CreateFile(Board map, string timeStamp)
        {
            if (map == null)
            {
                return(false);
            }
            string newMap = "";

            newMap += String.Format("{0}X{1}\n", map.numRows, map.numColumns);
            for (int i = 0; i < map.numRows; i++)
            {
                for (int j = 0; j < map.numColumns; j++)
                {
                    int             row         = i;
                    int             column      = j;
                    Tile            currentTile = map.spaces[row, column];
                    TileEnumeration terrain     = currentTile.m_terrainType;
                    Unit            unit        = currentTile.m_unit;
                    if (i == map.numRows - 1 && j == map.numColumns - 1)
                    {
                        newMap += String.Format("{0}{1} {2}{3}", (char)(row + 'A'), column + 1, (int)terrain, (unit == null) ? "" : " " + ConvertUnitToRegexFormat(unit));
                    }
                    else
                    {
                        newMap += String.Format("{0}{1} {2}{3}\n", (char)(row + 'A'), column + 1, (int)terrain, (unit == null) ? "" : " " + ConvertUnitToRegexFormat(unit));
                    }
                }
            }
            ResourceSet                 reader   = new ResourceSet("MapFiles.resources");
            IDictionaryEnumerator       saves    = reader.GetEnumerator();
            Dictionary <object, object> saveInfo = new Dictionary <object, object>();

            foreach (DictionaryEntry entry in reader)
            {
                saveInfo.Add(entry.Key, entry.Value);
            }
            reader.Close();
            ResourceWriter resWriter = new ResourceWriter("MapFiles.resources");

            foreach (KeyValuePair <object, object> entry in saveInfo)
            {
                string key   = entry.Key.ToString();
                string value = entry.Value.ToString();
                resWriter.AddResource(key, value);
            }
            resWriter.AddResource(String.Format("{0}_{1}", map.name, timeStamp), newMap);
            resWriter.Close();
            return(true);
        }
コード例 #4
0
        public static Dictionary <string, string> ConvertActorLabelType()
        {
            Dictionary <string, string> labelTypes = new Dictionary <string, string>();

            System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager(typeof(Resources.ActorLabelType));
            ResourceSet           resourceSet = resourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);
            IDictionaryEnumerator id          = resourceSet.GetEnumerator();

            while (id.MoveNext())
            {
                labelTypes.Add(id.Key.ToString(), id.Value.ToString());
            }
            resourceSet.Close();
            return(labelTypes);
        }
コード例 #5
0
ファイル: getenumerator.cs プロジェクト: winxxp/samples
    public static void Main()
    {
        // Create a ResourceSet for the file items.resources.
        ResourceSet rs = new ResourceSet("items.resources");

        // Create an IDictionaryEnumerator to read the data in the ResourceSet.
        IDictionaryEnumerator id = rs.GetEnumerator();

        // Iterate through the ResourceSet and display the contents to the console.
        while (id.MoveNext())
        {
            Console.WriteLine("\n[{0}] \t{1}", id.Key, id.Value);
        }

        rs.Close();
    }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: cansou/sharpQQ
        private void onclick(object sender, RoutedEventArgs e)
        {
            tab1.IsSelected = true;
            MessageBox.Show("hello boy!");

            foreach (Window win in Application.Current.Windows)
            {
                MessageBox.Show(win.Title);
            }
            Assembly        assembly     = Assembly.GetExecutingAssembly();
            String          resourceName = assembly.GetName().Name + ".g";
            ResourceManager rm           = new ResourceManager(resourceName, assembly);
            ResourceSet     rs           = rm.GetResourceSet(CultureInfo.CurrentCulture, true, true);

            foreach (DictionaryEntry entry in rs)
            {
                MessageBox.Show(entry.Key.ToString() + "        " + entry.Value);
            }
            rs.Close();
        }
コード例 #7
0
        public void TestResourceManagerResourceSets()
        {
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            ResourceManagerPoker rm = new ResourceManagerPoker();

            rm.InitResourceSets();

            ResourceSet rs = rm.GetResourceSet(CultureInfo.InvariantCulture,
                                               true, true);

            Assert.AreEqual(1, rm.GetResourceSets().Keys.Count, "#01");

            rs.Close();

            Assert.AreEqual(1, rm.GetResourceSets().Keys.Count, "#02");

            rs = rm.GetResourceSet(CultureInfo.InvariantCulture,
                                   true, true);

            Assert.AreEqual(1, rm.GetResourceSets().Keys.Count, "#03");

            rm.ReleaseAllResources();
        }
コード例 #8
0
        private void Form2_Load(object sender, EventArgs e)
        {
reTry:

            ParamKeys.Clear();

            try
            {
                ResourceReader ResRead = new ResourceReader(@".\ConnectResources.resources");

                ResourceSet ResSet = new ResourceSet(@".\ConnectResources.resources");

                DataSet dS = new DataSet();
                dS.Tables.Add("Settings");
                dS.Tables["Settings"].Columns.Add("parameter");
                dS.Tables["Settings"].Columns.Add("value");

                IDictionaryEnumerator id = ResSet.GetEnumerator();

                while (id.MoveNext())
                {
                    DataRow dTr = dS.Tables["Settings"].NewRow();
                    dTr["parameter"] = id.Key;
                    dTr["value"]     = id.Value;

                    ParamKeys.Add(id.Key.ToString(), id.Value.ToString());

                    if (id.Key.ToString().ToLower().Contains("pass"))
                    {
                        dTr["value"] = "****";
                    }

                    dS.Tables["Settings"].Rows.Add(dTr);
                }


                dataGridView1.AutoGenerateColumns = true;
                dataGridView1.DataSource          = dS;
                dataGridView1.DataMember          = dS.Tables["Settings"].TableName;

                dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);

                ResRead.Close();
                ResSet.Close();

                ResRead.Dispose();
                ResSet.Dispose();
            }
            catch (Exception)
            {
                using (ResourceWriter rw = new ResourceWriter(@".\ConnectResources.resources"))
                {
                    rw.AddResource("UrlPGW", "http://10.215.32.30:8001;http://10.215.34.30:8001;");
                    rw.AddResource("urlSPG", "http://10.215.134.76:8080/spg;http://10.215.23.12:8080");
                    rw.AddResource("stpIP", "boNpdb=10.215.32.37;soNpdb=10.215.34.37");
                    rw.AddResource("stpIndex", "0:D95; 1:D12; 2:D11; 3:D83; 4:D84; 5:D85; 6:D92; 7:D81; 8:D82; 9:D13; 10:B14; 11:B12; 12:B11; 13:D20; 14:D21; 15:D90");
                    rw.AddResource("stpUser", "itmediation");
                    rw.AddResource("stpPass", Program.Base64Encode("itmediation")); //itmediation
                    rw.AddResource("pgwUser", "itbilling");
                    rw.AddResource("pgwPass", Program.Base64Encode("itbilling"));   //itbilling
                    rw.AddResource("spgUser", "bsstest");
                    rw.AddResource("spgPass", Program.Base64Encode("Huawei!@34"));  //Huawei!@34
                    rw.AddResource("DefaultRealm", "ims.ooredoo.om");
                    rw.AddResource("imsEnsZone", "8.6.9.e164.arpa");
                    rw.AddResource("userIFC", "10");
                    rw.AddResource("trunkIFC", "25");
                    rw.AddResource("imsSrvKey", "80");
                    rw.AddResource("imsScfAddr", "96895001060");
                    rw.AddResource("trunkSCSCF", "sip:boscscf1.ims.ooredoo.om");
                    rw.AddResource("AGCF", "BOAGCF");
                    rw.AddResource("ManualXmlInputDestination", "SPG");
                    rw.Generate();

                    rw.Close();
                    rw.Dispose();
                }

                goto reTry;
            }
        }