示例#1
0
        // Move to another method to avoid loading Zetbox.Objects
        private void InitializeClient(string[] args, ZetboxConfig config)
        {
            InitializeSplashScreenImageResource();

            StartupScreen.ShowSplashScreen(Zetbox.Client.Properties.Resources.Startup_Message, Zetbox.Client.Properties.Resources.Startup_InitApp, 6);
            if (config.Server != null && config.Server.StartServer)
            {
                StartupScreen.SetInfo(Zetbox.Client.Properties.Resources.Startup_Server);
                serverDomain = new ServerDomainManager();
                serverDomain.Start(config);
            }
            else
            {
                StartupScreen.SetInfo(Zetbox.Client.Properties.Resources.Startup_NoServerStart);
            }


            container = CreateMasterContainer(config);

            StartupScreen.SetInfo(Zetbox.Client.Properties.Resources.Startup_Launcher);

            // Make Gendarme happy
            var resources = this.Resources;

            resources.BeginInit();
            resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri("/Zetbox.Client.WPF;component/AppResources.xaml", UriKind.Relative)
            });

            // Create icon converter
            var iconConverter = new IconConverter(container.Resolve <IFrozenContext>(), container.Resolve <Func <IZetboxContext> >());

            resources["IconConverter"]      = iconConverter;
            resources["ImageCtrlConverter"] = new ImageCtrlConverter(iconConverter);

            // Init all Converter that are not using a Context
            var templateSelectorFactory = container.Resolve <Zetbox.Client.WPF.Toolkit.VisualTypeTemplateSelector.Factory>();

            resources["defaultTemplateSelector"]   = templateSelectorFactory(null);
            resources["listItemTemplateSelector"]  = templateSelectorFactory("Zetbox.App.GUI.SingleLineKind");
            resources["dashBoardTemplateSelector"] = templateSelectorFactory("Zetbox.App.GUI.DashboardKind");

            // Manually add DefaultStyles and DefaultViews
            // Otherwise converter are unknown
            resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultStyles.xaml", UriKind.Relative)
            });
            resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultHighlightColorDefinitions.xaml", UriKind.Relative)
            });

            // Load registrated dictionaries from autofac
            foreach (var dict in container.Resolve <IEnumerable <Meta <ResourceDictionary> > >().Where(m => WPFHelper.RESOURCE_DICTIONARY_STYLE.Equals(m.Metadata[WPFHelper.RESOURCE_DICTIONARY_KIND])).Select(m => m.Value))
            {
                resources.MergedDictionaries.Add(dict);
            }

            resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri("/Zetbox.Client.WPF;component/Styles/DefaultViews.xaml", UriKind.Relative)
            });
            // Load registrated dictionaries from autofac
            foreach (var dict in container.Resolve <IEnumerable <Meta <ResourceDictionary> > >().Where(m => WPFHelper.RESOURCE_DICTIONARY_VIEW.Equals(m.Metadata[WPFHelper.RESOURCE_DICTIONARY_KIND])).Select(m => m.Value))
            {
                resources.MergedDictionaries.Add(dict);
            }

            resources.EndInit();

            // Init credentials explicit
            StartupScreen.SetInfo(Zetbox.Client.Properties.Resources.Startup_EnsuringCredentials);
            container.Resolve <ICredentialsResolver>().EnsureCredentials();

            StartupScreen.SetInfo(Zetbox.Client.Properties.Resources.Startup_Launcher);

            // Tell icon converter that everything is initialized
            iconConverter.Initialized();

            // Focus nightmare
            // http://stackoverflow.com/questions/673536/wpf-cant-set-focus-to-a-child-of-usercontrol/4785124#4785124
            EventManager.RegisterClassHandler(typeof(Window), Window.LoadedEvent, new RoutedEventHandler(FocusFixLoaded));
            EventManager.RegisterClassHandler(typeof(Zetbox.Client.WPF.View.ZetboxBase.InstanceCollectionBase), UserControl.LoadedEvent, new RoutedEventHandler(FocusFixLoaded));

            wpfResourcesInitialized = true;

            FixupDatabase(container.Resolve <Func <IZetboxContext> >());

            IServiceControlManager scm = null;

            if (container.TryResolve <IServiceControlManager>(out scm))
            {
                Logging.Log.Info("Starting Zetbox Services");
                scm.Start();
            }
            else
            {
                Logging.Log.Info("Service control manager not registered");
            }

            StartupScreen.CanCloseOnWindowLoaded();
            // delegate all business logic into another class, which
            // allows us to load the Zetbox.Objects assemblies _before_
            // they are needed.
            var launcher = container.Resolve <Launcher>();

            launcher.Show(args);
        }
示例#2
0
        public static int Main(string[] arguments)
        {
            Logging.Configure();

            Log.InfoFormat("Starting Zetbox Server with args [{0}]", String.Join(" ", arguments));

            try
            {
                var config = ExtractConfig(ref arguments);
                AssemblyLoader.Bootstrap(AppDomain.CurrentDomain, config);

                using (var container = CreateMasterContainer(config))
                {
                    OptionSet options = new OptionSet();

                    // activate all registered options
                    container.Resolve <IEnumerable <Option> >().OrderBy(o => o.Prototype).ForEach(o => options.Add(o));

                    List <string> extraArguments = null;
                    try
                    {
                        extraArguments = options.Parse(arguments);
                    }
                    catch (OptionException e)
                    {
                        Log.Fatal("Error in commandline", e);
                        return(1);
                    }

                    if (extraArguments != null && extraArguments.Count > 0)
                    {
                        Log.FatalFormat("Unrecognized arguments on commandline: {0}", string.Join(", ", extraArguments.ToArray()));
                        return(1);
                    }

                    var actions = config.AdditionalCommandlineActions;

                    // process command line
                    if (actions.Count > 0)
                    {
                        using (Log.DebugTraceMethodCall("CmdLineActions", "processing commandline actions"))
                        {
                            foreach (var action in actions)
                            {
                                using (var innerContainer = container.BeginLifetimeScope())
                                {
                                    action(innerContainer);
                                }
                            }
                        }
                        Log.Info("Shutting down");
                    }
                    else
                    {
                        IServiceControlManager scm = null;
                        if (container.TryResolve <IServiceControlManager>(out scm))
                        {
                            Log.Info("Starting zetbox Services");
                            scm.Start();
                            Log.Info("Waiting for console input to shutdown");
                            Console.WriteLine("Services started, press the anykey to exit");
                            Console.ReadKey();
                            Log.Info("Shutting down");
                        }
                        else
                        {
                            Log.Error("No IServiceControlManager registered");
                        }

                        if (scm != null)
                        {
                            scm.Stop();
                        }
                    }
                }
                Log.Info("Exiting");
                return(0);
            }
            catch (Exception ex)
            {
                Log.Error("Server Application failed:", ex);
                return(1);
            }
        }