예제 #1
0
        static void Main(string[] args)
        {
#if DEBUG
            args = new string[] {
                "-yyyymm", "default"
                , "-ingest", "./"
                , "-onlydownload"
            };
#endif

            try
            {
                if (!AppSettingsImpl.Parse(SettingsSource.CommandLine, args))
                {
                    if (AppSettingsImpl.ParseErrorMessage != null)
                    {
                        Console.WriteLine(AppSettingsImpl.ParseErrorMessage);
                    }
                    else
                    {
                        AppSettingsImpl.ShowUsage();
                    }
                    Environment.ExitCode = (int)ExitCode.InvalidParameters;
                    return;
                }

                if (AppSettingsImpl.Encrypt.Value || AppSettingsImpl.Decrypt.Value) // only one can be true. Both are false by default
                {
                    if (!AppSettingsImpl.AccessKey.Initialized || !AppSettingsImpl.SecretKey.Initialized)
                    {
                        Globals.Log.ErrorMessage("The encrypt or decrypt option was specified, but either one or both of the keys were not proided.");
                        return;
                    }
                    // regardless of the output setting (to log or console or db) write this to the console so it
                    // is not persisted if the Decrypt function is specified

                    Console.WriteLine("Access Key:");
                    Console.WriteLine(EncryptOrDecryptKey(AppSettingsImpl.AccessKey.Value, AppSettingsImpl.Encrypt.Value));
                    Console.WriteLine("Secret Access Key:");
                    Console.WriteLine(EncryptOrDecryptKey(AppSettingsImpl.SecretKey.Value, AppSettingsImpl.Encrypt.Value));
                    return;
                }

                Globals.Log.InitLoggingSettings();

                Globals.Log.InformationMessage("Started");

                if (!AppSettingsImpl.OnlyDownload)
                {
                    string MonthlyFile = S3.FileExists();
                    if (MonthlyFile != string.Empty)
                    {
                        if (AppSettingsImpl.Force.Value)
                        {
                            Globals.Log.InformationMessage("Monthly File {0} has already been downloaded for this month, however the -Force argument was supplied, so the file will be re-downloaded", MonthlyFile);
                        }
                        else
                        {
                            Globals.Log.InformationMessage("Monthly File {0} has already been downloaded for this month. Nothing to do. Normal completion", MonthlyFile);
                            return;
                        }
                    }
                }

                DoWork();

                Environment.ExitCode = (int)ExitCode.Success;

                Globals.Log.InformationMessage("Normal completion");
            }
            catch (Exception Ex)
            {
                if (Ex is DownLoadException)
                {
                    Globals.Log.ErrorMessage(Ex.Message);
                }
                else
                {
                    Globals.Log.ErrorMessage("An unhandled exception occurred. The exception was: {0}. Stack trace follows:\n{1}", Ex.Message, Ex.StackTrace);
                }
                Environment.ExitCode = (int)ExitCode.OtherError;
            }
        }