public override async Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            switch (command)
            {
            case CheckIfInstalledDto checkIfInstalledDto:
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (checkIfInstalledDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.IsInstalled(checkIfInstalledDto.ManifestFilePath, mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            default:
            {
                throw new NotSupportedException();
            }
            }
        }
Exemplo n.º 2
0
        // ReSharper disable once MemberCanBeMadeStatic.Global
        public async Task <TOutput> Get <TOutput>(IProxyObjectWithOutput <TOutput> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            // ReSharper disable once StringLiteralTypo
            using (var pipeClient = await this.ipcManager.GetCommunicationChannel(cancellationToken).ConfigureAwait(false))
            {
                await pipeClient.ConnectAsync(4000, cancellationToken).ConfigureAwait(false);

                var stream = pipeClient;

                var binaryProcessor = new BinaryStreamProcessor(stream);
                await binaryProcessor.Write((IProxyObject)command, cancellationToken).ConfigureAwait(false);

                await stream.FlushAsync(cancellationToken).ConfigureAwait(false);

                while (true)
                {
                    var response = (ResponseType)await binaryProcessor.ReadInt32(cancellationToken).ConfigureAwait(false);

                    switch (response)
                    {
                    case ResponseType.Exception:
                        var msg = await binaryProcessor.ReadString(cancellationToken).ConfigureAwait(false);

                        // ReSharper disable once UnusedVariable
                        var stack = await binaryProcessor.ReadString(cancellationToken).ConfigureAwait(false);

                        await stream.FlushAsync(cancellationToken).ConfigureAwait(false);

                        throw new ForwardedException(msg);

                    case ResponseType.Result:
                        var deserializedObject = await binaryProcessor.Read <TOutput>(cancellationToken).ConfigureAwait(false);

                        if (progress != null)
                        {
                            progress.Report(new ProgressData(100, null));
                        }

                        return(deserializedObject);

                    case ResponseType.Progress:
                        var deserializedProgress = await binaryProcessor.Read <ProgressData>(cancellationToken).ConfigureAwait(false);

                        if (progress != null)
                        {
                            progress.Report(deserializedProgress);
                        }

                        break;

                    default:
                        throw new NotSupportedException();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override async Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is GetLogsDto getLogsDto)
            {
                object proxiedObject = await this.SelfElevationAwareObject.GetLogs(getLogsDto.MaxCount, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            throw new NotSupportedException();
        }
        public override async Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is GetRegistryMountStateDto getRegistryMountStateDto)
            {
                object proxiedResult = await this.SelfElevationAwareObject.GetRegistryMountState(getRegistryMountStateDto.InstallLocation, getRegistryMountStateDto.PackageName, cancellationToken).ConfigureAwait(false);

                return((TCommandResult)proxiedResult);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 5
0
        public override async Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is AddDto addDto)
            {
                object proxiedResult = await this.SelfElevationAwareObject.Add(addDto.DrivePath, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedResult);
            }

            if (command is GetAllDto)
            {
                object proxiedResult = await this.SelfElevationAwareObject.GetAll(cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedResult);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 6
0
        public override async Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
        {
            if (command is GetByManifestPathDto getByManifestPathDto)
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (getByManifestPathDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.GetByIdentity(getByManifestPathDto.Source, mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            if (command is GetByIdentityDto getByIdentityDto)
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (getByIdentityDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.GetByIdentity(getByIdentityDto.Source, mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            if (command is CheckIfInstalledDto checkIfInstalledDto)
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (checkIfInstalledDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.IsInstalled(checkIfInstalledDto.ManifestFilePath, mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            if (command is GetInstalledPackagesDto getInstalledPackagesDto)
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (getInstalledPackagesDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.GetInstalledPackages(mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            if (command is GetModificationPackagesDto getModificationPackagesDto)
            {
                // todo: replace by simple enum
                PackageFindMode mode;
                switch (getModificationPackagesDto.Context)
                {
                case PackageContext.CurrentUser:
                    mode = PackageFindMode.CurrentUser;
                    break;

                case PackageContext.AllUsers:
                    mode = PackageFindMode.AllUsers;
                    break;

                default:
                    mode = PackageFindMode.Auto;
                    break;
                }

                object proxiedObject = await this.SelfElevationAwareObject.GetModificationPackages(getModificationPackagesDto.FullPackageName, mode, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            if (command is GetUsersForPackageDto getUsersForPackageDto)
            {
                object proxiedObject = await this.SelfElevationAwareObject.GetUsersForPackage(getUsersForPackageDto.Source, cancellationToken, progress).ConfigureAwait(false);

                return((TCommandResult)proxiedObject);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 7
0
 public override Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
 {
     throw new InvalidOperationException("This command does not return anything.");
 }
 public abstract Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null);
Exemplo n.º 9
0
 public override Task <TCommandResult> Get <TCommandResult>(IProxyObjectWithOutput <TCommandResult> command, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = null)
 {
     throw new NotSupportedException();
 }