Exemplo n.º 1
0
        public ContainerEditorViewModel(CosmosContainer?container, int?throughput, bool databaseHasProvisionedThroughput, bool isServerlessAccount)
        {
            _id                  = container?.Id ?? string.Empty;
            _eTag                = container?.ETag;
            _throughput          = isServerlessAccount ? 0 : throughput ?? 400;
            _provisionThroughput = throughput.HasValue;
            _partitionKeyPath    = container?.PartitionKeyPath ?? string.Empty;
            _largePartitionKey   = container?.LargePartitionKey ?? false;
            IsServerlessAccount  = isServerlessAccount;
            if (container?.DefaultTTL is int defaultTTL)
            {
                _enableTTL     = true;
                _hasDefaultTTL = defaultTTL >= 0;
                _defaultTTL    = Math.Max(defaultTTL, 1);
            }
            else
            {
                _enableTTL     = false;
                _hasDefaultTTL = false;
                _defaultTTL    = 1;
            }

            IsNew = container is null;

            if (isServerlessAccount)
            {
                _provisionThroughput         = false;
                CanChangeProvisionThroughput = false;
            }
            else if (databaseHasProvisionedThroughput)
            {
                CanChangeProvisionThroughput = IsNew;
            }
            else
            {
                _provisionThroughput         = true;
                CanChangeProvisionThroughput = false;
            }

            Title = IsNew
                ? "Add container"
                : "Edit container";

            _saveCommand = new DelegateCommand(Save, CanSave);
            AddOkButton(button => button.Command = _saveCommand);
            AddCancelButton();

            Validator = new ViewModelValidator <ContainerEditorViewModel>(this);
            Validator.AddValidator(vm => vm.Id, id => CosmosHelper.ValidateId(id, "container id"));
            Validator.AddValidator(vm => vm.Throughput, throughput => CosmosHelper.ValidateThroughput(throughput, ProvisionThroughput));
            Validator.AddValidator(vm => vm.DefaultTTL, defaultTTL => CosmosHelper.ValidateDefaultTTL(defaultTTL, EnableTTL && HasDefaultTTL));
            Validator.AddValidator(vm => vm.PartitionKeyPath, CosmosHelper.ValidatePartitionKeyPath);
        }
        public DatabaseEditorViewModel(CosmosDatabase?database, int?throughput, bool isServerlessAccount)
        {
            _id                    = database?.Id ?? string.Empty;
            _eTag                  = database?.ETag;
            _throughput            = isServerlessAccount ? 0 : throughput ?? 400;
            _provisionThroughput   = throughput.HasValue;
            IsNew                  = database is null;
            CanProvisionThroughput = IsNew && !isServerlessAccount;
            IsServerlessAccount    = isServerlessAccount;

            Title = IsNew
                ? "Add database"
                : "Edit database";

            _saveCommand = new DelegateCommand(Save, CanSave);
            AddOkButton(button => button.Command = _saveCommand);
            AddCancelButton();

            Validator = new ViewModelValidator <DatabaseEditorViewModel>(this);
            Validator.AddValidator(vm => vm.Id, id => CosmosHelper.ValidateId(id, "container id"));
            Validator.AddValidator(vm => vm.Throughput, throughput => CosmosHelper.ValidateThroughput(throughput, ProvisionThroughput));
        }