/// <summary> /// Adds the given client-query to the list of queries /// </summary> /// <param parameterName="parameterExternalName">The parameterName to show to the end user</param> /// <param parameterName="table">The table descriptor that the query belongs to</param> /// <param parameterName="predicate">The predicate that defines the filter for the query</param> /// <param parameterName="parameterDefinitions">The parameter definitions defining the functionParameters to be used</param> private LiteQueryViewModel NewUserQuery(string externalName, FeatureTableDescriptor table, System.Linq.Expressions.Expression predicate, ParameterDefinitionCollection parameterDefinitions, bool addToQueries) { LiteQueryViewModel clientQuery = null; if (IsAuthenticated && Queries != null) { var predicateText = predicate != null?predicate.GeoLinqText(useInternalParameterNames : true) : null; var queryDefinition = new FeatureCollectionQueryDefinition() { ServiceProviderGroup = table.ServiceProviderGroup, Context = ServiceProviderDatumContext.User, Name = externalName.ToLower(), ExternalName = externalName, TableDescriptor = table, ParameterDefinitions = parameterDefinitions }; clientQuery = new LiteQueryViewModel(this.Messenger, queryDefinition, predicateText); if (addToQueries) { Queries.Add(clientQuery); SaveUserQueries(); } } return(clientQuery); }
/// <summary> /// Converts the storage model to a QueryViewModel that can be used within Lite. /// </summary> /// <param name="messenger">The messenger the ViewModel should be connected to</param> /// <param name="sources">The sources available for resolution of the Table</param> /// <returns>A LiteQueryViewModel</returns> public async Task <LiteQueryViewModel> ToUserQueryViewModel(Messenger messenger, ServiceProviderDatumCollection <FeatureSourceDescriptor> sources) { LiteQueryViewModel result = null; if (TransactionContext.ActiveContext.ProjectName == this.ProjectName) { var serviceProvider = ServiceProviderManager.Instance.ServiceProvider(ProviderName); if (serviceProvider != null) { var group = ProviderGroup.ToServiceProviderGroup(serviceProvider); var source = sources.Find(group); if (source != null) { var table = source.TableDescriptors[TableName]; // Check the table, since it can have disappeared in the mean-time if (table != null) { // Ensure we have a table with fields and all await table.EvaluateAsync(); var parameterDefinitions = this.ParameterDefinitions.ToParameterDefinitionCollection(serviceProvider); var queryDefinition = new FeatureCollectionQueryDefinition() { ServiceProviderGroup = table.ServiceProviderGroup, Context = ServiceProviderDatumContext.User, Name = Name, ExternalName = ExternalName, TableDescriptor = table, ParameterDefinitions = parameterDefinitions }; result = new LiteQueryViewModel(messenger, queryDefinition, PredicateText); } } } } return(result); }
/// <summary> /// The query view model constructor /// </summary> internal LiteQueryViewModel(Messenger messenger, FeatureCollectionQueryDefinition query, string predicateText = null) { Resources = new Lite.Resources.Localization.ApplicationResources(); // Set the query this.Query = query; this.Predicate = predicateText; // The initial functionParameters are determined by the user definitions available in the parameter definitions this.Parameters = new ParameterValuesViewModel(query.ParameterDefinitions); // Reports this.Reports = new ReportsViewModel(messenger) { AutoGetAvailableDefinitions = true }; this.Reports.PropertyChanged += Reports_PropertyChanged; // Exports this.Exports = new ExportsViewModel(messenger) { AutoGetAvailableDefinitions = true, AllowCoordinateSystemSettings = LiteClientSettingsViewModel.Instance.ExportAllowSetCS, AllowUnitSettings = LiteClientSettingsViewModel.Instance.ExportAllowSetUnits, DefinitionsFilter = definition => LiteClientSettingsViewModel.Instance.ExportAllowedTypes.Contains(definition.ExportType), ExportCoordinateSystemsFilter = cs => cs.SRId != 3785 }; // Get property changes this.Exports.PropertyChanged += Exports_PropertyChanged; // Set up the commands for running the query SetupCommands(); this.PathGeometry = Application.Current.Resources[PathGeometryKey()] as string; CalculateRecipe(); }