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);
        }
Esempio n. 2
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;
                }
            }
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
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
            }
        }
Esempio n. 5
0
        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.", string.Format(CultureInfo.InvariantCulture, "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.", string.Format(CultureInfo.InvariantCulture, "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.", string.Format(CultureInfo.InvariantCulture, "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.ExcludedBoundOperations            = microsoftConnectedServiceData.ExtendedData?.ExcludedBoundOperations ?? new List <string>();
                this.UserSettings.ExcludedSchemaTypes                = microsoftConnectedServiceData.ExtendedData?.ExcludedSchemaTypes ?? 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 and bound operations from metadata for excluding ExcludedOperationImports and ExcludedBoundOperations
                try
                {
                    ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath = ServiceWizard.ConfigODataEndpointViewModel.GetMetadata(out var version);
                    ServiceWizard.ConfigODataEndpointViewModel.EdmxVersion      = version;
                    if (version == Constants.EdmxVersion4)
                    {
                        Edm.IEdmModel model = EdmHelper.GetEdmModelFromFile(ServiceWizard.ConfigODataEndpointViewModel.MetadataTempPath);

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

                        IEnumerable <Edm.IEdmOperationImport> operations = EdmHelper.GetOperationImports(model);
                        ServiceWizard.OperationImportsViewModel.LoadOperationImports(operations, new HashSet <string>(), new Dictionary <string, SchemaTypeModel>());
                        ServiceWizard.ProcessedEndpointForOperationImports = this.UserSettings.Endpoint;
                        ServiceWizard.OperationImportsViewModel.LoadFromUserSettings();

                        //IDictionary<Edm.IEdmType, List<Edm.IEdmOperation>> allBoundOperations = EdmHelper.GetBoundOperations(model);
                        //ServiceWizard.BoundOperationsViewModel.LoadBoundOperations(allBoundOperations,
                        //    new HashSet<string>(), new Dictionary<string, SchemaTypeModel>());
                        //ServiceWizard.ProcessedEndpointForBoundOperations = this.UserSettings.Endpoint;
                        //ServiceWizard.BoundOperationsViewModel.LoadFromUserSettings();
                    }
                }
                catch
                {
                    // ignored
                }
            }
        }
        public void TestGetBoundOperationsWithNullModel()
        {
            var boundOperations = EdmHelper.GetBoundOperations(null);

            boundOperations.Should().BeEmpty();
        }