Beispiel #1
0
        internal void Terminate()
        {
            if (Deployment.Current.XapDir == null)
            {
                return;
            }

            for (int i = 0; i < ApplicationLifetimeObjects.Count; i++)
            {
                IApplicationLifetimeAware asvc = ApplicationLifetimeObjects[i] as IApplicationLifetimeAware;
                if (asvc != null)
                {
                    asvc.Exiting();
                }
            }

            if (Exit != null)
            {
                Exit(this, EventArgs.Empty);
            }

            for (int i = 0; i < ApplicationLifetimeObjects.Count; i++)
            {
                IApplicationLifetimeAware asvc = ApplicationLifetimeObjects[i] as IApplicationLifetimeAware;
                if (asvc != null)
                {
                    asvc.Exited();
                }
            }

            // note: this loop goes in reverse order
            for (int i = ApplicationLifetimeObjects.Count - 1; i >= 0; i--)
            {
                IApplicationService svc = ApplicationLifetimeObjects[i] as IApplicationService;
                if (svc != null)
                {
                    svc.StopService();
                }
            }

            try {
                Directory.Delete(Deployment.Current.XapDir, true);
                Deployment.Current.XapDir = null;
            } catch {
            }

            foreach (KeyValuePair <Assembly, ResourceDictionary> kv in assemblyToGenericXaml)
            {
                kv.Value.Clear();
            }
            assemblyToGenericXaml.Clear();
            root_visual         = null;
            Application.Current = null;

            ReinitializeStaticData();
        }
Beispiel #2
0
        internal void OnStartup(StartupEventArgs e)
        {
            // FIXME: should we be sharing the
            // Dictionary<string,string> for each call to
            // the lifetime objects?  or should we be
            // creating a new one for each call?
            ApplicationServiceContext ctx = new ApplicationServiceContext(e.InitParams as Dictionary <string, string>);

            lifetime_objects.Close();              // it's now too late to add items to this collection

            for (int i = 0; i < ApplicationLifetimeObjects.Count; i++)
            {
                IApplicationService svc = ApplicationLifetimeObjects[i] as IApplicationService;
                if (svc != null)
                {
                    svc.StartService(ctx);
                }
            }

            for (int i = 0; i < ApplicationLifetimeObjects.Count; i++)
            {
                IApplicationLifetimeAware asvc = ApplicationLifetimeObjects[i] as IApplicationLifetimeAware;
                if (asvc != null)
                {
                    asvc.Starting();
                }
            }

            if (Startup != null)
            {
                Startup(this, e);
            }

            for (int i = 0; i < ApplicationLifetimeObjects.Count; i++)
            {
                IApplicationLifetimeAware asvc = ApplicationLifetimeObjects[i] as IApplicationLifetimeAware;
                if (asvc != null)
                {
                    asvc.Started();
                }
            }
        }