public ResourceSet(Stream stream) { Reader = new ResourceReader(stream); Table = new Hashtable(); ignoreCaseTable = null; ReadResources(); }
public ResourceSet (IResourceReader reader) { if (reader == null) throw new ArgumentNullException ("reader"); Table = new Hashtable (); Reader = reader; }
public ResourceSet(String fileName) { Reader = new ResourceReader(fileName); Table = new Hashtable(); ignoreCaseTable = null; ReadResources(); }
public RssFeedResources(IResourceReader resources) { this.resources = resources; var r = XmlReader.Create(new MemoryStream(new UTF8Encoding().GetBytes(resources.Read("http://molecule.nl/decorrespondent/rss.php")))); var xml = XDocument.Load(r); items = xml.XPathSelectElements("rss/channel/item").Select(i => new RssItem(i)).ToList(); }
/// <summary> /// Constructor. /// </summary> /// <param name="reader"></param> public ResourceReader(IResourceReader reader) { _resources = new Dictionary<string, Object>(); foreach (DictionaryEntry entry in reader) _resources.Add(entry.Key, entry.Value); }
public ResourceSet(String fileName, Assembly assembly) { Reader = new ResourceReader(fileName); CommonInit(); _assembly = assembly; ReadResources(); }
/// <summary> /// Override that reads existing resources into the list /// </summary> /// <param name="reader"></param> /// <param name="baseName"></param> /// <param name="cultureInfo"></param> public DbResourceWriter(IResourceReader reader, string baseName, CultureInfo cultureInfo) { this.baseName = baseName; this.cultureInfo = cultureInfo; resourceList = reader as IDictionary; }
/// <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 override void LoadContent(IResourceReader reader) { base.LoadContent(reader); IDictionaryEnumerator en = ((ResXResourceReader)reader).GetMetadataEnumerator(); while (en.MoveNext()) { this.metadata.Add((string)en.Key, en.Value); } }
public BuiltinResourceSet(IResourceReader reader) : base() { if(reader == null) { throw new ArgumentNullException("reader"); } Reader = reader; readResourcesCalled = false; }
public ResourceSet(IResourceReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } this.Reader = reader; this.CommonInit(); this.ReadResources(); }
string CompileResource(AppResourceFileInfo arfi, bool local) { string path = arfi.Info.FullName; string rname = Path.GetFileNameWithoutExtension(path) + ".resources"; if (!local) { rname = "Resources." + rname; } string resource = Path.Combine(TempDirectory, rname); FileStream source = null, destination = null; IResourceReader reader = null; ResourceWriter writer = null; try { source = new FileStream(path, FileMode.Open, FileAccess.Read); destination = new FileStream(resource, FileMode.Create, FileAccess.Write); reader = GetReaderForKind(arfi.Kind, source, path); writer = new ResourceWriter(destination); foreach (DictionaryEntry de in reader) { object val = de.Value; if (val is string) { writer.AddResource((string)de.Key, (string)val); } else { writer.AddResource((string)de.Key, val); } } } catch (Exception ex) { throw new HttpException("Failed to compile resource file", ex); } finally { if (reader != null) { reader.Dispose(); } if (source != null) { source.Dispose(); } if (writer != null) { writer.Dispose(); } if (destination != null) { destination.Dispose(); } } return(resource); }
public ResourceSet(IResourceReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } Contract.EndContractBlock(); Reader = reader; CommonInit(); ReadResources(); }
public ResourceSet(IResourceReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } Reader = reader; Table = new Hashtable(); ignoreCaseTable = null; ReadResources(); }
private IDictionaryEnumerator GetEnumeratorHelper() { IResourceReader copyOfReader = Reader; if (copyOfReader == null || _resCache == null) { throw new ObjectDisposedException(null, SR.ObjectDisposed_ResourceSet); } return(copyOfReader.GetEnumerator()); }
public ResourceSet(IResourceReader reader) { if(reader == null) { throw new ArgumentNullException("reader"); } Reader = reader; Table = new Hashtable(); ignoreCaseTable = null; ReadResources(); }
private void GenerateResourceFile(AssemblyBuilder assemblyBuilder, IResourceReader reader) { string str; if (this._ns == null) { str = UrlPath.GetFileNameWithoutExtension(base.VirtualPath) + ".resources"; } else if (this._cultureName == null) { str = this._ns + "." + this._typeName + ".resources"; } else { str = this._ns + "." + this._typeName + "." + this._cultureName + ".resources"; } str = str.ToLower(CultureInfo.InvariantCulture); Stream stream = null; try { try { try { } finally { stream = assemblyBuilder.CreateEmbeddedResource(this, str); } } catch (ArgumentException) { throw new HttpException(System.Web.SR.GetString("Duplicate_Resource_File", new object[] { base.VirtualPath })); } using (stream) { using (ResourceWriter writer = new ResourceWriter(stream)) { writer.TypeNameConverter = new Func<Type, string>(TargetFrameworkUtil.TypeNameConverter); foreach (DictionaryEntry entry in reader) { writer.AddResource((string) entry.Key, entry.Value); } } } } finally { if (stream != null) { stream.Close(); } } }
// 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 IDictionary GetResourceList(IResourceReader reader) { // Read the resources into a dictionary. IDictionary resourceList = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (DictionaryEntry de in reader) { resourceList.Add(de.Key, de.Value); } return(resourceList); }
public ResourceSet(IResourceReader reader, Assembly assembly) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } Contract.EndContractBlock(); Reader = reader; CommonInit(); _assembly = assembly; ReadResources(); }
private static void ProcessChunks(ChunkReader chunkReader, Stream stream, long readLength, IReadOnlyDictionary <uint, ObjectActivator <IResourceReader> > activators, ICollection <IResource> resources, IResourceReader resourceReader = null) { var endPosition = stream.Position + readLength; while (stream.Position < endPosition) { var chunk = chunkReader.NextChunk(); // Make sure we're dealing with a data chunk (ID 0 = padding) if (chunk.Id != 0) { // resourceReader will be null if we're at the top level if (resourceReader == null) { // Create resource reader and recurse var activatorExists = activators.TryGetValue(chunk.Id, out var activator); var newReader = activatorExists ? activator() : new GenericResourceReader(); if (activatorExists && chunk.IsContainer) { ProcessChunks(chunkReader, stream, chunk.Size, activators, resources, newReader); } else { newReader.ProcessChunk(chunk, chunkReader.BinaryReader); } var resource = newReader.GetResource(); Debug.Assert(resource != null, "resource != null"); resources.Add(resource); } else { if (chunk.IsContainer) { ProcessChunks(chunkReader, stream, chunk.Size, activators, resources, resourceReader); } else { resourceReader.ProcessChunk(chunk, chunkReader.BinaryReader); } } } stream.Position = chunk.EndOffset; } }
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); } } }
/// <summary> /// Initializes a new instance of a <see cref="T:Linguist.Resources.Binary.BinaryResourceSet" /> class /// using the default <see cref="T:Linguist.Resources.Binary.BinaryResourceExtractor" /> that opens /// and reads resources from the specified file. /// </summary> /// <param name="reader">The reader to read resources from.</param> public BinaryResourceSet ( IResourceReader reader ) { // NOTE: ResourceManager does not respect DefaultReader type and // creates a default ResourceReader. This forces the reader // back to a BinaryResourceExtractor. if ( reader is ResourceReader resourceReader ) reader = ConvertToDefaultReader ( resourceReader ); Reader = reader; Table = new Hashtable ( ); ReadResources ( ); }
public ResourceViewLocationProviderFixture() { this.reader = A.Fake <IResourceReader>(); this.assemblyProvider = A.Fake <IResourceAssemblyProvider>(); this.viewProvider = new ResourceViewLocationProvider(this.reader, this.assemblyProvider); if (!ResourceViewLocationProvider.RootNamespaces.ContainsKey(this.GetType().Assembly)) { ResourceViewLocationProvider.RootNamespaces.Add(this.GetType().Assembly, "Some.Resource"); } A.CallTo(() => this.assemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().Assembly }); }
public ImagesFolder(IResourceReader resources) : this("<root>", null) { foreach (DictionaryEntry e in resources) { if (!(e.Value is Image)) continue; AddImage(e.Key.ToString(), (Image)e.Value); } IsChanged = false; }
protected virtual void Dispose(bool disposing) { if (disposing) { // Close the Reader in a thread-safe way. IResourceReader?copyOfReader = Reader; Reader = null !; copyOfReader?.Close(); } Reader = null !; _caseInsensitiveTable = null; _table = null; }
public static string FindString <T>([NotNull] this IResourceReader resources, [NotNull] Expression <Func <string, bool> > predicateExpression) { if (resources == null) { throw new ArgumentNullException(nameof(resources)); } if (predicateExpression == null) { throw new ArgumentNullException(nameof(predicateExpression)); } return(resources.GetString(typeof(T).Assembly, resources.FindName <T>(predicateExpression))); }
object GetResource(CallExpression callExpression) { IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture); if (reader != null) { using (ResourceSet resources = new ResourceSet(reader)) { List <object> args = deserializer.GetArguments(callExpression); return(resources.GetObject(args[0] as String)); } } return(null); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (Reader != null) { Reader.Close(); } } Reader = null; Table = null; }
public Resource(string name, IResourceReader reader, IResourceWriter writer) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Resource name is not set", nameof(name)); } _name = name; _reader = reader ?? throw new ArgumentNullException(nameof(reader)); _writer = writer ?? throw new ArgumentNullException(nameof(writer)); _formatter = new CompositeResourceFormatter( new JsonResourceFormatter(), new XmlResourceFormatter()); }
private void GenerateStronglyTypedClass(AssemblyBuilder assemblyBuilder, IResourceReader reader) { IDictionary resourceList; string[] strArray; using (reader) { resourceList = this.GetResourceList(reader); } CodeDomProvider codeDomProvider = assemblyBuilder.CodeDomProvider; CodeCompileUnit compileUnit = StronglyTypedResourceBuilder.Create(resourceList, this._typeName, this._ns, codeDomProvider, false, out strArray); assemblyBuilder.AddCodeCompileUnit(this, compileUnit); }
public ResourceSet(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream is null"); } if (!stream.CanRead) { throw new ArgumentException("stream is not readable"); } Reader = new ResourceReader(stream); }
public ILocalizer Load(IResourceReader reader, out IEnumerable <string> missing, out IEnumerable <string> extra) { var lmissing = new List <string>(); var lextra = new List <string>(); var newLocalizer = new Localizer(); foreach (DictionaryEntry entry in reader) { var fullKey = (string)entry.Key; var semi = fullKey.IndexOf(SEPARATOR[0]); var type = fullKey.Substring(0, semi); var key = fullKey.Substring(semi + 1); var val = (string)entry.Value; if (type == "CULTURE") { newLocalizer.Culture = new CultureInfo(val); } else if (type == "VALUE") { newLocalizer.Add(key, val); } else if (type == "LIST") { newLocalizer.Add(key, val.SplitList().ToArray()); } else if (type == "TEMPLATE") { var elements = key.SplitList(); var usage = elements.First(); var fields = elements.Skip(1); var patterns = val.SplitList(); var template = new TemplateAttribute((TemplateUsage)Enum.Parse(typeof(TemplateUsage), usage), patterns.ToArray()); foreach (var field in fields) { newLocalizer.Add(field, template); } } } // Find missing and extra keys lmissing.AddRange(_translations.Keys.Except(newLocalizer._translations.Keys)); lmissing.AddRange(_arrayTranslations.Keys.Except(newLocalizer._arrayTranslations.Keys)); lmissing.AddRange(_templateTranslations.Keys.Except(newLocalizer._templateTranslations.Keys)); lextra.AddRange(newLocalizer._translations.Keys.Except(_translations.Keys)); lextra.AddRange(newLocalizer._arrayTranslations.Keys.Except(_arrayTranslations.Keys)); lextra.AddRange(newLocalizer._templateTranslations.Keys.Except(_templateTranslations.Keys)); missing = lmissing; extra = lextra; return(newLocalizer); }
public EmbeddedViewLocationProviderFixture() { EmbeddedViewLocationProvider.Ignore.Clear(); this.reader = A.Fake<IResourceReader>(); this.resourceAssemblyProvider = A.Fake<IResourceAssemblyProvider>(); this.viewProvider = new EmbeddedViewLocationProvider(this.reader, this.resourceAssemblyProvider); if (!EmbeddedViewLocationProvider.RootNamespaces.ContainsKey(this.GetType().Assembly)) { EmbeddedViewLocationProvider.RootNamespaces.Add(this.GetType().Assembly, "Some.Resource"); } A.CallTo(() => this.resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { this.GetType().Assembly }); }
public ImagesFolder(IResourceReader resources) : this("<root>", null) { foreach (DictionaryEntry e in resources) { if (!(e.Value is Image)) { continue; } AddImage(e.Key.ToString(), (Image)e.Value); } IsChanged = false; }
protected virtual void Dispose(bool disposing) { if (disposing) { IResourceReader reader = this.Reader; this.Reader = null; if (reader != null) { reader.Close(); } } this.Reader = null; this._caseInsensitiveTable = null; this.Table = null; }
/// <summary>释放与当前实例关联的资源(内存除外),并关闭内部托管对象(如果请求这样做)。</summary> /// <param name="disposing">指示是否应显式关闭当前实例中包含的对象。</param> protected virtual void Dispose(bool disposing) { if (disposing) { IResourceReader resourceReader = this.Reader; this.Reader = (IResourceReader)null; if (resourceReader != null) { resourceReader.Close(); } } this.Reader = (IResourceReader)null; this._caseInsensitiveTable = (Hashtable)null; this.Table = (Hashtable)null; }
protected virtual void Dispose(bool disposing) { if (disposing) { if (Reader != null) { Reader.Close(); } } Reader = null; Table = null; table_nocase = null; disposed = true; }
public override bool Walk(FunctionDefinition node) { if (IsInitializeComponentMethod(node)) { Type type = GetComponentType(); component = componentCreator.CreateComponent(type, componentName); IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture); if (reader != null) { reader.Dispose(); } node.Body.Walk(this); } return(false); }
public T Load <T>(string path, IResourceReader <T> reader) { object item; if (IsLoaded(path)) { item = this.loaded[path]; } else { item = reader.Read(path); this.loaded.Add(path, item); } return((T)item); }
public override void GenerateCode(AssemblyBuilder assemblyBuilder) { _cultureName = GetCultureName(); if (!_dontGenerateStronglyTypedClass) { // Get the namespace and type name that we will use _ns = Util.GetNamespaceAndTypeNameFromVirtualPath(VirtualPathObject, (_cultureName == null) ? 1 : 2 /*chunksToIgnore*/, out _typeName); // Always prepend the namespace with Resources. if (_ns.Length == 0) { _ns = DefaultResourcesNamespace; } else { _ns = DefaultResourcesNamespace + "." + _ns; } } // Get an input stream for our virtual path, and get a resource reader from it using (Stream inputStream = OpenStream()) { IResourceReader reader = GetResourceReader(inputStream); try { GenerateResourceFile(assemblyBuilder, reader); } catch (ArgumentException e) { // If the inner exception is Xml, throw that instead, as it contains more // useful info if (e.InnerException != null && (e.InnerException is XmlException || e.InnerException is XmlSchemaException)) { throw e.InnerException; } // Otherwise, so just rethrow throw; } // Skip the code part for satellite assemblies, or if dontGenerate is set if (_cultureName == null && !_dontGenerateStronglyTypedClass) { GenerateStronglyTypedClass(assemblyBuilder, reader); } } }
protected override void Walk(MethodDefinition node) { if (IsInitializeComponentMethod(node)) { Type type = GetComponentType(); component = componentCreator.CreateComponent(type, componentName); IResourceReader reader = componentCreator.GetResourceReader(CultureInfo.InvariantCulture); if (reader != null) { reader.Dispose(); } WalkMethodStatements(node.Body.Statements); } }
/// <include file='doc\ResourceSet.uex' path='docs/doc[@for="ResourceSet.Dispose"]/*' /> protected virtual void Dispose(bool disposing) { if (disposing) { // Close the Reader in a thread-safe way. Note that calling // Close multiple times needs to be thread-safe. IResourceReader copyOfReader = Reader; if (copyOfReader != null) { copyOfReader.Close(); } } Reader = null; _caseInsensitiveTable = null; Table = null; }
internal RuntimeResourceSet(IResourceReader reader) : // explicitly do not call IResourceReader constructor since it caches all resources // the purpose of RuntimeResourceSet is to lazily load and cache. base() { if (reader == null) throw new ArgumentNullException(nameof(reader)); _defaultReader = reader as DeserializingResourceReader ?? throw new ArgumentException(SR.Format(SR.NotSupported_WrongResourceReader_Type, reader.GetType()), nameof(reader)); _resCache = new Dictionary<string, ResourceLocator>(FastResourceComparer.Default); // in the CoreLib version RuntimeResourceSet creates ResourceReader and passes this in, // in the custom case ManifestBasedResourceReader creates the ResourceReader and passes it in // so we must initialize the cache here. _defaultReader._resCache = _resCache; }
protected virtual void Dispose(bool disposing) { if (disposing) { // Close the Reader in a thread-safe way. IResourceReader copyOfReader = Reader; Reader = null; if (copyOfReader != null) { copyOfReader.Close(); } } Reader = null; _caseInsensitiveTable = null; Table = null; }
protected virtual void Dispose(bool disposing) { if (disposing) { // Close the Reader in a thread-safe way. IResourceReader?copyOfReader = Reader; Reader = null !; // TODO-NULLABLE: Avoid nulling out in Dispose if (copyOfReader != null) { copyOfReader.Close(); } } Reader = null !; // TODO-NULLABLE: Avoid nulling out in Dispose _caseInsensitiveTable = null; Table = null; }
private static void GenerateResourceStream( LocBamlOptions options, // options from the command line string resourceName, // the name of the .resources file IResourceReader reader, // the reader for the .resources IResourceWriter writer, // the writer for the output .resources TranslationDictionariesReader dictionaries // the translations ) { options.WriteLine(StringLoader.Get("GenerateResource", resourceName)); // enumerate through each resource and generate it foreach(DictionaryEntry entry in reader) { string name = entry.Key as string; object resourceValue = null; // See if it looks like a Baml resource if (BamlStream.IsResourceEntryBamlStream(name, entry.Value)) { Stream targetStream = null; options.Write(" "); options.Write(StringLoader.Get("GenerateBaml", name)); // grab the localizations available for this Baml string bamlName = BamlStream.CombineBamlStreamName(resourceName, name); BamlLocalizationDictionary localizations = dictionaries[bamlName]; if (localizations != null) { targetStream = new MemoryStream(); // generate into a new Baml stream GenerateBamlStream( (Stream) entry.Value, targetStream, localizations, options ); } options.WriteLine(StringLoader.Get("Done")); // sets the generated object to be the generated baml stream resourceValue = targetStream; } if (resourceValue == null) { // // The stream is not localized as Baml yet, so we will make a copy of this item into // the localized resources // // We will add the value as is if it is serializable. Otherwise, make a copy resourceValue = entry.Value; object[] serializableAttributes = resourceValue.GetType().GetCustomAttributes(typeof(SerializableAttribute), true); if (serializableAttributes.Length == 0) { // The item returned from resource reader is not serializable // If it is Stream, we can wrap all the values in a MemoryStream and // add to the resource. Otherwise, we had to skip this resource. Stream resourceStream = resourceValue as Stream; if (resourceStream != null) { Stream targetStream = new MemoryStream(); byte[] buffer = new byte[resourceStream.Length]; resourceStream.Read(buffer, 0, buffer.Length); targetStream = new MemoryStream(buffer); resourceValue = targetStream; } } } if (resourceValue != null) { writer.AddResource(name, resourceValue); } } }
public ResourceSet(string fileName) { this.Reader = new ResourceReader(fileName); this.CommonInit(); this.ReadResources(); }
public MockResourceService() { reader = new MockResourceReader(); }
public void SetResourceReader(IResourceReader reader) { this.reader = reader; }
public ResourceSet (string fileName) { Table = new Hashtable (); Reader = new ResourceReader (fileName); }
public ResourceSet(IResourceReader reader) { }
public ResourceSet (Stream stream) { Table = new Hashtable (); Reader = new ResourceReader (stream); }
internal ResourceSet (UnmanagedMemoryStream stream) { Table = new Hashtable (); Reader = new ResourceReader (stream); }
protected virtual void Dispose (bool disposing) { if (disposing) { if(Reader != null) Reader.Close(); } Reader = null; Table = null; table_nocase = null; }
/// <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); } } }
/// <summary> /// Initializes a new instance of the <see cref="ResourceViewLocationProvider"/> class. /// </summary> /// <param name="resourceReader">An <see cref="IResourceReader"/> instance that should be used when extracting embedded views.</param> /// <param name="resourceAssemblyProvider">An <see cref="IResourceAssemblyProvider"/> instance that should be used to determine which assemblies to scan for embedded views.</param> public ResourceViewLocationProvider(IResourceReader resourceReader, IResourceAssemblyProvider resourceAssemblyProvider) { this.resourceReader = resourceReader; this.resourceAssemblyProvider = resourceAssemblyProvider; }
public HtmlArticleRenderer(ILogger log, IArticleRendererConfig config) { this.log = log; this.config = config; this.resources = new WebReader(new ConsoleLogger(false)); }
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); } } }
/// <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); } }
/// <summary> /// Creates a new message catalog, by reading the string/value pairs from /// the given <paramref name="reader"/>. The message catalog will support /// plural forms only if the reader can produce values of type /// <c>String[]</c> and if the <c>PluralEval</c> method is overridden. /// </summary> public GettextResourceSet(IResourceReader reader) : base(reader) { }