public void TestGetOperationImports()
        {
            var model            = EdmHelper.GetEdmModelFromFile(MetadataPath);
            var operationImports = EdmHelper.GetOperationImports(model);

            var actualOperationImports = new List <string>();

            foreach (var operation in operationImports)
            {
                actualOperationImports.Add(operation.Name);
            }

            var expectedOperationImports = new List <string>()
            {
                "GetNearestAirport",
                "GetPersonWithMostFriends",
                "ResetDataSource",
            };

            // Sort the Lists in ascending order
            expectedOperationImports.Sort();
            actualOperationImports.Sort();

            //In order to get compare lists you should use the CollectionAssert
            CollectionAssert.AreEqual(expectedOperationImports, actualOperationImports);
        }
Exemplo n.º 2
0
        public void OperationImportsViewModel_PageEntering(object sender, EventArgs args)
        {
            if (sender is OperationImportsViewModel operationImportsViewModel)
            {
                if (this.ProcessedEndpointForOperationImports != ConfigODataEndpointViewModel.Endpoint)
                {
                    if (ConfigODataEndpointViewModel.EdmxVersion != Constants.EdmxVersion4)
                    {
                        operationImportsViewModel.View.IsEnabled          = false;
                        operationImportsViewModel.IsSupportedODataVersion = false;
                        return;
                    }

                    var model      = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);
                    var operations = EdmHelper.GetOperationImports(model);
                    OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(SchemaTypesViewModel.ExcludedSchemaTypeNames), SchemaTypesViewModel.SchemaTypeModelMap);

                    if (Context.IsUpdating)
                    {
                        operationImportsViewModel.ExcludeOperationImports(this._serviceConfig?.ExcludedOperationImports ?? Enumerable.Empty <string>());
                    }
                }

                this.ProcessedEndpointForOperationImports = ConfigODataEndpointViewModel.Endpoint;
            }
        }
Exemplo n.º 3
0
        public void SchemaTypeSelectionViewModel_PageLeaving(object sender, EventArgs args)
        {
            var model = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);

            // exclude related operation imports for excluded types
            var operations          = EdmHelper.GetOperationImports(model);
            var operationsToExclude = operations.Where(x => !OperationImportsViewModel.IsOperationImportIncluded(x,
                                                                                                                 SchemaTypesViewModel.ExcludedSchemaTypeNames.ToList())).ToList();

            foreach (var operationImport in OperationImportsViewModel.OperationImports)
            {
                if (operationsToExclude.Any(x => x.Name == operationImport.Name))
                {
                    operationImport.IsSelected = false;
                }
            }

            // exclude bound operations for excluded types
            var boundOperations          = EdmHelper.GetBoundOperations(model);
            var boundOperationsToExclude = boundOperations.SelectMany(x => x.Value)
                                           .Where(x => !SchemaTypesViewModel.IsBoundOperationIncluded(x,
                                                                                                      SchemaTypesViewModel.ExcludedSchemaTypeNames.ToList())).ToList();

            foreach (var boundOperation in SchemaTypesViewModel.SchemaTypes.SelectMany(x => x.BoundOperations))
            {
                if (boundOperationsToExclude.Any(x => $"{x.Name}({x.Parameters.First().Type.Definition.FullTypeName()})" == boundOperation.Name))
                {
                    boundOperation.IsSelected = false;
                }
            }
        }
Exemplo n.º 4
0
        public void SchemaTypeSelectionViewModel_PageLeaving(object sender, EventArgs args)
        {
            // exclude related operationimports for excluded types
            var model               = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);
            var operations          = EdmHelper.GetOperationImports(model);
            var operationsToExclude = operations.Where(x => !OperationImportsViewModel.IsOperationImportIncluded(x,
                                                                                                                 SchemaTypesViewModel.ExcludedSchemaTypeNames.ToList())).ToList();

            foreach (var operationImport in OperationImportsViewModel.OperationImports)
            {
                if (operationsToExclude.Any(x => x.Name == operationImport.Name))
                {
                    operationImport.IsSelected = false;
                }
            }
        }
        public void ObjectSelectionViewModel_PageEntering(object sender, EventArgs args)
        {
            if (sender is OperationImportsViewModel objectSelectionViewModel)
            {
                if (ConfigODataEndpointViewModel.EdmxVersion != Constants.EdmxVersion4)
                {
                    objectSelectionViewModel.View.IsEnabled          = false;
                    objectSelectionViewModel.IsSupportedODataVersion = false;
                    return;
                }
                var model      = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath);
                var operations = EdmHelper.GetOperationImports(model);
                OperationImportsViewModel.LoadOperationImports(operations);

                if (Context.IsUpdating)
                {
                    var serviceConfig = Context.GetExtendedDesignerData <ServiceConfigurationV4>();
                    objectSelectionViewModel.ExcludeOperationImports(serviceConfig?.ExcludedOperationImports ?? Enumerable.Empty <string>());
                }
            }
        }
Exemplo n.º 6
0
        private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEventArgs e)
        {
            var fileDialogTitle = "Open OData Connected Service Config File";

            var openFileDialog = new Win32.OpenFileDialog
            {
                DefaultExt = ".json",
                Filter     = "JSON File (.json)|*.json",
                Title      = fileDialogTitle
            };

            if (!(openFileDialog.ShowDialog() == true)) // Result of ShowDialog() call is bool?
            {
                return;
            }

            if (!File.Exists(openFileDialog.FileName))
            {
                MessageBox.Show(
                    $"File \"{openFileDialog.FileName}\" does not exists.",
                    string.Format(CultureInfo.InvariantCulture, fileDialogTitle),
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                return;
            }

            var jsonFileText = File.ReadAllText(openFileDialog.FileName);

            if (string.IsNullOrWhiteSpace(jsonFileText))
            {
                MessageBox.Show("Config file is empty.",
                                string.Format(CultureInfo.InvariantCulture, fileDialogTitle),
                                MessageBoxButton.OK,
                                MessageBoxImage.Warning);
                return;
            }

            ConnectedServiceJsonFileData connectedServiceData;

            try
            {
                connectedServiceData = JsonConvert.DeserializeObject <ConnectedServiceJsonFileData>(jsonFileText);
            }
            catch (JsonException ex)
            {
                System.Diagnostics.Debug.Assert(ex != null);
                MessageBox.Show(
                    "Contents of the config file could not be deserialized.",
                    string.Format(CultureInfo.InvariantCulture, fileDialogTitle),
                    MessageBoxButton.OK,
                    MessageBoxImage.Warning);
                return;
            }

            // connectedServiceData not expected to be null at this point
            if (connectedServiceData.ExtendedData != null)
            {
                this.UserSettings.CopyPropertiesFrom(connectedServiceData.ExtendedData);
            }

            ODataConnectedServiceWizard connectedServiceWizard = GetODataConnectedServiceWizard();

            // get Operation Imports and bound operations from metadata for excluding ExcludedOperationImports and ExcludedBoundOperations
            try
            {
                connectedServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath = connectedServiceWizard.ConfigODataEndpointViewModel.GetMetadata(out var version);
                connectedServiceWizard.ConfigODataEndpointViewModel.EdmxVersion      = version;
                if (version == Constants.EdmxVersion4)
                {
                    Edm.IEdmModel model = EdmHelper.GetEdmModelFromFile(connectedServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath);

                    IEnumerable <Edm.IEdmSchemaType> entityTypes = EdmHelper.GetSchemaTypes(model);
                    IDictionary <Edm.IEdmType, List <Edm.IEdmOperation> > boundOperations = EdmHelper.GetBoundOperations(model);
                    connectedServiceWizard.SchemaTypesViewModel.LoadSchemaTypes(entityTypes, boundOperations);
                    connectedServiceWizard.ProcessedEndpointForSchemaTypes = this.UserSettings.Endpoint;
                    connectedServiceWizard.SchemaTypesViewModel.LoadFromUserSettings();

                    IEnumerable <Edm.IEdmOperationImport> operations = EdmHelper.GetOperationImports(model);
                    connectedServiceWizard.OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(), new Dictionary <string, SchemaTypeModel>());
                    connectedServiceWizard.ProcessedEndpointForOperationImports = this.UserSettings.Endpoint;
                    connectedServiceWizard.OperationImportsViewModel.LoadFromUserSettings();
                }
            }
            catch
            {
                // ignored
            }
        }
        private void OpenConnectedServiceJsonFileButton_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new Microsoft.Win32.OpenFileDialog
            {
                DefaultExt = ".json",
                Filter     = "JSON File (.json)|*.json",
                Title      = "Open OData Connected Service Config File"
            };

            var result = openFileDialog.ShowDialog();

            if (result == false)
            {
                return;
            }
            if (!File.Exists(openFileDialog.FileName))
            {
                MessageBox.Show($"File \"{openFileDialog.FileName}\" does not exists.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            var jsonFileText = File.ReadAllText(openFileDialog.FileName);

            if (string.IsNullOrWhiteSpace(jsonFileText))
            {
                MessageBox.Show("File have not content.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            if (JObject.Parse(jsonFileText) == null)
            {
                MessageBox.Show("Can't convert file content to JObject.", "Open OData Connected Service json-file", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            var microsoftConnectedServiceData = JsonConvert.DeserializeObject <ConnectedServiceJsonFileData>(jsonFileText);

            if (microsoftConnectedServiceData != null)
            {
                this.UserSettings                          = new UserSettings();
                this.UserSettings.Endpoint                 = microsoftConnectedServiceData.ExtendedData?.Endpoint ?? this.UserSettings.Endpoint;
                this.UserSettings.ServiceName              = microsoftConnectedServiceData.ExtendedData?.ServiceName ?? this.UserSettings.ServiceName;
                this.UserSettings.GeneratedFileNamePrefix  = microsoftConnectedServiceData.ExtendedData?.GeneratedFileNamePrefix ?? this.UserSettings.GeneratedFileNamePrefix;
                this.UserSettings.OpenGeneratedFilesInIDE  = microsoftConnectedServiceData.ExtendedData?.OpenGeneratedFilesInIDE ?? this.UserSettings.OpenGeneratedFilesInIDE;
                this.UserSettings.MakeTypesInternal        = microsoftConnectedServiceData.ExtendedData?.MakeTypesInternal ?? this.UserSettings.MakeTypesInternal;
                this.UserSettings.NamespacePrefix          = microsoftConnectedServiceData.ExtendedData?.NamespacePrefix ?? this.UserSettings.NamespacePrefix;
                this.UserSettings.UseDataServiceCollection = microsoftConnectedServiceData.ExtendedData?.UseDataServiceCollection ?? this.UserSettings.UseDataServiceCollection;
                this.UserSettings.UseNamespacePrefix       = microsoftConnectedServiceData.ExtendedData?.UseNamespacePrefix ?? this.UserSettings.UseNamespacePrefix;
                this.UserSettings.IncludeT4File            = microsoftConnectedServiceData.ExtendedData?.IncludeT4File ?? this.UserSettings.IncludeT4File;
                this.UserSettings.IgnoreUnexpectedElementsAndAttributes = microsoftConnectedServiceData.ExtendedData?.IgnoreUnexpectedElementsAndAttributes ?? this.UserSettings.IgnoreUnexpectedElementsAndAttributes;
                this.UserSettings.GenerateMultipleFiles              = microsoftConnectedServiceData.ExtendedData?.GenerateMultipleFiles ?? this.UserSettings.GenerateMultipleFiles;
                this.UserSettings.EnableNamingAlias                  = microsoftConnectedServiceData.ExtendedData?.EnableNamingAlias ?? this.UserSettings.EnableNamingAlias;
                this.UserSettings.CustomHttpHeaders                  = microsoftConnectedServiceData.ExtendedData?.CustomHttpHeaders ?? this.UserSettings.CustomHttpHeaders;
                this.UserSettings.IncludeCustomHeaders               = microsoftConnectedServiceData.ExtendedData?.IncludeCustomHeaders ?? this.UserSettings.IncludeCustomHeaders;
                this.UserSettings.ExcludedOperationImports           = microsoftConnectedServiceData.ExtendedData?.ExcludedOperationImports ?? new List <string>();
                this.UserSettings.WebProxyHost                       = microsoftConnectedServiceData.ExtendedData?.WebProxyHost ?? this.UserSettings.WebProxyHost;
                this.UserSettings.IncludeWebProxy                    = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxy ?? this.UserSettings.IncludeWebProxy;
                this.UserSettings.IncludeWebProxyNetworkCredentials  = microsoftConnectedServiceData.ExtendedData?.IncludeWebProxyNetworkCredentials ?? this.UserSettings.IncludeWebProxyNetworkCredentials;
                this.UserSettings.WebProxyNetworkCredentialsDomain   = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsDomain ?? this.UserSettings.WebProxyNetworkCredentialsDomain;
                this.UserSettings.WebProxyNetworkCredentialsPassword = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsPassword ?? this.UserSettings.WebProxyNetworkCredentialsPassword;
                this.UserSettings.WebProxyNetworkCredentialsUsername = microsoftConnectedServiceData.ExtendedData?.WebProxyNetworkCredentialsUsername ?? this.UserSettings.WebProxyNetworkCredentialsUsername;
                ODataConnectedServiceWizard ServiceWizard = ((ConfigODataEndpointViewModel)this.DataContext).ServiceWizard;
                this.UserSettings.MruEndpoints = UserSettings.Load(ServiceWizard.Context.Logger)?.MruEndpoints;

                ServiceWizard.ConfigODataEndpointViewModel.UserSettings = this.UserSettings;
                ServiceWizard.ConfigODataEndpointViewModel.LoadFromUserSettings();

                ServiceWizard.AdvancedSettingsViewModel.UserSettings = this.UserSettings;
                ServiceWizard.AdvancedSettingsViewModel.LoadFromUserSettings();

                ServiceWizard.OperationImportsViewModel.UserSettings = this.UserSettings;

                // get Operation Imports from metadata for excluding ExcludedOperationImports
                try
                {
                    ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath = ServiceWizard.ConfigODataEndpointViewModel.GetMetadata(out var version);
                    ServiceWizard.ConfigODataEndpointViewModel.EdmxVersion      = version;
                    if (version == Constants.EdmxVersion4)
                    {
                        var model      = EdmHelper.GetEdmModelFromFile(ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath);
                        var operations = EdmHelper.GetOperationImports(model);
                        ServiceWizard.OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(), new Dictionary <string, SchemaTypeModel>());
                        ServiceWizard.ProcessedEndpointForOperationImports = this.UserSettings.Endpoint;
                        ServiceWizard.OperationImportsViewModel.LoadFromUserSettings();
                        ServiceWizard.SchemaTypesViewModel.LoadFromUserSettings();
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
        public void TestGetOperationImportsWithNullModel()
        {
            var operationImports = EdmHelper.GetOperationImports(null);

            operationImports.Should().BeEmpty();
        }