예제 #1
0
        public PropertyPad()
        {
            frame = new InvisibleFrame();

#if MAC
            isNative = FeatureSwitchService.IsFeatureEnabled("NativePropertyPanel") ?? false;

            if (isNative)
            {
                nativeGrid   = new MacPropertyGrid();
                propertyGrid = nativeGrid;

                gtkWidget           = Components.Mac.GtkMacInterop.NSViewToGtkWidget(nativeGrid);
                gtkWidget.CanFocus  = true;
                gtkWidget.Sensitive = true;
                gtkWidget.Focused  += Widget_Focused;

                nativeGrid.Focused += PropertyGrid_Focused;
                frame.Add(gtkWidget);
            }
            else
            {
#endif
            grid          = new pg.PropertyGrid();
            propertyGrid  = grid;
            grid.Changed += Grid_Changed;
            frame.Add(grid);
#if MAC
        }
#endif
            frame.ShowAll();
        }
        public void CanRegisterSwitches(string version, bool expected)
        {
            var feature = FeatureSwitchService.RegisterFeature(Guid.NewGuid().ToString(),
                                                               new VersionGreaterThanFeatureSwitchCondition(version));

            Assert.That(feature.IsEnabled, Is.EqualTo(expected));
        }
 public void CanDisableMultipleWithEnvVar()
 {
     Environment.SetEnvironmentVariable("MD_FEATURES_DISABLED", "Feature1;Feature2;Feature3;Feature4");
     Assert.False(FeatureSwitchService.IsFeatureEnabled("Feature1") ?? true);
     Assert.False(FeatureSwitchService.IsFeatureEnabled("Feature2") ?? true);
     Assert.False(FeatureSwitchService.IsFeatureEnabled("Feature3") ?? true);
     Assert.False(FeatureSwitchService.IsFeatureEnabled("Feature4") ?? true);
 }
예제 #4
0
        void RefreshCombo()
        {
            configs.Clear();
            runtimes.Clear();

            foreach (string conf in IdeApp.Workspace.GetConfigurations())
            {
                DropDownBox.ComboItem item = new DropDownBox.ComboItem(conf, conf);
                configs.Add(item);
                if (conf == IdeApp.Workspace.ActiveConfigurationId)
                {
                    configs.CurrentItem = item.Item;
                }
            }

            var enabled = FeatureSwitchService.IsFeatureEnabled("RUNTIME_SELECTOR");

            if (enabled.GetValueOrDefault())
            {
                foreach (TargetRuntime tr in Runtime.SystemAssemblyService.GetTargetRuntimes())
                {
                    DropDownBox.ComboItem item = new DropDownBox.ComboItem(tr.DisplayName, tr);
                    runtimes.Add(item);
                    if (tr == IdeApp.Workspace.ActiveRuntime)
                    {
                        runtimes.CurrentItem = tr;
                    }
                }

                // If there is only one runtime, there is no need to show it
                if (runtimes.Count == 1)
                {
                    runtimes.Clear();
                }
                else
                {
                    DropDownBox.ComboItem item = new DropDownBox.ComboItem(GettextCatalog.GetString("Default Runtime"), defaultRuntime);
                    runtimes.Insert(0, item);
                    if (IdeApp.Workspace.UseDefaultRuntime)
                    {
                        runtimes.CurrentItem = defaultRuntime;
                    }
                }
            }

            UpdateLabel();
            Combo.ShowAll();

            if (configs.CurrentItem == null && configs.Count > 0)
            {
                IdeApp.Workspace.ActiveConfigurationId = (string)configs [0].Item;
            }

            if (runtimes.CurrentItem == null && runtimes.Count > 0)
            {
                IdeApp.Workspace.ActiveRuntime = Runtime.SystemAssemblyService.CurrentRuntime;
            }
        }
 internal static bool?IsFeatureEnabledIgnoringConfiguration(string featureName)
 {
     try {
         bypass = true;
         return(FeatureSwitchService.IsFeatureEnabled(featureName));
     } finally {
         bypass = false;
     }
 }
        bool IsSupportedDesignerFileName(FilePath fileName, WorkspaceObject ownerProject)
        {
            if (!FeatureSwitchService.IsFeatureEnabled("DesignersNewEditor").GetValueOrDefault())
            {
                return(false);
            }

            return(fileName.HasExtension(".xaml") ||
                   IsSupportedAndroidFileName(fileName, ownerProject));
        }
예제 #7
0
        public void CanChangeWhileRunning()
        {
            string featureName = nameof(CanChangeWhileRunning);

            Assert.IsNull(FeatureSwitchService.IsFeatureEnabled(featureName));
            FeatureSwitchService.SetFeatureSwitchValue(featureName, true);
            Assert.True(FeatureSwitchService.IsFeatureEnabled(featureName) ?? false);

            FeatureSwitchService.SetFeatureSwitchValue(featureName, false);
            Assert.False(FeatureSwitchService.IsFeatureEnabled(featureName) ?? true);
        }
        public Task <bool> AcceptLicenses(IEnumerable <NuGetPackageLicense> licenses)
        {
            if (FeatureSwitchService.IsFeatureEnabled("NuGetLicenseAcceptanceDialog") == false)
            {
                return(Task.FromResult(true));
            }

            if (Runtime.IsMainThread)
            {
                return(ShowLicenseAcceptanceDialog(licenses));
            }

            return(Runtime.RunInMainThread(() => ShowLicenseAcceptanceDialog(licenses)));
        }
예제 #9
0
        protected override IEnumerable <DocumentControllerDescription> GetSupportedControllers(FileDescriptor modelDescriptor)
        {
            var nodes = Mono.Addins.AddinManager.GetExtensionNodes <SupportedFileTypeExtensionNode> ("/MonoDevelop/TextEditor/SupportedFileTypes");

            bool supported =
                (
                    modelDescriptor.FilePath.IsNotNull &&
                    IdeServices.DesktopService.GetFileIsText(modelDescriptor.FilePath, modelDescriptor.MimeType) &&
                    nodes.Any(n => ExtensionMatch(n) && BuildActionAndFeatureFlagMatch(n))
                ) || (
                    !string.IsNullOrEmpty(modelDescriptor.MimeType) &&
                    IdeServices.DesktopService.GetMimeTypeIsText(modelDescriptor.MimeType) &&
                    nodes.Any(n => MimeMatch(n) && BuildActionAndFeatureFlagMatch(n))
                    );

            if (supported)
            {
                yield return(new DocumentControllerDescription(GettextCatalog.GetString("New Source Code Editor"), true, DocumentControllerRole.Source));
            }

            bool ExtensionMatch(SupportedFileTypeExtensionNode node) =>
            node.Extensions != null &&
            node.Extensions.Any(ext => modelDescriptor.FilePath.HasExtension(ext));

            bool MimeMatch(SupportedFileTypeExtensionNode node) =>
            node.MimeTypes != null &&
            node.MimeTypes.Any(
                mime => string.Equals(modelDescriptor.MimeType, mime, StringComparison.OrdinalIgnoreCase)
                );

            bool BuildActionAndFeatureFlagMatch(SupportedFileTypeExtensionNode node)
            {
                if (!string.IsNullOrEmpty(node.FeatureFlag))
                {
                    if (!(FeatureSwitchService.IsFeatureEnabled(node.FeatureFlag) ?? node.FeatureFlagDefault))
                    {
                        return(false);
                    }
                }
                if (!string.IsNullOrEmpty(node.BuildAction))
                {
                    var buildAction = (modelDescriptor.Owner as Project)?.GetProjectFile(modelDescriptor.FilePath)?.BuildAction;
                    if (!string.Equals(buildAction, node.BuildAction, StringComparison.OrdinalIgnoreCase))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
예제 #10
0
        protected override void Update(CommandArrayInfo info)
        {
            var enabled = FeatureSwitchService.IsFeatureEnabled(FeatureSwitches.RuntimeSelectorFeatureSwitchName);

            if (enabled.GetValueOrDefault() && IdeApp.Workspace.IsOpen && Runtime.SystemAssemblyService.GetTargetRuntimes().Count() > 1)
            {
                foreach (var tr in Runtime.SystemAssemblyService.GetTargetRuntimes())
                {
                    var item = info.Add(tr.DisplayName, tr);
                    if (tr == IdeApp.Workspace.ActiveRuntime)
                    {
                        item.Checked = true;
                    }
                }
            }
        }
        public VisualStudioMacLSPEditorFeatureDetector(
            AggregateProjectCapabilityResolver projectCapabilityResolver,
            TextBufferProjectService textBufferProjectService)
        {
            _projectCapabilityResolver = projectCapabilityResolver;
            _textBufferProjectService  = textBufferProjectService;

            _useLegacyEditor = new Lazy <bool>(() =>
            {
                // TODO: Pull from preview features collection

                if (FeatureSwitchService.IsFeatureEnabled(RazorLSPEditorFeatureFlag) == true)
                {
                    return(false);
                }

                return(true);
            });
        }
예제 #12
0
        public void CanRegisterAndUnregisterFeatureSwitches()
        {
            string featureName = nameof(CanRegisterAndUnregisterFeatureSwitches);

            for (int i = 1; i <= 10; i++)
            {
                FeatureSwitchService.RegisterFeatureSwitch($"{featureName}{i}", "Test feature", i % 2 == 0);

                var switches = FeatureSwitchService.DescribeFeatures()
                               .Where(x => x.Name.StartsWith(featureName, StringComparison.OrdinalIgnoreCase))
                               .ToList();

                foreach (var feature in switches)
                {
                    Assert.That(FeatureSwitchService.IsFeatureEnabled(feature.Name).GetValueOrDefault(), Is.EqualTo(feature.DefaultValue));
                    Assert.That(switches.Count(x => x.Name == feature.Name), Is.EqualTo(1));

                    // Check we can bypass the controller with the environment variables
                    if (feature.DefaultValue)
                    {
                        Environment.SetEnvironmentVariable("MD_FEATURES_DISABLED", feature.Name);
                        Assert.False(FeatureSwitchService.IsFeatureEnabled(feature.Name).GetValueOrDefault(true));
                    }
                    else
                    {
                        Environment.SetEnvironmentVariable("MD_FEATURES_ENABLED", feature.Name);
                        Assert.True(FeatureSwitchService.IsFeatureEnabled(feature.Name).GetValueOrDefault(false));
                    }

                    Environment.SetEnvironmentVariable("MD_FEATURES_ENABLED", null);
                    Environment.SetEnvironmentVariable("MD_FEATURES_DISABLED", null);
                }

                FeatureSwitchService.UnregisterFeatureSwitch($"{featureName}{i}");
            }
        }
 public void CanDisableWithEnvVar()
 {
     Environment.SetEnvironmentVariable("MD_FEATURES_DISABLED", "MonoDevelop.Core.FeatureSwitchTests");
     Assert.False(FeatureSwitchService.IsFeatureEnabled("MonoDevelop.Core.FeatureSwitchTests") ?? true);
 }
 public void IgnoresUnknownFeatures()
 {
     Assert.IsNull(FeatureSwitchService.IsFeatureEnabled("FakeFeature"));
 }
예제 #15
0
        public static void Initialize(bool updateAddinRegistry)
        {
            if (initialized)
            {
                return;
            }

            using var initTimer = Counters.RuntimeInitialization.BeginTiming();
            SetupInstrumentation();

            Platform.Initialize();

            mainThread = 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;
            AddinManager.AddinAssembliesLoaded += OnAssembliesLoaded;

            try {
                initTimer.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);
                initTimer.Trace("Initialized Addin Manager");

                PropertyService.Initialize();

                WebRequestHelper.Initialize();
                Web.HttpClientProvider.Initialize();
                Mono.Addins.Setup.HttpClientProvider.SetHttpClientFactory(Web.HttpClientProvider.CreateHttpClient);

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

                RegisterAddinRepositories();

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

                // Initialize extra services
                FeatureSwitchService.Initialize();

                initialized = true;
            } catch (Exception ex) {
                Console.WriteLine(ex);
                AddinManager.AddinLoadError -= OnLoadError;
                AddinManager.AddinLoaded    -= OnLoad;
                AddinManager.AddinUnloaded  -= OnUnload;
            }
        }
        public IEnumerable <TargetRuntime> CreateRuntimes()
        {
            MonoRuntimeInfo currentRuntime = MonoRuntimeInfo.FromCurrentRuntime();

            if (currentRuntime != null)
            {
                yield return(new MonoTargetRuntime(currentRuntime));
            }

            if (!FeatureSwitchService.IsFeatureEnabled("RUNTIME_SELECTOR").GetValueOrDefault())
            {
                yield break;
            }

            if (Platform.IsWindows)
            {
                string progs = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                foreach (string dir in Directory.EnumerateDirectories(progs, "Mono*"))
                {
                    MonoRuntimeInfo info = new MonoRuntimeInfo(dir);
                    if (info.IsValidRuntime)
                    {
                        yield return(new MonoTargetRuntime(info));
                    }
                }
            }
            else if (Platform.IsMac)
            {
                if (!Directory.Exists(MAC_FRAMEWORK_DIR))
                {
                    yield break;
                }
                foreach (string dir in Directory.EnumerateDirectories(MAC_FRAMEWORK_DIR))
                {
                    if (dir.EndsWith("/Current", StringComparison.Ordinal) || currentRuntime.Prefix == dir)
                    {
                        continue;
                    }
                    MonoRuntimeInfo info = new MonoRuntimeInfo(dir);
                    if (info.IsValidRuntime)
                    {
                        yield return(new MonoTargetRuntime(info));
                    }
                }
            }
            else
            {
                foreach (string pref in commonLinuxPrefixes)
                {
                    if (currentRuntime != null && currentRuntime.Prefix == pref)
                    {
                        continue;
                    }
                    MonoRuntimeInfo info = new MonoRuntimeInfo(pref);
                    if (info.IsValidRuntime)
                    {
                        // Clean up old registered runtimes
                        foreach (MonoRuntimeInfo ei in customRuntimes)
                        {
                            if (ei.Prefix == info.Prefix)
                            {
                                customRuntimes.Remove(ei);
                                break;
                            }
                        }
                        yield return(new MonoTargetRuntime(info));
                    }
                }
            }
            foreach (MonoRuntimeInfo info in customRuntimes)
            {
                MonoTargetRuntime rt = new MonoTargetRuntime(info);
                rt.UserDefined = true;
                yield return(rt);
            }
        }