public AccountEditorViewModel(CosmosAccount?account, IClipboardService clipboardService)
        {
            _name         = account?.Name ?? string.Empty;
            _endpoint     = account?.Endpoint ?? string.Empty;
            _key          = account?.Key ?? string.Empty;
            _isServerless = account?.IsServerless ?? false;
            _folder       = account?.Folder ?? string.Empty;

            if (account is null && clipboardService.TryGetText(out string copiedText))
            {
                TrySetValuesFromConnectionString(copiedText);
            }

            Title = account is null
                ? "Add Cosmos DB account"
                : "Edit Cosmos DB account";

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

            Validator = new ViewModelValidator <AccountEditorViewModel>(this);
            Validator.AddValidator(vm => vm.Name, ValidateName);
            Validator.AddValidator(vm => vm.Endpoint, ValidateEndpoint);
            Validator.AddValidator(vm => vm.Key, ValidateKey);
        }
예제 #2
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));
        }
예제 #4
0
        public QuerySheetViewModel(
            QuerySheet querySheet,
            string?path,
            IContainerContext?containerContext,
            IViewModelFactory viewModelFactory,
            IDialogService dialogService,
            IMessenger messenger,
            IQueryPersistenceService queryPersistenceService)
        {
            _containerContext        = containerContext;
            _queryPersistenceService = queryPersistenceService;
            _viewModelFactory        = viewModelFactory;
            _dialogService           = dialogService;
            _messenger = messenger;
            _filePath  = path;
            _title     = string.IsNullOrEmpty(path)
                ? "Untitled " + (++UntitledCounter)
                : Path.GetFileNameWithoutExtension(path);
            _text   = querySheet.Text;
            _result = _viewModelFactory.CreateNotRunQueryResult();

            _partitionKey   = querySheet.PartitionKey;
            PartitionKeyMRU = new ObservableCollection <string>();
            foreach (var mru in querySheet.PartitionKeyMRU)
            {
                PartitionKeyMRU.Add(mru);
            }

            Parameters = new ParametersViewModel <QueryParameterViewModel>();
            foreach (var p in querySheet.Parameters)
            {
                Parameters.AddParameter(CreateParameter(p));
                ShowParameters = true;
            }

            Parameters.AddPlaceholder();
            Parameters.Changed += OnParametersChanged;

            Errors = new ViewModelValidator <QuerySheetViewModel>(this);
            Errors.AddValidator(
                vm => vm.PartitionKey,
                value => string.IsNullOrEmpty(value) || JsonHelper.TryParseJsonValue(value, out _)
                    ? string.Empty
                    : "Invalid partition key value");

            _messenger.Subscribe(this).To <ExplorerSelectedContainerChangedMessage>(
                (vm, message) => vm.OnExplorerSelectedContainerChanged(message));
        }
 public ParameterViewModelBase()
 {
     MRU    = new ObservableCollection <string>();
     Errors = new ViewModelValidator <TViewModel>((TViewModel)this);
     Errors.AddValidator(vm => vm.RawValue, ValidateValue);
 }