Beispiel #1
0
        public static void Initialize(bool updateAddinRegistry)
        {
            if (initialized)
            {
                return;
            }

            Counters.RuntimeInitialization.BeginTiming();
            SetupInstrumentation();

            Platform.Initialize();

            mainThread = Thread.CurrentThread;
            // Set a default sync context
            if (SynchronizationContext.Current == null)
            {
                defaultSynchronizationContext = new SynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(defaultSynchronizationContext);
            }
            else
            {
                defaultSynchronizationContext = SynchronizationContext.Current;
            }


            // Hook up the SSL certificate validation codepath
            ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
                if (sslPolicyErrors == SslPolicyErrors.None)
                {
                    return(true);
                }

                if (sender is WebRequest)
                {
                    sender = ((WebRequest)sender).RequestUri.Host;
                }
                return(WebCertificateService.GetIsCertificateTrusted(sender as string, certificate.GetPublicKeyString()));
            };

            AddinManager.AddinLoadError += OnLoadError;
            AddinManager.AddinLoaded    += OnLoad;
            AddinManager.AddinUnloaded  += OnUnload;

            try {
                Counters.RuntimeInitialization.Trace("Initializing Addin Manager");

                string configDir, addinsDir, databaseDir;
                GetAddinRegistryLocation(out configDir, out addinsDir, out databaseDir);
                AddinManager.Initialize(configDir, addinsDir, databaseDir);
                AddinManager.InitializeDefaultLocalizer(new DefaultAddinLocalizer());

                if (updateAddinRegistry)
                {
                    AddinManager.Registry.Update(null);
                }
                setupService = new AddinSetupService(AddinManager.Registry);
                Counters.RuntimeInitialization.Trace("Initialized Addin Manager");

                PropertyService.Initialize();

                WebRequestHelper.Initialize();
                Mono.Addins.Setup.WebRequestHelper.SetRequestHandler(WebRequestHelper.GetResponse);

                //have to do this after the addin service and property service have initialized
                if (UserDataMigrationService.HasSource)
                {
                    Counters.RuntimeInitialization.Trace("Migrating User Data from MD " + UserDataMigrationService.SourceVersion);
                    UserDataMigrationService.StartMigration();
                }

                RegisterAddinRepositories();

                Counters.RuntimeInitialization.Trace("Initializing Assembly Service");
                systemAssemblyService = new SystemAssemblyService();
                systemAssemblyService.Initialize();
                LoadMSBuildLibraries();

                initialized = true;
            } catch (Exception ex) {
                Console.WriteLine(ex);
                AddinManager.AddinLoadError -= OnLoadError;
                AddinManager.AddinLoaded    -= OnLoad;
                AddinManager.AddinUnloaded  -= OnUnload;
            } finally {
                Counters.RuntimeInitialization.EndTiming();
            }
        }
        public static void Initialize(bool updateAddinRegistry)
        {
            if (initialized)
            {
                return;
            }
            Counters.RuntimeInitialization.BeginTiming();
            SetupInstrumentation();

            if (Platform.IsMac)
            {
                InitMacFoundation();
            }

            // Set a default sync context
            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            }

            // Hook up the SSL certificate validation codepath
            System.Net.ServicePointManager.ServerCertificateValidationCallback += delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                if (sslPolicyErrors == SslPolicyErrors.None)
                {
                    return(true);
                }

                if (sender is WebRequest)
                {
                    sender = ((WebRequest)sender).RequestUri.Host;
                }
                return(WebCertificateService.GetIsCertificateTrusted(sender as string, certificate.GetPublicKeyString()));
            };

            AddinManager.AddinLoadError += OnLoadError;
            AddinManager.AddinLoaded    += OnLoad;
            AddinManager.AddinUnloaded  += OnUnload;

            //provides a development-time way to load addins that are being developed in a asperate solution
            var devAddinDir = Environment.GetEnvironmentVariable("MONODEVELOP_DEV_ADDINS");

            if (devAddinDir != null && devAddinDir.Length == 0)
            {
                devAddinDir = null;
            }

            try
            {
                Counters.RuntimeInitialization.Trace("Initializing Addin Manager");
                AddinManager.Initialize(
                    UserProfile.Current.ConfigDir,
                    devAddinDir ?? UserProfile.Current.LocalInstallDir.Combine("Addins"),
                    devAddinDir ?? UserProfile.Current.CacheDir);
                AddinManager.InitializeDefaultLocalizer(new DefaultAddinLocalizer());

                if (updateAddinRegistry)
                {
                    AddinManager.Registry.Update(null);
                }
                setupService = new AddinSetupService(AddinManager.Registry);
                Counters.RuntimeInitialization.Trace("Initialized Addin Manager");

                PropertyService.Initialize();

                //have to do this after the addin service and property service have initialized
                if (UserDataMigrationService.HasSource)
                {
                    Counters.RuntimeInitialization.Trace("Migrating User Data from MD " + UserDataMigrationService.SourceVersion);
                    UserDataMigrationService.StartMigration();
                }

                RegisterAddinRepositories();

                Counters.RuntimeInitialization.Trace("Initializing Assembly Service");
                systemAssemblyService = new SystemAssemblyService();
                systemAssemblyService.Initialize();

                initialized = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                AddinManager.AddinLoadError -= OnLoadError;
                AddinManager.AddinLoaded    -= OnLoad;
                AddinManager.AddinUnloaded  -= OnUnload;
            }
            finally
            {
                Counters.RuntimeInitialization.EndTiming();
            }
        }