Check-in [3bd88a0184]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Small code optimizations.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | develop
Files: files | file ages | folders
SHA1:3bd88a018488629663e23d148acd205160959c61
User & Date: tinus 2018-06-28 19:57:59
Context
2018-06-28
19:57
Small code optimizations. Leaf check-in: 3bd88a0184 user: tinus tags: develop
2018-05-31
05:59
Bugfix: /? help now works. Enhanced: when the /verbose flag is specified, show the full stack track for exceptions. Refactor: increased code readability by not using `var` when it's not apparent at first glance what the type is going to be. check-in: b80ceff467 user: tinus tags: develop
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ZTUpdater/Program.cs.

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
170
171
172
173
174
175
176
177





178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
                    FilesUpdated = UpdateTask.Result;
                }
                WriteLog($"{FilesUpdated} files updated.", TraceLevel.Info);
                return FilesUpdated > 0 ? 0 : 1;
            }
            catch (Exception ex)
            {
                Func<Exception,bool> WriteException = (iex) =>
                {
                    if (MinimumLevel >= TraceLevel.Verbose)
                        Console.Error.WriteLine(iex.ToString());
                    else
                        Console.Error.WriteLine(iex.Message);
                    return true;
                };
                var BackupColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                if (ex is AggregateException)
                    ((AggregateException)ex).Handle(WriteException);
                else
                    WriteException(ex);
                Console.ForegroundColor = BackupColor;
................................................................................
                if (level <= minimumLevel)
                {
                    WriteLog(message, level);
                }
            };
        }

        private static Dictionary<TraceLevel, ConsoleColor> _levelColors = new Dictionary<TraceLevel, ConsoleColor>();






        private static void WriteLog(string message, TraceLevel level)
        {
            if (_levelColors.Count == 0)
            {
                _levelColors.Add(TraceLevel.Verbose, ConsoleColor.DarkGray);
                _levelColors.Add(TraceLevel.Warning, ConsoleColor.Yellow);
                _levelColors.Add(TraceLevel.Error, ConsoleColor.Red);
            }
            var Output = level >= TraceLevel.Warning ? Console.Out : Console.Error;
            var BackupColor = Console.ForegroundColor;
            if (_levelColors.TryGetValue(level, out var Color))
                Console.ForegroundColor = Color;
            Output.WriteLine(message);
            Console.ForegroundColor = BackupColor;
        }







|






|







 







|
>
>
>
>
>



<
<
<
<
<
<







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185






186
187
188
189
190
191
192
                    FilesUpdated = UpdateTask.Result;
                }
                WriteLog($"{FilesUpdated} files updated.", TraceLevel.Info);
                return FilesUpdated > 0 ? 0 : 1;
            }
            catch (Exception ex)
            {
                bool WriteException(Exception iex)
                {
                    if (MinimumLevel >= TraceLevel.Verbose)
                        Console.Error.WriteLine(iex.ToString());
                    else
                        Console.Error.WriteLine(iex.Message);
                    return true;
                }
                var BackupColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Magenta;
                if (ex is AggregateException)
                    ((AggregateException)ex).Handle(WriteException);
                else
                    WriteException(ex);
                Console.ForegroundColor = BackupColor;
................................................................................
                if (level <= minimumLevel)
                {
                    WriteLog(message, level);
                }
            };
        }

        private static readonly Dictionary<TraceLevel, ConsoleColor> _levelColors = new Dictionary<TraceLevel, ConsoleColor>
        {
            { TraceLevel.Verbose, ConsoleColor.DarkGray },
            { TraceLevel.Warning, ConsoleColor.Yellow },
            { TraceLevel.Error, ConsoleColor.Red },
        };

        private static void WriteLog(string message, TraceLevel level)
        {






            var Output = level >= TraceLevel.Warning ? Console.Out : Console.Error;
            var BackupColor = Console.ForegroundColor;
            if (_levelColors.TryGetValue(level, out var Color))
                Console.ForegroundColor = Color;
            Output.WriteLine(message);
            Console.ForegroundColor = BackupColor;
        }