Exemplo n.º 1
0
 public AutofacSteps(AutofacContext context)
 {
     _context = context;
 }
Exemplo n.º 2
0
 public ManualLoggingSteps(AutofacContext autofac, ManualLoggingContext context)
 {
     _autofac = autofac;
     _context = context;
 }
Exemplo n.º 3
0
 public LoggingContextSteps(LoggingContext context, InterceptionContext interception, MoqContext moq, AutofacContext autofac)
 {
     _context      = context;
     _interception = interception;
     _moq          = moq;
     _autofac      = autofac;
 }
Exemplo n.º 4
0
        // Methods
        public static void Run(Window window = null)
        {
            // Loger
            var loggerContext = LoggerContext.Initialize(new Log4netLoggerFactory());
            var logger        = new Logger <Application>();

            // Execute
            try
            {
                // AppSettings
                var appSettings = SettingsHelper.GetAllAppSettings();
                if (appSettings == null)
                {
                    throw new InvalidOperationException("appSettings=null");
                }

                // Variables
                var appName          = appSettings["appName"];
                var appVersion       = appSettings["appVersion"];
                var listenUrl        = appSettings["appListen"];
                var hostingFilename  = @"*.Hosting.json";
                var servicesFilename = @"*.Services.dll";

                // Context
                var    autofacContext = new AutofacContext(hostingFilename);
                var    aspnetContext  = string.IsNullOrEmpty(listenUrl) == false ? new AspnetContext(autofacContext, listenUrl, servicesFilename) : null;
                var    windowContext  = new WindowContext(autofacContext, window);
                Action startAction    = () =>
                {
                    aspnetContext?.Start();
                    windowContext?.Start();
                };
                Action endAction = () =>
                {
                    windowContext?.Dispose();
                    aspnetContext?.Dispose();
                    autofacContext?.Dispose();
                    loggerContext?.Dispose();
                };

                // Run
                logger.Info("========================================");
                logger.Info(string.Format("Application started: appName={0}, appVersion={1}", appName, appVersion));
                startAction.Invoke();
                System.Windows.Application.Current.Exit += (s, e) =>
                {
                    endAction.Invoke();
                    logger.Info("Application ended");
                    logger.Info("========================================");
                };

                // Setting
                System.Windows.Application.Current.MainWindow.Title = string.Format("{0} ({1})", appName, appVersion);
            }
            catch (Exception exception)
            {
                // Error
                while (exception?.InnerException != null)
                {
                    exception = exception.InnerException;
                }
                logger.Info(string.Format("Application error: exception={0}", exception?.Message), exception);
                logger.Info("========================================");

                // Notify
                System.Windows.MessageBox.Show(string.Format("Application error: exception={0}", exception?.Message), "Application error");
            }
        }
Exemplo n.º 5
0
        // Methods
        public static void Run()
        {
            // Loger
            var loggerContext = LoggerContext.Initialize(new Log4netLoggerFactory());
            var logger        = new Logger <Application>();

            // Execute
            try
            {
                // AppSettings
                var appSettings = SettingsHelper.GetAllAppSettings();
                if (appSettings == null)
                {
                    throw new InvalidOperationException("appSettings=null");
                }

                // Variables
                var appName          = appSettings["appName"];
                var appVersion       = appSettings["appVersion"];
                var listenUrl        = appSettings["appListen"];
                var hostingFilename  = @"*.Hosting.json";
                var servicesFilename = @"*.Services.dll";

                // Context
                var    autofacContext = new AutofacContext(hostingFilename);
                var    aspnetContext  = string.IsNullOrEmpty(listenUrl) == false ? new AspnetContext(autofacContext, listenUrl, servicesFilename) : null;
                Action startAction    = () =>
                {
                    aspnetContext?.Start();
                };
                Action endAction = () =>
                {
                    aspnetContext?.Dispose();
                    autofacContext?.Dispose();
                    loggerContext?.Dispose();
                };

                // Setting
                Console.Title = string.Format("{0} ({1})", appName, appVersion);

                // Run
                logger.Info("========================================");
                logger.Info(string.Format("Application started: appName={0}, appVersion={1}, appListen={2}", appName, appVersion, listenUrl));
                startAction.Invoke();
                {
                    var executeEvent = new ManualResetEvent(false);
                    Console.WriteLine("Press Ctrl + C to shut down.");
                    Console.CancelKeyPress += (s, e) => { executeEvent.Set(); e.Cancel = true; };
                    executeEvent.WaitOne();
                }
                endAction.Invoke();
                logger.Info("Application ended");
                logger.Info("========================================");
            }
            catch (Exception exception)
            {
                // Error
                while (exception?.InnerException != null)
                {
                    exception = exception.InnerException;
                }
                logger.Info(string.Format("Application error: exception={0}", exception?.Message), exception);
                logger.Info("========================================");

                // Notify
                var notifyEvent = new ManualResetEvent(false);
                Console.WriteLine("Press Ctrl + C to shut down.");
                Console.CancelKeyPress += (s, e) => { notifyEvent.Set(); e.Cancel = true; };
                notifyEvent.WaitOne();
            }
        }
Exemplo n.º 6
0
 public DateTimeInfoSteps(DateTimeInfoContext context, AutofacContext autofac)
 {
     _context = context;
     _autofac = autofac;
 }
Exemplo n.º 7
0
 public LoggingModuleSteps(AutofacContext context, MoqContext moq)
 {
     _context = context;
     _moq     = moq;
 }