public void Init(string logFileName, StringBuilder appVersionString) { lock (m_lock) { try { m_filepath = Path.IsPathRooted(logFileName) ? logFileName : Path.Combine(MyFileSystem.UserDataPath, logFileName); m_stream = MyFileSystem.OpenWrite(m_filepath); m_streamWriter = new StreamWriter(m_stream); m_normalWriter = new Action <string>(WriteLine); m_closedLogWriter = new Action <string>((s) => File.AppendAllText(m_filepath, s + Environment.NewLine)); m_enabled = true; } catch (Exception e) { SystemTrace.Fail("Cannot create log file: " + e.ToString()); } m_indentsByThread = new Dictionary <int, int>(); m_indents = new Dictionary <MyLogIndentKey, MyLogIndentValue>(); int timezone = (int)Math.Round((DateTime.Now - DateTime.UtcNow).TotalHours); WriteLine("Log Started"); WriteLine(String.Format("Timezone (local - UTC): {0}h", timezone)); WriteLine("App Version: " + appVersionString); } }
public static void FailRelease(string format, params object[] args) { string message = String.Format(format, args); MyLog.Default.WriteLine("Assert Fail: " + message); SystemTrace.Fail(message); }
public void Log(MyLogSeverity severity, StringBuilder builder) { if (m_enabled) { lock (m_lock) { if (m_enabled) { WriteDateTimeAndThreadId(); StringBuilder sb = m_stringBuilder; sb.Clear(); sb.AppendFormat("{0}: ", severity); sb.AppendStringBuilder(builder); sb.Append('\n'); WriteStringBuilder(sb); if ((int)severity >= (int)AssertLevel) { SystemTrace.Fail(sb.ToString()); } } } } }
public static void Call(MethodBase mb, params object[] args) { if (mb == null) { throw new ArgumentNullException("mb"); } StringBuilder line = new StringBuilder(); line.Append("["); line.Append(System.IO.Path.GetFileName(mb.DeclaringType.Assembly.Location)); line.Append("] "); line.Append(mb.DeclaringType.Name); line.Append("."); line.Append(mb.Name); line.Append("("); line.Append(_Parameterize(mb, args)); line.Append(")"); #if LOG4NET _Logger.Debug(line.ToString()); #else SysTrace.WriteLine(line.ToString()); #endif }
/// <summary> /// This "assert" is executed in DEBUG and RELEASE modes. Use it in code that that won't suffer from more work (e.g. loading), not in frequently used loops /// </summary> /// <param name="condition"></param> public static void AssertRelease(bool condition, string assertMessage) { if (condition == false) { MyLog.Default.WriteLine("Assert: " + assertMessage); SystemTrace.Fail(assertMessage); } }
/// <inheritdoc cref="IAmLogger.Info" /> public void Info ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Info"); } }
/// <inheritdoc cref="IAmLogger.Error" /> public void Error ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Error"); } }
/// <inheritdoc cref="IAmLogger.Debug" /> public void Debug ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Debug"); } }
/// <inheritdoc cref="IAmLogger.Warn" /> public void Warn ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Warn"); } }
/// <inheritdoc cref="IAmLogger.Trace" /> public void Trace ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Trace"); } }
/// <inheritdoc cref="IAmLogger.Fatal" /> public void Fatal ( string text ) { if (!string.IsNullOrEmpty(text)) { SysTrace.WriteLine(text, "Fatal"); } }
public static void CallFull(params object[] args) { MethodBase mb = new StackTrace(new StackFrame(1)).GetFrame(0).GetMethod(); string methodname = mb.DeclaringType.Name + "." + mb.Name; string line = GetStackTrace(); line += methodname + "(" + _Parameterize(mb, args) + ")"; #if LOG4NET _Logger.Debug(line); #else SysTrace.Write(line); #endif }
public void Log(MyLogSeverity severity, StringBuilder builder) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}: ", severity); sb.AppendStringBuilder(builder); sb.Append('\n'); WriteStringBuilder(sb); if ((int)severity >= (int)AssertLevel) { SystemTrace.Fail(sb.ToString()); } }
public void Log(MyLogSeverity severity, string format, params object[] args) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}: ", severity); sb.AppendFormat(format, args); sb.Append('\n'); WriteStringBuilder(sb); if ((int)severity >= (int)AssertLevel) { SystemTrace.Fail(sb.ToString()); } }
bool ok(int[] s, int k) { Debug.WriteLine($"start {k}"); var a = new Stack <int[]>(); a.Push(new int[] { 0, s[0] }); for (int i = 1; i < s.Length; i++) { //Debug.WriteLine(a.Reverse().Select(x => $"[{x[0]} {x[1]}]").AsJoinedString()); if (s[i] > s[i - 1]) { if (a.Peek()[0] != 0) { a.Push(new int[] { 0, s[i] - s[i - 1] }); } else { a.Peek()[1] += s[i] - s[i - 1]; } } else { var v = s[i - 1] - s[i]; while (v > 0) { if (a.Count == 0) { return(false); } if (a.Peek()[1] <= v) { v -= a.Pop()[1]; } else { a.Peek()[1] -= v; break; } } if (!increment(a, k)) { return(false); } } } //Debug.WriteLine(a.Reverse().Select(x => $"[{x[0]} {x[1]}]").AsJoinedString()); return(true); }
/// <summary> /// Writes the trace to the Debug /// </summary> /// <param name="type">Type of trace</param> /// <param name="module">Module responsible for the error</param> /// <param name="message">The message to be displayed</param> /// [Conditional("DEBUG")] private static void writeToDebug(String type, String module, String message) { int space1 = 8; int space2 = 40; string line = null; if (useHPTime) { line = HPTime.Now.ToString() + ": " + type.PadRight(space1 + 4, ' ') + module.PadRight(space2, ' ') + message; } else { line = System.DateTime.Now.ToString("HH:mm:ss:ffff") + ": " + type.PadRight(space1, ' ') + module.PadRight(space2, ' ') + message; } SysTrace.WriteLine(line); }
public void CanTrace() { var listener = new Listener(); Trace.Listeners.Add(listener); try { var logger = new TraceDiagnosticLogger(SentryLevel.Debug); logger.Log(SentryLevel.Debug, "the message {0}", new Exception("the exception"), "arg1"); Trace.Flush(); Assert.Equal(@" Debug: the message arg1 System.Exception: the exception", listener.Messages.Single()); } finally { Trace.Listeners.Remove(listener); } }
private static void LoadPlugins(Assembly assembly) { var pluginInterfaceClasses = assembly.GetTypes().Where(s => s.GetInterfaces().Contains(typeof(IPlugin))); foreach (var pluginClass in pluginInterfaceClasses) { try { // Log may not be available yet (DS?) //MyLog.Default.WriteLine("Creating instance of: " + pluginClass.FullName); m_plugins.Add((IPlugin)Activator.CreateInstance(pluginClass)); } catch (Exception e) { // Log may not be available yet (DS?) SystemTrace.Fail("Cannot create instance of '" + pluginClass.FullName + "': " + e.ToString()); //MyLog.Default.WriteLine("Error instantiating plugin class: " + pluginClass); //MyLog.Default.WriteLine(e); } } }
public void Solve() { var n = ri; var a = new long[n]; var b = new long[n]; for (int i = 0; i < n; i++) { a[i] = ri; b[i] = ri; } a = a.OrderByDescending(x => x).ToArray(); b = b.OrderBy(x => x).ToArray(); Debug.WriteLine(a.AsJoinedString()); Debug.WriteLine(b.AsJoinedString()); var ans = 0L; var u = 0L; var cnt = 0; for (int i = 0; i < n; i++) { u += 2 * a[i]; u -= 2 * b[i]; cnt += 2; Debug.WriteLine(u); if (cnt <= n) { ans = Max(ans, u); } if (cnt - 1 <= n) { ans = Max(ans, u - 2 * a[i]); ans = Max(ans, u + 2 * b[i]); } } Console.WriteLine(ans); }
public static void Info(string message) => Trace.TraceInformation(AddInfo(message));
/// <summary> /// Logs the message on release and also displays a message on DEBUG. /// </summary> /// <param name="message"></param> public static void FailRelease(string message) { MyLog.Default.WriteLine("Assert Fail: " + message); SystemTrace.Fail(message); }
public static void Warn(string message) => Trace.TraceWarning(AddInfo(message));
public void Solve() { const long M = (long)1e9 + 7; var n = ri * 2; var k = ri; var a = Enumerate(k, x => new int[] { ri - 1, ri - 1 }); long[][] dp = Enumerate(n, x => new long[n]); long[][] ep = Enumerate(n, x => new long[n]); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dp[i][j] = ep[i][j] = -1; } } long[] f = new long[n + 5]; f[0] = 1; for (int i = 2; i <= n; i += 2) { f[i] = f[i - 2] * (i - 1) % M; } Func <int, int, long> efs = null; efs = (l, r) => { if (ep[l][r] != -1) { return(ep[l][r]); } var cnt = 0; foreach (var v in a) { if (l <= v[0] && v[0] <= r) { cnt++; } if (l <= v[1] && v[1] <= r) { cnt++; } if (cnt % 2 == 1) { return(dp[l][r] = 0); } } return(ep[l][r] = f[r - l + 1 - cnt]); }; Func <int, int, long> dfs = null; dfs = (l, r) => { if (dp[l][r] != -1) { return(dp[l][r]); } var ret = efs(l, r); for (int i = l + 1; i < r; i += 2) { ret = (ret + M - dfs(l, i) * efs(i + 1, r) % M) % M; } return(dp[l][r] = ret); }; long ans = 0; for (int l = 0; l < n; l++) { for (int r = l + 1; r < n; r++) { var add = dfs(l, r); if (add == 0) { continue; } var cnt = 0; foreach (var v in a) { if (l <= v[0] && v[0] <= r) { cnt++; } if (l <= v[1] && v[1] <= r) { cnt++; } } var rem = n - (r - l + 1); rem -= 2 * k - cnt; add = add * f[rem] % M; Debug.WriteLine($"{l + 1} {r + 1} {add}"); ans = (ans + add) % M; } } Console.WriteLine(ans); }
public static void Error(string message) => Trace.TraceError(AddInfo(message));