Пример #1
0
 public CommandLineOptionsValidator(CommandLineOptions commandLineOptions,
                                    RuntimeTokenParams runtimeTokenParams, VolumeOwnersStore volumeOwnersStore)
 {
     _commandLineOptions = commandLineOptions;
     _runtimeTokenParams = runtimeTokenParams;
     _volumeOwnersStore  = volumeOwnersStore;
 }
Пример #2
0
 public LogMessageBuilder(RuntimeTokenParams runtimeTokenParams,
                          VolumeOwnersStore volumeOwnersStore,
                          VolumeAttributesStore volumeAttributesStore)
 {
     _runtimeTokenParams = runtimeTokenParams ??
                           throw new ArgumentNullException(nameof(runtimeTokenParams), Resources.TokenParamsNotSet);
     _volumeOwnersStore = volumeOwnersStore ??
                          throw new ArgumentNullException(nameof(volumeOwnersStore), Resources.VolumeOwnersStoreNotSet);
     _volumeAttributesStore = volumeAttributesStore ??
                              throw new ArgumentNullException(nameof(volumeAttributesStore), Resources.VolumeAttributesStoreNotSet);
 }
Пример #3
0
        public CommandHandlerBuilder(ILogger <RtAdmin> logger, RuntimeTokenParams runtimeTokenParams,
                                     PinsStorage pinsStorage, VolumeOwnersStore volumeOwnersStore, VolumeAttributesStore volumeAttributesStore,
                                     LogMessageBuilder logMessageBuilder)
        {
            _logger                = logger;
            _runtimeTokenParams    = runtimeTokenParams;
            _pinsStorage           = pinsStorage;
            _volumeOwnersStore     = volumeOwnersStore;
            _volumeAttributesStore = volumeAttributesStore;
            _logMessageBuilder     = logMessageBuilder;

            _commands      = new ConcurrentQueue <Action>();
            _prerequisites = new ConcurrentQueue <Action>();
        }
        public static IEnumerable <ChangeVolumeAttributesParams> Create(
            VolumeAttributesStore volumeAttributesStore,
            IEnumerable <string> changeParams,
            IEnumerable <VolumeInfoExtended> volumeInfos,
            RuntimeTokenParams runtimeTokenParams)
        {
            var changeParamsList = changeParams.ToList();
            var volumeInfosList  = volumeInfos.ToList();

            if (changeParamsList.Count % _changeParamsCount != 0)
            {
                throw new ArgumentException(Resources.ChangeVolumeAttributesInvalidCommandParamsCount);
            }

            for (var i = 0; i < changeParamsList.Count; i += _changeParamsCount)
            {
                var volumeParams = changeParamsList.Skip(i).Take(_changeParamsCount).ToList();

                if (!(uint.TryParse(volumeParams[0], out var volumeId)))
                {
                    throw new ArgumentException(Resources.VolumeInfoInvalidVolumeId);
                }

                if (!volumeAttributesStore.TryGetAccessMode(volumeParams[1], out var accessMode))
                {
                    throw new ArgumentException(Resources.FormatDriveInvalidAccessMode);
                }

                if (!volumeAttributesStore.TryGetPermanentState(volumeParams[2], out var permanent))
                {
                    throw new ArgumentException(Resources.ChangeVolumeAttributesInvalidPermanentState);
                }

                var volumeInfo = volumeInfosList.SingleOrDefault(x => x.VolumeId == volumeId);
                if (volumeInfo == null)
                {
                    throw new ArgumentException(Resources.VolumeInfoInvalidVolumeId);
                }

                string ownerPin;
                switch (volumeInfo.VolumeOwner)
                {
                case CKU.CKU_SO:
                    if (!runtimeTokenParams.OldAdminPin.EnteredByUser)
                    {
                        Console.WriteLine(Resources.DefaultAdminPinWillBeUsed);
                    }

                    ownerPin = runtimeTokenParams.OldAdminPin.Value;
                    break;

                case CKU.CKU_USER:
                    if (!runtimeTokenParams.OldUserPin.EnteredByUser)
                    {
                        Console.WriteLine(Resources.DefaultUserPinWillBeUsed);
                    }

                    ownerPin = runtimeTokenParams.OldUserPin.Value;
                    break;

                default:
                    if (runtimeTokenParams.LocalUserPins == null)
                    {
                        throw new InvalidOperationException(Resources.ChangeVolumeAttributesNeedSetLocalPin);
                    }
                    if (!(runtimeTokenParams.LocalUserPins.TryGetValue((uint)volumeInfo.VolumeOwner, out ownerPin)))
                    {
                        throw new InvalidOperationException(Resources.NewLocalPinInvalidOwnerId);
                    }

                    break;
                }

                yield return(new ChangeVolumeAttributesParams
                {
                    VolumeId = volumeId,
                    AccessMode = accessMode,
                    VolumeOwner = volumeInfo.VolumeOwner,
                    OwnerPin = ownerPin,
                    Permanent = permanent
                });
            }
        }