private void Initialize()
        {
            var targetFrameworkVersion          = NetFrameworkVersioningHelper.TargetNetFrameworkVersion(Wizard.Project, ServiceProvider);
            var installedEntityFrameworkVersion = VsUtils.GetInstalledEntityFrameworkAssemblyVersion(Wizard.Project);

            // NOTE: Despite the fact that this provider is for design-time, we use
            //       RuntimeProviderInvariantName since this is how modern providers are
            //       registered
            var isModernProviderAvailable = VsUtils.IsModernProviderAvailable(
                Wizard.ModelBuilderSettings.RuntimeProviderInvariantName,
                Wizard.Project,
                ServiceProvider);

            var viewModel = new RuntimeConfigViewModel(
                targetFrameworkVersion,
                installedEntityFrameworkVersion,
                isModernProviderAvailable,
                Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase);

            versionsPanel.Controls.Clear();
            versionsPanel.Controls.AddRange(viewModel.EntityFrameworkVersions.Select(CreateRadioButton).ToArray());

            if (!string.IsNullOrWhiteSpace(viewModel.Message))
            {
                notificationPictureBox.Image = GetNotificationBitmap(viewModel.State);
                notificationLabel.Text       = viewModel.Message;

                if (!string.IsNullOrWhiteSpace(viewModel.HelpUrl))
                {
                    notificationLinkLabel.Links[0].LinkData = viewModel.HelpUrl;
                    notificationLinkLabel.Visible           = true;
                }
                else
                {
                    notificationLinkLabel.Visible = false;
                }

                notificationPanel.Visible = true;
            }
            else
            {
                notificationPanel.Visible = false;
            }

            _state = viewModel.State;
            if (isModernProviderAvailable && _state == RuntimeConfigState.Skip)
            {
                // we are skipping this page but need to set UseLegacyProvider to false
                // on ModelBuilderSettings for later pages (and the engine) to use
                Wizard.ModelBuilderSettings.UseLegacyProvider = false;
            }
        }
        private Bitmap GetNotificationBitmap(RuntimeConfigState state)
        {
            Bitmap bitmap;

            switch (state)
            {
            case RuntimeConfigState.Normal:
                bitmap = Resources.Information;
                break;

            case RuntimeConfigState.Error:
                bitmap = Resources.Error;
                break;

            default:
                return(null);
            }
            return(ThemeUtils.GetThemedButtonImage(bitmap, BackColor));
        }
        private static Bitmap GetNotificationBitmap(RuntimeConfigState state)
        {
            Bitmap bitmap;

            switch (state)
            {
            case RuntimeConfigState.Normal:
                bitmap = Resources.Information;
                break;

            case RuntimeConfigState.Error:
                bitmap = Resources.Error;
                break;

            default:
                return(null);
            }

            bitmap.MakeTransparent(Color.FromArgb(255, 0, 255));

            return(bitmap);
        }
Пример #4
0
        public RuntimeConfigViewModel(
            Version targetNetFrameworkVersion,
            Version installedEntityFrameworkVersion,
            bool isModernProviderAvailable)
        {
            if (targetNetFrameworkVersion == NetFrameworkVersioningHelper.NetFrameworkVersion3_5)
            {
                _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest)
                {
                    Disabled = true
                });
                _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Version1)
                {
                    IsDefault = true
                });

                _message = Resources.RuntimeConfig_Net35;
            }
            else
            {
                if (installedEntityFrameworkVersion != null)
                {
                    if (installedEntityFrameworkVersion < RuntimeVersion.Version6)
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest)
                        {
                            Disabled = true
                        });
                        if (installedEntityFrameworkVersion == RuntimeVersion.Version4)
                        {
                            // EF V4 (i.e. System.Data.Entity) is installed, but when we go through the wizard we
                            // will end up with DbContext templates which will automatically install V5 of the
                            // runtime - so update the options so that the only choice other than V6 is V5
                            installedEntityFrameworkVersion =
                                targetNetFrameworkVersion == NetFrameworkVersioningHelper.NetFrameworkVersion4
                                    ? RuntimeVersion.Version5Net40
                                    : RuntimeVersion.Version5Net45;
                        }
                        _entityFrameworkVersions.Add(
                            new EntityFrameworkVersionOption(installedEntityFrameworkVersion, targetNetFrameworkVersion)
                        {
                            IsDefault = true
                        });

                        _message = Resources.RuntimeConfig_BelowSixInstalled;
                    }
                    else if (!isModernProviderAvailable)
                    {
                        _entityFrameworkVersions.Add(
                            new EntityFrameworkVersionOption(installedEntityFrameworkVersion)
                        {
                            Disabled  = true,
                            IsDefault = true
                        });

                        _state   = RuntimeConfigState.Error;
                        _message = Resources.RuntimeConfig_SixInstalledButNoProvider;
                        _helpUrl = Resources.RuntimeConfig_LearnProvidersUrl;
                    }
                    else
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(installedEntityFrameworkVersion)
                        {
                            IsDefault = true
                        });

                        _state = RuntimeConfigState.Skip;
                    }
                }
                else
                {
                    if (isModernProviderAvailable)
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest)
                        {
                            IsDefault = true
                        });
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Version5(targetNetFrameworkVersion)));

                        _message = Resources.RuntimeConfig_TargetingHint;
                        _helpUrl = Resources.RuntimeConfig_LearnTargetingUrl;
                    }
                    else
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest)
                        {
                            Disabled = true
                        });
                        _entityFrameworkVersions.Add(
                            new EntityFrameworkVersionOption(RuntimeVersion.Version5(targetNetFrameworkVersion))
                        {
                            IsDefault = true
                        });

                        _message = Resources.RuntimeConfig_NoProvider;
                        _helpUrl = Resources.RuntimeConfig_LearnProvidersUrl;
                    }
                }
            }

            Debug.Assert(_entityFrameworkVersions.Count != 0, "_entityFrameworkVersions is empty.");
            Debug.Assert(_entityFrameworkVersions.Any(v => v.IsDefault), "No element of _entityFrameworkVersions is the default.");
        }
        public RuntimeConfigViewModel(
            Version targetNetFrameworkVersion,
            Version installedEntityFrameworkVersion,
            bool isModernProviderAvailable, 
            bool isCodeFirst)
        {
            if (targetNetFrameworkVersion == NetFrameworkVersioningHelper.NetFrameworkVersion3_5)
            {
                Debug.Assert(!isCodeFirst, "CodeFirst not supported on .NET Framework 3.5");

                _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest) { Disabled = true });
                _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Version1) { IsDefault = true });

                _message = Resources.RuntimeConfig_Net35;
            }
            else
            {
                if (installedEntityFrameworkVersion != null)
                {
                    if (installedEntityFrameworkVersion < RuntimeVersion.Version6)
                    {
                        Debug.Assert(!isCodeFirst, "CodeFirst only valid for no EF or EF6");

                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest) { Disabled = true });
                        if (installedEntityFrameworkVersion == RuntimeVersion.Version4)
                        {
                            // EF V4 (i.e. System.Data.Entity) is installed, but when we go through the wizard we
                            // will end up with DbContext templates which will automatically install V5 of the
                            // runtime - so update the options so that the only choice other than V6 is V5
                            installedEntityFrameworkVersion =
                                targetNetFrameworkVersion == NetFrameworkVersioningHelper.NetFrameworkVersion4
                                    ? RuntimeVersion.Version5Net40
                                    : RuntimeVersion.Version5Net45;
                        }
                        _entityFrameworkVersions.Add(
                            new EntityFrameworkVersionOption(installedEntityFrameworkVersion, targetNetFrameworkVersion)
                                {
                                    IsDefault = true
                                });

                        _message = Resources.RuntimeConfig_BelowSixInstalled;
                    }
                    else if (!isModernProviderAvailable)
                    {
                        _entityFrameworkVersions.Add(
                            new EntityFrameworkVersionOption(installedEntityFrameworkVersion)
                                {
                                    Disabled = true,
                                    IsDefault = true
                                });

                        _state = RuntimeConfigState.Error;
                        _message = Resources.RuntimeConfig_SixInstalledButNoProvider;
                        _helpUrl = Resources.RuntimeConfig_LearnProvidersUrl;
                    }
                    else
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(installedEntityFrameworkVersion) { IsDefault = true });

                        _state = RuntimeConfigState.Skip;
                    }
                }
                else
                {
                    if (isModernProviderAvailable)
                    {
                        _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest) { IsDefault = true });

                        if (!isCodeFirst)
                        {
                            _entityFrameworkVersions.Add(
                                new EntityFrameworkVersionOption(RuntimeVersion.Version5(targetNetFrameworkVersion)));
                            _message = Resources.RuntimeConfig_TargetingHint;
                            _helpUrl = Resources.RuntimeConfig_LearnTargetingUrl;
                        }
                        else
                        {
                            _state = RuntimeConfigState.Skip;
                        }
                    }
                    else
                    {
                        if (isCodeFirst)
                        {
                            _state = RuntimeConfigState.Error;
                            _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest)
                            {
                                Disabled = true, 
                                IsDefault = true
                            });
                        }
                        else
                        {
                            _entityFrameworkVersions.Add(new EntityFrameworkVersionOption(RuntimeVersion.Latest) { Disabled = true });
                            _entityFrameworkVersions.Add(
                                new EntityFrameworkVersionOption(RuntimeVersion.Version5(targetNetFrameworkVersion))
                                {
                                    IsDefault = true
                                });                            
                        }

                        _message = Resources.RuntimeConfig_NoProvider;
                        _helpUrl = Resources.RuntimeConfig_LearnProvidersUrl;
                    }
                }
            }

            Debug.Assert(_entityFrameworkVersions.Count != 0, "_entityFrameworkVersions is empty.");
            Debug.Assert(_entityFrameworkVersions.Any(v => v.IsDefault), "No element of _entityFrameworkVersions is the default.");
        }
        private Bitmap GetNotificationBitmap(RuntimeConfigState state)
        {
            Bitmap bitmap;

            switch (state)
            {
                case RuntimeConfigState.Normal:
                    bitmap = Resources.Information;
                    break;

                case RuntimeConfigState.Error:
                    bitmap = Resources.Error;
                    break;

                default:
                    return null;
            }
            return ThemeUtils.GetThemedButtonImage(bitmap, BackColor);
        }
        private void Initialize()
        {
            var targetFrameworkVersion = NetFrameworkVersioningHelper.TargetNetFrameworkVersion(Wizard.Project, ServiceProvider);
            var installedEntityFrameworkVersion = VsUtils.GetInstalledEntityFrameworkAssemblyVersion(Wizard.Project);

            // NOTE: Despite the fact that this provider is for design-time, we use
            //       RuntimeProviderInvariantName since this is how modern providers are
            //       registered
            var isModernProviderAvailable = VsUtils.IsModernProviderAvailable(
                Wizard.ModelBuilderSettings.RuntimeProviderInvariantName,
                Wizard.Project,
                ServiceProvider);

            var viewModel = new RuntimeConfigViewModel(
                targetFrameworkVersion,
                installedEntityFrameworkVersion,
                isModernProviderAvailable, 
                Wizard.ModelBuilderSettings.GenerationOption == ModelGenerationOption.CodeFirstFromDatabase);

            versionsPanel.Controls.Clear();
            versionsPanel.Controls.AddRange(viewModel.EntityFrameworkVersions.Select(CreateRadioButton).ToArray());

            if (!string.IsNullOrWhiteSpace(viewModel.Message))
            {
                notificationPictureBox.Image = GetNotificationBitmap(viewModel.State);
                notificationLabel.Text = viewModel.Message;

                if (!string.IsNullOrWhiteSpace(viewModel.HelpUrl))
                {
                    notificationLinkLabel.Links[0].LinkData = viewModel.HelpUrl;
                    notificationLinkLabel.Visible = true;
                }
                else
                {
                    notificationLinkLabel.Visible = false;
                }

                notificationPanel.Visible = true;
            }
            else
            {
                notificationPanel.Visible = false;
            }

            _state = viewModel.State;
            if (isModernProviderAvailable && _state == RuntimeConfigState.Skip)
            {
                // we are skipping this page but need to set UseLegacyProvider to false
                // on ModelBuilderSettings for later pages (and the engine) to use
                Wizard.ModelBuilderSettings.UseLegacyProvider = false;
            }
        }