Ejemplo n.º 1
0
        protected virtual void CleanupApplication()
        {
            var exceptions = new List <Exception>();

            lock (m_FinishNotifiables)
            {
                string name = CoreConsts.UNKNOWN;
                foreach (var notifiable in m_FinishNotifiables)
                {
                    try
                    {
                        name = notifiable.Name ?? notifiable.GetType().FullName;
                        notifiable.ApplicationFinishBeforeCleanup(this);
                    }
                    catch (Exception error)
                    {
                        error = new AzosException(StringConsts.APP_FINISH_NOTIFIABLE_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error);
                        exceptions.Add(error);
                        WriteLog(MessageType.Error, "CleanupApplication()", error.Message);
                    }
                }
            }

            try
            {
                DoModuleBeforeCleanupApplication();
                DoCleanupApplication(); //<----------------------------------------------
            }
            finally
            {
                ExecutionContext.__UnbindApplication(this);
            }

            lock (m_FinishNotifiables)
            {
                string name = CoreConsts.UNKNOWN;
                foreach (var notifiable in m_FinishNotifiables)
                {
                    try
                    {
                        name = notifiable.Name ?? notifiable.GetType().FullName;
                        notifiable.ApplicationFinishAfterCleanup(this);
                    }
                    catch (Exception error)
                    {
                        error = new AzosException(StringConsts.APP_FINISH_NOTIFIABLE_AFTER_ERROR.Args(name, error.ToMessageWithType()), error);
                        exceptions.Add(error);
                        //log not available at this point
                    }
                }
            }

            if (exceptions.Count > 0)
            {
                var text = new StringBuilder();

                text.AppendLine(StringConsts.APP_FINISH_NOTIFIABLES_ERROR);

                foreach (var exception in exceptions)
                {
                    text.AppendLine(exception.ToMessageWithType());
                }

                throw new AzosException(text.ToString());
            }
        }
Ejemplo n.º 2
0
        protected virtual void InitApplication()
        {
            if (ForceInvariantCulture)//used in all server applications
            {
                Azos.Platform.Abstraction.PlatformAbstractionLayer.SetProcessInvariantCulture();
            }

            PreloadAssemblies();

            var exceptions = new List <Exception>();

            var starters = GetStarters().ToList();

            string name         = CoreConsts.UNKNOWN;
            bool   breakOnError = true;

            foreach (var starter in starters)
            {
                try
                {
                    breakOnError = starter.ApplicationStartBreakOnException;
                    name         = starter.Name ?? starter.GetType().FullName;
                    starter.ApplicationStartBeforeInit(this);
                }
                catch (Exception error)
                {
                    error = new AzosException(StringConsts.APP_STARTER_BEFORE_ERROR.Args(name, error.ToMessageWithType()), error);
                    if (breakOnError)
                    {
                        throw error;
                    }
                    exceptions.Add(error);
                    //log not available at this point
                }
            }


            ExecutionContext.__BindApplication(this);
            DoInitApplication(); //<----------------------------------------------
            DoModuleAfterInitApplication();


            name         = CoreConsts.UNKNOWN;
            breakOnError = true;
            foreach (var starter in starters)
            {
                try
                {
                    breakOnError = starter.ApplicationStartBreakOnException;
                    name         = starter.Name ?? starter.GetType().FullName;
                    starter.ApplicationStartAfterInit(this);
                }
                catch (Exception error)
                {
                    error = new AzosException(StringConsts.APP_STARTER_AFTER_ERROR.Args(name, error.ToMessageWithType()), error);
                    WriteLog(MessageType.CatastrophicError, "InitApplication().After", error.ToMessageWithType(), error);
                    if (breakOnError)
                    {
                        throw error;
                    }
                }
            }

            if (exceptions.Count > 0)
            {
                foreach (var exception in exceptions)
                {
                    WriteLog(MessageType.CatastrophicError, "InitApplication().Before", exception.ToMessageWithType());
                }
            }
        }