Пример #1
0
        private WorkspaceStack(
            string name,
            Workspace workspace,
            WorkspaceStackInitMode mode,
            CancellationToken cancellationToken)
        {
            this.Name      = name;
            this.Workspace = workspace;
            this.State     = new WorkspaceStackState(this);

            this._readyTask = mode switch
            {
                WorkspaceStackInitMode.Create => workspace.CreateStackAsync(name, cancellationToken),
                WorkspaceStackInitMode.Select => workspace.SelectStackAsync(name, cancellationToken),
                WorkspaceStackInitMode.CreateOrSelect => Task.Run(async() =>
                {
                    try
                    {
                        await workspace.CreateStackAsync(name, cancellationToken).ConfigureAwait(false);
                    }
                    catch (StackAlreadyExistsException)
                    {
                        await workspace.SelectStackAsync(name, cancellationToken).ConfigureAwait(false);
                    }
                }),
                _ => throw new InvalidOperationException($"Unexpected Stack creation mode: {mode}")
            };
        }
Пример #2
0
        private WorkspaceStack(
            string name,
            Workspace workspace,
            WorkspaceStackInitMode mode,
            CancellationToken cancellationToken)
        {
            this.Name      = name;
            this.Workspace = workspace;

            switch (mode)
            {
            case WorkspaceStackInitMode.Create:
                this._readyTask = workspace.CreateStackAsync(name, cancellationToken);
                break;

            case WorkspaceStackInitMode.Select:
                this._readyTask = workspace.SelectStackAsync(name, cancellationToken);
                break;

            case WorkspaceStackInitMode.CreateOrSelect:
                this._readyTask = Task.Run(async() =>
                {
                    try
                    {
                        await workspace.CreateStackAsync(name, cancellationToken).ConfigureAwait(false);
                    }
                    catch (StackAlreadyExistsException)
                    {
                        await workspace.SelectStackAsync(name, cancellationToken).ConfigureAwait(false);
                    }
                });
                break;

            default:
                throw new InvalidOperationException($"Unexpected Stack creation mode: {mode}");
            }
        }