private Hashtable GetMetadata() { if (this.metadata == null) { IResourceService service = (IResourceService)this.manager.GetService(typeof(IResourceService)); if (service != null) { IResourceReader resourceReader = service.GetResourceReader(CultureInfo.InvariantCulture); if (resourceReader != null) { try { ResXResourceReader reader2 = resourceReader as ResXResourceReader; if (reader2 != null) { this.metadata = new Hashtable(); IDictionaryEnumerator metadataEnumerator = reader2.GetMetadataEnumerator(); while (metadataEnumerator.MoveNext()) { this.metadata[metadataEnumerator.Key] = metadataEnumerator.Value; } } } finally { resourceReader.Close(); } } } } return(this.metadata); }
/// <summary> /// Loads the content of the file into the cache. /// </summary> protected virtual void LoadContent() { using (IResourceReader reader = this.GetResourceReader()) { if (reader != null) { this.LoadContent(reader); reader.Close(); } } }
// Dispose this resource set. protected virtual void Dispose(bool disposing) { if (Reader != null) { Reader.Close(); Reader = null; } Table = null; ignoreCaseTable = null; }
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.Close(); } else if (source != null) { source.Close(); } if (writer != null) { writer.Close(); } else if (destination != null) { destination.Close(); } } return(resource); }
// 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(); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (Reader != null) { Reader.Close(); } } Reader = null; Table = null; }
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; }
/// <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; }
/// <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; }
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; }
private Hashtable GetResourceSet(CultureInfo culture) { Hashtable hashtable = null; object obj2 = this.ResourceTable[culture]; if (obj2 == null) { IResourceService service = (IResourceService)this.manager.GetService(typeof(IResourceService)); if (service != null) { IResourceReader resourceReader = service.GetResourceReader(culture); if (resourceReader != null) { try { hashtable = this.CreateResourceSet(resourceReader, culture); } finally { resourceReader.Close(); } this.ResourceTable[culture] = hashtable; return(hashtable); } if (culture.Equals(CultureInfo.InvariantCulture)) { hashtable = new Hashtable(); this.ResourceTable[culture] = hashtable; return(hashtable); } this.ResourceTable[culture] = resourceSetSentinel; } return(hashtable); } return(obj2 as Hashtable); }
public void Close() { reader.Close(); }
static int CompileResourceFile(string sname, string dname, bool useSourcePath) { FileStream source = null; FileStream dest = null; IResourceReader reader = null; IResourceWriter writer = null; try { source = new FileStream(sname, FileMode.Open, FileAccess.Read); reader = GetReader(source, sname, useSourcePath); dest = new FileStream(dname, FileMode.Create, FileAccess.Write); writer = GetWriter(dest, dname); int rescount = 0; foreach (DictionaryEntry e in reader) { rescount++; object val = e.Value; if (val is string) { writer.AddResource((string)e.Key, (string)e.Value); } else { writer.AddResource((string)e.Key, e.Value); } } Console.WriteLine("Read in {0} resources from '{1}'", rescount, sname); reader.Close(); writer.Close(); Console.WriteLine("Writing resource file... Done."); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); Exception inner = e.InnerException; // under 2.0 ResXResourceReader can wrap an exception into an XmlException // and this hides some helpful message from the original exception XmlException xex = (inner as XmlException); if (xex != null) { // message is identical to the inner exception (from MWF ResXResourceReader) Console.WriteLine("Position: Line {0}, Column {1}.", xex.LineNumber, xex.LinePosition); inner = inner.InnerException; } if (inner is System.Reflection.TargetInvocationException && inner.InnerException != null) { inner = inner.InnerException; } if (inner != null) { Console.WriteLine("Inner exception: {0}", inner.Message); } if (reader != null) { reader.Dispose(); } if (source != null) { source.Close(); } if (writer != null) { writer.Dispose(); } if (dest != null) { dest.Close(); } // since we're not first reading all entries in source, we may get a // read failure after we're started writing to the destination file // and leave behind a broken resources file, so remove it here try { File.Delete(dname); } catch { } return(1); } return(0); }
static int CompileResourceFile(string sname, string dname, bool useSourcePath, Options options) { FileStream source = null; FileStream dest = null; IResourceReader reader = null; IResourceWriter writer = null; try { source = new FileStream(sname, FileMode.Open, FileAccess.Read); reader = GetReader(source, sname, useSourcePath, options); dest = new FileStream(dname, FileMode.Create, FileAccess.Write); writer = GetWriter(dest, dname, options, sname); int rescount = 0; foreach (DictionaryEntry e in reader) { rescount++; object val = e.Value; if (val is string) { writer.AddResource((string)e.Key, (string)e.Value); } else { // refactoring to do: We should probably wrap the ResXResourceWriter, and replace our use of IResourceWriter with a ResourceItem based interface ResourceItem item = val as ResourceItem; try { if (writer is ResXResourceWriter && item != null) { // only write if the ResourceItem can be cast to ResXDataNode ResXDataNode dataNode = ((ResourceItem)val).ToResXDataNode(); if (dataNode != null) { writer.AddResource((string)e.Key, dataNode); } } else { writer.AddResource((string)e.Key, e.Value); } } catch { if (item != null && item.Metadata_OriginalSourceLine > 0) { Console.WriteLine("Line: {0}", item.Metadata_OriginalSourceLine); } throw; } } } Console.WriteLine("Read in {0} resources from '{1}'", rescount, sname); reader.Close(); writer.Close(); Console.WriteLine("Writing resource file... Done."); } catch (Exception e) { Console.WriteLine("Error: {0}", e.Message); Exception inner = e.InnerException; // under 2.0 ResXResourceReader can wrap an exception into an XmlException // and this hides some helpful message from the original exception XmlException xex = (inner as XmlException); if (xex != null) { // message is identical to the inner exception (from MWF ResXResourceReader) Console.WriteLine("Position: Line {0}, Column {1}.", xex.LineNumber, xex.LinePosition); inner = inner.InnerException; } if (inner is TargetInvocationException && inner.InnerException != null) { inner = inner.InnerException; } if (inner != null) { Console.WriteLine("Inner exception: {0}", inner.Message); } if (reader != null) { reader.Dispose(); } if (source != null) { source.Close(); } if (writer != null) { writer.Dispose(); } if (dest != null) { dest.Close(); } // since we're not first reading all entries in source, we may get a // read failure after we're started writing to the destination file // and leave behind a broken resources file, so remove it here try { File.Delete(dname); } catch { } return(1); } return(0); }
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; } } }