Beispiel #1
0
        public override async Task <ConnectedServiceInstance> GetFinishedServiceInstanceAsync()
        {
            // ensure that the data has been loaded from wizard pages and saved to UserSettings
            if (Context.IsUpdating)
            {
                if (!OperationImportsViewModel.IsEntered)
                {
                    await OperationImportsViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await OperationImportsViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }

                if (!SchemaTypesViewModel.IsEntered)
                {
                    await SchemaTypesViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await SchemaTypesViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }

                if (!AdvancedSettingsViewModel.IsEntered)
                {
                    await AdvancedSettingsViewModel.OnPageEnteringAsync(null).ConfigureAwait(false);

                    await AdvancedSettingsViewModel.OnPageLeavingAsync(null).ConfigureAwait(false);
                }
            }

            UserSettings.Save();
            ServiceInstance.InstanceId           = UserSettings.GeneratedFileNamePrefix;
            ServiceInstance.Name                 = UserSettings.ServiceName;
            ServiceInstance.MetadataTempFilePath = ConfigODataEndpointViewModel.MetadataTempPath;
            ServiceInstance.ServiceConfig        = CreateServiceConfiguration();

            return(await Task.FromResult <ConnectedServiceInstance>(ServiceInstance).ConfigureAwait(false));
        }
Beispiel #2
0
        public StreamViewModel(MainViewModel mainViewModel, bool addInitialProperties, MediaStreamModel model)
        {
            MediaStreamer = model;

            dialogService = ServiceLocator.GetInstance <IDialogService>();

            MainViewModel = mainViewModel;
            StartCommand  = new DelegateCommand(SwitchStreamingState);

            //EditModeCommand = new RelayCommand(() => MainViewModel.IsEdit = true);
            //EditModeCommand = new DelegateCommand(() => MainViewModel.IsEdit = true);

            EditModeCommand = new DelegateCommand(SetEditMode);

            EditNameCommand     = new DelegateCommand(SwitchEditNameState);
            CopyUrlCommand      = new DelegateCommand(CopyUrl);
            PreferencesCommand  = new DelegateCommand <WindowViewModel>(ShowPreferencesDialog);
            HideBorderCommand   = new DelegateCommand(HideBorder);
            ShowSettingsCommand = new DelegateCommand(ShowSettings);


            if (addInitialProperties)
            {
                VideoViewModel  = new PropertyVideoViewModel(this, MediaStreamer.PropertyVideo);
                PropertyAudio   = new PropertyAudioViewModel(this, MediaStreamer.PropertyAudio);
                PropertyNetwork = new PropertyNetworkViewModel(this, MediaStreamer.PropertyNetwork);

                Properties.Add(VideoViewModel);
                Properties.Add(PropertyAudio);
                Properties.Add(PropertyNetwork);

                // Properties.Add(PropertyQuality = new PropertyQualityViewModel(this, Model.PropertyQuality));
                //  Properties.Add(PropertyCursor = new PropertyCursorViewModel(this, Model.PropertyCursor));

                //Properties.Add(PropertyBorder = new PropertyBorderViewModel(this, Model.PropertyBorder));
            }

            AdvancedSettingsViewModel = new AdvancedSettingsViewModel(MediaStreamer.AdvancedSettings, this);

            BorderViewModel = new BorderViewModel(this, MediaStreamer.PropertyBorder);

            DesignBorderViewModel = new DesignBorderViewModel(this, MediaStreamer.PropertyBorder);

            VideoViewModel.SetupDisplayRegion();

            dispatcher = Dispatcher.CurrentDispatcher;

            dispatcher.BeginInvoke(
                DispatcherPriority.Loaded,
                new Action(() => OnStreamStateChanged(IsStarted)));

            MediaStreamer.StateChanged  += MediaStreamer_StateChanged;
            MediaStreamer.ErrorOccurred += MediaStreamer_ErrorOccurred;
        }
Beispiel #3
0
        public IActionResult AdvancedSettings()
        {
            var settings = _blogConfig.AdvancedSettings;
            var vm       = new AdvancedSettingsViewModel
            {
                DNSPrefetchEndpoint   = settings.DNSPrefetchEndpoint,
                EnablePingBackSend    = settings.EnablePingBackSend,
                EnablePingBackReceive = settings.EnablePingBackReceive
            };

            return(View(vm));
        }
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.userSettings = UserSettings.Load(context.Logger);

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.userSettings);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel();

            if (this.Context.IsUpdating)
            {
                //Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
                ServiceConfigurationV4 serviceConfig = this.Context.GetExtendedDesignerData <ServiceConfigurationV4>();
                ConfigODataEndpointViewModel.Endpoint          = serviceConfig.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion       = serviceConfig.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName       = serviceConfig.ServiceName;
                ConfigODataEndpointViewModel.CustomHttpHeaders = serviceConfig.CustomHttpHeaders;
                var configODataEndpoint = (ConfigODataEndpointViewModel.View as ConfigODataEndpoint);
                configODataEndpoint.IsEnabled = false;

                //Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += (sender, args) =>
                {
                    var advancedSettingsViewModel = sender as AdvancedSettingsViewModel;
                    if (advancedSettingsViewModel != null)
                    {
                        AdvancedSettings advancedSettings = advancedSettingsViewModel.View as AdvancedSettings;

                        advancedSettingsViewModel.GeneratedFileName        = serviceConfig.GeneratedFileNamePrefix;
                        advancedSettings.ReferenceFileName.IsEnabled       = false;
                        advancedSettingsViewModel.UseNamespacePrefix       = serviceConfig.UseNameSpacePrefix;
                        advancedSettingsViewModel.NamespacePrefix          = serviceConfig.NamespacePrefix;
                        advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;
                        advancedSettingsViewModel.GenerateMultipleFiles    = serviceConfig.GenerateMultipleFiles;
                        advancedSettings.GenerateMultipleFiles.IsEnabled   = false;

                        if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                        {
                            advancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes = serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                            advancedSettingsViewModel.EnableNamingAlias = serviceConfig.EnableNamingAlias;
                            advancedSettingsViewModel.IncludeT4File     = serviceConfig.IncludeT4File;
                            advancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal;
                            advancedSettings.IncludeT4File.IsEnabled    = false;
                        }
                    }
                };
            }

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.Project      = ProjectHelper.GetProjectFromHierarchy(this.Context.ProjectHierarchy);
            this.userSettings = UserSettings.Load(context.Logger);

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.userSettings);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel();
            AdvancedSettingsViewModel.NamespacePrefix = ProjectHelper.GetProjectNamespace(this.Project);
            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);

            this.IsFinishEnabled = true;
        }
Beispiel #6
0
        public IActionResult Advanced()
        {
            var settings = _blogConfig.AdvancedSettings;
            var vm       = new AdvancedSettingsViewModel
            {
                DNSPrefetchEndpoint   = settings.DNSPrefetchEndpoint,
                RobotsTxtContent      = settings.RobotsTxtContent,
                EnablePingbackSend    = settings.EnablePingBackSend,
                EnablePingbackReceive = settings.EnablePingBackReceive,
                EnableOpenGraph       = settings.EnableOpenGraph
            };

            return(View(vm));
        }
Beispiel #7
0
        public async Task <IActionResult> Advanced(AdvancedSettingsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var settings = _blogConfig.AdvancedSettings;

            settings.DNSPrefetchEndpoint        = model.DNSPrefetchEndpoint;
            settings.RobotsTxtContent           = model.RobotsTxtContent;
            settings.EnablePingBackSend         = model.EnablePingbackSend;
            settings.EnablePingBackReceive      = model.EnablePingbackReceive;
            settings.EnableOpenGraph            = model.EnableOpenGraph;
            settings.EnableCDNRedirect          = model.EnableCDNRedirect;
            settings.FitImageToDevicePixelRatio = model.FitImageToDevicePixelRatio;

            if (model.EnableCDNRedirect)
            {
                if (string.IsNullOrWhiteSpace(model.CDNEndpoint))
                {
                    throw new ArgumentNullException(nameof(model.CDNEndpoint),
                                                    $"{nameof(model.CDNEndpoint)} must be specified when {nameof(model.EnableCDNRedirect)} is enabled.");
                }

                _logger.LogWarning("Images are configured to use CDN, the endpoint is out of control, use it on your own risk.");

                // Validate endpoint Url to avoid security risks
                // But it still has risks:
                // e.g. If the endpoint is compromised, the attacker could return any kind of response from a image with a big f**k to a script that can attack users.

                var endpoint        = model.CDNEndpoint;
                var isValidEndpoint = endpoint.IsValidUrl(UrlExtension.UrlScheme.Https);
                if (!isValidEndpoint)
                {
                    throw new UriFormatException("CDN Endpoint is not a valid HTTPS Url.");
                }

                settings.CDNEndpoint = model.CDNEndpoint;
            }

            await _blogConfig.SaveAsync(settings);

            await _blogAudit.AddAuditEntry(EventType.Settings, AuditEventId.SettingsSavedAdvanced, "Advanced Settings updated.");

            return(Ok());
        }
Beispiel #8
0
        public IActionResult Advanced()
        {
            var settings = _blogConfig.AdvancedSettings;
            var vm       = new AdvancedSettingsViewModel
            {
                DNSPrefetchEndpoint        = settings.DNSPrefetchEndpoint,
                RobotsTxtContent           = settings.RobotsTxtContent,
                EnablePingbackSend         = settings.EnablePingBackSend,
                EnablePingbackReceive      = settings.EnablePingBackReceive,
                EnableOpenGraph            = settings.EnableOpenGraph,
                EnableCDNRedirect          = settings.EnableCDNRedirect,
                CDNEndpoint                = settings.CDNEndpoint,
                FitImageToDevicePixelRatio = settings.FitImageToDevicePixelRatio
            };

            return(View(vm));
        }
Beispiel #9
0
        public async Task <IActionResult> AdvancedSettings(AdvancedSettingsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var settings = _blogConfig.AdvancedSettings;
                settings.DNSPrefetchEndpoint   = model.DNSPrefetchEndpoint;
                settings.EnablePingBackSend    = model.EnablePingBackSend;
                settings.EnablePingBackReceive = model.EnablePingBackReceive;

                var response = await _blogConfig.SaveConfigurationAsync(settings);

                _blogConfig.RequireRefresh();

                Logger.LogInformation($"User '{User.Identity.Name}' updated AdvancedSettings");
                return(Json(response));
            }
            return(Json(new FailedResponse((int)ResponseFailureCode.InvalidModelState, "Invalid ModelState")));
        }
Beispiel #10
0
        public void OnGet()
        {
            var settings = _blogConfig.AdvancedSettings;

            ViewModel = new()
            {
                RobotsTxtContent      = settings.RobotsTxtContent,
                EnablePingbackSend    = settings.EnablePingBackSend,
                EnablePingbackReceive = settings.EnablePingBackReceive,
                EnableOpenGraph       = settings.EnableOpenGraph,
                EnableOpenSearch      = settings.EnableOpenSearch,
                EnableMetaWeblog      = settings.EnableMetaWeblog,
                WarnExternalLink      = settings.WarnExternalLink,
                AllowScriptsInPage    = settings.AllowScriptsInPage,
                ShowAdminLoginButton  = settings.ShowAdminLoginButton
            };
        }
    }
Beispiel #11
0
        public void OnGet()
        {
            var settings = _blogConfig.AdvancedSettings;

            ViewModel = new()
            {
                DNSPrefetchEndpoint        = settings.DNSPrefetchEndpoint,
                RobotsTxtContent           = settings.RobotsTxtContent,
                EnablePingbackSend         = settings.EnablePingBackSend,
                EnablePingbackReceive      = settings.EnablePingBackReceive,
                EnableOpenGraph            = settings.EnableOpenGraph,
                EnableCDNRedirect          = settings.EnableCDNRedirect,
                EnableOpenSearch           = settings.EnableOpenSearch,
                CDNEndpoint                = settings.CDNEndpoint,
                FitImageToDevicePixelRatio = settings.FitImageToDevicePixelRatio
            };
        }
    }
Beispiel #12
0
        /// <summary>
        /// Cleanup object references
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    if (AdvancedSettingsViewModel != null)
                    {
                        AdvancedSettingsViewModel.Dispose();
                        AdvancedSettingsViewModel = null;
                    }

                    if (OperationImportsViewModel != null)
                    {
                        OperationImportsViewModel.Dispose();
                        OperationImportsViewModel = null;
                    }

                    if (SchemaTypesViewModel != null)
                    {
                        SchemaTypesViewModel.Dispose();
                        SchemaTypesViewModel = null;
                    }

                    if (ConfigODataEndpointViewModel != null)
                    {
                        ConfigODataEndpointViewModel.Dispose();
                        ConfigODataEndpointViewModel = null;
                    }

                    if (serviceInstance != null)
                    {
                        serviceInstance.Dispose();
                        serviceInstance = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Beispiel #13
0
        public async Task <IActionResult> Advanced(AdvancedSettingsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var settings = _blogConfig.AdvancedSettings;
                settings.DNSPrefetchEndpoint   = model.DNSPrefetchEndpoint;
                settings.RobotsTxtContent      = model.RobotsTxtContent;
                settings.EnablePingBackSend    = model.EnablePingBackSend;
                settings.EnablePingBackReceive = model.EnablePingBackReceive;

                var response = await _blogConfig.SaveConfigurationAsync(settings);

                _blogConfig.RequireRefresh();

                await _moongladeAudit.AddAuditEntry(EventType.Settings, Auditing.AuditEventId.SettingsSavedAdvanced, "Advanced Settings updated.");

                return(Json(response));
            }
            return(Json(new FailedResponse((int)ResponseFailureCode.InvalidModelState, "Invalid ModelState")));
        }
Beispiel #14
0
        public async Task <IActionResult> Advanced(AdvancedSettingsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var settings = _blogConfig.AdvancedSettings;

            settings.DNSPrefetchEndpoint   = model.DNSPrefetchEndpoint;
            settings.RobotsTxtContent      = model.RobotsTxtContent;
            settings.EnablePingBackSend    = model.EnablePingbackSend;
            settings.EnablePingBackReceive = model.EnablePingbackReceive;
            settings.EnableOpenGraph       = model.EnableOpenGraph;

            await _blogConfig.SaveAsync(settings);

            await _blogAudit.AddAuditEntry(EventType.Settings, AuditEventId.SettingsSavedAdvanced, "Advanced Settings updated.");

            return(Ok());
        }
Beispiel #15
0
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.UserSettings = UserSettings.Load(context?.Logger);

            // Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
            this._serviceConfig = this.Context?.GetExtendedDesignerData <ServiceConfigurationV4>();

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.UserSettings, this);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(this.UserSettings);
            SchemaTypesViewModel         = new SchemaTypesViewModel(this.UserSettings);
            OperationImportsViewModel    = new OperationImportsViewModel(this.UserSettings);

            OperationImportsViewModel.PageEntering += OperationImportsViewModel_PageEntering;

            SchemaTypesViewModel.PageEntering += SchemaTypeSelectionViewModel_PageEntering;
            SchemaTypesViewModel.PageLeaving  += SchemaTypeSelectionViewModel_PageLeaving;
            if (this.Context != null && this.Context.IsUpdating)
            {
                ConfigODataEndpointViewModel.Endpoint          = this._serviceConfig?.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion       = this._serviceConfig?.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName       = this._serviceConfig?.ServiceName;
                ConfigODataEndpointViewModel.CustomHttpHeaders = this._serviceConfig?.CustomHttpHeaders;

                // Restore the main settings to UI elements.
                ConfigODataEndpointViewModel.PageEntering += ConfigODataEndpointViewModel_PageEntering;

                // The ViewModel should always be filled otherwise if the wizard is completed without visiting this page the generated code becomes wrong
                AdvancedSettingsViewModel_PageEntering(AdvancedSettingsViewModel, EventArgs.Empty);

                // Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += AdvancedSettingsViewModel_PageEntering;
            }

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(SchemaTypesViewModel);
            this.Pages.Add(OperationImportsViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }
Beispiel #16
0
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            Context = context;
            // We only use most recently used endpoints from the config file saved in user's isolated storage
            // The UserSettings constructor will load those endpoints
            UserSettings = new UserSettings(context?.Logger);

            // Since ServiceConfigurationV4 is a derived type of ServiceConfiguration,
            // we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
            ServiceConfig = Context?.GetExtendedDesignerData <ServiceConfigurationV4>();

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(UserSettings);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(UserSettings);
            SchemaTypesViewModel         = new SchemaTypesViewModel(UserSettings);
            OperationImportsViewModel    = new OperationImportsViewModel(UserSettings);

            OperationImportsViewModel.PageEntering += OperationImportsViewModel_PageEntering;
            SchemaTypesViewModel.PageEntering      += SchemaTypeSelectionViewModel_PageEntering;
            SchemaTypesViewModel.PageLeaving       += SchemaTypeSelectionViewModel_PageLeaving;

            if (Context != null && Context.IsUpdating)
            {
                LoadUserSettingsFromServiceConfig();
                ConfigODataEndpointViewModel.EdmxVersion = ServiceConfig?.EdmxVersion;

                // Restore the main settings to UI elements.
                ConfigODataEndpointViewModel.PageEntering += ConfigODataEndpointViewModel_PageEntering;
                // The ViewModel should always be filled otherwise if the wizard is completed without visiting this page the generated code becomes wrong
                AdvancedSettingsViewModel_PageEntering(AdvancedSettingsViewModel, EventArgs.Empty);
                // Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += AdvancedSettingsViewModel_PageEntering;
            }

            Pages.Add(ConfigODataEndpointViewModel);
            Pages.Add(SchemaTypesViewModel);
            Pages.Add(OperationImportsViewModel);
            Pages.Add(AdvancedSettingsViewModel);
            IsFinishEnabled = true;
        }
Beispiel #17
0
        public void OnGet()
        {
            var settings = _blogConfig.AdvancedSettings;

            ViewModel = new()
            {
                DNSPrefetchEndpoint        = settings.DNSPrefetchEndpoint,
                RobotsTxtContent           = settings.RobotsTxtContent,
                EnablePingbackSend         = settings.EnablePingBackSend,
                EnablePingbackReceive      = settings.EnablePingBackReceive,
                EnableOpenGraph            = settings.EnableOpenGraph,
                EnableCDNRedirect          = settings.EnableCDNRedirect,
                EnableOpenSearch           = settings.EnableOpenSearch,
                EnableMetaWeblog           = settings.EnableMetaWeblog,
                MetaWeblogPassword         = settings.MetaWeblogPassword,
                CDNEndpoint                = settings.CDNEndpoint,
                FitImageToDevicePixelRatio = settings.FitImageToDevicePixelRatio,
                WarnExternalLink           = settings.WarnExternalLink,
                AllowScriptsInPage         = settings.AllowScriptsInPage,
                ShowAdminLoginButton       = settings.ShowAdminLoginButton
            };
        }
    }
        public Wizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.UserSettings = UserSettings.Load(context.Logger);

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.UserSettings, this);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(this.UserSettings, this);
            FunctionImportsViewModel     = new FunctionImportsViewModel(this.UserSettings, this);

            if (this.Context.IsUpdating)
            {
                // Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
                var serviceConfig = this.Context.GetExtendedDesignerData <ServiceConfigurationV4>();
                ConfigODataEndpointViewModel.LanguageOption = serviceConfig.LanguageOption;
                ConfigODataEndpointViewModel.Endpoint       = serviceConfig.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion    = serviceConfig.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName    = serviceConfig.ServiceName;
                ConfigODataEndpointViewModel.AcceptAllUntrustedCertificates = serviceConfig.AcceptAllUntrustedCertificates;
                ConfigODataEndpointViewModel.UseWebProxy = serviceConfig.UseWebProxy;
                ConfigODataEndpointViewModel.NetworkCredentialsDomain           = serviceConfig.NetworkCredentialsDomain;
                ConfigODataEndpointViewModel.NetworkCredentialsUserName         = serviceConfig.NetworkCredentialsUserName;
                ConfigODataEndpointViewModel.NetworkCredentialsPassword         = serviceConfig.NetworkCredentialsPassword;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsDomain   = serviceConfig.WebProxyNetworkCredentialsDomain;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsUserName = serviceConfig.WebProxyNetworkCredentialsUserName;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsPassword = serviceConfig.WebProxyNetworkCredentialsPassword;
                ConfigODataEndpointViewModel.UseNetworkCredentials = serviceConfig.UseNetworkCredentials;
                ConfigODataEndpointViewModel.WebProxyUri           = serviceConfig.WebProxyUri;
                if (ConfigODataEndpointViewModel.View is ConfigODataEndpoint configODataEndpoint)
                {
                    configODataEndpoint.IsEnabled = false;
                }

                // The Viewmodel should always be filled otherwise if the wizard is completed without visiting this page  the generated code becomes wrong
                AdvancedSettingsViewModel.GeneratedFileNameEnabled      = false; // advancedSettings.ReferenceFileName.IsEnabled = false;
                AdvancedSettingsViewModel.GeneratedFileNamePrefix       = serviceConfig.GeneratedFileNamePrefix;
                AdvancedSettingsViewModel.UseNamespacePrefix            = serviceConfig.UseNameSpacePrefix;
                AdvancedSettingsViewModel.NamespacePrefix               = serviceConfig.NamespacePrefix;
                AdvancedSettingsViewModel.UseDataServiceCollection      = serviceConfig.UseDataServiceCollection;
                AdvancedSettingsViewModel.UseAsyncDataServiceCollection = serviceConfig.UseAsyncDataServiceCollection;
                AdvancedSettingsViewModel.OperationImportsGenerator     = serviceConfig.OperationImportsGenerator;
                AdvancedSettingsViewModel.SelectOperationImports        = serviceConfig.GenerateOperationImports;
                AdvancedSettingsViewModel.ExcludedOperationImportsNames = serviceConfig.ExcludedOperationImportsNames;

                if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                {
                    AdvancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes =
                        serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                    AdvancedSettingsViewModel.GenerateDynamicPropertiesCollection = serviceConfig.GenerateDynamicPropertiesCollection;
                    AdvancedSettingsViewModel.DynamicPropertiesCollectionName     = serviceConfig.DynamicPropertiesCollectionName;
                    AdvancedSettingsViewModel.EnableNamingAlias    = serviceConfig.EnableNamingAlias;
                    AdvancedSettingsViewModel.IncludeT4File        = serviceConfig.IncludeT4File;
                    AdvancedSettingsViewModel.MakeTypesInternal    = serviceConfig.MakeTypesInternal;
                    AdvancedSettingsViewModel.IncludeT4FileEnabled = true;
                }

                // Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += (sender, args) =>
                {
                    if (sender is AdvancedSettingsViewModel advancedSettingsViewModel)
                    {
                        if (advancedSettingsViewModel.View is AdvancedSettings advancedSettings)
                        {
                            advancedSettings.ReferenceFileName.IsEnabled            = false;
                            advancedSettingsViewModel.GeneratedFileNamePrefix       = serviceConfig.GeneratedFileNamePrefix;
                            advancedSettingsViewModel.UseNamespacePrefix            = serviceConfig.UseNameSpacePrefix;
                            advancedSettingsViewModel.NamespacePrefix               = serviceConfig.NamespacePrefix;
                            advancedSettingsViewModel.UseDataServiceCollection      = serviceConfig.UseDataServiceCollection;
                            advancedSettingsViewModel.UseAsyncDataServiceCollection = serviceConfig.UseAsyncDataServiceCollection;
                            advancedSettingsViewModel.OperationImportsGenerator     = serviceConfig.OperationImportsGenerator;
                            advancedSettingsViewModel.SelectOperationImports        = serviceConfig.GenerateOperationImports;
                            advancedSettingsViewModel.ExcludedOperationImportsNames = serviceConfig.ExcludedOperationImportsNames;

                            if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                            {
                                advancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes =
                                    serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                                advancedSettingsViewModel.GenerateDynamicPropertiesCollection = serviceConfig.GenerateDynamicPropertiesCollection;
                                advancedSettingsViewModel.DynamicPropertiesCollectionName     = serviceConfig.DynamicPropertiesCollectionName;
                                advancedSettingsViewModel.EnableNamingAlias    = serviceConfig.EnableNamingAlias;
                                advancedSettingsViewModel.IncludeT4File        = serviceConfig.IncludeT4File;
                                advancedSettingsViewModel.MakeTypesInternal    = serviceConfig.MakeTypesInternal;
                                advancedSettingsViewModel.IncludeT4FileEnabled = true;
                                advancedSettings.IncludeT4File.IsEnabled       = true;
                            }

                            if (!advancedSettingsViewModel.SelectOperationImports || UserSettings.LanguageOption != LanguageOption.GenerateCSharpCode)
                            {
                                RemoveOperationImportsSettingsPage();
                            }
                            else
                            {
                                AddOperationImportsSettingsPage();
                            }
                        }
                    }
                };

                FunctionImportsViewModel.FunctionImports       = serviceConfig.FunctionImports ?? new List <FunctionImportModel>();
                FunctionImportsViewModel.OperationImports      = serviceConfig.OperationImports ?? new List <OperationImportModel>();
                FunctionImportsViewModel.FunctionImportsCount  = serviceConfig.FunctionImports?.Count ?? 0;
                FunctionImportsViewModel.OperationImportsCount = serviceConfig.OperationImports?.Count ?? 0;
            }

            AdvancedSettingsViewModel.PageEntering += (sender, args) =>
            {
                if (sender is AdvancedSettingsViewModel advancedSettingsViewModel)
                {
                    advancedSettingsViewModel.IncludeExtensionsT4File           = AdvancedSettingsViewModel.IncludeExtensionsT4File;
                    advancedSettingsViewModel.IncludeExtensionsT4FileVisibility = ConfigODataEndpointViewModel.EdmxVersion != Common.Constants.EdmxVersion4 ? Visibility.Visible : Visibility.Collapsed;
                    advancedSettingsViewModel.OperationImportsGenerator         = AdvancedSettingsViewModel.OperationImportsGenerator;
                    advancedSettingsViewModel.SelectOperationImports            = AdvancedSettingsViewModel.SelectOperationImports;
                    advancedSettingsViewModel.IncludeT4FileEnabled = true;
                    if (!advancedSettingsViewModel.SelectOperationImports || UserSettings.LanguageOption != LanguageOption.GenerateCSharpCode)
                    {
                        RemoveOperationImportsSettingsPage();
                    }
                    else
                    {
                        AddOperationImportsSettingsPage();
                    }
                }
            };

            FunctionImportsViewModel.PageEntering += (sender, args) =>
            {
                if (sender is FunctionImportsViewModel functionImportsViewModel)
                {
                    if (ConfigODataEndpointViewModel.EdmxVersion == Common.Constants.EdmxVersion4 && (FunctionImportsViewModel.OperationImports == null ||
                                                                                                      !FunctionImportsViewModel.OperationImports.Any() ||
                                                                                                      (AdvancedSettingsViewModel.UseNamespacePrefix && FunctionImportsViewModel.OperationImports.Any(fi => fi.Namespace != AdvancedSettingsViewModel.NamespacePrefix)) ||
                                                                                                      FunctionImportsViewModel.OperationImports.Any(fi =>
                                                                                                                                                    !this.UserSettings.Endpoint.Contains(fi.EndpointUri))))
                    {
                        FunctionImportsViewModel.OperationImports = OperationImportsHelper.GetOperationsImports(
                            (this.CreateServiceConfiguration() as ServiceConfigurationV4).GetODataEdmModel(),
                            AdvancedSettingsViewModel.UseNamespacePrefix
                                ? AdvancedSettingsViewModel.NamespacePrefix
                                : null,
                            File.Exists(ConfigODataEndpointViewModel.Endpoint) ? ConfigODataEndpointViewModel.Endpoint : ConfigODataEndpointViewModel.Endpoint.Replace("$metadata", string.Empty));
                        FunctionImportsViewModel.OperationImportsCount = FunctionImportsViewModel.OperationImports?.Count ?? 0;
                    }

                    if (ConfigODataEndpointViewModel.EdmxVersion != Common.Constants.EdmxVersion4 && (FunctionImportsViewModel.FunctionImports == null ||
                                                                                                      !FunctionImportsViewModel.FunctionImports.Any() ||
                                                                                                      (AdvancedSettingsViewModel.UseNamespacePrefix && FunctionImportsViewModel.FunctionImports.Any(fi => fi.Namespace != AdvancedSettingsViewModel.NamespacePrefix)) ||
                                                                                                      FunctionImportsViewModel.FunctionImports.Any(fi =>
                                                                                                                                                   !this.UserSettings.Endpoint.Contains(fi.EndpointUri))))
                    {
                        FunctionImportsViewModel.FunctionImports = FunctionImportsHelper.GetFunctionImports(
                            this.CreateServiceConfiguration().GetDataEdmModel(),
                            AdvancedSettingsViewModel.UseNamespacePrefix
                                ? AdvancedSettingsViewModel.NamespacePrefix
                                : null,
                            File.Exists(ConfigODataEndpointViewModel.Endpoint) ? ConfigODataEndpointViewModel.Endpoint : ConfigODataEndpointViewModel.Endpoint.Replace("$metadata", string.Empty));
                        FunctionImportsViewModel.FunctionImportsCount = FunctionImportsViewModel.FunctionImports?.Count ?? 0;
                    }

                    functionImportsViewModel.FunctionImports       = FunctionImportsViewModel.FunctionImports;
                    functionImportsViewModel.FunctionImportsCount  = functionImportsViewModel.FunctionImports?.Count ?? 0;
                    functionImportsViewModel.OperationImports      = FunctionImportsViewModel.OperationImports;
                    functionImportsViewModel.OperationImportsCount = functionImportsViewModel.OperationImports?.Count ?? 0;
                }
            };

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }
        public ODataConnectedServiceWizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.UserSettings = UserSettings.Load(context.Logger);

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.UserSettings, this);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(this.UserSettings);
            OperationImportsViewModel    = new OperationImportsViewModel();

            ServiceConfigurationV4 serviceConfig = null;

            OperationImportsViewModel.PageEntering += ObjectSelectionViewModel_PageEntering;

            if (this.Context.IsUpdating)
            {
                //Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
                serviceConfig = this.Context.GetExtendedDesignerData <ServiceConfigurationV4>();
                ConfigODataEndpointViewModel.Endpoint          = serviceConfig.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion       = serviceConfig.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName       = serviceConfig.ServiceName;
                ConfigODataEndpointViewModel.CustomHttpHeaders = serviceConfig.CustomHttpHeaders;



                // The ViewModel should always be filled otherwise if the wizard is completed without visiting this page the generated code becomes wrong
                AdvancedSettingsViewModel.UseNamespacePrefix       = serviceConfig.UseNamespacePrefix;
                AdvancedSettingsViewModel.NamespacePrefix          = serviceConfig.NamespacePrefix;
                AdvancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;

                if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                {
                    AdvancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes =
                        serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                    AdvancedSettingsViewModel.EnableNamingAlias = serviceConfig.EnableNamingAlias;
                    AdvancedSettingsViewModel.IncludeT4File     = serviceConfig.IncludeT4File;
                    AdvancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal;
                }


                ConfigODataEndpointViewModel.PageEntering += (sender, args) =>
                {
                    var configOdataViewModel = sender as ConfigODataEndpointViewModel;
                    if (configOdataViewModel != null)
                    {
                        var configOdataView = configOdataViewModel.View as ConfigODataEndpoint;
                        configOdataView.Endpoint.IsEnabled = false;
                        configOdataView.OpenConnectedServiceJsonFileButton.IsEnabled = false;
                        configOdataView.OpenEndpointFileButton.IsEnabled             = !serviceConfig.Endpoint.StartsWith("http");
                        configOdataView.ServiceName.IsEnabled     = false;
                        configOdataViewModel.IncludeCustomHeaders = serviceConfig.IncludeCustomHeaders;
                        configOdataViewModel.IncludeWebProxy      = serviceConfig.IncludeWebProxy;
                        configOdataViewModel.WebProxyHost         = serviceConfig.WebProxyHost;

                        configOdataViewModel.IncludeWebProxyNetworkCredentials = serviceConfig.IncludeWebProxyNetworkCredentials;
                        configOdataViewModel.WebProxyNetworkCredentialsDomain  = serviceConfig.WebProxyNetworkCredentialsDomain;

                        // don't accept any credentials from the restored settings
                        configOdataViewModel.WebProxyNetworkCredentialsUsername = null;
                        configOdataViewModel.WebProxyNetworkCredentialsPassword = null;
                    }
                };


                //Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += (sender, args) =>
                {
                    if (sender is AdvancedSettingsViewModel advancedSettingsViewModel)
                    {
                        if (advancedSettingsViewModel.View is AdvancedSettings advancedSettings)
                        {
                            advancedSettingsViewModel.GeneratedFileNamePrefix  = serviceConfig.GeneratedFileNamePrefix;
                            advancedSettings.ReferenceFileName.IsEnabled       = false;
                            advancedSettingsViewModel.UseNamespacePrefix       = serviceConfig.UseNamespacePrefix;
                            advancedSettingsViewModel.NamespacePrefix          = serviceConfig.NamespacePrefix;
                            advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;
                            advancedSettingsViewModel.GenerateMultipleFiles    = serviceConfig.GenerateMultipleFiles;
                            advancedSettings.GenerateMultipleFiles.IsEnabled   = false;

                            if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                            {
                                advancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes = serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                                advancedSettingsViewModel.EnableNamingAlias = serviceConfig.EnableNamingAlias;
                                advancedSettingsViewModel.IncludeT4File     = serviceConfig.IncludeT4File;
                                advancedSettingsViewModel.MakeTypesInternal = serviceConfig.MakeTypesInternal;
                                advancedSettings.IncludeT4File.IsEnabled    = false;
                            }
                        }
                    }
                };
            }

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(OperationImportsViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }
Beispiel #20
0
        public Wizard(ConnectedServiceProviderContext context)
        {
            this.Context      = context;
            this.UserSettings = UserSettings.Load(context.Logger);

            ConfigODataEndpointViewModel = new ConfigODataEndpointViewModel(this.UserSettings);
            AdvancedSettingsViewModel    = new AdvancedSettingsViewModel(this.UserSettings);

            if (this.Context.IsUpdating)
            {
                //Since ServiceConfigurationV4 is a derived type of ServiceConfiguration. So we can deserialize a ServiceConfiguration into a ServiceConfigurationV4.
                var serviceConfig = this.Context.GetExtendedDesignerData <ServiceConfigurationV4>();
                ConfigODataEndpointViewModel.Endpoint    = serviceConfig.Endpoint;
                ConfigODataEndpointViewModel.EdmxVersion = serviceConfig.EdmxVersion;
                ConfigODataEndpointViewModel.ServiceName = serviceConfig.ServiceName;
                ConfigODataEndpointViewModel.UseWebProxy = serviceConfig.UseWebProxy;
                ConfigODataEndpointViewModel.NetworkCredentialsDomain           = serviceConfig.NetworkCredentialsDomain;
                ConfigODataEndpointViewModel.NetworkCredentialsUserName         = serviceConfig.NetworkCredentialsUserName;
                ConfigODataEndpointViewModel.NetworkCredentialsPassword         = serviceConfig.NetworkCredentialsPassword;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsDomain   = serviceConfig.WebProxyNetworkCredentialsDomain;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsUserName = serviceConfig.WebProxyNetworkCredentialsUserName;
                ConfigODataEndpointViewModel.WebProxyNetworkCredentialsPassword = serviceConfig.WebProxyNetworkCredentialsPassword;
                ConfigODataEndpointViewModel.UseNetworkCredentials = serviceConfig.UseNetworkCredentials;
                ConfigODataEndpointViewModel.WebProxyUri           = serviceConfig.WebProxyUri;
                if (ConfigODataEndpointViewModel.View is ConfigODataEndpoint configODataEndpoint)
                {
                    configODataEndpoint.IsEnabled = false;
                }

                //Restore the advanced settings to UI elements.
                AdvancedSettingsViewModel.PageEntering += (sender, args) =>
                {
                    if (sender is AdvancedSettingsViewModel advancedSettingsViewModel)
                    {
                        if (advancedSettingsViewModel.View is AdvancedSettings advancedSettings)
                        {
                            advancedSettings.ReferenceFileName.IsEnabled       = false;
                            advancedSettingsViewModel.GeneratedFileName        = serviceConfig.GeneratedFileNamePrefix;
                            advancedSettingsViewModel.UseNamespacePrefix       = serviceConfig.UseNameSpacePrefix;
                            advancedSettingsViewModel.NamespacePrefix          = serviceConfig.NamespacePrefix;
                            advancedSettingsViewModel.UseDataServiceCollection = serviceConfig.UseDataServiceCollection;

                            if (serviceConfig.EdmxVersion == Common.Constants.EdmxVersion4)
                            {
                                advancedSettingsViewModel.IgnoreUnexpectedElementsAndAttributes =
                                    serviceConfig.IgnoreUnexpectedElementsAndAttributes;
                                advancedSettingsViewModel.EnableNamingAlias = serviceConfig.EnableNamingAlias;
                                advancedSettingsViewModel.IncludeT4File     = serviceConfig.IncludeT4File;
                                advancedSettings.IncludeT4File.IsEnabled    = false;
                            }
                        }
                    }
                };
            }

            AdvancedSettingsViewModel.PageEntering += (sender, args) =>
            {
                if (sender is AdvancedSettingsViewModel advancedSettingsViewModel)
                {
                    advancedSettingsViewModel.IncludeExtensionsT4File           = ConfigODataEndpointViewModel.EdmxVersion != Common.Constants.EdmxVersion4;
                    advancedSettingsViewModel.IncludeExtensionsT4FileVisibility = ConfigODataEndpointViewModel.EdmxVersion != Common.Constants.EdmxVersion4 ? Visibility.Visible : Visibility.Collapsed;
                    advancedSettingsViewModel.FunctionImportsGenerator          = AdvancedSettingsViewModel.FunctionImportsGenerator;
                    advancedSettingsViewModel.GenerateFunctionImports           = AdvancedSettingsViewModel.GenerateFunctionImports;
                }
            };

            this.Pages.Add(ConfigODataEndpointViewModel);
            this.Pages.Add(AdvancedSettingsViewModel);
            this.IsFinishEnabled = true;
        }