BTSControl /BTSControl/Microsoft.BizTalk.ApplicationDeployment.CommandLine/Program.cs

Language C# Lines 190
MD5 Hash f91c937f05d085a4284d08525bd4f9c0 Estimated Cost $4,126 (why?)
Repository https://BTSControl.svn.codeplex.com/svn View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
namespace Microsoft.BizTalk.ApplicationDeployment.CommandLine
{
    using Microsoft.BizTalk.ApplicationDeployment;
    //using Microsoft.BizTalk.Internal;
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Diagnostics;
    using System.Globalization;
    using System.Reflection;

    internal sealed class Program
    {
        private int errors;
        private int warnings;

        public Program()
        {
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Program.Console_CancelKeyPress);
        }

        private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
        {
            using (new Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer(MethodBase.GetCurrentMethod()))
            {
                string format = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CancelKeyPress);
                using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Warning)))
                {
                    //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(format, new object[0]);
                    Console.WriteLine(format);
                }
            }
        }

        public static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.Program_UnhandledException);
            using (new Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer(MethodBase.GetCurrentMethod()))
            {
                Microsoft.BizTalk.ApplicationDeployment.CommandLine.MethodTracer.TraceAssembly();
                Program program = new Program();
                return program.Run(args);
            }
        }

        private static void Program_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            //new WatsonReportGenerator().WatsonExceptionHandler(sender, e);
            if (!e.IsTerminating)
            {
                Exception exceptionObject = e.ExceptionObject as Exception;
                if (exceptionObject != null)
                {
                    string format = "FATAL ERROR: An unhandled exception occurred in a thread pool or finalizer thread.";
                    //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(format, new object[0]);
                    Console.WriteLine(format);
                    //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exceptionObject.ToString(), new object[0]);
                    Console.WriteLine(exceptionObject.ToString());
                }
            }
            else
            {
                string str2 = "FATAL ERROR: An unhandled exception occurred in a managed thread.";
                //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(str2, new object[0]);
                Console.WriteLine(str2);
            }
        }

        private int Run(string[] args)
        {
            try
            {
                NameValueCollection nameValueArgs = CommandLineParser.Parse(args);
                WriteHeader();
                CommandLineHelper.TraceWriteArguments(args, nameValueArgs);
                if (CommandLineHelper.ArgSpecified(nameValueArgs, "Debug"))
                {
                    nameValueArgs.Remove("Debug");
                    CommandLineHelper.ConsoleWriteArguments(nameValueArgs);
                }
                Command command = CommandFactory.Create(nameValueArgs);
                bool flag2 = CommandLineHelper.ArgSpecified(nameValueArgs, "?") || CommandLineHelper.ArgSpecified(nameValueArgs, "Help");
                if ((nameValueArgs.Count == 0) || flag2)
                {
                    using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
                    {
                        //if (command is AddResourceCommand)
                        //{
                        //    command.ValidateArgs();
                        //}
                        command.WriteUsage();
                        goto Label_02F4;
                    }
                }
                if (command is HelpCommand)
                {
                    command.Execute();
                    this.errors += command.Result.ErrorCount;
                    this.warnings += command.Result.WarningCount;
                    this.WriteCommandSummary();
                    return this.errors;
                }
                List<CommandLineArgumentException> list = command.ValidateArgs();
                if (list.Count > 0)
                {
                    foreach (CommandLineArgumentException exception in list)
                    {
                        this.errors += (exception.Severity == TraceLevel.Error) ? 1 : 0;
                        this.warnings += (exception.Severity == TraceLevel.Warning) ? 1 : 0;
                        using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(exception.Severity)))
                        {
                            Console.WriteLine(exception.Severity.ToString() + ": " + exception.Message);
                            Console.WriteLine(string.Empty);
                            continue;
                        }
                    }
                }
                if (this.errors == 0)
                {
                    command.Execute();
                    this.errors += command.Result.ErrorCount;
                    this.warnings += command.Result.WarningCount;
                    this.WriteCommandSummary();
                }
                else
                {
                    using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
                    {
                        command.WriteUsageHint();
                    }
                }
            }
            catch (Exception exception2)
            {
                //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(exception2.ToString(), new object[0]);
                this.errors++;
                using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Error)))
                {
                    Console.WriteLine(exception2.Message);
                }
                if (((exception2 is OutOfMemoryException) || (exception2 is ExecutionEngineException)) || (exception2 is StackOverflowException))
                {
                    throw;
                }
            }
            finally
            {
                string formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandCompleted, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
                //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(string.Empty, new object[0]);
                //Microsoft.BizTalk.ApplicationDeployment.Trace.WriteLine(formattedString, new object[0]);
            }
        Label_02F4:
            return this.errors;
        }

        private void WriteCommandSummary()
        {
            string formattedString;
            if (this.errors > 0)
            {
                formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandResultFailed, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
            }
            else
            {
                formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.CommandResultSucceeded, new object[] { this.errors.ToString(CultureInfo.InvariantCulture), this.warnings.ToString(CultureInfo.InvariantCulture) });
            }
            using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine(formattedString);
                Console.WriteLine(string.Empty);
            }
        }

        private static void WriteHeader()
        {
            using (new ConsoleColorChanger(ConsoleColorManager.GetInstance().GetColor(TraceLevel.Info)))
            {
                string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
                string formattedString = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetFormattedString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.HeaderDescription, new object[] { fileVersion });
                string str3 = Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.GetString(Microsoft.BizTalk.ApplicationDeployment.CommandLine.StringResources.ResourceID.HeaderCopyright);
                Console.WriteLine(formattedString);
                Console.WriteLine(str3);
                Console.WriteLine(string.Empty);
            }
        }
    }
}
Back to Top