public ResxException(ResxGenItem item) { _items = new List <ResxExceptionString>(); _items.Add(new ResxExceptionString(item)); _memberName = item.MemberName; _hresult = item.HResult; _baseException = item.Comments.StartsWith(":") ? item.Comments : null; }
public ResxException(ResxGenItem item) { _items = new List<ResxExceptionString>(); _items.Add(new ResxExceptionString(item)); _memberName = item.MemberName; _hresult = item.HResult; _baseException = item.Comments.StartsWith(":") ? item.Comments : null; }
public ResxExceptionString(ResxGenItem item) : base(item) { Check.Assert<ArgumentException>(item.IsException); }
public ResxString(ResxGenItem item) { _item = Check.NotNull(item); }
public void Write(TextWriter writerIn) { Dictionary <int, string> catId = new Dictionary <int, string>(); Dictionary <int, string> facId = new Dictionary <int, string>(); IndentedTextWriter writer = new IndentedTextWriter(writerIn); writer.WriteLine("MessageIdTypedef=long"); writer.WriteLine("LanguageNames=(English=0x409:MSG00409)");//need to discover language from resx? writer.WriteLine(); writer.WriteLine("SeverityNames=("); writer.Indent++; writer.WriteLine("Success=0x0"); writer.WriteLine("Information=0x1"); writer.WriteLine("Warning=0x2"); writer.WriteLine("Error=0x3"); writer.Indent--; writer.WriteLine(")"); writer.WriteLine(); if (_facilities.Count > 0) { List <int> keys = new List <int>(_facilities.Keys); keys.Sort(); writer.WriteLine("FacilityNames=("); writer.Indent++; foreach (int key in keys) { facId[key] = "FACILITY_" + StronglyTypedResourceBuilder.VerifyResourceName(_facilities[key], Csharp).ToUpper(); writer.WriteLine("{0}=0x{1:x}", facId[key], key); } writer.Indent--; writer.WriteLine(")"); writer.WriteLine(); } if (_categories.Count > 0) { List <int> keys = new List <int>(_categories.Keys); keys.Sort(); writer.WriteLine(";// CATEGORIES"); writer.WriteLine(); foreach (int key in keys) { catId[key] = "CATEGORY_" + StronglyTypedResourceBuilder.VerifyResourceName(_categories[key], Csharp).ToUpper(); writer.WriteLine("MessageId = 0x{0:x}", key); writer.WriteLine("SymbolicName = {0}", catId[key]); writer.WriteLine("Language = English"); writer.WriteLine(_categories[key]); writer.WriteLine("."); writer.WriteLine(); } } writer.WriteLine(";// MESSAGES"); writer.WriteLine(); foreach (KeyValuePair <uint, ResxGenItem> pair in _itemsByHResult) { ResxGenItem item = pair.Value; uint hr = pair.Key; writer.WriteLine("MessageId = 0x{0:x}", hr & 0x0FFFF); writer.WriteLine("Severity = {0}", (hr & 0x80000000) == 0 ? "Information" : (hr & 0x40000000) == 0 ? "Warning" : "Error"); if (0 != (int)((hr >> 16) & 0x3FF)) { writer.WriteLine("Facility = {0}", facId[(int)((hr >> 16) & 0x3FF)]); } writer.WriteLine("SymbolicName = {0}", item.Identifier.ToUpper()); writer.WriteLine("Language = English"); int ordinal = 1; string messageFormat = null; string messageText = String.Empty; if (item.Options.ContainsKey("EventMessageFormat") && !String.IsNullOrEmpty(item.Options["EventMessageFormat"])) { FormatNumbering numbering = new FormatNumbering(ordinal); messageFormat = StringUtils.Transform( item.Options["EventMessageFormat"].Replace("%", "%%"), RegexPatterns.FormatSpecifier, numbering.Transform); ordinal = 1 + numbering.MaxIdentifier; } messageText = StringUtils.Transform( item.Value.Replace("%", "%%"), RegexPatterns.FormatSpecifier, new FormatNumbering(ordinal).Transform); if (messageFormat != null) { messageText = String.Format("{0}\r\n{1}", messageText, messageFormat); } writer.WriteLine( messageText .Replace("{{", "{") .Replace("}}", "}") .Replace("\r\n", "\n") .Replace("\n", "%n\r\n") .Replace("\r\n.", "\r\n%.") .Replace("!", "%!") ); writer.WriteLine("."); writer.WriteLine(); } }
public void AddOverload(ResxGenItem item) { Check.Assert<InvalidOperationException>(_hresult == item.HResult, "The hresult must be the same for " + MemberName); Check.Assert<ArgumentException>(item.MemberName == _memberName); _items.Add(new ResxExceptionString(item)); }
void WriteEventLogCall(CsWriter code, ResxGenItem item) { Dictionary<int, string> formatting = new Dictionary<int, string>(); for (int i = 0; i < item.Args.Count; i++) formatting[i] = "{0}"; foreach (Match m in RegexPatterns.FormatSpecifier.Matches(item.Value)) { Group field = m.Groups["field"]; int ix; if (int.TryParse(field.Value, out ix)) { formatting[ix] = String.Format("{0}0{1}", m.Value.Substring(0, field.Index - m.Index), m.Value.Substring(field.Index + field.Length - m.Index)); } } code.WriteLine("string[] ctorEventArguments = new string[] {"); for (int i = 0; i < item.Args.Count; i++) code.WriteLine("{0}.ExceptionStrings.SafeFormat(@\"{1}\", {2}),", _fullClassName, formatting[i], item.Args[i].ParamName); code.WriteLine("};"); using (code.WriteBlock("try")) { EventLogEntryType etype = item.MessageId < 0x80000000 ? EventLogEntryType.Information : ((item.MessageId & 0xC0000000) == 0xC0000000) ? EventLogEntryType.Error : EventLogEntryType.Warning; string logMethod = String.IsNullOrEmpty(_eventLogger) ? String.Format("{0}.WriteEvent", _fullClassName) : _eventLogger; code.WriteLine("{0}(", logMethod); code.Indent++; code.WriteLine("{0}.EventLogName,", _fullClassName); code.WriteLine("{0}.EventSourceName,", _fullClassName); code.WriteLine("{0}.EventCategoryId,", _fullClassName); code.WriteLine("System.Diagnostics.EventLogEntryType.{0},", etype); code.WriteLine("0x0{0:X8}L, ctorEventArguments, {1});", item.MessageId, item.IsException ? "this" : "null"); code.Indent--; } code.WriteLine("catch { }"); }
void WriteAutoLog(CsWriter code, ResxGenItem item) { code.WriteSummaryXml("Prepares the arguments as strings and writes the event"); using (code.WriteBlock("private void WriteEvent({0})", item.Parameters(true))) { WriteEventLogCall(code, item); } }
public void AddOverload(ResxGenItem item) { Check.Assert <InvalidOperationException>(_hresult == item.HResult, "The hresult must be the same for " + MemberName); Check.Assert <ArgumentException>(item.MemberName == _memberName); _items.Add(new ResxExceptionString(item)); }
public ResxExceptionString(ResxGenItem item) : base(item) { Check.Assert <ArgumentException>(item.IsException); }