示例#1
0
        public async Task Execute()
        {
            ShowOptions();
            Console.WriteLine();
            //if (optionManager.Validate() < 0)
            //{
            ArgOptions.Errors.ForEach(x =>
            {
                _logger.Error(x);
            });
            //return;
            //}

            //show warning
            ArgOptions.Errors.ForEach(x =>
            {
                _logger.Warn(x);
            });
            _logger.Info($"Start processing url: { odataConnectionString.ServiceUrl}");
            //show result
            await GenerateCodeCommandAsync();

            GenerateProjectCommand();
            ServiceInfo();

            SaveMetaDataCommand();
            ShowHeaderCommand();
            ListPocoCommand();
            VerboseCommand();
            ShowErrors();
        }
示例#2
0
 public async Task <int> RunOptionsAsync(string[] args)
 {
     return(await RunOptionsAsync(args, async x =>
     {
         Logger.Info(ApplicationInfo.HeadingInfo);
         Logger.Normal(ApplicationInfo.Copyright);
         //Console.WriteLine(ApplicationInfo.Description);
         await new CsCommand(x, StartUp._pocoFileSystem).Execute().ConfigureAwait(false);
     }));
 }
        public async Task Authenticate(OdataConnectionString odataConnString)
        {
            switch (odataConnString.Authenticate)
            {
            case AuthenticationType.none:
                break;

            case AuthenticationType.basic:
                Logger.Info("Authenticating with Basic");
                //Basic auth user/password
                if (!string.IsNullOrEmpty(odataConnString.UserName) &&
                    !string.IsNullOrEmpty(odataConnString.Password))
                {
                    Authenticate(odataConnString.UserName, odataConnString.Password);
                }
                break;;

            case AuthenticationType.token:
                Logger.Info("Authenticating with Token");
                //token
                if (!string.IsNullOrEmpty(odataConnString.Password) &&
                    string.IsNullOrEmpty(odataConnString.UserName))
                {
                    Authenticate(odataConnString.Password);
                }
                break;

            case AuthenticationType.oauth2:
                Logger.Info("Authenticating with OAuth2");
                //OAuth2
                if (!string.IsNullOrEmpty(odataConnString.TokenUrl))
                {
                    var accessToken = await new TokenEndpoint(odataConnString).GetAccessTokenAsync();
                    Authenticate(accessToken);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#4
0
 public void SaveToFile(string filePath, string content)
 {
     try
     {
         SaveToFile(filePath, content, Encoding.UTF8);
         Logger.Info($"Success saving to {filePath}");
     }
     catch (Exception e)
     {
         Logger.Error($"Fail to save file: {filePath}");
         Logger.Error(e.Message);
     }
 }
示例#5
0
        public static async Task Main1(string[] args)
        {
            var argument = string.Join(" ", args);

            try
            {
                _pocoFileSystem = new PocoFileSystem();
                if (!(Console.IsOutputRedirected || Console.IsErrorRedirected))
                {
                    Console.BufferHeight = Int16.MaxValue - 1;
                }

                // Catch all unhandled exceptions in all threads.
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Sw.Start();
                RetCode = await RunOptionsAsync(args);

                Sw.Stop();
                Console.WriteLine();
                if (!ArgumentParser.ShowVersionOrHelp)
                {
                    Logger.Sucess($"Total processing time: {Sw.ElapsedMilliseconds / 1000.0} sec");
                }
            }
            catch (Exception ex)
            {
                RetCode = (int)ExitCodes.HandledException;
                Logger.Error($"Error in executing the command: o2pgen {argument}");
                Logger.Error($"Error Message:\n {ex.FullExceptionMessage()}");

#if DEBUG
                Logger.Error("--------------------Exception Details---------------------");
                Logger.Error($"Error Message:\n {ex.FullExceptionMessage(true)}");
                Console.ReadKey();
#endif
            }
            finally
            {
                if (!ArgumentParser.ShowVersionOrHelp)
                {
                    Logger.Info($"Application Exit code: {RetCode}");
                }
                Environment.Exit(RetCode);
            }
        }