public void TestGetBoundOperations() { var model = EdmHelper.GetEdmModelFromFile(MetadataPath); var boundOperations = EdmHelper.GetBoundOperations(model); var actualBoundOperations = new List <string>(); foreach (var operation in boundOperations) { foreach (var boundValue in operation.Value) { actualBoundOperations.Add(boundValue.FullName()); } } var expectedBoundOperations = new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.GetFavoriteAirline", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.GetFriendsTrips", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.UpdatePersonLastName", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.ShareTrip", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.GetInvolvedPeople" }; // Sort the Lists in ascending order actualBoundOperations.Sort(); expectedBoundOperations.Sort(); //In order to get compare lists you should use the CollectionAssert CollectionAssert.AreEqual(expectedBoundOperations, actualBoundOperations); }
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; } } }
public void TestGetSchemaTypes() { var model = EdmHelper.GetEdmModelFromFile(MetadataPath); var schemaTypes = EdmHelper.GetSchemaTypes(model); var actualSchemaTypes = new List <string>(); foreach (var type in schemaTypes) { actualSchemaTypes.Add(type.FullName()); } var expectedSchemaTypes = new List <string>() { "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airline", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Airport", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.City", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Flight", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Location", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PlanItem", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PublicTransportation", "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip", }; // Sort the Lists in ascending order expectedSchemaTypes.Sort(); actualSchemaTypes.Sort(); //In order to get compare lists you should use the CollectionAssert CollectionAssert.AreEqual(expectedSchemaTypes, actualSchemaTypes); }
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); }
public void GetSsdlFromEdmxTest() { var path = Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\ChinookDatabase\Chinook.edmx"); var ssdl = EdmHelper.GetSsdlFromEdmx(path); Assert.NotNull(ssdl); }
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; } }
public void TestGetParametersString_WithEmptyParameters() { string actualResult = EdmHelper.GetParametersString(new List <IEdmOperationParameter>()); string expectedResult = "()"; actualResult.ShouldBeEquivalentTo(expectedResult); }
/// <summary> /// Loads operation imports except the ones that require a type that is excluded. /// </summary> /// <param name="operationImports">A list of all the operation imports.</param> /// <param name="excludedSchemaTypes">A collection of schema types that will be excluded from generated code.</param> /// <param name="schemaTypeModels">A dictionary of schema type and the associated schematypemodel.</param> public void LoadOperationImports(IEnumerable <IEdmOperationImport> operationImports, ICollection <string> excludedSchemaTypes, IDictionary <string, SchemaTypeModel> schemaTypeModels) { var toLoad = new List <OperationImportModel>(); var alreadyAdded = new HashSet <string>(); foreach (var operation in operationImports) { if (!alreadyAdded.Contains(operation.Name)) { var operationImportModel = new OperationImportModel() { Name = operation.Name, ReturnType = operation.Operation?.ReturnType?.FullName() ?? "void", ParametersString = EdmHelper.GetParametersString(operation.Operation?.Parameters), IsSelected = IsOperationImportIncluded(operation, excludedSchemaTypes) }; operationImportModel.PropertyChanged += (s, args) => { if (s is OperationImportModel currentOperationImportModel) { IEnumerable <IEdmOperationParameter> parameters = operation.Operation.Parameters; foreach (var parameter in parameters) { if (schemaTypeModels.TryGetValue(parameter.Type.FullName(), out SchemaTypeModel model) && !model.IsSelected) { model.IsSelected = currentOperationImportModel.IsSelected; } } string returnTypeName = operation.Operation.ReturnType?.FullName(); if (returnTypeName != null && schemaTypeModels.TryGetValue(returnTypeName, out SchemaTypeModel schemaTypeModel) && !schemaTypeModel.IsSelected) { schemaTypeModel.IsSelected = currentOperationImportModel.IsSelected; } } if (this.View is OperationImports view) { view.SelectedOperationImportsCount.Text = OperationImports.Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture); } }; toLoad.Add(operationImportModel); alreadyAdded.Add(operation.Name); } } OperationImports = toLoad.OrderBy(o => o.Name).ToList(); _operationImportsCount = OperationImports.Count(); }
public void TestGetParametersString_WithSingleParameter() { var typeReference = new EdmTypeReferenceForTest(new EdmSchemaTypeForTest("Type1", "Test"), false); List <IEdmOperationParameter> parameters = new List <IEdmOperationParameter> { new EdmOperationParameter(new EdmAction("Test", "Action", typeReference, false, new EdmPropertyPathExpression("TestPath")), "par1", typeReference) }; string actualResult = EdmHelper.GetParametersString(parameters); string expectedResult = "(Test.Type1 par1)"; actualResult.ShouldBeEquivalentTo(expectedResult); }
public void TestGetTypeNameFromFullName() { var employeeFullName = "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Employee"; var personFullName = "Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"; var personGenderFullName = "Microsoft.OData.Service.Sample.TrippinInMemory.Models.PersonGender"; var employeeTypeName = EdmHelper.GetTypeNameFromFullName(employeeFullName); var personTypeName = EdmHelper.GetTypeNameFromFullName(personFullName); var personGenderTypeName = EdmHelper.GetTypeNameFromFullName(personGenderFullName); Assert.AreEqual(employeeTypeName, "Employee"); Assert.AreEqual(personTypeName, "Person"); Assert.AreEqual(personGenderTypeName, "PersonGender"); }
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 SchemaTypeSelectionViewModel_PageEntering(object sender, EventArgs args) { if (sender is SchemaTypesViewModel entityTypeViewModel) { if (this.ProcessedEndpointForSchemaTypes != ConfigODataEndpointViewModel.Endpoint) { var model = EdmHelper.GetEdmModelFromFile(ConfigODataEndpointViewModel.MetadataTempPath); var entityTypes = EdmHelper.GetSchemaTypes(model); var boundOperations = EdmHelper.GetBoundOperations(model); SchemaTypesViewModel.LoadSchemaTypes(entityTypes, boundOperations); if (Context.IsUpdating) { entityTypeViewModel.ExcludeSchemaTypes(this._serviceConfig?.ExcludedSchemaTypes ?? Enumerable.Empty <string>()); } } this.ProcessedEndpointForSchemaTypes = ConfigODataEndpointViewModel.Endpoint; } }
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>()); } } }
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 } }
public void TestGetBoundOperationsWithNullModel() { var boundOperations = EdmHelper.GetBoundOperations(null); boundOperations.Should().BeEmpty(); }
/// <summary> /// Creates a list of types that needs to be loaded on the UI. /// Initially all the types are loaded /// </summary> /// <param name="schemaTypes">A list of schema types that need to be laoded.</param> /// <param name="boundOperations">The associated bound operations.</param> public void LoadSchemaTypes( IEnumerable <IEdmSchemaType> schemaTypes, IDictionary <IEdmStructuredType, List <IEdmOperation> > boundOperations) { var toLoad = new List <SchemaTypeModel>(); foreach (var type in schemaTypes) { if (!SchemaTypeModelMap.ContainsKey(type.FullName()) || SchemaTypeModelMap.Count() != schemaTypes.Count()) { SchemaTypes = toLoad; SchemaTypeModelMap.Clear(); break; } } if (SchemaTypes.Any()) { return; } foreach (var schemaType in schemaTypes) { var schemaTypeModel = new SchemaTypeModel() { Name = schemaType.FullTypeName(), ShortName = EdmHelper.GetTypeNameFromFullName(schemaType.FullTypeName()) }; // Create propertyChange handler. // Anytime a property is selected/unslected, the handler ensures // all the related types and operations are selected/unselected schemaTypeModel.PropertyChanged += (s, args) => { if (schemaTypeModel.IsSelected && schemaType is IEdmStructuredType structuredType) { //Check for the base type and automatically select it if not selected already. string baseTypeFullName = structuredType.BaseType?.FullTypeName(); if (baseTypeFullName != null) { AddRelatedType(baseTypeFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(baseTypeFullName, out SchemaTypeModel baseTypeSchemaTypeModel) && !baseTypeSchemaTypeModel.IsSelected) { baseTypeSchemaTypeModel.IsSelected = true; } } // Check the required navigational property types and ensure they are selected as well foreach (var property in structuredType.DeclaredProperties) { string propertyName = property is IEdmNavigationProperty?property.Type.ToStructuredType().FullTypeName() : property.Type.FullName(); if (property.Type.ToStructuredType() != null || property.Type.IsEnum()) { propertyName = property.Type.ToStructuredType()?.FullTypeName() ?? property.Type.FullName(); AddRelatedType(propertyName, structuredType.FullTypeName()); bool hasProperty = SchemaTypeModelMap.TryGetValue(propertyName, out SchemaTypeModel navigationPropertyModel); if (hasProperty && !navigationPropertyModel.IsSelected) { navigationPropertyModel.IsSelected = true; } } } // Check for bound operations and ensure related types are also selected. // In this case related types means return types and parameter types. if (boundOperations.TryGetValue(structuredType, out List <IEdmOperation> operations)) { foreach (var operation in operations) { // Check if return type of associated bound operation has been selected. if (operation.ReturnType != null && (operation.ReturnType.ToStructuredType() != null || operation.ReturnType.IsEnum())) { string returnTypeFullName = operation.ReturnType.ToStructuredType()?.FullTypeName() ?? operation.ReturnType.FullName(); AddRelatedType(returnTypeFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(returnTypeFullName, out SchemaTypeModel referencedSchemaTypeModel) && !referencedSchemaTypeModel.IsSelected) { referencedSchemaTypeModel.IsSelected = true; } } // Check if parameter types of associated bound operations has been selected. IEnumerable <IEdmOperationParameter> parameters = operation.Parameters; foreach (var parameter in parameters) { if (parameter.Type.ToStructuredType() != null || parameter.Type.IsEnum()) { string parameterFullName = parameter.Type.ToStructuredType()?.FullTypeName() ?? parameter.Type.FullName(); AddRelatedType(parameterFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(parameterFullName, out SchemaTypeModel model) && !model.IsSelected) { model.IsSelected = true; } } } } } } else if (!schemaTypeModel.IsSelected) { // automatically deselect related types for deselected type if (RelatedTypes.TryGetValue(schemaTypeModel.Name, out ICollection <string> relatedTypes)) { foreach (var relatedType in relatedTypes) { if (SchemaTypeModelMap.TryGetValue(relatedType, out SchemaTypeModel relatedSchemaTypeModel) && relatedSchemaTypeModel.IsSelected) { relatedSchemaTypeModel.IsSelected = false; } } } } }; toLoad.Add(schemaTypeModel); schemaTypeModel.IsSelected = true; SchemaTypeModelMap.Add(schemaType.FullTypeName(), schemaTypeModel); } SchemaTypes = toLoad.OrderBy(o => o.Name).ToList(); }
public void TestGetSchemaTypesWithNullModel() { var schemaTypes = EdmHelper.GetSchemaTypes(null); schemaTypes.Should().BeEmpty(); }
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(); }
public void TestGetEdmFromFile() { var model = EdmHelper.GetEdmModelFromFile(MetadataPath); Assert.IsNotNull(model); }
/// <summary> /// Creates a list of types that needs to be loaded on the UI. /// Initially all the types are loaded /// </summary> /// <param name="schemaTypes">A list of schema types that need to be laoded.</param> /// <param name="boundOperations">The associated bound operations.</param> public void LoadSchemaTypes( IEnumerable <IEdmSchemaType> schemaTypes, IDictionary <IEdmType, List <IEdmOperation> > boundOperations) { var toLoad = new List <SchemaTypeModel>(); foreach (var type in schemaTypes) { if (!SchemaTypeModelMap.ContainsKey(type.FullName()) || SchemaTypeModelMap.Count != schemaTypes.Count()) { SchemaTypes = toLoad; SchemaTypeModelMap.Clear(); break; } } if (SchemaTypes.Any()) { return; } foreach (var schemaType in schemaTypes) { var schemaTypeModel = new SchemaTypeModel { Name = schemaType.FullTypeName(), ShortName = EdmHelper.GetTypeNameFromFullName(schemaType.FullTypeName()) }; // Create propertyChange handler. // Anytime a property is selected/unslected, the handler ensures // all the related types and operations are selected/unselected schemaTypeModel.PropertyChanged += (s, args) => { if (schemaTypeModel.IsSelected && schemaType is IEdmStructuredType structuredType) { //Check for the base type and automatically select it if not selected already. string baseTypeFullName = structuredType.BaseType?.FullTypeName(); if (baseTypeFullName != null) { AddRelatedType(baseTypeFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(baseTypeFullName, out SchemaTypeModel baseTypeSchemaTypeModel) && !baseTypeSchemaTypeModel.IsSelected) { baseTypeSchemaTypeModel.IsSelected = true; } } // Check the required property types and ensure they are selected as well foreach (var property in structuredType.DeclaredProperties) { IEdmTypeReference propertyType = property.Type.IsCollection() ? property.Type.AsCollection().ElementType() : property.Type; if (propertyType.ToStructuredType() != null || propertyType.IsEnum()) { string propertyTypeName = propertyType.ToStructuredType()?.FullTypeName() ?? propertyType.FullName(); AddRelatedType(propertyTypeName, structuredType.FullTypeName()); bool hasProperty = SchemaTypeModelMap.TryGetValue(propertyTypeName, out SchemaTypeModel propertySchemaTypeModel); if (hasProperty && !propertySchemaTypeModel.IsSelected) { propertySchemaTypeModel.IsSelected = true; } } } // Check for bound operations and ensure related types are also selected. // In this case related types means return types and parameter types. if (boundOperations.TryGetValue(structuredType, out List <IEdmOperation> operations)) { foreach (var operation in operations) { // Check if return type of associated bound operation has been selected. if (operation.ReturnType != null && (operation.ReturnType.ToStructuredType() != null || operation.ReturnType.IsEnum())) { string returnTypeFullName = operation.ReturnType.ToStructuredType()?.FullTypeName() ?? operation.ReturnType.FullName(); AddRelatedType(returnTypeFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(returnTypeFullName, out SchemaTypeModel referencedSchemaTypeModel) && !referencedSchemaTypeModel.IsSelected) { referencedSchemaTypeModel.IsSelected = true; } } // Check if parameter types of associated bound operations has been selected. IEnumerable <IEdmOperationParameter> parameters = operation.Parameters; foreach (var parameter in parameters) { if (parameter.Type.ToStructuredType() != null || parameter.Type.IsEnum()) { string parameterFullName = parameter.Type.ToStructuredType()?.FullTypeName() ?? parameter.Type.FullName(); AddRelatedType(parameterFullName, structuredType.FullTypeName()); if (SchemaTypeModelMap.TryGetValue(parameterFullName, out SchemaTypeModel model) && !model.IsSelected) { model.IsSelected = true; } } } } } } else if (!schemaTypeModel.IsSelected) { // automatically deselect related types for deselected type if (RelatedTypes.TryGetValue(schemaTypeModel.Name, out ICollection <string> relatedTypes)) { foreach (var relatedType in relatedTypes) { if (SchemaTypeModelMap.TryGetValue(relatedType, out SchemaTypeModel relatedSchemaTypeModel) && relatedSchemaTypeModel.IsSelected) { relatedSchemaTypeModel.IsSelected = false; } } } // deselect all related bound operations foreach (var boundOperation in schemaTypeModel.BoundOperations) { boundOperation.IsSelected = false; } } if (this.View is SchemaTypes view) { view.SelectedSchemaTypesCount.Text = SchemaTypes.Count(x => x.IsSelected).ToString(CultureInfo.InvariantCulture); } }; // load bound operations that require the schema type var boundOperationsToLoad = boundOperations .Where(x => x.Key == schemaType || x.Key.AsElementType() == schemaType) .ToDictionary(x => x.Key, x => x.Value); LoadBoundOperations(schemaTypeModel, boundOperationsToLoad, ExcludedSchemaTypeNames.ToList(), SchemaTypeModelMap); toLoad.Add(schemaTypeModel); schemaTypeModel.IsSelected = true; SchemaTypeModelMap.Add(schemaType.FullTypeName(), schemaTypeModel); } SchemaTypes = toLoad.OrderBy(o => o.Name).ToList(); _schemaTypesCount = SchemaTypes.Count(); _boundOperationsCount = SchemaTypes.Where(x => x?.BoundOperations?.Any() == true) .SelectMany(x => x.BoundOperations).Count(); }