Пример #1
0
        /// <summary>
        /// Returns a flag if there are any editable collections
        /// </summary>
        private async Task <bool> HasEditableCollections()
        {
            bool hasEditable = false;

            if (IsAuthenticated)
            {
                var service = ServiceLocator.Current.GetInstance <ICollectionService>();

                // Get all the bare descriptors
                var request = new GetDDRequest {
                    IncludeFields = false, GroupTypes = new ServiceProviderGroupType[] { ServiceProviderGroupType.Business }
                };

                var sourceDescriptors = await service.GetDDAsync(request);

                if (sourceDescriptors != null && sourceDescriptors.Count == 1)
                {
                    var businessSourceDescriptor = sourceDescriptors[0];
                    foreach (var tableDescriptor in businessSourceDescriptor.TableDescriptors)
                    {
                        var editProps = tableDescriptor.EditabilityProperties;

                        if (editProps.AllowInsert || editProps.AllowUpdate || editProps.AllowDelete)
                        {
                            hasEditable = true;
                            break;
                        }
                    }
                }
            }

            return(hasEditable);
        }
        /// <summary>
        /// Gets the query definitions as stored in the Isolated Storage
        /// </summary>
        private async Task <IList <LiteQueryViewModel> > GetUserQueries()
        {
            var queryViewModels = new List <LiteQueryViewModel>();

            try
            {
                var request = new GetDDRequest()
                {
                    GroupTypes = new ServiceProviderGroupType[] { ServiceProviderGroupType.Business, ServiceProviderGroupType.Analysis }
                };

                var allSources = await ServiceLocator.Current.GetInstance <ICollectionService>().GetDDAsync(request);

                var isolatedStorageQueries = LiteIsolatedStorageManager.Instance.UserQueries;

                if (isolatedStorageQueries != null)
                {
                    foreach (var isolatedStorageQuery in isolatedStorageQueries)
                    {
                        var userQuery = await isolatedStorageQuery.ToUserQueryViewModel(this.Messenger, allSources);

                        if (userQuery != null)
                        {
                            queryViewModels.Add(userQuery);
                        }
                    }
                }
            }
            catch
            {
                // The stored queries could not be matched with our model
                // We could choose to clear the stored client queries
            }

            return(queryViewModels);
        }
Пример #3
0
        /// <summary>
        /// Setup the insertable items
        /// </summary>
        private async void SetupItems()
        {
            var service = ServiceLocator.Current.GetInstance <ICollectionService>();

            // Get all the bare descriptors
            var request = new GetDDRequest {
                IncludeFields = false, GroupTypes = new ServiceProviderGroupType[] { ServiceProviderGroupType.Business }
            };
            var sourceDescriptors = await service.GetDDAsync(request);

            var items = CreateItemCollection();

            foreach (var descriptor in sourceDescriptors)
            {
                // Only process updatable and allowed sources
                if (descriptor.EditabilityProperties.AllowUpdate)
                {
                    foreach (var tableDescriptor in descriptor.TableDescriptors)
                    {
                        var allowed   = LiteClientSettingsViewModel.Instance.IsGeoNoteAllowed(tableDescriptor.ExternalName);
                        var editProps = tableDescriptor.EditabilityProperties;

                        if (allowed && editProps.AllowInsert && AllowCategory(editProps.Category))
                        {
                            if (this.DoInsertAttached && DoInsertUnattached)
                            {
                                bool isAttachRequired = editProps.IsAttachRequired;
                                bool isAttachPossible = editProps.IsAttachPossible;

                                // Do insert attached and attach is possible
                                items.Add(new FeatureInsertItemViewModel(tableDescriptor, isAttachRequired, isAttachPossible));
                            }
                            else
                            {
                                if (this.DoInsertAttached)
                                {
                                    // Insert attached
                                    if (editProps.IsAttachPossible)
                                    {
                                        // Do insert attached and attach is possible
                                        items.Add(new FeatureInsertItemViewModel(tableDescriptor, true, true));
                                    }
                                }
                                else if (this.DoInsertUnattached)
                                {
                                    // Insert unattached
                                    if (!editProps.IsAttachRequired)
                                    {
                                        // Do insert attached and attach is possible
                                        items.Add(new FeatureInsertItemViewModel(tableDescriptor, false, false));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Set the items
            this.Items = items;
        }