コード例 #1
0
        public void Write(TzdbDatabase database, WindowsZones cldrWindowsZones)
        {
            var timeZoneMap = new Dictionary <string, string>();

            foreach (var zone in database.GenerateDateTimeZones())
            {
                timeZoneMap.Add(zone.Id, zone.Id);
                WriteTimeZone(zone);
            }

            // Normalize the aliases
            foreach (var key in database.Aliases.Keys)
            {
                var value = database.Aliases[key];
                while (database.Aliases.ContainsKey(value))
                {
                    value = database.Aliases[value];
                }
                timeZoneMap.Add(key, value);
            }
            resourceWriter.AddResource(TzdbResourceData.VersionKey, database.Version);
            WriteDictionary(TzdbResourceData.IdMapKey, timeZoneMap);
            WriteDictionary(TzdbResourceData.WindowsToPosixMapKey, cldrWindowsZones.PrimaryMapping);
            resourceWriter.AddResource(TzdbResourceData.WindowsToPosixMapVersionKey, cldrWindowsZones.Version);
            resourceWriter.Close();
        }
コード例 #2
0
 public void Build()
 {
     foreach (var i in _resourceEntries)
     {
         _resourceWriter.AddResource(i.Key, i.Value);
     }
     _resourceWriter.Generate();
     _resourceWriter.Close();
 }
コード例 #3
0
 /// <summary>
 /// Save changes done to the resource content to disk.
 /// </summary>
 protected virtual void SaveContent()
 {
     using (IResourceWriter writer = this.GetResourceWriter()) {
         if (writer != null)
         {
             this.SaveContent(writer);
             writer.Close();
         }
     }
 }
コード例 #4
0
ファイル: resgen.cs プロジェクト: ydunk/masters
 // closes writer automatically
 private static void WriteResources(IResourceWriter writer)
 {
     foreach (Entry entry in resources)
     {
         string key   = entry.name;
         object value = entry.value;
         writer.AddResource(key, value);
     }
     Console.Write(SR.GetString(SR.BeginWriting));
     writer.Close();
     Console.WriteLine(SR.GetString(SR.DoneDot));
 }
コード例 #5
0
 private void WriteResources(IResourceWriter writer)
 {
     try
     {
         foreach (Entry entry in this.resources)
         {
             string name = entry.name;
             object obj2 = entry.value;
             writer.AddResource(name, obj2);
         }
     }
     finally
     {
         writer.Close();
     }
 }
コード例 #6
0
        // Creates a default resource file for the current
        // CultureInfo and adds 3 strings to it.
        private void CreateResources(object sender, EventArgs e)
        {
            IResourceService rs = (IResourceService)this.Component.Site.GetService(typeof(IResourceService));

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

            IResourceWriter rw = rs.GetResourceWriter(CultureInfo.CurrentUICulture);

            rw.AddResource("string1", "Persisted resource string #1");
            rw.AddResource("string2", "Persisted resource string #2");
            rw.AddResource("string3", "Persisted resource string #3");
            rw.Generate();
            rw.Close();
        }
コード例 #7
0
 private void OnSerializationComplete(object sender, EventArgs e)
 {
     if (this.writer != null)
     {
         this.writer.Close();
         this.writer = null;
     }
     if (this.invariantCultureResourcesDirty || this.metadataResourcesDirty)
     {
         IResourceService service = (IResourceService)this.manager.GetService(typeof(IResourceService));
         if (service != null)
         {
             IResourceWriter resourceWriter = service.GetResourceWriter(CultureInfo.InvariantCulture);
             try
             {
                 object obj2 = this.ResourceTable[CultureInfo.InvariantCulture];
                 IDictionaryEnumerator enumerator = ((Hashtable)obj2).GetEnumerator();
                 while (enumerator.MoveNext())
                 {
                     string key  = (string)enumerator.Key;
                     object obj3 = enumerator.Value;
                     resourceWriter.AddResource(key, obj3);
                 }
                 this.invariantCultureResourcesDirty = false;
                 ResXResourceWriter writer2 = resourceWriter as ResXResourceWriter;
                 if (writer2 != null)
                 {
                     foreach (DictionaryEntry entry in this.metadata)
                     {
                         writer2.AddMetadata((string)entry.Key, entry.Value);
                     }
                 }
                 this.metadataResourcesDirty = false;
                 return;
             }
             finally
             {
                 resourceWriter.Close();
             }
         }
         this.invariantCultureResourcesDirty = false;
         this.metadataResourcesDirty         = false;
     }
 }
 private void WriteResources(IResourceWriter writer)
 {
     try
     {
         foreach (Entry entry in this.resources)
         {
             string name = entry.name;
             object obj2 = entry.value;
             writer.AddResource(name, obj2);
         }
     }
     finally
     {
         writer.Close();
     }
 }
コード例 #9
0
    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);
    }
コード例 #10
0
ファイル: GenerateResource.cs プロジェクト: ChronosWS/msbuild
 /// <summary>
 /// Write resources to an XML or binary format resources file.
 /// </summary>
 /// <remarks>Closes writer automatically</remarks>
 /// <param name="writer">Appropriate IResourceWriter</param>
 private void WriteResources(ReaderInfo reader, IResourceWriter writer)
 {
     Exception capturedException = null;
     try
     {
         foreach (Entry entry in reader.resources)
         {
             string key = entry.name;
             object value = entry.value;
             writer.AddResource(key, value);
         }
     }
     catch (Exception e)
     {
         capturedException = e; // Rethrow this after catching exceptions thrown by Close().
     }
     finally
     {
         if (capturedException == null)
         {
             writer.Close(); // If this throws, exceptions will be caught upstream.
         }
         else
         {
             // It doesn't hurt to call Close() twice. In the event of a full disk, we *need* to call Close() twice.
             // In that case, the first time we catch an exception indicating that the XML written to disk is malformed,
             // specifically an InvalidOperationException: "Token EndElement in state Error would result in an invalid XML document."
             try { writer.Close(); }
             catch (Exception) { } // We agressively catch all exception types since we already have one we will throw.
             // The second time we catch the out of disk space exception.
             try { writer.Close(); }
             catch (Exception) { } // We agressively catch all exception types since we already have one we will throw.
             throw capturedException; // In the event of a full disk, this is an out of disk space IOException.
         }
     }
 }
コード例 #11
0
        /// <summary>
        /// Write resources to an XML or binary format resources file.
        /// </summary>
        /// <remarks>Closes writer automatically</remarks>
        /// <param name="writer">Appropriate IResourceWriter</param>
        private void WriteResources(IResourceWriter writer)
        {
            try
            {
                foreach (Entry entry in resources)
                {
                    string key = entry.RawName;
                    object value = entry.Value;

                    if(writer is TinyResourceWriter)
                    {
                        ((TinyResourceWriter)writer).AddResource( entry );
                    }
                    else
                    {
                        writer.AddResource(key, value);
                    }
                }

                writer.Generate();
            }
            finally
            {
                writer.Close();
            }
        }
コード例 #12
0
 // closes writer automatically
 private static void WriteResources(IResourceWriter writer) {
     foreach (Entry entry in resources) {
         string key = entry.name;
         object value = entry.value;
         writer.AddResource(key, value);
     }
     Console.Write(SR.GetString(SR.BeginWriting));
     writer.Close();
     Console.WriteLine(SR.GetString(SR.DoneDot));
 }
コード例 #13
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);
        }
コード例 #14
0
ファイル: ResourceManagement.cs プロジェクト: Aiden-p77/Chess
 public void Close()
 {
     writer.Close();
 }