Esempio n. 1
0
        protected virtual void ReadResources()
        {
            if (resources_read)
            {
                return;
            }

            if (Reader == null)
            {
                throw new ObjectDisposedException("ResourceSet is closed.");
            }
            lock (Table) {
                if (resources_read)
                {
                    return;
                }

                IDictionaryEnumerator i = Reader.GetEnumerator();
                i.Reset();
                while (i.MoveNext())
                {
                    Table.Add(i.Key, i.Value);
                }
                resources_read = true;
            }
        }
        // Sets the string list for the control to the strings
        // loaded from a resource file.
        private void LoadResources(object sender, EventArgs e)
        {
            IResourceService rs = (IResourceService)this.Component.Site.GetService(typeof(IResourceService));

            if (rs == null)
            {
                throw new Exception("Could not obtain IResourceService.");
            }

            IResourceReader rr = rs.GetResourceReader(CultureInfo.CurrentUICulture);

            if (rr == null)
            {
                throw new Exception("Resource file could not be obtained. You may need to create one first.");
            }

            IDictionaryEnumerator de = rr.GetEnumerator();

            if (this.Control.GetType() == typeof(ResourceTestControl))
            {
                ResourceTestControl rtc = (ResourceTestControl)this.Control;
                string s1, s2, s3;
                de.MoveNext();
                s1 = (string)((DictionaryEntry)de.Current).Value;
                de.MoveNext();
                s2 = (string)((DictionaryEntry)de.Current).Value;
                de.MoveNext();
                s3 = (string)((DictionaryEntry)de.Current).Value;
                de.MoveNext();
                rtc.resource_strings = new string[] { s1, s2, s3 };
                this.Control.Refresh();
            }
        }
            private Hashtable CreateResourceSet(IResourceReader reader, CultureInfo culture)
            {
                Hashtable hashtable = new Hashtable();

                try
                {
                    IDictionaryEnumerator enumerator = reader.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        string key  = (string)enumerator.Key;
                        object obj2 = enumerator.Value;
                        hashtable[key] = obj2;
                    }
                }
                catch (Exception exception)
                {
                    Exception exception2;
                    string    message = exception.Message;
                    if ((message == null) || (message.Length == 0))
                    {
                        message = exception.GetType().Name;
                    }
                    if (culture == CultureInfo.InvariantCulture)
                    {
                        exception2 = new SerializationException(System.Design.SR.GetString("SerializerResourceExceptionInvariant", new object[] { message }), exception);
                    }
                    else
                    {
                        exception2 = new SerializationException(System.Design.SR.GetString("SerializerResourceException", new object[] { culture.ToString(), message }), exception);
                    }
                    this.manager.ReportError(exception2);
                }
                return(hashtable);
            }
Esempio n. 4
0
        private IDictionaryEnumerator GetEnumeratorHelper()
        {
            IResourceReader copyOfReader = Reader;
            if (copyOfReader == null || _resCache == null)
                throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet);

            return copyOfReader.GetEnumerator();
        }
Esempio n. 5
0
        /// <include file='doc\ResourceSet.uex' path='docs/doc[@for="ResourceSet.GetString2"]/*' />
        public virtual String GetString(String name, bool ignoreCase)
        {
            if (Table == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("Arg_ClosedResourceTable"));
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            String s;

            try {
                s = (String)Table[name];
            }
            catch (InvalidCastException) {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ResourceNotString_Name", name));
            }
            if (s != null || !ignoreCase)
            {
                return(s);
            }

            // Try doing a case-insensitive lookup.
            if (_caseInsensitiveTable == null)
            {
                _caseInsensitiveTable = new Hashtable(new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture), new CaseInsensitiveComparer(CultureInfo.InvariantCulture));
#if _DEBUG
                //Console.WriteLine("ResourceSet::GetString loading up data.  ignoreCase: "+ignoreCase);
                BCLDebug.Perf(!ignoreCase, "Using case-insensitive lookups is bad perf-wise.  Consider capitalizing " + name + " correctly in your source");
#endif
                IDictionaryEnumerator en = Reader.GetEnumerator();
                while (en.MoveNext())
                {
                    _caseInsensitiveTable.Add(en.Key, en.Value);
                }
            }
            try {
                return((String)_caseInsensitiveTable[name]);
            }
            catch (InvalidCastException) {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ResourceNotString_Name", name));
            }
        }
Esempio n. 6
0
        // Read all resources into the hash table.
        protected virtual void ReadResources()
        {
            IDictionaryEnumerator e = Reader.GetEnumerator();

            while (e.MoveNext())
            {
                Table.Add(e.Key, e.Value);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Loads the content of the specified <see cref="IResourceReader" /> into the cache.
        /// </summary>
        /// <param name="reader">The <see cref="IResourceReader" /> to be used to read the resource content.</param>
        protected virtual void LoadContent(IResourceReader reader)
        {
            IDictionaryEnumerator en = reader.GetEnumerator();

            while (en.MoveNext())
            {
                this.data.Add((string)en.Key, en.Value);
            }
        }
Esempio n. 8
0
        private IDictionaryEnumerator GetEnumeratorHelper()
        {
            IResourceReader reader = base.Reader;

            if ((reader == null) || (this._resCache == null))
            {
                throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
            }
            return(reader.GetEnumerator());
        }
Esempio n. 9
0
        public void CopyFrom(IResourceReader reader)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            var enumerator = reader.GetEnumerator();
            hasBeenSaved = false;

            while (enumerator.MoveNext())
                resources[(string)enumerator.Key] = enumerator.Value;
        }
Esempio n. 10
0
        private IDictionaryEnumerator GetEnumeratorHelper()
        {
            IResourceReader copyOfReader = Reader;

            if (copyOfReader == null || _resCache == null)
            {
                throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
            }

            return(copyOfReader.GetEnumerator());
        }
Esempio n. 11
0
        /// <include file='doc\ResourceSet.uex' path='docs/doc[@for="ResourceSet.ReadResources"]/*' />
        protected virtual void ReadResources()
        {
            IDictionaryEnumerator en = Reader.GetEnumerator();

            while (en.MoveNext())
            {
                Table.Add(en.Key, en.Value);
            }
            // While technically possible to close the Reader here, don't close it
            // to help with some WinRes lifetime issues.
        }
Esempio n. 12
0
        protected virtual void ReadResources()
        {
            if (Reader == null)
            {
                throw new InvalidOperationException("ResourceSet is closed.");
            }

            IDictionaryEnumerator i = Reader.GetEnumerator();

            if (Table == null)
            {
                Table = new Hashtable();
            }
            i.Reset();

            while (i.MoveNext())
            {
                Table.Add(i.Key, i.Value);
            }
        }
Esempio n. 13
0
        // closes reader when done
        private static void ReadResources(IResourceReader reader)
        {
            IDictionaryEnumerator resEnum = reader.GetEnumerator();

            while (resEnum.MoveNext())
            {
                string name  = (string)resEnum.Key;
                object value = resEnum.Value;
                AddResource(name, value);
            }
            reader.Close();
        }
 private void ReadResources(IResourceReader reader, string fileName)
 {
     using (reader)
     {
         IDictionaryEnumerator enumerator = reader.GetEnumerator();
         while (enumerator.MoveNext())
         {
             string key  = (string)enumerator.Key;
             object obj2 = enumerator.Value;
             this.AddResource(key, obj2, fileName);
         }
     }
 }
Esempio n. 15
0
 protected virtual void ReadResources()
 {
     Debug.Assert(Table != null);
     Debug.Assert(Reader != null);
     IDictionaryEnumerator en = Reader.GetEnumerator();
     while (en.MoveNext())
     {
         object? value = en.Value;
         Table.Add(en.Key, value);
     }
     // While technically possible to close the Reader here, don't close it
     // to help with some WinRes lifetime issues.
 }
Esempio n. 16
0
        public Image ReadImage(String aName)
        {
            // Create an IDictionaryEnumerator to iterate through the resources.
            IDictionaryEnumerator id = reader.GetEnumerator();

            // Iterate through the resources and display the contents to the console.
            while (id.MoveNext())
            {
                if (id.Key.ToString() == aName)
                {
                    return((Image)id.Value);
                }
            }

            return(null);
        }
        private IDictionaryEnumerator GetEnumeratorHelper()
        {
            Hashtable       copyOfTable   = _table;
            IResourceReader copyOfReader  = Reader;
            Hashtable       copyOfCITable = _caseInsensitiveTable;

            if (copyOfReader == null || copyOfTable == null)
            {
                throw new InvalidOperationException("ResourceSet is closed");
            }

            if (_haveReadFromReader && copyOfCITable != null)
            {
                return(copyOfCITable.GetEnumerator());
            }
            return(copyOfReader.GetEnumerator());
        }
        protected virtual void ReadResources()
        {
            IDictionaryEnumerator en = Reader.GetEnumerator();

            while (en.MoveNext())
            {
                Object value = en.Value;
#if LOOSELY_LINKED_RESOURCE_REFERENCE
                if (Assembly != null && value is LooselyLinkedResourceReference)
                {
                    LooselyLinkedResourceReference assRef = (LooselyLinkedResourceReference)value;
                    value = assRef.Resolve(Assembly);
                }
#endif //LOOSELYLINKEDRESOURCEREFERENCE
                Table.Add(en.Key, value);
            }
            // While technically possible to close the Reader here, don't close it
            // to help with some WinRes lifetime issues.
        }
 private void ReadResources(IResourceReader reader, string fileName)
 {
     using (reader)
     {
         IDictionaryEnumerator enumerator = reader.GetEnumerator();
         while (enumerator.MoveNext())
         {
             string key = (string) enumerator.Key;
             object obj2 = enumerator.Value;
             this.AddResource(key, obj2, fileName);
         }
     }
 }
Esempio n. 20
0
 // closes reader when done
 private static void ReadResources(IResourceReader reader) {
     IDictionaryEnumerator resEnum = reader.GetEnumerator();
     while (resEnum.MoveNext()) {
         string name = (string)resEnum.Key;
         object value = resEnum.Value;
         AddResource(name, value);
     }
     reader.Close();
 }
		/// <summary>
		/// Loads the content of the specified <see cref="IResourceReader" /> into the cache.
		/// </summary>
		/// <param name="reader">The <see cref="IResourceReader" /> to be used to read the resource content.</param>
		protected virtual void LoadContent(IResourceReader reader)
		{
			IDictionaryEnumerator en = reader.GetEnumerator();
			while (en.MoveNext()) {
				this.data.Add((string)en.Key, en.Value);
			}
		}
        void IVsSingleFileGenerator.Generate(string wszInputFilePath,
                                             string bstrInputFileContents,
                                             string wszDefaultNamespace,
                                             out IntPtr outputFileContents,
                                             out int outputFileContentSize,
                                             IVsGeneratorProgress generationProgress)
        {
            if (bstrInputFileContents == null || bstrInputFileContents.Length <= 0)
            {
                outputFileContents    = IntPtr.Zero;
                outputFileContentSize = 0;

                if (generationProgress != null)
                {
                    generationProgress.Progress(100, 100);
                }

                return;
            }

            try {
                MemoryStream          outputStream = new MemoryStream();
                IResourceReader       reader       = ResXResourceReader.FromFileContents(bstrInputFileContents, this.typeResolver);
                IResourceWriter       writer       = new ResourceWriter(outputStream);
                IDictionaryEnumerator resEnum      = reader.GetEnumerator();

                // main conversion loop
                while (resEnum.MoveNext())
                {
                    string name  = (string)resEnum.Key;
                    object value = resEnum.Value;
                    writer.AddResource(name, value);
                }

                // cleanup
                reader.Close();
                writer.Generate();
                // don't close writer just yet -- that closes the stream, which we still need

                // Marshal into a bstr
                byte[] buffer        = outputStream.ToArray();
                int    bufferLength  = buffer.Length;
                IntPtr bufferPointer = Marshal.AllocCoTaskMem(bufferLength);
                Marshal.Copy(buffer, 0, bufferPointer, bufferLength);

                outputFileContents    = bufferPointer;
                outputFileContentSize = bufferLength;

                if (generationProgress != null)
                {
                    generationProgress.Progress(100, 100);
                }

                // Now close the stream
                writer.Close();
                outputStream.Close();

                writer       = null;
                outputStream = null;
                reader       = null;
            }
            catch (Exception e) {
                if (e.InnerException != null)
                {
                    throw e.InnerException;
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Read resources from an XML or binary format file
 /// </summary>
 /// <param name="reader">Appropriate IResourceReader</param>
 /// <param name="fileName">Filename, for error messages</param>
 private void ReadResources(ReaderInfo readerInfo, IResourceReader reader, String fileName)
 {
     using (reader)
     {
         IDictionaryEnumerator resEnum = reader.GetEnumerator();
         while (resEnum.MoveNext())
         {
             string name = (string)resEnum.Key;
             object value = resEnum.Value;
             AddResource(readerInfo, name, value, fileName);
         }
     }
 }
 private Hashtable CreateResourceSet(IResourceReader reader, CultureInfo culture)
 {
     Hashtable hashtable = new Hashtable();
     try
     {
         IDictionaryEnumerator enumerator = reader.GetEnumerator();
         while (enumerator.MoveNext())
         {
             string key = (string) enumerator.Key;
             object obj2 = enumerator.Value;
             hashtable[key] = obj2;
         }
     }
     catch (Exception exception)
     {
         Exception exception2;
         string message = exception.Message;
         if ((message == null) || (message.Length == 0))
         {
             message = exception.GetType().Name;
         }
         if (culture == CultureInfo.InvariantCulture)
         {
             exception2 = new SerializationException(System.Design.SR.GetString("SerializerResourceExceptionInvariant", new object[] { message }), exception);
         }
         else
         {
             exception2 = new SerializationException(System.Design.SR.GetString("SerializerResourceException", new object[] { culture.ToString(), message }), exception);
         }
         this.manager.ReportError(exception2);
     }
     return hashtable;
 }
        /// <summary>
        /// Read resources from an XML or binary format file
        /// </summary>
        /// <param name="reader">Appropriate IResourceReader</param>
        /// <param name="fileName">Filename, for error messages</param>
        private void ReadResources(IResourceReader reader, String fileName)
        {
            using (reader)
            {
                IDictionaryEnumerator resEnum = reader.GetEnumerator();
                while (resEnum.MoveNext())
                {
                    string name = (string)resEnum.Key;
                    // Replace dot in the name with underscore. 
                    // 1. First reason  - this is what desktop resource generator does.
                    // 2. Second reason - Extra dots causes resource generator to create name space and enumerations.
                    //    This complicates the syntax and finally create invalid code if 2 or more dots are present.
                    //    So we just make longer name.
                    name = name.Replace('.', '_');
                    object value = resEnum.Value;
                    AddResource(name, value, fileName);
                }
            }

            EnsureResourcesIds( this.resources );
        }